diff --git a/tests/fatal_error_v8function.phpt b/tests/fatal_error_v8function.phpt new file mode 100644 index 0000000..5693982 --- /dev/null +++ b/tests/fatal_error_v8function.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test V8Function() : Handle fatal errors gracefully +--SKIPIF-- + +--FILE-- +bar(); // trigger fatal error + } +} + +$sandbox = new V8Js(); +$sandbox->foo = new Foo(); + +$cb = $sandbox->executeString('(function() { PHP.foo.callback(); });'); +$cb(); + +?> +===EOF=== +--EXPECTF-- +goodbye cruel world! + +Fatal error: Call to undefined method Foo::bar() in %s diff --git a/v8js.cc b/v8js.cc index 0b5858b..8bd01b5 100644 --- a/v8js.cc +++ b/v8js.cc @@ -446,7 +446,7 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) / #endif { zval *object = this_ptr, ***argv = NULL; - int i = 0, argc = ZEND_NUM_ARGS(); + int argc = ZEND_NUM_ARGS(); php_v8js_object *obj; obj = (php_v8js_object *) zend_object_store_get_object(object TSRMLS_CC); @@ -467,33 +467,27 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) / zend_get_parameters_array_ex(argc, argv); } - v8::Isolate *isolate = obj->ctx->isolate; - v8::Locker locker(isolate); - v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope local_scope(isolate); - v8::Local temp_context = v8::Context::New(isolate); - v8::Context::Scope temp_scope(temp_context); + std::function< v8::Local(v8::Isolate *) > v8_call = [obj, method, argc, argv TSRMLS_CC](v8::Isolate *isolate) { + int i = 0; - v8::Local method_name = V8JS_SYML(method, strlen(method)); - v8::Local v8obj = v8::Local::New(isolate, obj->v8obj)->ToObject(); - v8::Local cb; + v8::Local method_name = V8JS_SYML(method, strlen(method)); + v8::Local v8obj = v8::Local::New(isolate, obj->v8obj)->ToObject(); + v8::Local cb; - if (method_name->Equals(V8JS_SYM(V8JS_V8_INVOKE_FUNC_NAME))) { - cb = v8::Local::Cast(v8obj); - } else { - cb = v8::Local::Cast(v8obj->Get(method_name)); - } + if (method_name->Equals(V8JS_SYM(V8JS_V8_INVOKE_FUNC_NAME))) { + cb = v8::Local::Cast(v8obj); + } else { + cb = v8::Local::Cast(v8obj->Get(method_name)); + } - v8::Local *jsArgv = static_cast *>(alloca(sizeof(v8::Local) * argc)); - v8::Local js_retval; + v8::Local *jsArgv = static_cast *>(alloca(sizeof(v8::Local) * argc)); + v8::Local js_retval; - for (i = 0; i < argc; i++) { - new(&jsArgv[i]) v8::Local; - jsArgv[i] = v8::Local::New(isolate, zval_to_v8js(*argv[i], isolate TSRMLS_CC)); - } + for (i = 0; i < argc; i++) { + new(&jsArgv[i]) v8::Local; + jsArgv[i] = v8::Local::New(isolate, zval_to_v8js(*argv[i], isolate TSRMLS_CC)); + } - - std::function< v8::Local(v8::Isolate *) > v8_call = [cb, argc, jsArgv](v8::Isolate *isolate) { return cb->Call(V8JS_GLOBAL(isolate), argc, jsArgv); };