Bläddra i källkod

Store error message and re-throw with original type & message

Stefan Siegl 11 år sedan
förälder
incheckning
35d8b815f8
4 ändrade filer med 35 tillägg och 5 borttagningar
  1. 0 2
      php_v8js_macros.h
  2. 26 0
      tests/fatal_error_rethrow.phpt
  3. 1 3
      v8js.cc
  4. 8 0
      v8js_convert.cc

+ 0 - 2
php_v8js_macros.h

@@ -263,8 +263,6 @@ ZEND_BEGIN_MODULE_GLOBALS(v8js)
   // 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)

+ 26 - 0
tests/fatal_error_rethrow.phpt

@@ -0,0 +1,26 @@
+--TEST--
+Test V8::executeString() : Fatal Error rethrowing
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--FILE--
+<?php
+
+$js = new V8Js();
+
+$js->foo = function() {
+	$bar = null;
+	$bar->bar();
+};
+
+$script = <<<END
+
+PHP.foo();
+
+END;
+
+$js->executeString($script);
+
+?>
+===EOF===
+--EXPECTF--
+Fatal error: Call to a member function bar() on a non-object in %s/fatal_error_rethrow.php on line 7

+ 1 - 3
v8js.cc

@@ -1135,7 +1135,7 @@ static PHP_METHOD(V8Js, executeString)
 	}
 
 	if(V8JSG(fatal_error_abort)) {
-		zend_error(E_ERROR, "V8Js caught fatal error; message lost, sorry :-)");
+		zend_error(V8JSG(error_num), "%s", V8JSG(error_message));
 	}
 
 	char exception_string[64];
@@ -1875,8 +1875,6 @@ static PHP_GINIT_FUNCTION(v8js)
 
 	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

+ 8 - 0
v8js_convert.cc

@@ -33,7 +33,15 @@ extern "C" {
 
 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;
+
+	buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
+
 	V8JSG(fatal_error_abort) = true;
+	V8JSG(error_num) = error_num;
+	V8JSG(error_message) = buffer;
+
 	longjmp(*V8JSG(unwind_env), 1);
 }