@@ -7,7 +7,7 @@ test(() => {
7
7
8
8
// Tag defined in JavaScript and imported into Wasm
9
9
const jsTag = new WebAssembly . Tag ( { parameters : [ "i32" ] } ) ;
10
- const jsTagIndex = builder . addImportedTag ( "module" , "jsTag" , kSig_v_i )
10
+ const jsTagIndex = builder . addImportedTag ( "module" , "jsTag" , kSig_v_i ) ;
11
11
const jsTagExn = new WebAssembly . Exception ( jsTag , [ 42 ] ) ;
12
12
const jsTagExnSamePayload = new WebAssembly . Exception ( jsTag , [ 42 ] ) ;
13
13
const jsTagExnDiffPayload = new WebAssembly . Exception ( jsTag , [ 53 ] ) ;
@@ -84,6 +84,33 @@ test(() => {
84
84
] )
85
85
. exportFunc ( ) ;
86
86
87
+ // Call a JS function that throws an exception, catches it with a 'catch'
88
+ // instruction, and returns its i32 payload.
89
+ builder
90
+ . addFunction ( "catch_js_tag_return_payload" , kSig_i_v )
91
+ . addBody ( [
92
+ kExprTry , kWasmI32 ,
93
+ kExprCallFunction , throwJSTagExnIndex ,
94
+ kExprI32Const , 0x00 ,
95
+ kExprCatch , jsTagIndex ,
96
+ kExprReturn ,
97
+ kExprEnd
98
+ ] )
99
+ . exportFunc ( ) ;
100
+
101
+ // Call a JS function that throws an exception, catches it with a 'catch'
102
+ // instruction, and throws a new exception using that payload.
103
+ builder
104
+ . addFunction ( "catch_js_tag_throw_payload" , kSig_v_v )
105
+ . addBody ( [
106
+ kExprTry , kWasmStmt ,
107
+ kExprCallFunction , throwJSTagExnIndex ,
108
+ kExprCatch , jsTagIndex ,
109
+ kExprThrow , jsTagIndex ,
110
+ kExprEnd
111
+ ] )
112
+ . exportFunc ( ) ;
113
+
87
114
const buffer = builder . toBuffer ( ) ;
88
115
89
116
WebAssembly . instantiate ( buffer , imports ) . then ( result => {
@@ -125,5 +152,19 @@ test(() => {
125
152
assert_not_equals ( e , wasmTagExnSamePayload ) ;
126
153
assert_not_equals ( e , wasmTagExnDiffPayload ) ;
127
154
}
155
+
156
+ // This function catches the exception and returns its i32 payload, which
157
+ // should match the original payload.
158
+ assert_equals ( result . instance . exports . catch_js_tag_return_payload ( ) , 42 ) ;
159
+
160
+ // This function catches the exception and throws a new exception using the
161
+ // its payload. Even if the payload is reused, the exception objects should
162
+ // not compare equal.
163
+ try {
164
+ result . instance . exports . catch_js_tag_throw_payload ( ) ;
165
+ } catch ( e ) {
166
+ assert_equals ( e . getArg ( jsTag , 0 ) , 42 ) ;
167
+ assert_not_equals ( e , jsTagExn ) ;
168
+ }
128
169
} ) ;
129
170
} , "Identity check" ) ;
0 commit comments