Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When FLAG_PROPAGATE_PHP_EXCEPTIONS is set, check for unwind or gracef… #498

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/issue_497_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Test V8::executeString() : Issue #497 (segmentation fault calling PHP exit inside object function)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
class Foo {
function __destruct() {
var_dump('Foo __destruct');
}

function somecall() {
var_dump('Foo somecall');
}

function bar() {
global $v8;
var_dump('Foo bar');
exit;
}
}

$v8 = new \V8Js();
$v8->foo = new Foo();

$JS = <<< EOT
PHP.foo.somecall();
PHP.foo.bar();
EOT;

$v8->executeString($JS, '', \V8JS::FLAG_PROPAGATE_PHP_EXCEPTIONS);
echo 'Not here!!';
?>
--EXPECTF--
string(12) "Foo somecall"
string(7) "Foo bar"
string(14) "Foo __destruct"
2 changes: 1 addition & 1 deletion v8js_object_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, c
}

if(EG(exception)) {
if(ctx->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
if((ctx->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) && !zend_is_graceful_exit(EG(exception)) && !zend_is_unwind_exit(EG(exception))) {
zval tmp_zv;
ZVAL_OBJ(&tmp_zv, EG(exception));
return_value = isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate));
Expand Down