Browse Source

Move zend_try block into v8::Unlocker block

If the v8::Unlocker block is within the zend_try block, then
v8::~Unlocker (dtor) is not called and hence V8 doesn't
re-aquire the lock.

Besides before we re-entered the isolate within zend_try
and hence *before* taking the lock.
Stefan Siegl 9 years ago
parent
commit
2d9c831eeb
2 changed files with 25 additions and 24 deletions
  1. 15 13
      v8js_methods.cc
  2. 10 11
      v8js_object_export.cc

+ 15 - 13
v8js_methods.cc

@@ -354,27 +354,29 @@ V8JS_METHOD(require)
 	int call_result;
 	int call_result;
 	zval params[1];
 	zval params[1];
 
 
-	zend_try {
-		{
-			isolate->Exit();
-			v8::Unlocker unlocker(isolate);
+	{
+		isolate->Exit();
+		v8::Unlocker unlocker(isolate);
 
 
+		zend_try {
 			ZVAL_STRING(&params[0], normalised_module_id);
 			ZVAL_STRING(&params[0], normalised_module_id);
 			call_result = call_user_function_ex(EG(function_table), NULL, &c->module_loader, &module_code, 1, params, 0, NULL TSRMLS_CC);
 			call_result = call_user_function_ex(EG(function_table), NULL, &c->module_loader, &module_code, 1, params, 0, NULL TSRMLS_CC);
 		}
 		}
-
-		isolate->Enter();
-
-		if (call_result == FAILURE) {
-			info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback failed")));
+		zend_catch {
+			v8js_terminate_execution(isolate);
+			V8JSG(fatal_error_abort) = 1;
 		}
 		}
+		zend_end_try();
 	}
 	}
-	zend_catch {
-		v8js_terminate_execution(isolate);
-		V8JSG(fatal_error_abort) = 1;
+
+	isolate->Enter();
+
+	if (V8JSG(fatal_error_abort)) {
 		call_result = FAILURE;
 		call_result = FAILURE;
 	}
 	}
-	zend_end_try();
+	else if (call_result == FAILURE) {
+		info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback failed")));
+	}
 
 
 	zval_dtor(&params[0]);
 	zval_dtor(&params[0]);
 
 

+ 10 - 11
v8js_object_export.cc

@@ -114,11 +114,11 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, v
 	fci.no_separation = 1;
 	fci.no_separation = 1;
 	info.GetReturnValue().Set(V8JS_NULL);
 	info.GetReturnValue().Set(V8JS_NULL);
 
 
-	zend_try {
-		{
-			isolate->Exit();
-			v8::Unlocker unlocker(isolate);
+	{
+		isolate->Exit();
+		v8::Unlocker unlocker(isolate);
 
 
+		zend_try {
 			/* zend_fcall_info_cache */
 			/* zend_fcall_info_cache */
 			fcc.initialized = 1;
 			fcc.initialized = 1;
 			fcc.function_handler = method_ptr;
 			fcc.function_handler = method_ptr;
@@ -128,14 +128,13 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, v
 
 
 			zend_call_function(&fci, &fcc TSRMLS_CC);
 			zend_call_function(&fci, &fcc TSRMLS_CC);
 		}
 		}
-
-		isolate->Enter();
-	}
-	zend_catch {
-		v8js_terminate_execution(isolate);
-		V8JSG(fatal_error_abort) = 1;
+		zend_catch {
+			v8js_terminate_execution(isolate);
+			V8JSG(fatal_error_abort) = 1;
+		}
+		zend_end_try();
 	}
 	}
-	zend_end_try();
+	isolate->Enter();
 
 
 failure:
 failure:
 	/* Cleanup */
 	/* Cleanup */