Browse Source

introduce V8JsException class

Stefan Siegl 10 years ago
parent
commit
c28c9f50f1
3 changed files with 54 additions and 6 deletions
  1. 7 3
      README.md
  2. 30 0
      tests/inheritance_basic.phpt
  3. 17 3
      v8js.cc

+ 7 - 3
README.md

@@ -134,7 +134,11 @@ PHP API
         public static array V8Js::getExtensions( )
     }
 
-    final class V8JsScriptException extends Exception
+    class V8JsException extends RuntimeException
+    {
+    }
+
+    final class V8JsScriptException extends V8JsException
     {
         /* Properties */
         protected string JsFileName = NULL;
@@ -153,11 +157,11 @@ PHP API
         final public string getJsTrace( )
     }
 
-    final class V8JsTimeLimitException extends Exception
+    final class V8JsTimeLimitException extends V8JsException
     {
     }
 
-    final class V8JsMemoryLimitException extends Exception
+    final class V8JsMemoryLimitException extends V8JsException
     {
     }
 ```

+ 30 - 0
tests/inheritance_basic.phpt

@@ -0,0 +1,30 @@
+--TEST--
+Test V8Js : class inheritance
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--FILE--
+<?php
+
+var_dump(class_exists('V8JsException'));
+var_dump(class_exists('V8JsScriptException'));
+var_dump(class_exists('V8JsTimeLimitException'));
+var_dump(class_exists('V8JsMemoryLimitException'));
+
+var_dump(is_subclass_of(new V8JsException(), 'RuntimeException'));
+
+var_dump(is_subclass_of(new V8JsScriptException(), 'V8JsException'));
+var_dump(is_subclass_of(new V8JsTimeLimitException(), 'V8JsException'));
+var_dump(is_subclass_of(new V8JsMemoryLimitException(), 'V8JsException'));
+
+?>
+===EOF===
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+===EOF===

+ 17 - 3
v8js.cc

@@ -32,6 +32,7 @@ extern "C" {
 #include "ext/standard/info.h"
 #include "ext/standard/php_string.h"
 #include "ext/standard/php_smart_str.h"
+#include "ext/spl/spl_exceptions.h"
 #include "zend_exceptions.h"
 }
 
@@ -115,6 +116,7 @@ ZEND_INI_END()
 zend_class_entry *php_ce_v8_object;
 zend_class_entry *php_ce_v8_function;
 static zend_class_entry *php_ce_v8js;
+static zend_class_entry *php_ce_v8js_exception;
 static zend_class_entry *php_ce_v8js_script_exception;
 static zend_class_entry *php_ce_v8js_time_limit_exception;
 static zend_class_entry *php_ce_v8js_memory_limit_exception;
@@ -1954,6 +1956,14 @@ static void php_v8js_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC
 
 /* }}} V8Js */
 
+/* {{{ Class: V8JsException */
+
+static const zend_function_entry v8js_exception_methods[] = { /* {{{ */
+	{NULL, NULL, NULL}
+};
+
+/* }}} */
+
 /* {{{ Class: V8JsScriptException */
 
 static void php_v8js_create_script_exception(zval *return_value, v8::TryCatch *try_catch TSRMLS_DC) /* {{{ */
@@ -2156,9 +2166,13 @@ static PHP_MINIT_FUNCTION(v8js)
 	zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_ALWAYS"),	V8JS_DEBUG_AUTO_BREAK_ALWAYS		TSRMLS_CC);
 #endif
 
+	/* V8JsException Class */
+	INIT_CLASS_ENTRY(ce, "V8JsException", v8js_exception_methods);
+	php_ce_v8js_exception = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
+
 	/* V8JsScriptException Class */
 	INIT_CLASS_ENTRY(ce, "V8JsScriptException", v8js_script_exception_methods);
-	php_ce_v8js_script_exception = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
+	php_ce_v8js_script_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception, NULL TSRMLS_CC);
 	php_ce_v8js_script_exception->ce_flags |= ZEND_ACC_FINAL;
 
 	/* Add custom JS specific properties */
@@ -2171,12 +2185,12 @@ static PHP_MINIT_FUNCTION(v8js)
 
 	/* V8JsTimeLimitException Class */
 	INIT_CLASS_ENTRY(ce, "V8JsTimeLimitException", v8js_time_limit_exception_methods);
-	php_ce_v8js_time_limit_exception = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
+	php_ce_v8js_time_limit_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception, NULL TSRMLS_CC);
 	php_ce_v8js_time_limit_exception->ce_flags |= ZEND_ACC_FINAL;
 
 	/* V8JsMemoryLimitException Class */
 	INIT_CLASS_ENTRY(ce, "V8JsMemoryLimitException", v8js_memory_limit_exception_methods);
-	php_ce_v8js_memory_limit_exception = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
+	php_ce_v8js_memory_limit_exception = zend_register_internal_class_ex(&ce, php_ce_v8js_exception, NULL TSRMLS_CC);
 	php_ce_v8js_memory_limit_exception->ce_flags |= ZEND_ACC_FINAL;
 
 	le_v8js_script = zend_register_list_destructors_ex(php_v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);