mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 15:11:53 +00:00
document (re-)throwing behaviour from exception filter
This commit is contained in:
parent
b635a16789
commit
bf51bf52a9
@ -413,5 +413,7 @@ via `getPrevious` method.
|
|||||||
|
|
||||||
Consider that the JS code has access to methods like `getTrace` on the exception
|
Consider that the JS code has access to methods like `getTrace` on the exception
|
||||||
object. This might be unwanted behaviour, if you execute untrusted code.
|
object. This might be unwanted behaviour, if you execute untrusted code.
|
||||||
Using `setExceptionFilter` method a callable can be provided, that converts
|
Using `setExceptionFilter` method a callable can be provided, that may convert
|
||||||
the PHP exception to not expose unwanted information.
|
the PHP exception to some other value that is safe to expose. The filter may
|
||||||
|
also decide not to propagate the exception to JS at all by either re-throwing
|
||||||
|
the passed exception or throwing another exception.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Test V8::setExceptionFilter() : Filter handling on exception in factory
|
Test V8::setExceptionFilter() : Filter handling on exception in converter
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
|
38
tests/exception_filter_006.phpt
Normal file
38
tests/exception_filter_006.phpt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::setExceptionFilter() : re-throw exception in exception filter
|
||||||
|
--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->setExceptionFilter(function (Throwable $ex) {
|
||||||
|
// re-throw exception so it is not forwarded
|
||||||
|
throw $ex;
|
||||||
|
});
|
||||||
|
|
||||||
|
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: Oops
|
||||||
|
===EOF===
|
Loading…
Reference in New Issue
Block a user