phpv8/php-v8

External exception lost

pinepain opened this issue · 0 comments

When V8 exception thrown with an V8 object that has no PHP reference stored, correspondent external exception did not pop up in a final result:

<?php
/** @var \Phpv8Testsuite $helper */
$helper = require '.testsuite.php';

require '.v8-helpers.php';
$v8_helper = new PhpV8Helpers($helper);


$isolate = new \V8\Isolate();
$context = new \V8\Context($isolate);
$v8_helper->injectConsoleLog($context);

$global = $context->globalObject();

$func_tpl = new \V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) {
    $isolate = $info->getIsolate();
    $context = $info->getContext();
    $info->getIsolate()->throwException($info->getContext(), \V8\ExceptionManager::createError($context, new \V8\StringValue($isolate, 'test')), new RuntimeException('test'));
});

$global->set($context, new \V8\StringValue($isolate, 'e'), $func_tpl);


try {
    $v8_helper->CompileRun($context, 'e()');
} catch (\V8\Exceptions\TryCatchException $e) {
    $helper->exception_export($e);

    $helper->assert('No external exception present', $e->getTryCatch()->getExternalException(), null);
}

$v8_helper->CompileRun($context, 'try {e()} catch(e) {}');

outputs

V8\Exceptions\TryCatchException: Error: test
No external exception present: ok

It looks like we might need to store reference to exception objects thrown on some isolate-specific stack.