@@ -47,11 +47,38 @@ test(() => {
47
47
] )
48
48
. exportFunc ( ) ;
49
49
50
+ // Call a JS function that throws an exception, catches it with a 'catch'
51
+ // instruction, and returns its i32 payload.
52
+ builder
53
+ . addFunction ( "catch_js_tag_return_payload" , kSig_i_v )
54
+ . addBody ( [
55
+ kExprTry , kWasmI32 ,
56
+ kExprCallFunction , throwJSTagExnIndex ,
57
+ kExprI32Const , 0x00 ,
58
+ kExprCatch , jsTagIndex ,
59
+ kExprReturn ,
60
+ kExprEnd ,
61
+ ] )
62
+ . exportFunc ( ) ;
63
+
64
+ // Call a JS function that throws an exception, catches it with a 'catch'
65
+ // instruction, and throws a new exception using that payload.
66
+ builder
67
+ . addFunction ( "catch_js_tag_throw_payload" , kSig_v_v )
68
+ . addBody ( [
69
+ kExprTry , kWasmStmt ,
70
+ kExprCallFunction , throwJSTagExnIndex ,
71
+ kExprCatch , jsTagIndex ,
72
+ kExprThrow , jsTagIndex ,
73
+ kExprEnd ,
74
+ ] )
75
+ . exportFunc ( ) ;
76
+
50
77
const buffer = builder . toBuffer ( ) ;
51
78
52
- // The exception object's identity should be preserved across 'rethrow's in
53
- // Wasm code. Do tests with a tag defined in JS.
54
79
WebAssembly . instantiate ( buffer , imports ) . then ( result => {
80
+ // The exception object's identity should be preserved across 'rethrow's in
81
+ // Wasm code. Do tests with a tag defined in JS.
55
82
try {
56
83
result . instance . exports . catch_js_tag_rethrow ( ) ;
57
84
} catch ( e ) {
@@ -68,5 +95,19 @@ test(() => {
68
95
assert_not_equals ( e , jsTagExnSamePayload ) ;
69
96
assert_not_equals ( e , jsTagExnDiffPayload ) ;
70
97
}
98
+
99
+ // This function catches the exception and returns its i32 payload, which
100
+ // should match the original payload.
101
+ assert_equals ( result . instance . exports . catch_js_tag_return_payload ( ) , 42 ) ;
102
+
103
+ // This function catches the exception and throws a new exception using the
104
+ // its payload. Even if the payload is reused, the exception objects should
105
+ // not compare equal.
106
+ try {
107
+ result . instance . exports . catch_js_tag_throw_payload ( ) ;
108
+ } catch ( e ) {
109
+ assert_equals ( e . getArg ( jsTag , 0 ) , 42 ) ;
110
+ assert_not_equals ( e , jsTagExn ) ;
111
+ }
71
112
} ) ;
72
113
} , "Identity check" ) ;
0 commit comments