mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 08:11:52 +00:00
run exceptions thrown in require() through proxy factory as well
This commit is contained in:
parent
456814703c
commit
7422ef2383
32
tests/exception_proxy_002.phpt
Normal file
32
tests/exception_proxy_002.phpt
Normal file
@ -0,0 +1,32 @@
|
||||
--TEST--
|
||||
Test V8::setExceptionProxyFactory() : Proxy handling on exception in setModuleLoader
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$v8 = new V8Js();
|
||||
$v8->setModuleLoader(function ($path) {
|
||||
throw new Error('moep');
|
||||
});
|
||||
|
||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
||||
echo "exception proxy factory called.\n";
|
||||
return $ex->getMessage();
|
||||
});
|
||||
|
||||
$v8->executeString('
|
||||
try {
|
||||
require("file");
|
||||
} catch(e) {
|
||||
var_dump(e);
|
||||
}
|
||||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
||||
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
exception proxy factory called.
|
||||
string(4) "moep"
|
||||
===EOF===
|
||||
|
34
tests/exception_proxy_003.phpt
Normal file
34
tests/exception_proxy_003.phpt
Normal file
@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
Test V8::setExceptionProxyFactory() : Proxy handling on exception in setModuleNormaliser
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$v8 = new V8Js();
|
||||
$v8->setModuleNormaliser(function ($path) {
|
||||
throw new Error('blarg');
|
||||
});
|
||||
$v8->setModuleLoader(function ($path) {
|
||||
throw new Error('moep');
|
||||
});
|
||||
|
||||
$v8->setExceptionProxyFactory(function (Throwable $ex) {
|
||||
echo "exception proxy factory called.\n";
|
||||
return $ex->getMessage();
|
||||
});
|
||||
|
||||
$v8->executeString('
|
||||
try {
|
||||
require("file");
|
||||
} catch(e) {
|
||||
var_dump(e);
|
||||
}
|
||||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
||||
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
exception proxy factory called.
|
||||
string(5) "blarg"
|
||||
===EOF===
|
@ -19,6 +19,7 @@
|
||||
#include "php_v8js_macros.h"
|
||||
#include "v8js_commonjs.h"
|
||||
#include "v8js_exceptions.h"
|
||||
#include "v8js_object_export.h"
|
||||
|
||||
extern "C" {
|
||||
#include "zend_exceptions.h"
|
||||
@ -337,14 +338,7 @@ V8JS_METHOD(require)
|
||||
|
||||
// Check if an exception was thrown
|
||||
if (EG(exception)) {
|
||||
if (c->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
|
||||
zval tmp_zv;
|
||||
ZVAL_OBJ(&tmp_zv, EG(exception));
|
||||
info.GetReturnValue().Set(isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate)));
|
||||
zend_clear_exception();
|
||||
} else {
|
||||
v8js_terminate_execution(isolate);
|
||||
}
|
||||
info.GetReturnValue().Set(v8js_propagate_exception(c));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -466,15 +460,7 @@ V8JS_METHOD(require)
|
||||
efree(normalised_module_id);
|
||||
efree(normalised_path);
|
||||
|
||||
if (c->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
|
||||
zval tmp_zv;
|
||||
ZVAL_OBJ(&tmp_zv, EG(exception));
|
||||
info.GetReturnValue().Set(isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate)));
|
||||
zend_clear_exception();
|
||||
} else {
|
||||
v8js_terminate_execution(isolate);
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(v8js_propagate_exception(c));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -485,7 +471,7 @@ V8JS_METHOD(require)
|
||||
|
||||
efree(normalised_path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(Z_TYPE(module_code) == IS_OBJECT) {
|
||||
v8::Local<v8::Object> newobj = zval_to_v8js(&module_code, isolate)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked();
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define V8JS_OBJECT_EXPORT_H
|
||||
|
||||
v8::Local<v8::Value> v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate);
|
||||
v8::Local<v8::Value> v8js_propagate_exception(v8js_ctx *ctx);
|
||||
|
||||
|
||||
typedef enum {
|
||||
|
Loading…
Reference in New Issue
Block a user