MCPcopy Index your code
hub / github.com/nodejs/node / TestCatchJS

Function TestCatchJS

deps/v8/test/mjsunit/wasm/exceptions-api.js:154–184  ·  view source on GitHub ↗
(types_str, types, values)

Source from the content-addressed store, hash-verified

152})();
153
154function TestCatchJS(types_str, types, values) {
155 // Create a JS exception, catch it in wasm and check the unpacked value(s).
156 let builder = new WasmModuleBuilder();
157 let js_tag = new WebAssembly.Tag({parameters: types_str});
158 let js_func_index = builder.addImport('m', 'js_func', kSig_v_v);
159 let sig1 = makeSig(types, []);
160 let sig2 = makeSig([], types);
161 let js_tag_index = builder.addImportedTag("m", "js_tag", sig1);
162 let tag_index = builder.addTag(sig1);
163 let return_type = builder.addType(sig2);
164 builder.addExportOfKind("wasm_tag", kExternalTag, tag_index);
165 builder.addFunction("catch", sig2)
166 .addBody([
167 kExprTry, return_type,
168 kExprCallFunction, js_func_index,
169 kExprUnreachable,
170 kExprCatch, js_tag_index,
171 kExprCatch, tag_index,
172 kExprEnd
173 ]).exportFunc();
174 let exception;
175 function js_func() {
176 throw exception;
177 }
178 let expected = values.length == 1 ? values[0] : values;
179 let instance = builder.instantiate({m: {js_func, js_tag}});
180 exception = new WebAssembly.Exception(js_tag, values);
181 assertEquals(expected, instance.exports.catch());
182 exception = new WebAssembly.Exception(instance.exports.wasm_tag, values);
183 assertEquals(expected, instance.exports.catch());
184}
185
186(function TestCatchJSExceptionWithPayload() {
187 print(arguments.callee.name);

Callers 1

exceptions-api.jsFile · 0.85

Calls 11

addImportMethod · 0.95
addImportedTagMethod · 0.95
addTagMethod · 0.95
addTypeMethod · 0.95
addExportOfKindMethod · 0.95
addFunctionMethod · 0.95
instantiateMethod · 0.95
makeSigFunction · 0.70
assertEqualsFunction · 0.50
exportFuncMethod · 0.45
addBodyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…