mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 15:18:41 +00:00
rename to setExceptionFilter
This commit is contained in:
parent
abb8b6df14
commit
4bfe2ef3ce
@ -110,7 +110,7 @@ class V8Js
|
|||||||
* The factory function will receive the PHP Exception instance that has not been caught and is
|
* The factory function will receive the PHP Exception instance that has not been caught and is
|
||||||
* due to be forwarded to JS.
|
* 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
|
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.
|
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.
|
the PHP exception to not expose unwanted information.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Test V8::setExceptionProxyFactory() : String conversion
|
Test V8::setExceptionFilter() : String conversion
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
@ -12,8 +12,8 @@ class myv8 extends V8Js
|
|||||||
}
|
}
|
||||||
|
|
||||||
$v8 = new myv8();
|
$v8 = new myv8();
|
||||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
$v8->setExceptionFilter(function (Throwable $ex) {
|
||||||
echo "exception proxy factory called.\n";
|
echo "exception filter called.\n";
|
||||||
return $ex->getMessage();
|
return $ex->getMessage();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ $v8->executeString('
|
|||||||
?>
|
?>
|
||||||
===EOF===
|
===EOF===
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
exception proxy factory called.
|
exception filter called.
|
||||||
string(6) "string"
|
string(6) "string"
|
||||||
string(4) "Oops"
|
string(4) "Oops"
|
||||||
===EOF===
|
===EOF===
|
@ -1,5 +1,5 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Test V8::setExceptionProxyFactory() : Proxy handling on exception in setModuleLoader
|
Test V8::setExceptionFilter() : Filter handling on exception in setModuleLoader
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
@ -10,8 +10,8 @@ $v8->setModuleLoader(function ($path) {
|
|||||||
throw new Error('moep');
|
throw new Error('moep');
|
||||||
});
|
});
|
||||||
|
|
||||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
$v8->setExceptionFilter(function (Throwable $ex) {
|
||||||
echo "exception proxy factory called.\n";
|
echo "exception filter called.\n";
|
||||||
return $ex->getMessage();
|
return $ex->getMessage();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ $v8->executeString('
|
|||||||
?>
|
?>
|
||||||
===EOF===
|
===EOF===
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
exception proxy factory called.
|
exception filter called.
|
||||||
string(4) "moep"
|
string(4) "moep"
|
||||||
===EOF===
|
===EOF===
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Test V8::setExceptionProxyFactory() : Proxy handling on exception in setModuleNormaliser
|
Test V8::setExceptionFilter() : Filter handling on exception in setModuleNormaliser
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
@ -13,8 +13,8 @@ $v8->setModuleLoader(function ($path) {
|
|||||||
throw new Error('moep');
|
throw new Error('moep');
|
||||||
});
|
});
|
||||||
|
|
||||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
$v8->setExceptionFilter(function (Throwable $ex) {
|
||||||
echo "exception proxy factory called.\n";
|
echo "exception filter called.\n";
|
||||||
return $ex->getMessage();
|
return $ex->getMessage();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -29,6 +29,6 @@ $v8->executeString('
|
|||||||
?>
|
?>
|
||||||
===EOF===
|
===EOF===
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
exception proxy factory called.
|
exception filter called.
|
||||||
string(5) "blarg"
|
string(5) "blarg"
|
||||||
===EOF===
|
===EOF===
|
@ -1,5 +1,5 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Test V8::setExceptionProxyFactory() : Proxy handling on exception in factory
|
Test V8::setExceptionFilter() : Filter handling on exception in factory
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
@ -12,7 +12,7 @@ class myv8 extends V8Js
|
|||||||
}
|
}
|
||||||
|
|
||||||
$v8 = new myv8();
|
$v8 = new myv8();
|
||||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
$v8->setExceptionFilter(function (Throwable $ex) {
|
||||||
throw new Exception('moep');
|
throw new Exception('moep');
|
||||||
});
|
});
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Test V8::setExceptionProxyFactory() : Simple test
|
Test V8::setExceptionFilter() : Simple test
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
@ -11,11 +11,11 @@ class myv8 extends V8Js
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExceptionProxy {
|
class ExceptionFilter {
|
||||||
private $ex;
|
private $ex;
|
||||||
|
|
||||||
public function __construct(Throwable $ex) {
|
public function __construct(Throwable $ex) {
|
||||||
echo "ExceptionProxy::__construct called!\n";
|
echo "ExceptionFilter::__construct called!\n";
|
||||||
var_dump($ex->getMessage());
|
var_dump($ex->getMessage());
|
||||||
|
|
||||||
$this->ex = $ex;
|
$this->ex = $ex;
|
||||||
@ -28,9 +28,9 @@ class ExceptionProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$v8 = new myv8();
|
$v8 = new myv8();
|
||||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
$v8->setExceptionFilter(function (Throwable $ex) {
|
||||||
echo "exception proxy factory called.\n";
|
echo "exception filter called.\n";
|
||||||
return new ExceptionProxy($ex);
|
return new ExceptionFilter($ex);
|
||||||
});
|
});
|
||||||
|
|
||||||
$v8->executeString('
|
$v8->executeString('
|
||||||
@ -38,15 +38,15 @@ $v8->executeString('
|
|||||||
PHP.throwException("Oops");
|
PHP.throwException("Oops");
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
var_dump(e.getMessage()); // calls ExceptionProxy::getMessage
|
var_dump(e.getMessage()); // calls ExceptionFilter::getMessage
|
||||||
var_dump(typeof e.getTrace);
|
var_dump(typeof e.getTrace);
|
||||||
}
|
}
|
||||||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
||||||
?>
|
?>
|
||||||
===EOF===
|
===EOF===
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
exception proxy factory called.
|
exception filter called.
|
||||||
ExceptionProxy::__construct called!
|
ExceptionFilter::__construct called!
|
||||||
string(4) "Oops"
|
string(4) "Oops"
|
||||||
getMessage called
|
getMessage called
|
||||||
string(4) "Oops"
|
string(4) "Oops"
|
@ -92,7 +92,7 @@ static void v8js_free_storage(zend_object *object) /* {{{ */
|
|||||||
zval_ptr_dtor(&c->pending_exception);
|
zval_ptr_dtor(&c->pending_exception);
|
||||||
zval_ptr_dtor(&c->module_normaliser);
|
zval_ptr_dtor(&c->module_normaliser);
|
||||||
zval_ptr_dtor(&c->module_loader);
|
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 */
|
/* Delete PHP global object from JavaScript */
|
||||||
if (!c->context.IsEmpty()) {
|
if (!c->context.IsEmpty()) {
|
||||||
@ -401,7 +401,7 @@ static PHP_METHOD(V8Js, __construct)
|
|||||||
|
|
||||||
ZVAL_NULL(&c->module_normaliser);
|
ZVAL_NULL(&c->module_normaliser);
|
||||||
ZVAL_NULL(&c->module_loader);
|
ZVAL_NULL(&c->module_loader);
|
||||||
ZVAL_NULL(&c->exception_proxy_factory);
|
ZVAL_NULL(&c->exception_filter);
|
||||||
|
|
||||||
/* Include extensions used by this context */
|
/* Include extensions used by this context */
|
||||||
/* Note: Extensions registered with auto_enable do not need to be added separately like this. */
|
/* 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;
|
zval *callable;
|
||||||
|
|
||||||
@ -893,7 +893,7 @@ static PHP_METHOD(V8Js, setExceptionProxyFactory)
|
|||||||
}
|
}
|
||||||
|
|
||||||
v8js_ctx *c = Z_V8JS_CTX_OBJ_P(getThis());
|
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_ARG_INFO(0, callable)
|
||||||
ZEND_END_ARG_INFO()
|
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_ARG_INFO(0, callable)
|
||||||
ZEND_END_ARG_INFO()
|
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, clearPendingException, arginfo_v8js_clearpendingexception, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
|
||||||
PHP_ME(V8Js, setModuleNormaliser, arginfo_v8js_setmodulenormaliser, ZEND_ACC_PUBLIC)
|
PHP_ME(V8Js, setModuleNormaliser, arginfo_v8js_setmodulenormaliser, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(V8Js, setModuleLoader, arginfo_v8js_setmoduleloader, 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, setTimeLimit, arginfo_v8js_settimelimit, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
|
PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(V8Js, setAverageObjectSize, arginfo_v8js_setaverageobjectsize, ZEND_ACC_PUBLIC)
|
PHP_ME(V8Js, setAverageObjectSize, arginfo_v8js_setaverageobjectsize, ZEND_ACC_PUBLIC)
|
||||||
|
@ -55,7 +55,7 @@ struct v8js_ctx {
|
|||||||
|
|
||||||
zval module_normaliser;
|
zval module_normaliser;
|
||||||
zval module_loader;
|
zval module_loader;
|
||||||
zval exception_proxy_factory;
|
zval exception_filter;
|
||||||
|
|
||||||
std::vector<char *> modules_stack;
|
std::vector<char *> modules_stack;
|
||||||
std::map<char *, v8js_persistent_value_t, cmp_str> modules_loaded;
|
std::map<char *, v8js_persistent_value_t, cmp_str> modules_loaded;
|
||||||
|
@ -45,12 +45,12 @@ v8::Local<v8::Value> v8js_propagate_exception(v8js_ctx *ctx) /* {{{ */
|
|||||||
|
|
||||||
zval tmp_zv;
|
zval tmp_zv;
|
||||||
|
|
||||||
if (Z_TYPE(ctx->exception_proxy_factory) != IS_NULL) {
|
if (Z_TYPE(ctx->exception_filter) != IS_NULL) {
|
||||||
zval params[1];
|
zval params[1];
|
||||||
ZVAL_OBJ(¶ms[0], EG(exception));
|
ZVAL_OBJ(¶ms[0], EG(exception));
|
||||||
Z_ADDREF_P(¶ms[0]);
|
Z_ADDREF_P(¶ms[0]);
|
||||||
zend_clear_exception();
|
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]);
|
zval_ptr_dtor(¶ms[0]);
|
||||||
|
|
||||||
if(EG(exception)) {
|
if(EG(exception)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user