File tree 2 files changed +44
-3
lines changed
2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test V8Js::setModuleLoader : Forward exceptions
3
+ --SKIPIF--
4
+ <?php require_once (dirname (__FILE__ ) . '/skipif.inc ' ); ?>
5
+ --FILE--
6
+ <?php
7
+
8
+ $ JS = <<< EOT
9
+ var foo = require("./test");
10
+ EOT ;
11
+
12
+ $ v8 = new V8Js ();
13
+ $ v8 ->setModuleLoader (function ($ module ) {
14
+ throw new Exception ('some exception ' );
15
+ });
16
+
17
+ $ v8 ->executeString ($ JS , 'module.js ' , V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS );
18
+ ?>
19
+ ===EOF===
20
+ --EXPECTF--
21
+ Fatal error: Uncaught Exception: some exception in %s%ecommonjs_exception_001.php:9
22
+ Stack trace:
23
+ #0 [internal function]: {closure}('test')
24
+ #1 %s%ecommonjs_exception_001.php(12): V8Js->executeString('var foo = requi...', 'module.js', 4)
25
+ #2 {main}
26
+
27
+ Next V8JsScriptException: module.js:1: Exception: some exception in %s%ecommonjs_exception_001.php:9
28
+ Stack trace:
29
+ #0 [internal function]: {closure}('test')
30
+ #1 %s%ecommonjs_exception_001.php(12): V8Js->executeString('var foo = requi...', 'module.js', 4)
31
+ #2 {main} in %s%ecommonjs_exception_001.php:12
32
+ Stack trace:
33
+ #0 %s%ecommonjs_exception_001.php(12): V8Js->executeString('var foo = requi...', 'module.js', 4)
34
+ #1 {main}
35
+ thrown in %s%ecommonjs_exception_001.php on line 12
Original file line number Diff line number Diff line change @@ -390,9 +390,15 @@ V8JS_METHOD(require)
390
390
efree (normalised_module_id);
391
391
efree (normalised_path);
392
392
393
- // Clear the PHP exception and throw it in V8 instead
394
- zend_clear_exception (TSRMLS_C);
395
- info.GetReturnValue ().Set (isolate->ThrowException (V8JS_SYM (" Module loader callback exception" )));
393
+ if (c->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
394
+ zval tmp_zv;
395
+ ZVAL_OBJ (&tmp_zv, EG (exception ));
396
+ info.GetReturnValue ().Set (isolate->ThrowException (zval_to_v8js (&tmp_zv, isolate)));
397
+ zend_clear_exception ();
398
+ } else {
399
+ v8js_terminate_execution (isolate);
400
+ }
401
+
396
402
return ;
397
403
}
398
404
You can’t perform that action at this time.
0 commit comments