11cb0ef41Sopenharmony_ci// META: global=window,dedicatedworker,jsshell 21cb0ef41Sopenharmony_ci// META: script=/wasm/jsapi/assertions.js 31cb0ef41Sopenharmony_ci// META: script=/wasm/jsapi/wasm-module-builder.js 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_citest(() => { 61cb0ef41Sopenharmony_ci const tag = new WebAssembly.Tag({ parameters: ["i32"] }); 71cb0ef41Sopenharmony_ci const exn = new WebAssembly.Exception(tag, [42]); 81cb0ef41Sopenharmony_ci const exn_same_payload = new WebAssembly.Exception(tag, [42]); 91cb0ef41Sopenharmony_ci const exn_diff_payload = new WebAssembly.Exception(tag, [53]); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci const builder = new WasmModuleBuilder(); 121cb0ef41Sopenharmony_ci const jsfuncIndex = builder.addImport("module", "jsfunc", kSig_v_v); 131cb0ef41Sopenharmony_ci const tagIndex = builder.addImportedTag("module", "tag", kSig_v_i); 141cb0ef41Sopenharmony_ci const imports = { 151cb0ef41Sopenharmony_ci module: { 161cb0ef41Sopenharmony_ci jsfunc: function() { throw exn; }, 171cb0ef41Sopenharmony_ci tag: tag 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci }; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci builder 221cb0ef41Sopenharmony_ci .addFunction("catch_rethrow", kSig_v_v) 231cb0ef41Sopenharmony_ci .addBody([ 241cb0ef41Sopenharmony_ci kExprTry, kWasmStmt, 251cb0ef41Sopenharmony_ci kExprCallFunction, jsfuncIndex, 261cb0ef41Sopenharmony_ci kExprCatch, tagIndex, 271cb0ef41Sopenharmony_ci kExprDrop, 281cb0ef41Sopenharmony_ci kExprRethrow, 0x00, 291cb0ef41Sopenharmony_ci kExprEnd 301cb0ef41Sopenharmony_ci ]) 311cb0ef41Sopenharmony_ci .exportFunc(); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci builder 341cb0ef41Sopenharmony_ci .addFunction("catch_all_rethrow", kSig_v_v) 351cb0ef41Sopenharmony_ci .addBody([ 361cb0ef41Sopenharmony_ci kExprTry, kWasmStmt, 371cb0ef41Sopenharmony_ci kExprCallFunction, jsfuncIndex, 381cb0ef41Sopenharmony_ci kExprCatchAll, 391cb0ef41Sopenharmony_ci kExprRethrow, 0x00, 401cb0ef41Sopenharmony_ci kExprEnd 411cb0ef41Sopenharmony_ci ]) 421cb0ef41Sopenharmony_ci .exportFunc(); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci const buffer = builder.toBuffer(); 451cb0ef41Sopenharmony_ci WebAssembly.instantiate(buffer, imports).then(result => { 461cb0ef41Sopenharmony_ci try { 471cb0ef41Sopenharmony_ci result.instance.exports.catch_rethrow(); 481cb0ef41Sopenharmony_ci } catch (e) { 491cb0ef41Sopenharmony_ci assert_equals(e, exn); 501cb0ef41Sopenharmony_ci assert_not_equals(e, exn_same_payload); 511cb0ef41Sopenharmony_ci assert_not_equals(e, exn_diff_payload); 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci try { 541cb0ef41Sopenharmony_ci result.instance.exports.catch_all_rethrow(); 551cb0ef41Sopenharmony_ci } catch (e) { 561cb0ef41Sopenharmony_ci assert_equals(e, exn); 571cb0ef41Sopenharmony_ci assert_not_equals(e, exn_same_payload); 581cb0ef41Sopenharmony_ci assert_not_equals(e, exn_diff_payload); 591cb0ef41Sopenharmony_ci } 601cb0ef41Sopenharmony_ci }); 611cb0ef41Sopenharmony_ci}, "Identity check"); 62