0
0
mirror of https://github.com/phpv8/v8js.git synced 2025-04-21 09:14:35 +00:00

Store error message and re-throw with original type & message

This commit is contained in:
Stefan Siegl 2014-04-13 21:46:31 +02:00
parent dfd8a1f386
commit 35d8b815f8
4 changed files with 35 additions and 5 deletions

@ -263,8 +263,6 @@ ZEND_BEGIN_MODULE_GLOBALS(v8js)
// fatal error unwinding
bool fatal_error_abort;
int error_num;
const char *error_filename;
uint error_lineno;
char *error_message;
jmp_buf *unwind_env;
ZEND_END_MODULE_GLOBALS(v8js)

@ -0,0 +1,26 @@
--TEST--
Test V8::executeString() : Fatal Error rethrowing
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$js = new V8Js();
$js->foo = function() {
$bar = null;
$bar->bar();
};
$script = <<<END
PHP.foo();
END;
$js->executeString($script);
?>
===EOF===
--EXPECTF--
Fatal error: Call to a member function bar() on a non-object in %s/fatal_error_rethrow.php on line 7

@ -1135,7 +1135,7 @@ static PHP_METHOD(V8Js, executeString)
}
if(V8JSG(fatal_error_abort)) {
zend_error(E_ERROR, "V8Js caught fatal error; message lost, sorry :-)");
zend_error(V8JSG(error_num), "%s", V8JSG(error_message));
}
char exception_string[64];
@ -1875,8 +1875,6 @@ static PHP_GINIT_FUNCTION(v8js)
v8js_globals->fatal_error_abort = 0;
v8js_globals->error_num = 0;
v8js_globals->error_filename = NULL;
v8js_globals->error_lineno = 0;
v8js_globals->error_message = 0;
v8js_globals->unwind_env = NULL;
#endif

@ -33,7 +33,15 @@ extern "C" {
static void php_v8js_error_handler(int error_num, const char *error_filename, const uint error_lineno, const char *format, va_list args)
{
char *buffer;
int buffer_len;
buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
V8JSG(fatal_error_abort) = true;
V8JSG(error_num) = error_num;
V8JSG(error_message) = buffer;
longjmp(*V8JSG(unwind_env), 1);
}