The following program is based on the example in the v8 Getting Started page. I have made three changes to demonstrate a problem I am encountering:
- I create an empty array put it into the global context.
- The script being run references the zeroth element in the array, which should return undefined.
- I run the compiled script twice.
The first run works fine. The second fails: v8 calls V8_Fatal() in Deoptimizer::DoComputeCompiledStubFrame() because descriptor->register_param_count_ == -1.
Am I doing something wrong here? How can I fix it?
Isolate* isolate = Isolate::New();
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);
Local<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
Local<Array> a = Array::New(isolate);
context->Global()->Set(String::NewFromUtf8(isolate, "a"), a);
Local<String> source = String::NewFromUtf8(isolate, "a[0];");
Local<Script> script = Script::Compile(source);
Local<Value> result = script->Run();
Local<Value> result2 = script->Run();
return 0;
NOTES:
- This is the entire body of main().
- 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.
- 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.
- I have tried compiling the script as an UnboundScript and then binding it for each execution, but the result is the same.
- I have reported this as a v8 issue, but nobody has responded so I'm hoping that the StackOverflow community can help.
- 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.
v8_nosnapshot.lib
rather thanv8_snapshot.lib
it all seems to do the right thing (including deoptimisation). Do you need snapshots? – Fadein