Skip to content

Commit 5a10dec

Browse files
committed
When FLAG_PROPAGATE_PHP_EXCEPTIONS is set, check for unwind or graceful exit before propagate
1 parent 461230b commit 5a10dec

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

tests/issue_497_001.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Test V8::executeString() : Issue #497 (segmentation fault calling PHP exit inside object function)
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
class Foo {
8+
function __destruct() {
9+
var_dump('Foo __destruct');
10+
}
11+
12+
function somecall() {
13+
var_dump('Foo somecall');
14+
}
15+
16+
function bar() {
17+
global $v8;
18+
var_dump('Foo bar');
19+
exit;
20+
}
21+
}
22+
23+
$v8 = new \V8Js();
24+
$v8->foo = new Foo();
25+
26+
$JS = <<< EOT
27+
PHP.foo.somecall();
28+
PHP.foo.bar();
29+
EOT;
30+
31+
$v8->executeString($JS, '', \V8JS::FLAG_PROPAGATE_PHP_EXCEPTIONS);
32+
echo 'Not here!!';
33+
?>
34+
--EXPECTF--
35+
string(12) "Foo somecall"
36+
string(7) "Foo bar"
37+
string(14) "Foo __destruct"

v8js_object_export.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, c
167167
}
168168

169169
if(EG(exception)) {
170-
if(ctx->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
170+
if((ctx->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) && !zend_is_graceful_exit(EG(exception)) && !zend_is_unwind_exit(EG(exception))) {
171171
zval tmp_zv;
172172
ZVAL_OBJ(&tmp_zv, EG(exception));
173173
return_value = isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate));

0 commit comments

Comments
 (0)