mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 23:08:41 +00:00
Use v8::TryCatch if calling V8Function, refs #127
This commit is contained in:
parent
6d43ec6dbc
commit
0023c03280
25
tests/issue_127_001.phpt
Normal file
25
tests/issue_127_001.phpt
Normal file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
Test V8Function::__call() : Check v8::TryCatch behaviour
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if(!function_exists('json_encode')) {
|
||||
die('SKIP');
|
||||
}
|
||||
require_once(dirname(__FILE__) . '/skipif.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$sandbox = new V8Js();
|
||||
|
||||
$cb = $sandbox->executeString('(function() { return oh; });');
|
||||
|
||||
try {
|
||||
$cb();
|
||||
} catch(\Exception $e) {
|
||||
echo "caught: ".$e->getMessage()."\n";
|
||||
}
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
caught: V8Js::compileString():1: ReferenceError: oh is not defined
|
||||
===EOF===
|
8
v8js.cc
8
v8js.cc
@ -486,6 +486,9 @@ 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));
|
||||
}
|
||||
|
||||
/* Catch JS exceptions */
|
||||
v8::TryCatch try_catch;
|
||||
|
||||
js_retval = cb->Call(V8JS_GLOBAL(isolate), argc, jsArgv);
|
||||
|
||||
zval_ptr_dtor(&object);
|
||||
@ -494,6 +497,11 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /
|
||||
efree(argv);
|
||||
}
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
php_v8js_throw_script_exception(&try_catch TSRMLS_CC);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (return_value_used) {
|
||||
return v8js_to_zval(js_retval, return_value, obj->flags, isolate TSRMLS_CC);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user