0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-23 06:01:52 +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; int error_num;
char *error_message; char *error_message;
jmp_buf *unwind_env; jmp_buf *unwind_env;
void (*old_error_handler)(int, const char *, const uint, const char*, va_list);
ZEND_END_MODULE_GLOBALS(v8js) ZEND_END_MODULE_GLOBALS(v8js)
extern zend_v8js_globals v8js_globals; extern zend_v8js_globals v8js_globals;

View File

@ -42,6 +42,11 @@ static void php_v8js_error_handler(int error_num, const char *error_filename,
char *buffer; char *buffer;
int buffer_len; int buffer_len;
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); buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
V8JSG(fatal_error_abort) = true; V8JSG(fatal_error_abort) = true;
@ -49,6 +54,11 @@ static void php_v8js_error_handler(int error_num, const char *error_filename,
V8JSG(error_message) = buffer; V8JSG(error_message) = buffer;
longjmp(*V8JSG(unwind_env), 1); 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; jmp_buf env;
int val = 0; 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 /* 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 * handler for fatal errors; we must fall back through V8 to keep
* it from crashing. */ * it from crashing. */
if (V8JSG(unwind_env) == NULL) { 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; zend_error_cb = php_v8js_error_handler;
val = setjmp (env); 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); zend_call_function(&fci, &fcc TSRMLS_CC);
} }
if (old_error_handler != NULL) { if (V8JSG(old_error_handler) != NULL) {
zend_error_cb = old_error_handler; zend_error_cb = V8JSG(old_error_handler);
V8JSG(unwind_env) = NULL; V8JSG(unwind_env) = NULL;
} }
} }