From b8726409f41f9cf8a7e684c987eb88120c859757 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 3 Oct 2015 00:01:12 +0200 Subject: [PATCH] Throw V8JsException if v8 context cannot be created We used to reset This to NULL, which never reallt was supposed to work and PHP doc explicitly tell to not touch EX(This) --- tests/extensions_error.phpt | 8 +++++--- v8js_class.cc | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/extensions_error.phpt b/tests/extensions_error.phpt index 89118c8..e4f3629 100644 --- a/tests/extensions_error.phpt +++ b/tests/extensions_error.phpt @@ -37,6 +37,8 @@ Exception thrown during bootstrapping Extension or internal compilation error%sin handlebars at line 1. Error installing extension 'handlebars'. -Warning: V8Js::__construct(): Failed to create V8 context. Check that registered extensions do not have errors. in %s on line %d -NULL -===EOF=== +Fatal error: Uncaught V8JsException: Failed to create V8 context. Check that registered extensions do not have errors. in %s%eextensions_error.php:7 +Stack trace: +#0 %s%eextensions_error.php(7): V8Js->__construct() +#1 {main} + thrown in %s%eextensions_error.php on line 7 diff --git a/v8js_class.cc b/v8js_class.cc index 1742807..b13f16c 100644 --- a/v8js_class.cc +++ b/v8js_class.cc @@ -347,7 +347,8 @@ static PHP_METHOD(V8Js, __construct) { exts_count = zend_hash_num_elements(Z_ARRVAL_P(exts_arr)); if (v8js_create_ext_strarr(&exts, exts_count, Z_ARRVAL_P(exts_arr)) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid extensions array passed"); + zend_throw_exception(php_ce_v8js_exception, + "Invalid extensions array passed", 0); return; } } @@ -387,8 +388,9 @@ static PHP_METHOD(V8Js, __construct) /* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */ if (context.IsEmpty()) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to create V8 context. Check that registered extensions do not have errors."); - ZVAL_NULL(getThis()); + zend_throw_exception(php_ce_v8js_exception, + "Failed to create V8 context. " + "Check that registered extensions do not have errors.", 0); return; }