Skip to content

Commit

Permalink
Merge branch 'php8-exit_segfault' of https://github.com/chrisbckr/v8js
Browse files Browse the repository at this point in the history
…into php8

Conflicts:
	v8js_object_export.cc
  • Loading branch information
stesie committed Feb 3, 2023
2 parents 7887ec6 + 5a10dec commit 8aa6bc2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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 @@ -38,7 +38,7 @@ v8::Local<v8::Value> v8js_propagate_exception(v8js_ctx *ctx) /* {{{ */
{
v8::Local<v8::Value> return_value = v8::Null(ctx->isolate);

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))) {
v8js_terminate_execution(ctx->isolate);
return return_value;
}
Expand Down

0 comments on commit 8aa6bc2

Please sign in to comment.