mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 08:11:52 +00:00
handle exceptions thrown in proxy factory
This commit is contained in:
parent
7422ef2383
commit
ca38f724c8
37
tests/exception_proxy_004.phpt
Normal file
37
tests/exception_proxy_004.phpt
Normal file
@ -0,0 +1,37 @@
|
||||
--TEST--
|
||||
Test V8::setExceptionProxyFactory() : Proxy handling on exception in factory
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
class myv8 extends V8Js
|
||||
{
|
||||
public function throwException(string $message) {
|
||||
throw new Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
$v8 = new myv8();
|
||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
||||
throw new Exception('moep');
|
||||
});
|
||||
|
||||
try {
|
||||
$v8->executeString('
|
||||
try {
|
||||
PHP.throwException("Oops");
|
||||
print("done\\n");
|
||||
}
|
||||
catch (e) {
|
||||
print("caught\\n");
|
||||
var_dump(e);
|
||||
}
|
||||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
||||
} catch (Exception $ex) {
|
||||
echo "caught in php: " . $ex->getMessage() . PHP_EOL;
|
||||
}
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
caught in php: moep
|
||||
===EOF===
|
@ -53,7 +53,12 @@ v8::Local<v8::Value> v8js_propagate_exception(v8js_ctx *ctx) /* {{{ */
|
||||
call_user_function(EG(function_table), NULL, &ctx->exception_proxy_factory, &tmp_zv, 1, params);
|
||||
zval_ptr_dtor(¶ms[0]);
|
||||
|
||||
return_value = ctx->isolate->ThrowException(zval_to_v8js(&tmp_zv, ctx->isolate));
|
||||
if(EG(exception)) {
|
||||
// exception proxy threw exception itself, don't forward, just stop execution.
|
||||
v8js_terminate_execution(ctx->isolate);
|
||||
} else {
|
||||
return_value = ctx->isolate->ThrowException(zval_to_v8js(&tmp_zv, ctx->isolate));
|
||||
}
|
||||
} else {
|
||||
ZVAL_OBJ(&tmp_zv, EG(exception));
|
||||
return_value = ctx->isolate->ThrowException(zval_to_v8js(&tmp_zv, ctx->isolate));
|
||||
|
Loading…
Reference in New Issue
Block a user