0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 15:25:19 +00:00

Use v8::TryCatch if calling V8Function, refs #127

This commit is contained in:
Stefan Siegl 2014-12-01 22:09:59 +01:00
parent 6d43ec6dbc
commit 0023c03280
2 changed files with 33 additions and 0 deletions

25
tests/issue_127_001.phpt Normal file
View 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===

View File

@ -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);
}