Status: New
Owner: ----
New issue 3400 by [email protected]: Cannot TerminateExecution() from
an interceptor function (crash)
http://code.google.com/p/v8/issues/detail?id=3400
I'd like to run a script, and terminate it from C++ code, by the decision
of a callback function (interceptor). I tried using TerminateExectuion(),
but the program crashes.
Here is a small sample. I assign values to the "specific" object using
JavaScript. Whenever its "alfa" field is set to "666", I'd like the script
to terminate.
#include <v8.h>
#include <stdio.h>
using namespace v8;
void SetAlfa(Local<String> property, Local<Value> value, const
PropertyCallbackInfo<void>& info)
{
String::Utf8Value property_str(property);
String::Utf8Value value_str(value);
printf("SetAlfa: about to set %s=%s\n", *property_str, *value_str);
Handle<Value> show_stopper =
String::NewFromUtf8(info.GetIsolate(),"666");
if (value->Equals(show_stopper))
{
printf("SetAlfa: STOPPING!\n");
V8::TerminateExecution(info.GetIsolate());
}
}
void RunIt(Isolate *isolate, const char *script_text)
{
printf("RunIt: about to run \"%s\"\n", script_text);
Handle<String> source = String::NewFromUtf8(isolate,script_text);
Handle<Script> script = Script::Compile(source);
Handle<Value> result = script->Run();
String::Utf8Value ascii(result);
printf("RunIt: returned \"%s\"\n", *ascii);
}
int main(int argc, char* argv[])
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope handle_scope(isolate);
Handle<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
Handle<String> alfa_str = String::NewFromUtf8(isolate,"alfa");
Handle<String> specific_str = String::NewFromUtf8(isolate,"specific");
Handle<Object> specific_obj = Object::New(isolate);
specific_obj->SetAccessor(alfa_str, NULL, SetAlfa);
context->Global()->Set(specific_str, specific_obj);
TryCatch();
RunIt(isolate,"specific.alfa=123");
RunIt(isolate,"specific.alfa=666; specific.alfa=999");
return 0;
}
The output I get is:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
RunIt: about to run "specific.alfa=123"
SetAlfa: about to set alfa=123
RunIt: returned "123"
RunIt: about to run "specific.alfa=666; specific.alfa=999"
SetAlfa: about to set alfa=666
SetAlfa: STOPPING!
SetAlfa: about to set alfa=(null)
#
# Fatal error in ../src/api.cc, line 2899
# CHECK(!(isolate)->external_caught_exception()) failed
#
==== C stack trace ===============================
1: V8_Fatal
2: v8::Value::Equals(v8::Handle<v8::Value>) const
3: SetAlfa(v8::Local<v8::String>, v8::Local<v8::Value>,
v8::PropertyCallbackInfo<void> const&)
4: v8::internal::PropertyCallbackArguments::Call(void
(*)(v8::Local<v8::String>, v8::Local<v8::Value>,
v8::PropertyCallbackInfo<void> const&), v8::Local<v8::String>,
v8::Local<v8::Value>)
5:
v8::internal::JSObject::SetPropertyWithCallback(v8::internal::Handle<v8::internal::JSObject>,
v8::internal::Handle<v8::internal::Object>,
v8::internal::Handle<v8::internal::Name>,
v8::internal::Handle<v8::internal::Object>,
v8::internal::Handle<v8::internal::JSObject>, v8::internal::StrictModeFlag)
6:
v8::internal::JSObject::SetPropertyForResult(v8::internal::Handle<v8::internal::JSObject>,
v8::internal::LookupResult*, v8::internal::Handle<v8::internal::Name>,
v8::internal::Handle<v8::internal::Object>, PropertyAttributes,
v8::internal::StrictModeFlag, v8::internal::JSReceiver::StoreFromKeyed)
7:
v8::internal::JSReceiver::SetProperty(v8::internal::Handle<v8::internal::JSReceiver>,
v8::internal::LookupResult*, v8::internal::Handle<v8::internal::Name>,
v8::internal::Handle<v8::internal::Object>, PropertyAttributes,
v8::internal::StrictModeFlag, v8::internal::JSReceiver::StoreFromKeyed)
8:
v8::internal::JSReceiver::SetProperty(v8::internal::Handle<v8::internal::JSReceiver>,
v8::internal::Handle<v8::internal::Name>,
v8::internal::Handle<v8::internal::Object>, PropertyAttributes,
v8::internal::StrictModeFlag, v8::internal::JSReceiver::StoreFromKeyed)
9:
v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>,
v8::internal::Handle<v8::internal::String>,
v8::internal::Handle<v8::internal::Object>,
v8::internal::JSReceiver::StoreFromKeyed)
10: ??
11: v8::internal::StoreIC_Miss(int, v8::internal::Object**,
v8::internal::Isolate*)
12: ??
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Is there a different way to accomplish the mid-run termination?
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.