diff --git a/README.md b/README.md index bca66e5..eab1a7d 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ class V8Js * The factory function will receive the PHP Exception instance that has not been caught and is * due to be forwarded to JS. */ - public function setExceptionProxyFactory(callable $factory) + public function setExceptionFilter(callable $factory) {} /** @@ -413,5 +413,5 @@ via `getPrevious` method. Consider that the JS code has access to methods like `getTrace` on the exception object. This might be unwanted behaviour, if you execute untrusted code. -Using `setExceptionProxyFactory` method a callable can be provided, that converts +Using `setExceptionFilter` method a callable can be provided, that converts the PHP exception to not expose unwanted information. diff --git a/tests/exception_proxy_001.phpt b/tests/exception_filter_001.phpt similarity index 72% rename from tests/exception_proxy_001.phpt rename to tests/exception_filter_001.phpt index 52c8286..115642e 100644 --- a/tests/exception_proxy_001.phpt +++ b/tests/exception_filter_001.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::setExceptionProxyFactory() : String conversion +Test V8::setExceptionFilter() : String conversion --SKIPIF-- --FILE-- @@ -12,8 +12,8 @@ class myv8 extends V8Js } $v8 = new myv8(); -$v8->setExceptionProxyFactory(function (Throwable $ex) { - echo "exception proxy factory called.\n"; +$v8->setExceptionFilter(function (Throwable $ex) { + echo "exception filter called.\n"; return $ex->getMessage(); }); @@ -29,7 +29,7 @@ $v8->executeString(' ?> ===EOF=== --EXPECT-- -exception proxy factory called. +exception filter called. string(6) "string" string(4) "Oops" ===EOF=== diff --git a/tests/exception_proxy_002.phpt b/tests/exception_filter_002.phpt similarity index 64% rename from tests/exception_proxy_002.phpt rename to tests/exception_filter_002.phpt index 9174eb2..add31ee 100644 --- a/tests/exception_proxy_002.phpt +++ b/tests/exception_filter_002.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::setExceptionProxyFactory() : Proxy handling on exception in setModuleLoader +Test V8::setExceptionFilter() : Filter handling on exception in setModuleLoader --SKIPIF-- --FILE-- @@ -10,8 +10,8 @@ $v8->setModuleLoader(function ($path) { throw new Error('moep'); }); -$v8->setExceptionProxyFactory(function (Throwable $ex) { - echo "exception proxy factory called.\n"; +$v8->setExceptionFilter(function (Throwable $ex) { + echo "exception filter called.\n"; return $ex->getMessage(); }); @@ -26,7 +26,7 @@ $v8->executeString(' ?> ===EOF=== --EXPECT-- -exception proxy factory called. +exception filter called. string(4) "moep" ===EOF=== diff --git a/tests/exception_proxy_003.phpt b/tests/exception_filter_003.phpt similarity index 67% rename from tests/exception_proxy_003.phpt rename to tests/exception_filter_003.phpt index fe70877..1caaab4 100644 --- a/tests/exception_proxy_003.phpt +++ b/tests/exception_filter_003.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::setExceptionProxyFactory() : Proxy handling on exception in setModuleNormaliser +Test V8::setExceptionFilter() : Filter handling on exception in setModuleNormaliser --SKIPIF-- --FILE-- @@ -13,8 +13,8 @@ $v8->setModuleLoader(function ($path) { throw new Error('moep'); }); -$v8->setExceptionProxyFactory(function (Throwable $ex) { - echo "exception proxy factory called.\n"; +$v8->setExceptionFilter(function (Throwable $ex) { + echo "exception filter called.\n"; return $ex->getMessage(); }); @@ -29,6 +29,6 @@ $v8->executeString(' ?> ===EOF=== --EXPECT-- -exception proxy factory called. +exception filter called. string(5) "blarg" ===EOF=== diff --git a/tests/exception_proxy_004.phpt b/tests/exception_filter_004.phpt similarity index 85% rename from tests/exception_proxy_004.phpt rename to tests/exception_filter_004.phpt index dfa4287..a5dec89 100644 --- a/tests/exception_proxy_004.phpt +++ b/tests/exception_filter_004.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::setExceptionProxyFactory() : Proxy handling on exception in factory +Test V8::setExceptionFilter() : Filter handling on exception in factory --SKIPIF-- --FILE-- @@ -12,7 +12,7 @@ class myv8 extends V8Js } $v8 = new myv8(); -$v8->setExceptionProxyFactory(function (Throwable $ex) { +$v8->setExceptionFilter(function (Throwable $ex) { throw new Exception('moep'); }); diff --git a/tests/exception_proxy_basic.phpt b/tests/exception_filter_basic.phpt similarity index 64% rename from tests/exception_proxy_basic.phpt rename to tests/exception_filter_basic.phpt index e7f8b3b..fca5305 100644 --- a/tests/exception_proxy_basic.phpt +++ b/tests/exception_filter_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::setExceptionProxyFactory() : Simple test +Test V8::setExceptionFilter() : Simple test --SKIPIF-- --FILE-- @@ -11,11 +11,11 @@ class myv8 extends V8Js } } -class ExceptionProxy { +class ExceptionFilter { private $ex; public function __construct(Throwable $ex) { - echo "ExceptionProxy::__construct called!\n"; + echo "ExceptionFilter::__construct called!\n"; var_dump($ex->getMessage()); $this->ex = $ex; @@ -28,9 +28,9 @@ class ExceptionProxy { } $v8 = new myv8(); -$v8->setExceptionProxyFactory(function (Throwable $ex) { - echo "exception proxy factory called.\n"; - return new ExceptionProxy($ex); +$v8->setExceptionFilter(function (Throwable $ex) { + echo "exception filter called.\n"; + return new ExceptionFilter($ex); }); $v8->executeString(' @@ -38,15 +38,15 @@ $v8->executeString(' PHP.throwException("Oops"); } catch (e) { - var_dump(e.getMessage()); // calls ExceptionProxy::getMessage + var_dump(e.getMessage()); // calls ExceptionFilter::getMessage var_dump(typeof e.getTrace); } ', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); ?> ===EOF=== --EXPECT-- -exception proxy factory called. -ExceptionProxy::__construct called! +exception filter called. +ExceptionFilter::__construct called! string(4) "Oops" getMessage called string(4) "Oops" diff --git a/v8js_class.cc b/v8js_class.cc index 57f5571..044a8c5 100644 --- a/v8js_class.cc +++ b/v8js_class.cc @@ -92,7 +92,7 @@ static void v8js_free_storage(zend_object *object) /* {{{ */ zval_ptr_dtor(&c->pending_exception); zval_ptr_dtor(&c->module_normaliser); zval_ptr_dtor(&c->module_loader); - zval_ptr_dtor(&c->exception_proxy_factory); + zval_ptr_dtor(&c->exception_filter); /* Delete PHP global object from JavaScript */ if (!c->context.IsEmpty()) { @@ -401,7 +401,7 @@ static PHP_METHOD(V8Js, __construct) ZVAL_NULL(&c->module_normaliser); ZVAL_NULL(&c->module_loader); - ZVAL_NULL(&c->exception_proxy_factory); + ZVAL_NULL(&c->exception_filter); /* Include extensions used by this context */ /* Note: Extensions registered with auto_enable do not need to be added separately like this. */ @@ -882,9 +882,9 @@ static PHP_METHOD(V8Js, setModuleLoader) } /* }}} */ -/* {{{ proto void V8Js::setExceptionProxyFactory(callable factory) +/* {{{ proto void V8Js::setExceptionFilter(callable factory) */ -static PHP_METHOD(V8Js, setExceptionProxyFactory) +static PHP_METHOD(V8Js, setExceptionFilter) { zval *callable; @@ -893,7 +893,7 @@ static PHP_METHOD(V8Js, setExceptionProxyFactory) } v8js_ctx *c = Z_V8JS_CTX_OBJ_P(getThis()); - ZVAL_COPY(&c->exception_proxy_factory, callable); + ZVAL_COPY(&c->exception_filter, callable); } /* }}} */ @@ -1271,7 +1271,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmoduleloader, 0, 0, 1) ZEND_ARG_INFO(0, callable) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setexceptionproxyfactory, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setexceptionfilter, 0, 0, 1) ZEND_ARG_INFO(0, callable) ZEND_END_ARG_INFO() @@ -1314,7 +1314,7 @@ const zend_function_entry v8js_methods[] = { /* {{{ */ PHP_ME(V8Js, clearPendingException, arginfo_v8js_clearpendingexception, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) PHP_ME(V8Js, setModuleNormaliser, arginfo_v8js_setmodulenormaliser, ZEND_ACC_PUBLIC) PHP_ME(V8Js, setModuleLoader, arginfo_v8js_setmoduleloader, ZEND_ACC_PUBLIC) - PHP_ME(V8Js, setExceptionProxyFactory, arginfo_v8js_setexceptionproxyfactory, ZEND_ACC_PUBLIC) + PHP_ME(V8Js, setExceptionFilter, arginfo_v8js_setexceptionfilter, ZEND_ACC_PUBLIC) PHP_ME(V8Js, setTimeLimit, arginfo_v8js_settimelimit, ZEND_ACC_PUBLIC) PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC) PHP_ME(V8Js, setAverageObjectSize, arginfo_v8js_setaverageobjectsize, ZEND_ACC_PUBLIC) diff --git a/v8js_class.h b/v8js_class.h index 0fcdcd5..38a3ce5 100644 --- a/v8js_class.h +++ b/v8js_class.h @@ -55,7 +55,7 @@ struct v8js_ctx { zval module_normaliser; zval module_loader; - zval exception_proxy_factory; + zval exception_filter; std::vector modules_stack; std::map modules_loaded; diff --git a/v8js_object_export.cc b/v8js_object_export.cc index e6e8354..a657ff1 100644 --- a/v8js_object_export.cc +++ b/v8js_object_export.cc @@ -45,12 +45,12 @@ v8::Local v8js_propagate_exception(v8js_ctx *ctx) /* {{{ */ zval tmp_zv; - if (Z_TYPE(ctx->exception_proxy_factory) != IS_NULL) { + if (Z_TYPE(ctx->exception_filter) != IS_NULL) { zval params[1]; ZVAL_OBJ(¶ms[0], EG(exception)); Z_ADDREF_P(¶ms[0]); zend_clear_exception(); - call_user_function(EG(function_table), NULL, &ctx->exception_proxy_factory, &tmp_zv, 1, params); + call_user_function(EG(function_table), NULL, &ctx->exception_filter, &tmp_zv, 1, params); zval_ptr_dtor(¶ms[0]); if(EG(exception)) {