title: Right way to run the same code twice in v8 (array out-of-bounds fails on second run - deoptimizer)
body: <p>The following program is based on the example in the v8 <a href="https://developers.google.com/v8/get_started" rel="noreferrer">Getting Started page</a>.  I have made three changes to demonstrate a problem I am encountering:</p>
  
  <ul>
  <li>I create an empty array put it into the global context.</li>
  <li>The script being run references the zeroth element in the array, which should return undefined.</li>
  <li>I run the compiled script twice.</li>
  </ul>
  
  <p>The first run works fine.  The second fails: v8 calls V8_Fatal() in Deoptimizer::DoComputeCompiledStubFrame() because descriptor->register_param_count_ == -1.</p>
  
  <p>Am I doing something wrong here?  How can I fix it?</p>
  
  <pre><code>Isolate* isolate = Isolate::New();
  Isolate::Scope isolate_scope(isolate);
  HandleScope handle_scope(isolate);
  Local&lt;Context&gt; context = Context::New(isolate);
  Context::Scope context_scope(context);
  Local&lt;Array&gt; a = Array::New(isolate);
  context-&gt;Global()-&gt;Set(String::NewFromUtf8(isolate, "a"), a);
  Local&lt;String&gt; source = String::NewFromUtf8(isolate, "a[0];");
  Local&lt;Script&gt; script = Script::Compile(source);
  Local&lt;Value&gt; result = script-&gt;Run();
  Local&lt;Value&gt; result2 = script-&gt;Run();
  return 0;
  </code></pre>
  
  <p>NOTES:</p>
  
  <ul>
  <li>This is the entire body of main().</li>
  <li>Other fragments of JavaScript code run twice without a problem.  Somehow this relates to the out-of-bound array reference, which is perhaps triggering deoptimization.</li>
  <li>I do not want to recompile the script from scratch each time because I am typically running these scripts thousands of times, and sometimes millions of times.</li>
  <li>I have tried compiling the script as an UnboundScript and then binding it for each execution, but the result is the same.</li>
  <li>I have reported this as a <a href="http://code.google.com/p/v8/issues/detail?id=3332" rel="noreferrer">v8 issue</a>, but nobody has responded so I'm hoping that the StackOverflow community can help.</li>
  <li>I am seeing this on VS2012 Update 4, but I also see it on VS2008, and in both x64 and x86 and in both Debug and Release builds.</li>
  </ul>