File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -413,5 +413,7 @@ via `getPrevious` method.
413
413
414
414
Consider that the JS code has access to methods like ` getTrace ` on the exception
415
415
object. This might be unwanted behaviour, if you execute untrusted code.
416
- Using ` setExceptionFilter ` method a callable can be provided, that converts
417
- the PHP exception to not expose unwanted information.
416
+ Using ` setExceptionFilter ` method a callable can be provided, that may convert
417
+ the PHP exception to some other value that is safe to expose. The filter may
418
+ also decide not to propagate the exception to JS at all by either re-throwing
419
+ the passed exception or throwing another exception.
Original file line number Diff line number Diff line change 1
1
--TEST--
2
- Test V8::setExceptionFilter() : Filter handling on exception in factory
2
+ Test V8::setExceptionFilter() : Filter handling on exception in converter
3
3
--SKIPIF--
4
4
<?php require_once (dirname (__FILE__ ) . '/skipif.inc ' ); ?>
5
5
--FILE--
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test V8::setExceptionFilter() : re-throw exception in exception filter
3
+ --SKIPIF--
4
+ <?php require_once (dirname (__FILE__ ) . '/skipif.inc ' ); ?>
5
+ --FILE--
6
+ <?php
7
+ class myv8 extends V8Js
8
+ {
9
+ public function throwException (string $ message ) {
10
+ throw new Exception ($ message );
11
+ }
12
+ }
13
+
14
+ $ v8 = new myv8 ();
15
+ $ v8 ->setExceptionFilter (function (Throwable $ ex ) {
16
+ // re-throw exception so it is not forwarded
17
+ throw $ ex ;
18
+ });
19
+
20
+ try {
21
+ $ v8 ->executeString ('
22
+ try {
23
+ PHP.throwException("Oops");
24
+ print("done \\n");
25
+ }
26
+ catch (e) {
27
+ print("caught \\n");
28
+ var_dump(e);
29
+ }
30
+ ' , null , V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS );
31
+ } catch (Exception $ ex ) {
32
+ echo "caught in php: " . $ ex ->getMessage () . PHP_EOL ;
33
+ }
34
+ ?>
35
+ ===EOF===
36
+ --EXPECT--
37
+ caught in php: Oops
38
+ ===EOF===
You can’t perform that action at this time.
0 commit comments