소스 검색

Use V8JSG instead of global variable.

Stefan Siegl 11 년 전
부모
커밋
dfd8a1f386
3개의 변경된 파일20개의 추가작업 그리고 11개의 파일을 삭제
  1. 8 2
      php_v8js_macros.h
  2. 8 1
      v8js.cc
  3. 4 8
      v8js_convert.cc

+ 8 - 2
php_v8js_macros.h

@@ -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;

+ 8 - 1
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<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
 }
 /* }}} */

+ 4 - 8
v8js_convert.cc

@@ -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;