0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 10:18:41 +00:00

wrap module loading in zend_try/zend_catch, closes #178

This commit is contained in:
Stefan Siegl 2015-12-04 22:09:04 +01:00
parent 39fff2301e
commit bf58fe67c1
2 changed files with 42 additions and 4 deletions

View File

@ -0,0 +1,17 @@
--TEST--
Test V8Js::setModuleLoader : Handle fatal errors gracefully
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
$v8->setModuleLoader(function() {
trigger_error('some fatal error', E_USER_ERROR);
});
$v8->executeString(' require("foo"); ');
?>
===EOF===
--EXPECTF--
Fatal error: some fatal error in %s%ecommonjs_fatal_error.php on line 5

View File

@ -257,13 +257,34 @@ V8JS_METHOD(require)
MAKE_STD_ZVAL(normalised_path_zend);
ZVAL_STRING(normalised_path_zend, normalised_module_id, 1);
int call_result;
zend_try {
{
isolate->Exit();
v8::Unlocker unlocker(isolate);
zval **params[1] = {&normalised_path_zend};
if (FAILURE == call_user_function_ex(EG(function_table), NULL, c->module_loader, &module_code, 1, params, 0, NULL TSRMLS_CC)) {
call_result = call_user_function_ex(EG(function_table), NULL, c->module_loader, &module_code, 1, params, 0, NULL TSRMLS_CC);
}
isolate->Enter();
if (call_result == FAILURE) {
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback failed")));
}
}
zend_catch {
v8js_terminate_execution(isolate);
V8JSG(fatal_error_abort) = 1;
call_result = FAILURE;
}
zend_end_try();
if (call_result == FAILURE) {
zval_ptr_dtor(&normalised_path_zend);
efree(normalised_module_id);
efree(normalised_path);
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback failed")));
return;
}
zval_ptr_dtor(&normalised_path_zend);