diff --git a/php_v8js_macros.h b/php_v8js_macros.h index 1ae9938..4b9a3f4 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -205,8 +205,6 @@ struct php_v8js_ctx { std::vector accessor_list; char *tz; - - bool fatal_error_abort; #ifdef ZTS void ***zts_ctx; #endif @@ -261,6 +259,14 @@ ZEND_BEGIN_MODULE_GLOBALS(v8js) bool timer_stop; std::map > modules_loaded; + + // 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) extern zend_v8js_globals v8js_globals; diff --git a/v8js.cc b/v8js.cc index a28cd5d..5f9cea2 100644 --- a/v8js.cc +++ b/v8js.cc @@ -1134,7 +1134,7 @@ static PHP_METHOD(V8Js, executeString) php_v8js_timer_pop(TSRMLS_C); } - if(c->fatal_error_abort) { + if(V8JSG(fatal_error_abort)) { zend_error(E_ERROR, "V8Js caught fatal error; message lost, sorry :-)"); } @@ -1872,6 +1872,13 @@ static PHP_GINIT_FUNCTION(v8js) new(&v8js_globals->timer_mutex) std::mutex; new(&v8js_globals->timer_stack) std::stack; new(&v8js_globals->modules_loaded) std::map>; + + 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 } /* }}} */ diff --git a/v8js_convert.cc b/v8js_convert.cc index db8fa3c..ef585e7 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -31,16 +31,13 @@ extern "C" { #include -jmp_buf *unwind_env; - static void php_v8js_error_handler(int error_num, const char *error_filename, const uint error_lineno, const char *format, va_list args) { - longjmp(*unwind_env, 1); + V8JSG(fatal_error_abort) = true; + longjmp(*V8JSG(unwind_env), 1); } - - static void php_v8js_weak_object_callback(const v8::WeakCallbackData &data); /* Callback for PHP methods and functions */ @@ -151,10 +148,9 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct zend_error_cb = php_v8js_error_handler; val = setjmp (env); - unwind_env = &env; + V8JSG(unwind_env) = &env; if (val) { - ctx->fatal_error_abort = true; zend_error_cb = old_error_handler; } else { @@ -165,7 +161,7 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct isolate->Enter(); - if(ctx->fatal_error_abort) { + if (V8JSG(fatal_error_abort)) { v8::V8::TerminateExecution(isolate); info.GetReturnValue().Set(V8JS_NULL); return;