From 659c0fb60170a46a24a7e5fd2bd679583b976f8c Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sun, 13 Apr 2014 22:59:35 +0200 Subject: [PATCH] Code folding marks and comments --- v8js.cc | 2 ++ v8js_convert.cc | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/v8js.cc b/v8js.cc index fb52aad..c8aa24d 100644 --- a/v8js.cc +++ b/v8js.cc @@ -1134,6 +1134,8 @@ static PHP_METHOD(V8Js, executeString) php_v8js_timer_pop(TSRMLS_C); } + /* Check for fatal error marker possibly set by php_v8js_error_handler; just + * rethrow the error since we're now out of V8. */ if(V8JSG(fatal_error_abort)) { zend_error(V8JSG(error_num), "%s", V8JSG(error_message)); } diff --git a/v8js_convert.cc b/v8js_convert.cc index ba74faf..97e3527 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -31,7 +31,13 @@ extern "C" { #include -static void php_v8js_error_handler(int error_num, const char *error_filename, const uint error_lineno, const char *format, va_list args) +/* Callback for PHP's zend_error_cb; catching any fatal PHP error. + * The callback is installed in the lowest (stack wise) php_v8js_call_php_func + * frame. Just store the error message and jump right back there and fall + * back into V8 context. */ +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; @@ -44,6 +50,7 @@ static void php_v8js_error_handler(int error_num, const char *error_filename, co longjmp(*V8JSG(unwind_env), 1); } +/* }}} */ static void php_v8js_weak_object_callback(const v8::WeakCallbackData &data); @@ -153,6 +160,9 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct 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; zend_error_cb = php_v8js_error_handler;