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

Only pass fatal errors to the V8JS error handler, others go to PHP's error handler.

This commit is contained in:
Taneli Leppa 2014-05-22 11:17:38 +03:00
parent a134129018
commit cbda704d7e
2 changed files with 21 additions and 12 deletions

View File

@ -265,6 +265,7 @@ ZEND_BEGIN_MODULE_GLOBALS(v8js)
int error_num;
char *error_message;
jmp_buf *unwind_env;
void (*old_error_handler)(int, const char *, const uint, const char*, va_list);
ZEND_END_MODULE_GLOBALS(v8js)
extern zend_v8js_globals v8js_globals;

View File

@ -42,13 +42,23 @@ static void php_v8js_error_handler(int error_num, const char *error_filename,
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);
switch (error_num)
{
case E_ERROR:
case E_CORE_ERROR:
case E_USER_ERROR:
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);
break;
default:
V8JSG(old_error_handler)(error_num, error_filename, error_lineno, format, args);
break;
}
}
/* }}} */
@ -158,13 +168,11 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct
jmp_buf env;
int val = 0;
void (*old_error_handler)(int, const char *, const uint, const char*, va_list);
/* If this is the first level call from V8 back to PHP, install a
* handler for fatal errors; we must fall back through V8 to keep
* it from crashing. */
if (V8JSG(unwind_env) == NULL) {
old_error_handler = zend_error_cb;
V8JSG(old_error_handler) = zend_error_cb;
zend_error_cb = php_v8js_error_handler;
val = setjmp (env);
@ -176,8 +184,8 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct
zend_call_function(&fci, &fcc TSRMLS_CC);
}
if (old_error_handler != NULL) {
zend_error_cb = old_error_handler;
if (V8JSG(old_error_handler) != NULL) {
zend_error_cb = V8JSG(old_error_handler);
V8JSG(unwind_env) = NULL;
}
}