Best JavaScript code snippet using wpt
exceptions.js
Source:exceptions.js
...7// The following method doesn't attempt to catch an raised exception.8(function TestThrowSimple() {9 print(arguments.callee.name);10 let builder = new WasmModuleBuilder();11 let except = builder.addException(kSig_v_v);12 builder.addFunction("throw_if_param_not_zero", kSig_i_i)13 .addBody([14 kExprLocalGet, 0,15 kExprI32Const, 0,16 kExprI32Ne,17 kExprIf, kWasmVoid,18 kExprThrow, except,19 kExprEnd,20 kExprI32Const, 121 ]).exportFunc();22 let instance = builder.instantiate();23 assertEquals(1, instance.exports.throw_if_param_not_zero(0));24 assertWasmThrows(instance, except, [], () => instance.exports.throw_if_param_not_zero(10));25 assertWasmThrows(instance, except, [], () => instance.exports.throw_if_param_not_zero(-1));26})();27// Test that empty try/catch blocks work.28(function TestCatchEmptyBlocks() {29 print(arguments.callee.name);30 let builder = new WasmModuleBuilder();31 let except = builder.addException(kSig_v_v);32 builder.addFunction("catch_empty_try", kSig_v_v)33 .addBody([34 kExprTry, kWasmVoid,35 kExprCatch, except,36 kExprEnd,37 ]).exportFunc();38 let instance = builder.instantiate();39 assertDoesNotThrow(instance.exports.catch_empty_try);40})();41// Now that we know throwing works, we test catching the exceptions we raise.42(function TestCatchSimple() {43 print(arguments.callee.name);44 let builder = new WasmModuleBuilder();45 let except = builder.addException(kSig_v_v);46 builder.addFunction("simple_throw_catch_to_0_1", kSig_i_i)47 .addBody([48 kExprTry, kWasmI32,49 kExprLocalGet, 0,50 kExprI32Eqz,51 kExprIf, kWasmVoid,52 kExprThrow, except,53 kExprEnd,54 kExprI32Const, 42,55 kExprCatch, except,56 kExprI32Const, 23,57 kExprEnd58 ]).exportFunc();59 let instance = builder.instantiate();60 assertEquals(23, instance.exports.simple_throw_catch_to_0_1(0));61 assertEquals(42, instance.exports.simple_throw_catch_to_0_1(1));62})();63(function TestTrapNotCaught() {64 print(arguments.callee.name);65 let builder = new WasmModuleBuilder();66 builder.addFunction('unreachable_in_try', kSig_v_v)67 .addBody([68 kExprTry, kWasmVoid,69 kExprUnreachable,70 kExprCatchAll,71 kExprEnd72 ]).exportFunc();73 builder.addFunction('unreachable_in_try_unwind', kSig_v_v)74 .addBody([75 kExprTry, kWasmVoid,76 kExprUnreachable,77 kExprUnwind,78 kExprEnd79 ]).exportFunc();80 let instance = builder.instantiate();81 assertTraps(kTrapUnreachable, () => instance.exports.unreachable_in_try());82 assertTraps(kTrapUnreachable, () => instance.exports.unreachable_in_try_unwind());83})();84(function TestTrapInCalleeNotCaught() {85 print(arguments.callee.name);86 let builder = new WasmModuleBuilder();87 let func_div = builder.addFunction('div', kSig_i_ii).addBody([88 kExprLocalGet, 0,89 kExprLocalGet, 1,90 kExprI32DivU91 ]);92 builder.addFunction('trap_in_callee', kSig_i_ii)93 .addBody([94 kExprTry, kWasmI32,95 kExprLocalGet, 0,96 kExprLocalGet, 1,97 kExprCallFunction, func_div.index,98 kExprCatchAll,99 kExprI32Const, 11,100 kExprEnd101 ]).exportFunc();102 builder.addFunction('trap_in_callee_unwind', kSig_i_ii)103 .addBody([104 kExprTry, kWasmI32,105 kExprLocalGet, 0,106 kExprLocalGet, 1,107 kExprCallFunction, func_div.index,108 kExprUnwind,109 kExprI32Const, 11,110 kExprEnd111 ]).exportFunc();112 let instance = builder.instantiate();113 assertEquals(3, instance.exports.trap_in_callee(7, 2));114 assertTraps(kTrapDivByZero, () => instance.exports.trap_in_callee(1, 0));115 assertTraps(kTrapDivByZero, () => instance.exports.trap_in_callee_unwind(1, 0));116})();117(function TestTrapViaJSNotCaught() {118 print(arguments.callee.name);119 let builder = new WasmModuleBuilder();120 let imp = builder.addImport('imp', 'ort', kSig_i_v);121 builder.addFunction('div', kSig_i_ii)122 .addBody([123 kExprLocalGet, 0,124 kExprLocalGet, 1,125 kExprI32DivU126 ]).exportFunc();127 builder.addFunction('call_import', kSig_i_v)128 .addBody([129 kExprTry, kWasmI32,130 kExprCallFunction, imp,131 kExprCatchAll,132 kExprI32Const, 11,133 kExprEnd134 ]).exportFunc();135 builder.addFunction('call_import_unwind', kSig_i_v)136 .addBody([137 kExprTry, kWasmI32,138 kExprCallFunction, imp,139 kExprUnwind,140 kExprI32Const, 11,141 kExprEnd142 ]).exportFunc();143 let exception = undefined;144 let instance;145 function js_import() {146 try {147 instance.exports.div(1, 0);148 } catch (e) {149 exception = e;150 }151 throw exception;152 }153 instance = builder.instantiate({imp: {ort: js_import}});154 let caught = undefined;155 try {156 let res = instance.exports.call_import();157 assertUnreachable('call_import should trap, but returned with ' + res);158 } catch (e) {159 caught = e;160 }161 assertSame(exception, caught);162 assertInstanceof(exception, WebAssembly.RuntimeError);163 assertEquals(exception.message, kTrapMsgs[kTrapDivByZero]);164 // Same test with unwind instead of catch_all.165 caught = undefined;166 try {167 let res = instance.exports.call_import_unwind();168 assertUnreachable('call_import_unwind should trap, but returned with ' + res);169 } catch (e) {170 caught = e;171 }172 assertSame(exception, caught);173 assertInstanceof(exception, WebAssembly.RuntimeError);174 assertEquals(exception.message, kTrapMsgs[kTrapDivByZero]);175})();176(function TestManuallyThrownRuntimeErrorCaught() {177 print(arguments.callee.name);178 let builder = new WasmModuleBuilder();179 let imp = builder.addImport('imp', 'ort', kSig_i_v);180 builder.addFunction('call_import', kSig_i_v)181 .addBody([182 kExprTry, kWasmI32,183 kExprCallFunction, imp,184 kExprCatchAll,185 kExprI32Const, 11,186 kExprEnd187 ]).exportFunc();188 builder.addFunction('call_import_unwind', kSig_i_v)189 .addBody([190 kExprTry, kWasmI32,191 kExprCallFunction, imp,192 kExprUnwind,193 kExprI32Const, 11,194 kExprEnd195 ]).exportFunc();196 function throw_exc() {197 throw new WebAssembly.RuntimeError('My user text');198 }199 let instance = builder.instantiate({imp: {ort: throw_exc}});200 assertEquals(11, instance.exports.call_import());201 assertThrows(instance.exports.call_import_unwind, WebAssembly.RuntimeError, "My user text");202})();203(function TestExnWithWasmProtoNotCaught() {204 print(arguments.callee.name);205 let builder = new WasmModuleBuilder();206 let except = builder.addException(kSig_v_v);207 let imp = builder.addImport('imp', 'ort', kSig_v_v);208 let throw_fn = builder.addFunction('throw', kSig_v_v)209 .addBody([kExprThrow, except])210 .exportFunc();211 builder.addFunction('test', kSig_v_v)212 .addBody([213 // Calling "throw" directly should produce the expected exception.214 kExprTry, kWasmVoid,215 kExprCallFunction, throw_fn.index,216 kExprCatch, except,217 kExprEnd,218 // Calling through JS produces a wrapped exceptions which does not match219 // the catch.220 kExprTry, kWasmVoid,221 kExprCallFunction, imp,222 kExprCatch, except,223 kExprEnd224 ]).exportFunc();225 let instance;226 let wrapped_exn;227 function js_import() {228 try {229 instance.exports.throw();230 } catch (e) {231 wrapped_exn = new Error();232 wrapped_exn.__proto__ = e;233 throw wrapped_exn;234 }235 }236 instance = builder.instantiate({imp: {ort: js_import}});237 let caught = undefined;238 try {239 instance.exports.test();240 } catch (e) {241 caught = e;242 }243 assertTrue(!!caught, 'should have trapped');244 assertEquals(caught, wrapped_exn);245 assertInstanceof(caught.__proto__, WebAssembly.RuntimeError);246})();247// Test that we can distinguish which exception was thrown by using a cascaded248// sequence of nested try blocks with a single catch block each.249(function TestCatchComplex1() {250 print(arguments.callee.name);251 let builder = new WasmModuleBuilder();252 let except1 = builder.addException(kSig_v_v);253 let except2 = builder.addException(kSig_v_v);254 let except3 = builder.addException(kSig_v_v);255 builder.addFunction("catch_complex", kSig_i_i)256 .addBody([257 kExprTry, kWasmI32,258 kExprTry, kWasmI32,259 kExprLocalGet, 0,260 kExprI32Eqz,261 kExprIf, kWasmVoid,262 kExprThrow, except1,263 kExprElse,264 kExprLocalGet, 0,265 kExprI32Const, 1,266 kExprI32Eq,267 kExprIf, kWasmVoid,268 kExprThrow, except2,269 kExprElse,270 kExprThrow, except3,271 kExprEnd,272 kExprEnd,273 kExprI32Const, 2,274 kExprCatch, except1,275 kExprI32Const, 3,276 kExprEnd,277 kExprCatch, except2,278 kExprI32Const, 4,279 kExprEnd,280 ]).exportFunc();281 let instance = builder.instantiate();282 assertEquals(3, instance.exports.catch_complex(0));283 assertEquals(4, instance.exports.catch_complex(1));284 assertWasmThrows(instance, except3, [], () => instance.exports.catch_complex(2));285})();286// Test that we can distinguish which exception was thrown by using a single287// try block with multiple associated catch blocks in sequence.288(function TestCatchComplex2() {289 print(arguments.callee.name);290 let builder = new WasmModuleBuilder();291 let except1 = builder.addException(kSig_v_v);292 let except2 = builder.addException(kSig_v_v);293 let except3 = builder.addException(kSig_v_v);294 builder.addFunction("catch_complex", kSig_i_i)295 .addBody([296 kExprTry, kWasmI32,297 kExprLocalGet, 0,298 kExprI32Eqz,299 kExprIf, kWasmVoid,300 kExprThrow, except1,301 kExprElse,302 kExprLocalGet, 0,303 kExprI32Const, 1,304 kExprI32Eq,305 kExprIf, kWasmVoid,306 kExprThrow, except2,307 kExprElse,308 kExprThrow, except3,309 kExprEnd,310 kExprEnd,311 kExprI32Const, 2,312 kExprCatch, except1,313 kExprI32Const, 3,314 kExprCatch, except2,315 kExprI32Const, 4,316 kExprEnd,317 ]).exportFunc();318 let instance = builder.instantiate();319 assertEquals(3, instance.exports.catch_complex(0));320 assertEquals(4, instance.exports.catch_complex(1));321 assertWasmThrows(instance, except3, [], () => instance.exports.catch_complex(2));322})();323// Test throwing an exception with multiple values.324(function TestThrowMultipleValues() {325 print(arguments.callee.name);326 let builder = new WasmModuleBuilder();327 let except = builder.addException(kSig_v_ii);328 builder.addFunction("throw_1_2", kSig_v_v)329 .addBody([330 kExprI32Const, 1,331 kExprI32Const, 2,332 kExprThrow, except,333 ]).exportFunc();334 let instance = builder.instantiate();335 assertWasmThrows(instance, except, [0, 1, 0, 2], () => instance.exports.throw_1_2());336})();337// Test throwing/catching the i32 parameter value.338(function TestThrowCatchParamI() {339 print(arguments.callee.name);340 let builder = new WasmModuleBuilder();341 let except = builder.addException(kSig_v_i);342 builder.addFunction("throw_catch_param", kSig_i_i)343 .addBody([344 kExprTry, kWasmI32,345 kExprLocalGet, 0,346 kExprThrow, except,347 kExprI32Const, 2,348 kExprCatch, except,349 kExprReturn,350 kExprEnd,351 ]).exportFunc();352 let instance = builder.instantiate();353 assertEquals(0, instance.exports.throw_catch_param(0));354 assertEquals(1, instance.exports.throw_catch_param(1));355 assertEquals(10, instance.exports.throw_catch_param(10));356})();357// Test the encoding of a thrown exception with an integer exception.358(function TestThrowParamI() {359 print(arguments.callee.name);360 let builder = new WasmModuleBuilder();361 let except = builder.addException(kSig_v_i);362 builder.addFunction("throw_param", kSig_v_i)363 .addBody([364 kExprLocalGet, 0,365 kExprThrow, except,366 ]).exportFunc();367 let instance = builder.instantiate();368 assertWasmThrows(instance, except, [0, 5], () => instance.exports.throw_param(5));369 assertWasmThrows(instance, except, [6, 31026], () => instance.exports.throw_param(424242));370})();371// Test throwing/catching the f32 parameter value.372(function TestThrowCatchParamF() {373 print(arguments.callee.name);374 let builder = new WasmModuleBuilder();375 let except = builder.addException(kSig_v_f);376 builder.addFunction("throw_catch_param", kSig_f_f)377 .addBody([378 kExprTry, kWasmF32,379 kExprLocalGet, 0,380 kExprThrow, except,381 kExprF32Const, 0, 0, 0, 0,382 kExprCatch, except,383 kExprReturn,384 kExprEnd,385 ]).exportFunc();386 let instance = builder.instantiate();387 assertEquals(5.0, instance.exports.throw_catch_param(5.0));388 assertEquals(10.5, instance.exports.throw_catch_param(10.5));389})();390// Test the encoding of a thrown exception with a float value.391(function TestThrowParamF() {392 print(arguments.callee.name);393 let builder = new WasmModuleBuilder();394 let except = builder.addException(kSig_v_f);395 builder.addFunction("throw_param", kSig_v_f)396 .addBody([397 kExprLocalGet, 0,398 kExprThrow, except,399 ]).exportFunc();400 let instance = builder.instantiate();401 assertWasmThrows(instance, except, [16544, 0], () => instance.exports.throw_param(5.0));402 assertWasmThrows(instance, except, [16680, 0], () => instance.exports.throw_param(10.5));403})();404// Test throwing/catching an I64 value405(function TestThrowCatchParamL() {406 print(arguments.callee.name);407 let builder = new WasmModuleBuilder();408 let except = builder.addException(kSig_v_l);409 builder.addFunction("throw_catch_param", kSig_i_i)410 .addLocals(kWasmI64, 1)411 .addBody([412 kExprLocalGet, 0,413 kExprI64UConvertI32,414 kExprLocalSet, 1,415 kExprTry, kWasmI32,416 kExprLocalGet, 1,417 kExprThrow, except,418 kExprI32Const, 2,419 kExprCatch, except,420 kExprLocalGet, 1,421 kExprI64Eq,422 kExprIf, kWasmI32,423 kExprI32Const, 1,424 kExprElse,425 kExprI32Const, 0,426 kExprEnd,427 kExprEnd,428 ]).exportFunc();429 let instance = builder.instantiate();430 assertEquals(1, instance.exports.throw_catch_param(5));431 assertEquals(1, instance.exports.throw_catch_param(0));432 assertEquals(1, instance.exports.throw_catch_param(-1));433})();434// Test the encoding of a thrown exception with an I64 value.435(function TestThrowParamL() {436 print(arguments.callee.name);437 let builder = new WasmModuleBuilder();438 let except = builder.addException(kSig_v_l);439 builder.addFunction("throw_param", kSig_v_ii)440 .addBody([441 kExprLocalGet, 0,442 kExprI64UConvertI32,443 kExprI64Const, 32,444 kExprI64Shl,445 kExprLocalGet, 1,446 kExprI64UConvertI32,447 kExprI64Ior,448 kExprThrow, except,449 ]).exportFunc();450 let instance = builder.instantiate();451 assertWasmThrows(instance, except, [0, 10, 0, 5], () => instance.exports.throw_param(10, 5));452 assertWasmThrows(instance, except, [65535, 65535, 0, 13], () => instance.exports.throw_param(-1, 13));453})();454// Test throwing/catching the F64 parameter value455(function TestThrowCatchParamD() {456 print(arguments.callee.name);457 let builder = new WasmModuleBuilder();458 let except = builder.addException(kSig_v_d);459 builder.addFunction("throw_catch_param", kSig_d_d)460 .addBody([461 kExprTry, kWasmF64,462 kExprLocalGet, 0,463 kExprThrow, except,464 kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0,465 kExprCatch, except,466 kExprReturn,467 kExprEnd,468 ]).exportFunc();469 let instance = builder.instantiate();470 assertEquals(5.0, instance.exports.throw_catch_param(5.0));471 assertEquals(10.5, instance.exports.throw_catch_param(10.5));472})();473// Test the encoding of a thrown exception with an f64 value.474(function TestThrowParamD() {475 print(arguments.callee.name);476 let builder = new WasmModuleBuilder();477 let except = builder.addException(kSig_v_d);478 builder.addFunction("throw_param", kSig_v_f)479 .addBody([480 kExprLocalGet, 0,481 kExprF64ConvertF32,482 kExprThrow, except,483 ]).exportFunc();484 let instance = builder.instantiate();485 assertWasmThrows(instance, except, [16404, 0, 0, 0], () => instance.exports.throw_param(5.0));486 assertWasmThrows(instance, except, [16739, 4816, 0, 0], () => instance.exports.throw_param(10000000.5));487})();488// Test the encoding of a computed parameter value.489(function TestThrowParamComputed() {490 print(arguments.callee.name);491 let builder = new WasmModuleBuilder();492 let except = builder.addException(kSig_v_i);493 builder.addFunction("throw_expr_with_params", kSig_v_ddi)494 .addBody([495 // p2 * (p0 + min(p0, p1))|0 - 20496 kExprLocalGet, 2,497 kExprLocalGet, 0,498 kExprLocalGet, 0,499 kExprLocalGet, 1,500 kExprF64Min,501 kExprF64Add,502 kExprI32SConvertF64,503 kExprI32Mul,504 kExprI32Const, 20,505 kExprI32Sub,506 kExprThrow, except,507 ]).exportFunc()508 let instance = builder.instantiate();509 assertWasmThrows(instance, except, [65535, 65536-8], () => instance.exports.throw_expr_with_params(1.5, 2.5, 4));510 assertWasmThrows(instance, except, [0, 12], () => instance.exports.throw_expr_with_params(5.7, 2.5, 4));511})();512// Now that we know catching works locally, we test catching exceptions that513// cross function boundaries and/or raised by JavaScript.514(function TestCatchCrossFunctions() {515 print(arguments.callee.name);516 let builder = new WasmModuleBuilder();517 let except = builder.addException(kSig_v_i);518 // Helper function for throwing from JS. It is imported by the Wasm module519 // as throw_i.520 function throw_value(value) {521 throw value;522 }523 let sig_index = builder.addType(kSig_v_i);524 let kJSThrowI = builder.addImport("", "throw_i", sig_index);525 // Helper function that throws a string. Wasm should not catch it.526 function throw_string() {527 throw "use wasm";528 }529 sig_index = builder.addType(kSig_v_v);530 let kJSThrowString = builder.addImport("", "throw_string", sig_index);531 // Helper function that throws undefined. Wasm should not catch it.532 function throw_undefined() {533 throw undefined;534 }535 let kJSThrowUndefined = builder.addImport("", "throw_undefined", sig_index);536 // Helper function that throws an fp. Wasm should not catch it.537 function throw_fp() {538 throw 10.5;539 }540 let kJSThrowFP = builder.addImport("", "throw_fp", sig_index);541 // Helper function that throws a large number. Wasm should not catch it.542 function throw_large() {543 throw 1e+28;544 }545 let kJSThrowLarge = builder.addImport("", "throw_large", sig_index);546 // Helper function for throwing from WebAssembly.547 let kWasmThrowFunction =548 builder.addFunction("throw", kSig_v_i)549 .addBody([550 kExprLocalGet, 0,551 kExprThrow, except,552 ])553 .index;554 // Scenario 1: Throw and catch appear on the same function. This should555 // happen in case of inlining, for example.556 builder.addFunction("same_scope", kSig_i_i)557 .addBody([558 kExprTry, kWasmI32,559 kExprLocalGet, 0,560 kExprI32Const, 0,561 kExprI32Ne,562 kExprIf, kWasmVoid,563 kExprLocalGet, 0,564 kExprThrow, except,565 kExprUnreachable,566 kExprEnd,567 kExprI32Const, 63,568 kExprCatch, except,569 kExprEnd570 ])571 .exportFunc();572 builder.addFunction("same_scope_ignore", kSig_i_i)573 .addBody([574 kExprTry, kWasmI32,575 kExprLocalGet, 0,576 kExprThrow, except,577 kExprUnreachable,578 kExprCatch, except,579 kExprEnd,580 ])581 .exportFunc();582 builder.addFunction("same_scope_multiple", kSig_i_i)583 // path = 0;584 //585 // try {586 // try {587 // try {588 // if (p == 1)589 // throw 1;590 // path |= 2591 // } catch (v) {592 // path |= v | 4;593 // throw path;594 // }595 // if (p == 2)596 // throw path|8;597 // path |= 16;598 // } catch (v) {599 // path |= v | 32;600 // throw path;601 // }602 // if (p == 3)603 // throw path|64;604 // path |= 128605 // } catch (v) {606 // path |= v | 256;607 // }608 //609 // return path;610 //611 // p == 1 -> path == 293612 // p == 2 -> path == 298613 // p == 3 -> path == 338614 // else -> path == 146615 .addLocals(kWasmI32, 1)616 .addBody([617 kExprTry, kWasmI32,618 kExprTry, kWasmI32,619 kExprTry, kWasmI32,620 kExprLocalGet, 0,621 kExprI32Const, 1,622 kExprI32Eq,623 kExprIf, kWasmVoid,624 kExprI32Const, 1,625 kExprThrow, except,626 kExprUnreachable,627 kExprEnd,628 kExprI32Const, 2,629 kExprCatch, except,630 kExprI32Const, 4,631 kExprI32Ior,632 kExprThrow, except,633 kExprUnreachable,634 kExprEnd,635 kExprLocalTee, 1,636 kExprLocalGet, 0,637 kExprI32Const, 2,638 kExprI32Eq,639 kExprIf, kWasmVoid,640 kExprLocalGet, 1,641 kExprI32Const, 8,642 kExprI32Ior,643 kExprThrow, except,644 kExprUnreachable,645 kExprEnd,646 kExprI32Const, 16,647 kExprI32Ior,648 kExprCatch, except,649 kExprI32Const, 32,650 kExprI32Ior,651 kExprThrow, except,652 kExprUnreachable,653 kExprEnd,654 kExprLocalTee, 1,655 kExprLocalGet, 0,656 kExprI32Const, 3,657 kExprI32Eq,658 kExprIf, kWasmVoid,659 kExprLocalGet, 1,660 kExprI32Const, /*64=*/ 192, 0,661 kExprI32Ior,662 kExprThrow, except,663 kExprUnreachable,664 kExprEnd,665 kExprI32Const, /*128=*/ 128, 1,666 kExprI32Ior,667 kExprCatch, except,668 kExprI32Const, /*256=*/ 128, 2,669 kExprI32Ior,670 kExprEnd,671 ])672 .exportFunc();673 // Scenario 2: Catches an exception raised from the direct callee.674 builder.addFunction("from_direct_callee", kSig_i_i)675 .addBody([676 kExprTry, kWasmI32,677 kExprLocalGet, 0,678 kExprCallFunction, kWasmThrowFunction,679 kExprUnreachable,680 kExprCatch, except,681 kExprEnd,682 ])683 .exportFunc();684 // Scenario 3: Catches an exception raised from an indirect callee.685 let sig_v_i = builder.addType(kSig_v_i);686 builder.appendToTable([kWasmThrowFunction, kWasmThrowFunction]);687 builder.addFunction("from_indirect_callee", kSig_i_ii)688 .addBody([689 kExprTry, kWasmI32,690 kExprLocalGet, 0,691 kExprLocalGet, 1,692 kExprCallIndirect, sig_v_i, kTableZero,693 kExprUnreachable,694 kExprCatch, except,695 kExprEnd696 ])697 .exportFunc();698 // Scenario 4: Does not catch an exception raised in JS, even if primitive699 // values are being used as exceptions.700 builder.addFunction("i_from_js", kSig_i_i)701 .addBody([702 kExprTry, kWasmI32,703 kExprLocalGet, 0,704 kExprCallFunction, kJSThrowI,705 kExprUnreachable,706 kExprCatch, except,707 kExprUnreachable,708 kExprEnd,709 ])710 .exportFunc();711 builder.addFunction("string_from_js", kSig_v_v)712 .addBody([713 kExprTry, kWasmVoid,714 kExprCallFunction, kJSThrowString,715 kExprCatch, except,716 kExprUnreachable,717 kExprEnd,718 ])719 .exportFunc();720 builder.addFunction("fp_from_js", kSig_v_v)721 .addBody([722 kExprTry, kWasmVoid,723 kExprCallFunction, kJSThrowFP,724 kExprCatch, except,725 kExprUnreachable,726 kExprEnd,727 ])728 .exportFunc();729 builder.addFunction("large_from_js", kSig_v_v)730 .addBody([731 kExprTry, kWasmVoid,732 kExprCallFunction, kJSThrowLarge,733 kExprCatch, except,734 kExprUnreachable,735 kExprEnd,736 ])737 .exportFunc();738 builder.addFunction("undefined_from_js", kSig_v_v)739 .addBody([740 kExprTry, kWasmVoid,741 kExprCallFunction, kJSThrowUndefined,742 kExprCatch, except,743 kExprUnreachable,744 kExprEnd,745 ])746 .exportFunc();747 let instance = builder.instantiate({"": {748 throw_i: throw_value,749 throw_string: throw_string,750 throw_fp: throw_fp,751 throw_large, throw_large,752 throw_undefined: throw_undefined753 }});754 assertEquals(63, instance.exports.same_scope(0));755 assertEquals(1024, instance.exports.same_scope(1024));756 assertEquals(-3, instance.exports.same_scope(-3));757 assertEquals(-1, instance.exports.same_scope_ignore(-1));758 assertEquals(1, instance.exports.same_scope_ignore(1));759 assertEquals(0x7FFFFFFF, instance.exports.same_scope_ignore(0x7FFFFFFF));760 assertEquals(1024, instance.exports.same_scope_ignore(1024));761 assertEquals(-1, instance.exports.same_scope_ignore(-1));762 assertEquals(293, instance.exports.same_scope_multiple(1));763 assertEquals(298, instance.exports.same_scope_multiple(2));764 assertEquals(338, instance.exports.same_scope_multiple(3));765 assertEquals(146, instance.exports.same_scope_multiple(0));766 assertEquals(-10024, instance.exports.from_direct_callee(-10024));767 assertEquals(3334333, instance.exports.from_direct_callee(3334333));768 assertEquals(-1, instance.exports.from_direct_callee(0xFFFFFFFF));769 assertEquals(0x7FFFFFFF, instance.exports.from_direct_callee(0x7FFFFFFF));770 assertEquals(10, instance.exports.from_indirect_callee(10, 0));771 assertEquals(77, instance.exports.from_indirect_callee(77, 1));772 assertThrowsEquals(() => instance.exports.i_from_js(10), 10);773 assertThrowsEquals(() => instance.exports.i_from_js(-10), -10);774 assertThrowsEquals(instance.exports.string_from_js, "use wasm");775 assertThrowsEquals(instance.exports.fp_from_js, 10.5);776 assertThrowsEquals(instance.exports.large_from_js, 1e+28);777 assertThrowsEquals(instance.exports.undefined_from_js, undefined);778})();779// Delegate with a try block that never throws.780(function TestDelegateNoThrow() {781 print(arguments.callee.name);782 let builder = new WasmModuleBuilder();783 let except1 = builder.addException(kSig_v_v);784 builder.addFunction('test', kSig_i_v)785 .addBody([786 kExprTry, kWasmI32,787 kExprTry, kWasmI32,788 kExprI32Const, 1,789 kExprDelegate, 0,790 kExprCatch, except1,791 kExprI32Const, 2,792 kExprEnd,793 ]).exportFunc();794 instance = builder.instantiate();795 assertEquals(1, instance.exports.test());796})();797// Delegate exception handling to outer try/catch block.798(function TestDelegateThrow() {799 print(arguments.callee.name);800 let builder = new WasmModuleBuilder();801 let except = builder.addException(kSig_v_v);802 let throw_if = builder.addFunction('throw', kSig_v_i)803 .addBody([804 kExprLocalGet, 0,805 kExprIf, kWasmVoid,806 kExprThrow, except,807 kExprEnd]).exportFunc();808 builder.addFunction('test', kSig_i_i)809 .addBody([810 kExprTry, kWasmI32,811 kExprTry, kWasmI32,812 kExprLocalGet, 0,813 kExprCallFunction, throw_if.index,814 kExprI32Const, 1,815 kExprDelegate, 0,816 kExprCatch, except,817 kExprI32Const, 2,818 kExprEnd,819 ]).exportFunc();820 instance = builder.instantiate();821 assertEquals(1, instance.exports.test(0));822 assertEquals(2, instance.exports.test(1));823})();824// No catch block matching the exception in the delegate target.825(function TestDelegateThrowNoCatch() {826 print(arguments.callee.name);827 let builder = new WasmModuleBuilder();828 let except1 = builder.addException(kSig_v_v);829 let except2 = builder.addException(kSig_v_v);830 let throw_fn = builder.addFunction('throw', kSig_v_v)831 .addBody([kExprThrow, except1])832 .exportFunc();833 let throw_fn_2 = builder.addFunction('throw_2', kSig_v_v)834 .addBody([kExprThrow, except2])835 .exportFunc();836 builder.addFunction('test', kSig_i_v)837 .addBody([838 kExprTry, kWasmI32,839 kExprTry, kWasmI32,840 kExprCallFunction, throw_fn.index,841 kExprI32Const, 1,842 kExprDelegate, 0,843 kExprCatch, except2,844 kExprI32Const, 2,845 kExprEnd,846 ]).exportFunc();847 instance = builder.instantiate();848 assertTraps(WebAssembly.RuntimeError, instance.exports.test);849})();850// Check that the exception is merged properly when both scopes can throw.851(function TestDelegateMerge() {852 print(arguments.callee.name);853 let builder = new WasmModuleBuilder();854 let except1 = builder.addException(kSig_v_v);855 let except2 = builder.addException(kSig_v_v);856 // throw_fn: 0 -> returns857 // 1 -> throw except1858 // 2 -> throw except2859 let throw_fn = builder.addFunction('throw', kSig_v_i)860 .addBody([861 kExprBlock, kWasmVoid,862 kExprBlock, kWasmVoid,863 kExprBlock, kWasmVoid,864 kExprLocalGet, 0,865 kExprBrTable, 2, 0, 1, 2,866 kExprEnd,867 kExprReturn,868 kExprEnd,869 kExprThrow, except1,870 kExprEnd,871 kExprThrow, except2])872 .exportFunc();873 builder.addFunction('test', kSig_i_ii)874 .addBody([875 kExprTry, kWasmI32,876 kExprLocalGet, 0,877 kExprCallFunction, throw_fn.index,878 kExprTry, kWasmI32,879 kExprLocalGet, 1,880 kExprCallFunction, throw_fn.index,881 kExprI32Const, 1,882 kExprDelegate, 0,883 kExprCatch, except1,884 kExprI32Const, 2,885 kExprEnd,886 ]).exportFunc();887 instance = builder.instantiate();888 assertEquals(2, instance.exports.test(1, 0));889 assertTraps(WebAssembly.RuntimeError, () => instance.exports.test(2, 0));890 assertEquals(2, instance.exports.test(0, 1));891 assertTraps(WebAssembly.RuntimeError, () => instance.exports.test(0, 2));892 assertEquals(1, instance.exports.test(0, 0));893})();894// Delegate to second enclosing try scope.895(function TestDelegate1() {896 print(arguments.callee.name);897 let builder = new WasmModuleBuilder();898 let except = builder.addException(kSig_v_v);899 let throw_fn = builder.addFunction('throw', kSig_v_v)900 .addBody([kExprThrow, except])901 .exportFunc();902 builder.addFunction('test', kSig_i_v)903 .addBody([904 kExprTry, kWasmI32,905 kExprTry, kWasmI32,906 kExprTry, kWasmI32,907 kExprCallFunction, throw_fn.index,908 kExprI32Const, 1,909 kExprDelegate, 1,910 kExprCatch, except,911 kExprI32Const, 2,912 kExprEnd,913 kExprCatch, except,914 kExprI32Const, 3,915 kExprEnd,916 ]).exportFunc();917 instance = builder.instantiate();918 assertEquals(3, instance.exports.test());919})();920(function TestDelegateUnreachable() {921 print(arguments.callee.name);922 let builder = new WasmModuleBuilder();923 let except1 = builder.addException(kSig_v_v);924 let except2 = builder.addException(kSig_v_v);925 builder.addFunction('test', kSig_i_v)926 .addBody([927 kExprTry, kWasmI32,928 kExprTry, kWasmVoid,929 kExprThrow, except1,930 kExprDelegate, 0,931 kExprI32Const, 1,932 kExprCatch, except1,933 kExprI32Const, 2,934 kExprCatch, except2,935 kExprI32Const, 3,936 kExprEnd,937 ]).exportFunc();938 instance = builder.instantiate();939 assertEquals(2, instance.exports.test());940})();941(function TestDelegateToCaller() {942 print(arguments.callee.name);943 let builder = new WasmModuleBuilder();944 let except = builder.addException(kSig_v_v);945 builder.addFunction('test', kSig_v_v)946 .addBody([947 kExprTry, kWasmVoid,948 kExprTry, kWasmVoid,949 kExprThrow, except,950 kExprDelegate, 1,951 kExprCatchAll,952 kExprEnd953 ]).exportFunc();954 builder.addFunction('test_unwind', kSig_v_v)955 .addBody([956 kExprTry, kWasmVoid,957 kExprTry, kWasmVoid,958 kExprThrow, except,959 kExprDelegate, 1,960 kExprUnwind,961 kExprEnd962 ]).exportFunc();963 instance = builder.instantiate();964 assertTraps(WebAssembly.RuntimeError, () => instance.exports.test());965 assertTraps(WebAssembly.RuntimeError, () => instance.exports.test_unwind());966})();967(function TestThrowBeforeUnreachable() {968 print(arguments.callee.name);969 let builder = new WasmModuleBuilder();970 let except = builder.addException(kSig_v_v);971 builder.addFunction('throw_before_unreachable', kSig_i_v)972 .addBody([973 kExprTry, kWasmI32,974 kExprThrow, except,975 kExprUnreachable,976 kExprCatchAll,977 kExprI32Const, 42,978 kExprEnd,979 ]).exportFunc();980 let instance = builder.instantiate();981 assertEquals(42, instance.exports.throw_before_unreachable());982})();983(function TestUnreachableInCatchAll() {984 print(arguments.callee.name);985 let builder = new WasmModuleBuilder();986 let except = builder.addException(kSig_v_v);987 builder.addFunction('throw_before_unreachable', kSig_i_v)988 .addBody([989 kExprTry, kWasmI32,990 kExprThrow, except,991 kExprCatchAll,992 kExprUnreachable,993 kExprI32Const, 42,994 kExprEnd,995 ]).exportFunc();996 let instance = builder.instantiate();997})();998(function TestThrowWithLocal() {999 print(arguments.callee.name);1000 let builder = new WasmModuleBuilder();1001 let except = builder.addException(kSig_v_v);1002 builder.addFunction('throw_with_local', kSig_i_v)1003 .addLocals(kWasmI32, 4)1004 .addBody([1005 kExprI32Const, 42,1006 kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0,1007 kExprTry, kWasmF32,1008 kExprThrow, except,1009 kExprCatchAll,1010 kExprF32Const, 0, 0, 0, 0,1011 kExprEnd,1012 kExprDrop, // Drop the f32.1013 kExprDrop, // Drop the f64.1014 // Leave the '42' on the stack.1015 ]).exportFunc();...
translations.ts
Source:translations.ts
1/*2 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one3 * or more contributor license agreements. Licensed under the Elastic License;4 * you may not use this file except in compliance with the Elastic License.5 */6import { i18n } from '@kbn/i18n';7export const CANCEL = i18n.translate('xpack.securitySolution.exceptions.addException.cancel', {8 defaultMessage: 'Cancel',9});10export const ADD_EXCEPTION = i18n.translate(11 'xpack.securitySolution.exceptions.addException.addException',12 {13 defaultMessage: 'Add Rule Exception',14 }15);16export const ADD_ENDPOINT_EXCEPTION = i18n.translate(17 'xpack.securitySolution.exceptions.addException.addEndpointException',18 {19 defaultMessage: 'Add Endpoint Exception',20 }21);22export const ADD_EXCEPTION_ERROR = i18n.translate(23 'xpack.securitySolution.exceptions.addException.error',24 {25 defaultMessage: 'Failed to add exception',26 }27);28export const ADD_EXCEPTION_SUCCESS = i18n.translate(29 'xpack.securitySolution.exceptions.addException.success',30 {31 defaultMessage: 'Successfully added exception',32 }33);34export const ADD_EXCEPTION_FETCH_ERROR_TITLE = i18n.translate(35 'xpack.securitySolution.exceptions.addException.fetchError.title',36 {37 defaultMessage: 'Error',38 }39);40export const ADD_EXCEPTION_FETCH_ERROR = i18n.translate(41 'xpack.securitySolution.exceptions.addException.fetchError',42 {43 defaultMessage: 'Error fetching exception list',44 }45);46export const ENDPOINT_QUARANTINE_TEXT = i18n.translate(47 'xpack.securitySolution.exceptions.addException.endpointQuarantineText',48 {49 defaultMessage:50 'On all Endpoint hosts, quarantined files that match the exception are automatically restored to their original locations. This exception applies to all rules using Endpoint exceptions.',51 }52);53export const BULK_CLOSE_LABEL = i18n.translate(54 'xpack.securitySolution.exceptions.addException.bulkCloseLabel',55 {56 defaultMessage: 'Close all alerts that match this exception and were generated by this rule',57 }58);59export const BULK_CLOSE_LABEL_DISABLED = i18n.translate(60 'xpack.securitySolution.exceptions.addException.bulkCloseLabel.disabled',61 {62 defaultMessage:63 'Close all alerts that match this exception and were generated by this rule (Lists and non-ECS fields are not supported)',64 }65);66export const EXCEPTION_BUILDER_INFO = i18n.translate(67 'xpack.securitySolution.exceptions.addException.infoLabel',68 {69 defaultMessage: "Alerts are generated when the rule's conditions are met, except when:",70 }71);72export const ADD_EXCEPTION_SEQUENCE_WARNING = i18n.translate(73 'xpack.securitySolution.exceptions.addException.sequenceWarning',74 {75 defaultMessage:76 "This rule's query contains an EQL sequence statement. The exception created will apply to all events in the sequence.",77 }...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.addException("www.example.com", function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7MIT © [WebPageTest](
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.addException(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11## getLocations(options, callback)12var wpt = require('wpt');13var options = {};14wpt.getLocations(options, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21## getTesters(options, callback)22var wpt = require('wpt');23var options = {};24wpt.getTesters(options, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31## getTestStatus(options, callback)32var wpt = require('wpt');33var options = {34};35wpt.getTestStatus(options, function(err, data) {36 if (err) {37 console.log(err);38 } else {39 console.log(data);40 }41});42## getTestResults(options, callback)43var wpt = require('wpt');44var options = {45};46wpt.getTestResults(options, function(err, data) {47 if (err) {48 console.log(err);49 } else {50 console.log(data);51 }52});53## getTestInfo(options, callback)
Using AI Code Generation
1wptbExceptionManager.addException('testException', 'testException1', 'testException2');2wptbExceptionManager.removeException('testException', 'testException1');3wptbExceptionManager.hasException('testException', 'testException1');4wptbExceptionManager.addException(exceptionName, exceptionValue1, exceptionValue2, ...)5wptbExceptionManager.addException('testException', 'testException1', 'testException2');6wptbExceptionManager.removeException(exceptionName, exceptionValue1, exceptionValue2, ...)7wptbExceptionManager.removeException('testException', 'testException1');8wptbExceptionManager.hasException(exceptionName, exceptionValue)
Using AI Code Generation
1var wpt = require('./wpt.js');2var wptObj = new wpt('wptserver', 'apikey');3wptObj.addException('test.com', 'www.test.com', function(err, data) {4 console.log(data);5});6var wpt = require('./wpt.js');7var wptObj = new wpt('wptserver', 'apikey');8 console.log(data);9});10var wpt = require('./wpt.js');11var wptObj = new wpt('wptserver', 'apikey');12wptObj.clearScript(function(err, data) {13 console.log(data);14});15var wpt = require('./wpt.js');16var wptObj = new wpt('wptserver', 'apikey');17wptObj.clearTest('testid', function(err, data) {18 console.log(data);19});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!