0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 17:31:53 +00:00

Use V8JSG instead of global variable.

This commit is contained in:
Stefan Siegl 2014-04-12 09:22:58 +02:00
parent a49fa8ce02
commit dfd8a1f386
3 changed files with 20 additions and 11 deletions

View File

@ -205,8 +205,6 @@ struct php_v8js_ctx {
std::vector<php_v8js_accessor_ctx *> 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<char *, v8::Handle<v8::Object> > 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;

View File

@ -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<php_v8js_timer_ctx *>;
new(&v8js_globals->modules_loaded) std::map<char *, v8::Handle<v8::Object>>;
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
}
/* }}} */

View File

@ -31,16 +31,13 @@ extern "C" {
#include <limits>
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<v8::Object, zval> &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;