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

56 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2022-05-31 12:21:32 +00:00
--TEST--
2022-06-24 10:04:11 +00:00
Test V8::setExceptionFilter() : Simple test
2022-05-31 12:21:32 +00:00
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
class myv8 extends V8Js
{
public function throwException(string $message) {
throw new Exception($message);
}
}
2022-06-24 10:04:11 +00:00
class ExceptionFilter {
2022-05-31 12:21:32 +00:00
private $ex;
public function __construct(Throwable $ex) {
2022-06-24 10:04:11 +00:00
echo "ExceptionFilter::__construct called!\n";
2022-05-31 12:21:32 +00:00
var_dump($ex->getMessage());
$this->ex = $ex;
}
public function getMessage() {
echo "getMessage called\n";
return $this->ex->getMessage();
}
}
$v8 = new myv8();
2022-06-24 10:04:11 +00:00
$v8->setExceptionFilter(function (Throwable $ex) {
echo "exception filter called.\n";
return new ExceptionFilter($ex);
2022-05-31 12:21:32 +00:00
});
$v8->executeString('
try {
PHP.throwException("Oops");
}
catch (e) {
2022-06-24 10:04:11 +00:00
var_dump(e.getMessage()); // calls ExceptionFilter::getMessage
2022-05-31 12:21:32 +00:00
var_dump(typeof e.getTrace);
}
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
?>
===EOF===
--EXPECT--
2022-06-24 10:04:11 +00:00
exception filter called.
ExceptionFilter::__construct called!
2022-05-31 12:21:32 +00:00
string(4) "Oops"
getMessage called
string(4) "Oops"
string(9) "undefined"
===EOF===