mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-23 04:51:53 +00:00
Unwind stack after fatal error in V8Function, closes #130
This commit is contained in:
parent
2252169a98
commit
7ac12c4fbd
26
tests/fatal_error_v8function.phpt
Normal file
26
tests/fatal_error_v8function.phpt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8Function() : Handle fatal errors gracefully
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
function callback() {
|
||||||
|
echo "goodbye cruel world!\n";
|
||||||
|
$this->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
|
12
v8js.cc
12
v8js.cc
@ -446,7 +446,7 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
zval *object = this_ptr, ***argv = NULL;
|
zval *object = this_ptr, ***argv = NULL;
|
||||||
int i = 0, argc = ZEND_NUM_ARGS();
|
int argc = ZEND_NUM_ARGS();
|
||||||
php_v8js_object *obj;
|
php_v8js_object *obj;
|
||||||
|
|
||||||
obj = (php_v8js_object *) zend_object_store_get_object(object TSRMLS_CC);
|
obj = (php_v8js_object *) zend_object_store_get_object(object TSRMLS_CC);
|
||||||
@ -467,12 +467,8 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /
|
|||||||
zend_get_parameters_array_ex(argc, argv);
|
zend_get_parameters_array_ex(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Isolate *isolate = obj->ctx->isolate;
|
std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [obj, method, argc, argv TSRMLS_CC](v8::Isolate *isolate) {
|
||||||
v8::Locker locker(isolate);
|
int i = 0;
|
||||||
v8::Isolate::Scope isolate_scope(isolate);
|
|
||||||
v8::HandleScope local_scope(isolate);
|
|
||||||
v8::Local<v8::Context> temp_context = v8::Context::New(isolate);
|
|
||||||
v8::Context::Scope temp_scope(temp_context);
|
|
||||||
|
|
||||||
v8::Local<v8::String> method_name = V8JS_SYML(method, strlen(method));
|
v8::Local<v8::String> method_name = V8JS_SYML(method, strlen(method));
|
||||||
v8::Local<v8::Object> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj)->ToObject();
|
v8::Local<v8::Object> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj)->ToObject();
|
||||||
@ -492,8 +488,6 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /
|
|||||||
jsArgv[i] = v8::Local<v8::Value>::New(isolate, zval_to_v8js(*argv[i], isolate TSRMLS_CC));
|
jsArgv[i] = v8::Local<v8::Value>::New(isolate, zval_to_v8js(*argv[i], isolate TSRMLS_CC));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [cb, argc, jsArgv](v8::Isolate *isolate) {
|
|
||||||
return cb->Call(V8JS_GLOBAL(isolate), argc, jsArgv);
|
return cb->Call(V8JS_GLOBAL(isolate), argc, jsArgv);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user