How to use exn method in wpt

Best JavaScript code snippet using wpt

instructions.js

Source:instructions.js Github

copy

Full Screen

1// Tests for Wasm exception proposal instructions.2// Test try blocks with no handlers.3assertEq(4 wasmEvalText(5 `(module6 (func (export "f") (result i32)7 try (result i32) (i32.const 0) end))`8 ).exports.f(),9 010);11assertEq(12 wasmEvalText(13 `(module14 (func (export "f") (result i32)15 try (result i32) (i32.const 0) (br 0) (i32.const 1) end))`16 ).exports.f(),17 018);19assertEq(20 wasmEvalText(21 `(module22 (type (func))23 (tag $exn (type 0))24 (func (export "f") (result i32)25 try (result i32)26 try (result i32)27 (throw $exn)28 (i32.const 1)29 end30 drop31 (i32.const 2)32 catch $exn33 (i32.const 0)34 end))`35 ).exports.f(),36 037);38assertEq(39 wasmEvalText(40 `(module41 (type (func))42 (tag $exn (type 0))43 (func (export "f") (result i32)44 try (result i32)45 try (result i32)46 try47 try48 (throw $exn)49 end50 end51 (i32.const 1)52 end53 drop54 (i32.const 2)55 catch $exn56 (i32.const 0)57 end))`58 ).exports.f(),59 060);61assertEq(62 wasmEvalText(63 `(module64 (type (func))65 (tag $exn (type 0))66 (func (export "f") (result i32)67 try (result i32)68 try (result i32)69 try70 try71 (throw $exn)72 end73 catch_all74 rethrow 075 end76 (i32.const 1)77 end78 drop79 (i32.const 2)80 catch $exn81 (i32.const 0)82 end))`83 ).exports.f(),84 085);86// Test trivial try-catch with empty bodies.87assertEq(88 wasmEvalText(89 `(module90 (type (func))91 (tag $exn (type 0))92 (func (export "f") (result i32)93 try nop catch $exn end94 (i32.const 0)))`95 ).exports.f(),96 097);98assertEq(99 wasmEvalText(100 `(module101 (func (export "f") (result i32)102 try nop catch_all end103 (i32.const 0)))`104 ).exports.f(),105 0106);107// Test try block with no throws108assertEq(109 wasmEvalText(110 `(module111 (type (func))112 (tag $exn (type 0))113 (func (export "f") (result i32)114 try (result i32)115 (i32.const 0)116 catch $exn117 (i32.const 1)118 end))`119 ).exports.f(),120 0121);122// Ensure catch block is really not run when no throw occurs.123assertEq(124 wasmEvalText(125 `(module126 (type (func))127 (tag $exn (type 0))128 (func (export "f") (result i32) (local i32)129 try130 (local.set 0 (i32.const 42))131 catch $exn132 (local.set 0 (i32.const 99))133 end134 (local.get 0)))`135 ).exports.f(),136 42137);138// Simple uses of throw.139assertEq(140 wasmEvalText(141 `(module142 (type (func (param i32)))143 (tag $exn (type 0))144 (func (export "f") (result i32)145 try (result i32)146 (i32.const 42)147 (throw $exn)148 catch $exn149 drop150 (i32.const 1)151 end))`152 ).exports.f(),153 1154);155assertEq(156 wasmEvalText(157 `(module158 (type (func (param i32)))159 (tag $exn (type 0))160 (func $foo (param i32) (result i32)161 (local.get 0) (throw $exn))162 (func (export "f") (result i32)163 try (result i32)164 (i32.const 42)165 (call $foo)166 catch $exn167 drop168 (i32.const 1)169 end))`170 ).exports.f(),171 1172);173// Further nested call frames should be ok.174assertEq(175 wasmEvalText(176 `(module177 (type (func (param i32)))178 (tag $exn (type 0))179 (func $foo (param i32) (result i32)180 (local.get 0) (call $bar))181 (func $bar (param i32) (result i32)182 (local.get 0) (call $quux))183 (func $quux (param i32) (result i32)184 (local.get 0) (throw $exn))185 (func (export "f") (result i32)186 try (result i32)187 (i32.const 42)188 (call $foo)189 catch $exn190 drop191 (i32.const 1)192 end))`193 ).exports.f(),194 1195);196// Ensure conditional throw works.197let conditional = wasmEvalText(198 `(module199 (type (func (param)))200 (tag $exn (type 0))201 (func (export "f") (param i32) (result i32)202 try (result i32)203 (local.get 0)204 if (result i32)205 (throw $exn)206 else207 (i32.const 42)208 end209 catch $exn210 (i32.const 99)211 end))`212).exports.f;213assertEq(conditional(0), 42);214assertEq(conditional(1), 99);215// Ensure multiple & nested try-catch blocks work.216assertEq(217 wasmEvalText(218 `(module219 (type (func (param)))220 (tag $exn (type 0))221 (func $foo (throw $exn))222 (func (export "f") (result i32) (local i32)223 try224 nop225 catch $exn226 (local.set 0 (i32.const 99))227 end228 try229 (call $foo)230 catch $exn231 (local.set 0 (i32.const 42))232 end233 (local.get 0)))`234 ).exports.f(),235 42236);237assertEq(238 wasmEvalText(239 `(module240 (type (func (param)))241 (tag $exn (type 0))242 (func (export "f") (result i32) (local i32)243 try244 try245 try246 (throw $exn)247 catch $exn248 (local.set 0 (i32.const 42))249 end250 catch $exn251 (local.set 0 (i32.const 97))252 end253 catch $exn254 (local.set 0 (i32.const 98))255 end256 (local.get 0)))`257 ).exports.f(),258 42259);260// Test tag dispatch for catches.261assertEq(262 wasmEvalText(263 `(module264 (type (func (param)))265 (tag $exn1 (type 0))266 (tag $exn2 (type 0))267 (tag $exn3 (type 0))268 (func (export "f") (result i32)269 try (result i32)270 throw $exn1271 catch $exn1272 i32.const 1273 catch $exn2274 i32.const 2275 catch $exn3276 i32.const 3277 end))`278 ).exports.f(),279 1280);281assertEq(282 wasmEvalText(283 `(module284 (type (func (param)))285 (tag $exn1 (type 0))286 (tag $exn2 (type 0))287 (tag $exn3 (type 0))288 (func (export "f") (result i32)289 try (result i32)290 throw $exn2291 catch $exn1292 i32.const 1293 catch $exn2294 i32.const 2295 catch $exn3296 i32.const 3297 end))`298 ).exports.f(),299 2300);301assertEq(302 wasmEvalText(303 `(module304 (type (func (param)))305 (tag $exn1 (type 0))306 (tag $exn2 (type 0))307 (tag $exn3 (type 0))308 (func (export "f") (result i32)309 try (result i32)310 throw $exn3311 catch $exn1312 i32.const 1313 catch $exn2314 i32.const 2315 catch $exn3316 i32.const 3317 end))`318 ).exports.f(),319 3320);321assertEq(322 wasmEvalText(323 `(module324 (type (func (param)))325 (tag $exn1 (type 0))326 (tag $exn2 (type 0))327 (tag $exn3 (type 0))328 (tag $exn4 (type 0))329 (func (export "f") (result i32)330 try (result i32)331 try (result i32)332 throw $exn4333 catch $exn1334 i32.const 1335 catch $exn2336 i32.const 2337 catch $exn3338 i32.const 3339 end340 catch $exn4341 i32.const 4342 end))`343 ).exports.f(),344 4345);346// Test usage of br before a throw.347assertEq(348 wasmEvalText(349 `(module350 (type (func (param i32)))351 (tag $exn (type 0))352 (func (export "f") (result i32)353 try $l (result i32)354 (i32.const 2)355 (br $l)356 (throw $exn)357 catch $exn358 drop359 (i32.const 1)360 end))`361 ).exports.f(),362 2363);364assertEq(365 wasmEvalText(366 `(module367 (type (func (param)))368 (tag $exn (type 0))369 (func (export "f") (result i32)370 try $l (result i32)371 (throw $exn)372 catch $exn373 (i32.const 2)374 (br $l)375 rethrow 0376 end))`377 ).exports.f(),378 2379);380assertEq(381 wasmEvalText(382 `(module383 (type (func (param)))384 (tag $exn (type 0))385 (func (export "f") (result i32)386 try $l (result i32)387 (throw $exn)388 catch_all389 (i32.const 2)390 (br $l)391 rethrow 0392 end))`393 ).exports.f(),394 2395);396// Test br branching out of a catch block.397assertEq(398 wasmEvalText(399 `(module400 (type (func (param i32)))401 (tag $exn (type 0))402 (func (export "f") (result i32)403 block $l (result i32)404 block (result i32)405 try (result i32)406 (i32.const 42)407 (throw $exn)408 catch $exn409 br $l410 (i32.const 99)411 end412 end413 end))`414 ).exports.f(),415 42416);417// Test dead catch block.418assertEq(419 wasmEvalText(420 `(module421 (type (func))422 (tag $exn (type 0))423 (func (export "f") (result i32)424 i32.const 0425 return426 try nop catch $exn end))`427 ).exports.f(),428 0429);430assertEq(431 wasmEvalText(432 `(module433 (func (export "f") (result i32)434 i32.const 0435 return436 try nop catch_all end))`437 ).exports.f(),438 0439);440// Test catch with exception values pushed to stack.441assertEq(442 wasmEvalText(443 `(module444 (type (func (param i32)))445 (type (func (param i32)))446 (type (func (param i64)))447 (tag $exn (type 0))448 (tag $foo (type 1))449 (tag $bar (type 2))450 (func (export "f") (result i32)451 try $l (result i32)452 (i32.const 42)453 (throw $exn)454 catch $exn455 catch_all456 (i32.const 99)457 end))`458 ).exports.f(),459 42460);461// Throw an exception carrying more than one value.462assertEq(463 wasmEvalText(464 `(module465 (type (func (param i32 i64 f32 f64)))466 (tag $exn (type 0))467 (func (export "f") (result i32)468 try $l (result i32 i64 f32 f64)469 (i32.const 42)470 (i64.const 84)471 (f32.const 42.2)472 (f64.const 84.4)473 (throw $exn)474 catch $exn475 catch_all476 (i32.const 99)477 (i64.const 999)478 (f32.const 99.9)479 (f64.const 999.9)480 end481 drop drop drop))`482 ).exports.f(),483 42484);485// This should also work inside nested frames.486assertEq(487 wasmEvalText(488 `(module489 (type (func (param i32 i64 f32 f64)))490 (tag $exn (type 0))491 (func $foo (param i32 i64 f32 f64) (result i32 i64 f32 f64)492 (local.get 0)493 (local.get 1)494 (local.get 2)495 (local.get 3)496 (throw $exn))497 (func (export "f") (result i32)498 try $l (result i32 i64 f32 f64)499 (i32.const 42)500 (i64.const 84)501 (f32.const 42.2)502 (f64.const 84.4)503 (call $foo)504 catch $exn505 catch_all506 (i32.const 99)507 (i64.const 999)508 (f32.const 99.9)509 (f64.const 999.9)510 end511 drop drop drop))`512 ).exports.f(),513 42514);515// Multiple tagged catch in succession.516assertEq(517 wasmEvalText(518 `(module519 (type (func (param i32)))520 (tag $exn1 (type 0))521 (tag $exn2 (type 0))522 (func (export "f") (result i32)523 try (result i32)524 (i32.const 42)525 (throw $exn2)526 catch $exn1527 catch $exn2528 catch_all529 (i32.const 99)530 end))`531 ).exports.f(),532 42533);534// Try catch with block parameters.535assertEq(536 wasmEvalText(537 `(module538 (type (func))539 (tag $exn (type 0))540 (func (export "f") (result i32)541 (i32.const 42)542 try (param i32) (result i32)543 nop544 catch $exn545 (i32.const 99)546 end))`547 ).exports.f(),548 42549);550assertEq(551 wasmEvalText(552 `(module553 (type (func (param i32)))554 (tag $exn (type 0))555 (func (export "f") (result i32)556 (i32.const 42)557 try $l (param i32) (result i32)558 (throw $exn)559 catch $exn560 catch_all561 (i32.const 99)562 end))`563 ).exports.f(),564 42565);566// Test the catch_all case.567assertEq(568 wasmEvalText(569 `(module570 (type (func (param i32)))571 (tag $exn1 (type 0))572 (tag $exn2 (type 0))573 (func (export "f") (result i32)574 try $l (result i32)575 (i32.const 42)576 (throw $exn2)577 catch $exn1578 catch_all579 (i32.const 99)580 end))`581 ).exports.f(),582 99583);584assertEq(585 wasmEvalText(586 `(module587 (tag $exn (param i32))588 (func (export "f") (result i32)589 try (result i32)590 try (result i32)591 (i32.const 42)592 (throw $exn)593 catch_all594 (i32.const 99)595 end596 catch $exn597 end))`598 ).exports.f(),599 99600);601// Test foreign exception catch.602assertEq(603 wasmEvalText(604 `(module605 (type (func))606 (import "m" "foreign" (func $foreign))607 (tag $exn (type 0))608 (func (export "f") (result i32) (local i32)609 try $l610 (call $foreign)611 catch $exn612 catch_all613 (local.set 0 (i32.const 42))614 end615 (local.get 0)))`,616 {617 m: {618 foreign() {619 throw 5;620 },621 },622 }623 ).exports.f(),624 42625);626// Exception handlers should not catch traps.627assertErrorMessage(628 () =>629 wasmEvalText(630 `(module631 (type (func))632 (tag $exn (type 0))633 (func (export "f") (result i32) (local i32)634 try $l635 unreachable636 catch $exn637 (local.set 0 (i32.const 98))638 catch_all639 (local.set 0 (i32.const 99))640 end641 (local.get 0)))`642 ).exports.f(),643 WebAssembly.RuntimeError,644 "unreachable executed"645);646// Ensure that a RuntimeError created by the user is not filtered out647// as a trap emitted by the runtime (i.e., the filtering predicate is not648// observable from JS).649assertEq(650 wasmEvalText(651 `(module652 (import "m" "foreign" (func $foreign))653 (func (export "f") (result i32)654 try (result i32)655 (call $foreign)656 (i32.const 99)657 catch_all658 (i32.const 42)659 end))`,660 {661 m: {662 foreign() {663 throw new WebAssembly.RuntimeError();664 },665 },666 }667 ).exports.f(),668 42669);670// Test uncatchable JS exceptions (OOM & stack overflow).671{672 let f = wasmEvalText(673 `(module674 (import "m" "foreign" (func $foreign))675 (func (export "f") (result)676 try677 (call $foreign)678 catch_all679 end))`,680 {681 m: {682 foreign() {683 throwOutOfMemory();684 },685 },686 }687 ).exports.f;688 var thrownVal;689 try {690 f();691 } catch (exn) {692 thrownVal = exn;693 }694 assertEq(thrownVal, "out of memory");695}696assertErrorMessage(697 () =>698 wasmEvalText(699 `(module700 (import "m" "foreign" (func $foreign))701 (func (export "f")702 try703 (call $foreign)704 catch_all705 end))`,706 {707 m: {708 foreign: function foreign() {709 foreign();710 },711 },712 }713 ).exports.f(),714 Error,715 "too much recursion"716);717// Ensure memory operations work after a throw. This is also testing that the718// WasmTlsReg/HeapReg are set correctly when throwing.719{720 let exports = wasmEvalText(721 `(module $m722 (memory $mem (data "bar"))723 (type (func))724 (tag $exn (export "e") (type 0))725 (func (export "f")726 (throw $exn)))`727 ).exports;728 assertEq(729 wasmEvalText(730 `(module731 (type (func))732 (import "m" "e" (tag $e (type 0)))733 (import "m" "f" (func $foreign))734 (memory $mem (data "foo"))735 (func (export "f") (result i32)736 try737 call $foreign738 catch $e739 end740 (i32.const 0)741 (i32.load8_u)))`,742 { m: exports }743 ).exports.f(),744 102745 );746}747// Test simple rethrow.748assertEq(749 wasmEvalText(750 `(module751 (type (func))752 (tag $exn (type 0))753 (func (export "f") (result i32)754 try (result i32)755 try756 throw $exn757 catch $exn758 rethrow 0759 end760 i32.const 1761 catch $exn762 i32.const 27763 end))`764 ).exports.f(),765 27766);767assertEq(768 wasmEvalText(769 `(module770 (type (func))771 (tag $exn (type 0))772 (func (export "f") (result i32)773 try (result i32)774 try775 throw $exn776 catch_all777 rethrow 0778 end779 i32.const 1780 catch $exn781 i32.const 27782 end))`783 ).exports.f(),784 27785);786// Test rethrows in nested blocks.787assertEq(788 wasmEvalText(789 `(module790 (type (func))791 (tag $exn (type 0))792 (func (export "f") (result i32)793 try (result i32)794 try795 throw $exn796 catch $exn797 block798 rethrow 1799 end800 end801 i32.const 1802 catch $exn803 i32.const 27804 end))`805 ).exports.f(),806 27807);808assertEq(809 wasmEvalText(810 `(module811 (type (func))812 (tag $exn (type 0))813 (func (export "f") (result i32)814 try (result i32)815 try816 throw $exn817 catch_all818 block819 rethrow 1820 end821 end822 i32.const 1823 catch $exn824 i32.const 27825 end))`826 ).exports.f(),827 27828);829assertEq(830 wasmEvalText(831 `(module832 (type (func))833 (tag $exn1 (type 0))834 (tag $exn2 (type 0))835 (func (export "f") (result i32)836 try (result i32)837 try838 throw $exn1839 catch $exn1840 try841 throw $exn2842 catch $exn2843 rethrow 1844 end845 end846 i32.const 0847 catch $exn1848 i32.const 1849 catch $exn2850 i32.const 2851 end))`852 ).exports.f(),853 1854);855assertEq(856 wasmEvalText(857 `(module858 (type (func))859 (tag $exn1 (type 0))860 (tag $exn2 (type 0))861 (func (export "f") (result i32)862 try (result i32)863 try864 throw $exn1865 catch $exn1866 try867 throw $exn2868 catch_all869 rethrow 1870 end871 end872 i32.const 0873 catch $exn1874 i32.const 1875 catch $exn2876 i32.const 2877 end))`878 ).exports.f(),879 1880);881// Test that rethrow makes the rest of the block dead code.882assertEq(883 wasmEvalText(884 `(module885 (tag (param i32))886 (func (export "f") (result i32)887 (try (result i32)888 (do (i32.const 1))889 (catch 0890 (rethrow 0)891 (i32.const 2)))))`892 ).exports.f(),893 1894);895assertEq(896 wasmEvalText(897 `(module898 (tag (param i32))899 (func (export "f") (result i32)900 (try (result i32)901 (do (try902 (do (i32.const 13)903 (throw 0))904 (catch 0905 (rethrow 0)))906 (unreachable))907 (catch 0))))`908 ).exports.f(),909 13910);911assertEq(912 wasmEvalText(913 `(module914 (tag)915 (func (export "f") (result i32)916 (try (result i32)917 (do918 (try919 (do (throw 0))920 (catch 0921 (i32.const 4)922 (rethrow 0)))923 (unreachable))924 (catch 0925 (i32.const 13)))))`926 ).exports.f(),927 13928);929// Test try-delegate blocks.930assertEq(931 wasmEvalText(932 `(module933 (tag $exn (param))934 (func (export "f") (result i32)935 i32.const 1936 br 0937 try938 throw $exn939 delegate 0))`940 ).exports.f(),941 1942);943assertEq(944 wasmEvalText(945 `(module946 (tag $exn (param))947 (func (export "f") (result i32)948 try (result i32)949 try950 try951 throw $exn952 delegate 0953 end954 i32.const 0955 catch $exn956 i32.const 1957 end))`958 ).exports.f(),959 1960);961assertEq(962 wasmEvalText(963 `(module964 (tag $exn (param))965 (func (export "f") (result i32)966 try (result i32)967 i32.const 1968 br 0969 delegate 0))`970 ).exports.f(),971 1972);973assertEq(974 wasmEvalText(975 `(module976 (tag $exn (param))977 (func (export "f") (result i32)978 try (result i32)979 i32.const 1980 return981 delegate 0))`982 ).exports.f(),983 1984);985assertEq(986 wasmEvalText(987 `(module988 (type (func (param i32)))989 (tag $exn (type 0))990 (func (export "f") (result i32)991 try (result i32)992 try993 i32.const 42994 throw $exn995 delegate 0996 i32.const 0997 catch $exn998 i32.const 1999 i32.add1000 end))`1001 ).exports.f(),1002 431003);1004assertEq(1005 wasmEvalText(1006 `(module1007 (type (func (param i32)))1008 (tag $exn (type 0))1009 (func (export "f") (result i32)1010 try (result i32)1011 try (result i32)1012 try1013 i32.const 421014 throw $exn1015 delegate 11016 i32.const 01017 catch $exn1018 i32.const 11019 i32.add1020 end1021 catch $exn1022 i32.const 21023 i32.add1024 end))`1025 ).exports.f(),1026 441027);1028assertEq(1029 wasmEvalText(1030 `(module1031 (type (func (param i32)))1032 (tag $exn (type 0))1033 (func (export "f") (result i32)1034 try (result i32)1035 try (result i32)1036 try (result i32)1037 try1038 i32.const 421039 throw $exn1040 delegate 11041 i32.const 01042 catch $exn1043 i32.const 11044 i32.add1045 end1046 delegate 01047 catch $exn1048 i32.const 21049 i32.add1050 end))`1051 ).exports.f(),1052 441053);1054assertEq(1055 wasmEvalText(1056 `(module1057 (tag $exn (param))1058 (func $g (param i32) (result i32) (i32.const 42))1059 (func (export "f") (result i32)1060 try (result i32)1061 try $t1062 block (result i32)1063 (i32.const 4)1064 (call $g)1065 try1066 throw $exn1067 delegate $t1068 end1069 drop1070 end1071 i32.const 01072 catch_all1073 i32.const 11074 end))`1075 ).exports.f(),1076 11077);1078// Test delegation to function body and blocks.1079assertEq(1080 wasmEvalText(1081 `(module1082 (tag $exn (param))1083 (func (export "f") (result i32)1084 try (result i32)1085 i32.const 11086 delegate 0))`1087 ).exports.f(),1088 11089);1090assertEq(1091 wasmEvalText(1092 `(module1093 (tag $exn (param i32))1094 (func (export "f") (result i32)1095 try (result i32)1096 block1097 try1098 i32.const 11099 throw $exn1100 delegate 01101 end1102 i32.const 01103 catch $exn1104 end))`1105 ).exports.f(),1106 11107);1108assertEq(1109 wasmEvalText(1110 `(module1111 (tag $exn (param))1112 (func (export "f") (result i32)1113 try (result i32)1114 try1115 throw $exn1116 catch $exn1117 try1118 throw $exn1119 delegate 01120 end1121 i32.const 01122 catch_all1123 i32.const 11124 end))`1125 ).exports.f(),1126 11127);1128assertEq(1129 wasmEvalText(1130 `(module1131 (type (func (param i32)))1132 (tag $exn (type 0))1133 (func (export "f") (result i32)1134 try (result i32)1135 call $g1136 catch $exn1137 end)1138 (func $g (result i32)1139 try (result i32)1140 try1141 i32.const 421142 throw $exn1143 delegate 11144 i32.const 01145 catch $exn1146 i32.const 11147 i32.add1148 end))`1149 ).exports.f(),1150 42...

Full Screen

Full Screen

throw-to-js.js

Source:throw-to-js.js Github

copy

Full Screen

1// Tests for throwing exceptions to JS from Wasm.2function assertWasmThrowsExn(thunk) {3 let thrown = false;4 try {5 thunk();6 } catch (exn) {7 thrown = true;8 assertEq(exn instanceof WebAssembly.Exception, true);9 }10 assertEq(thrown, true, "missing exception");11}12// Test that handler-less trys don't catch anything.13assertWasmThrowsExn(() =>14 wasmEvalText(15 `(module16 (type (func (param)))17 (tag $exn (type 0))18 (func (export "f")19 try (throw $exn) end))`20 ).exports.f()21);22assertWasmThrowsExn(() =>23 wasmEvalText(24 `(module25 (type (func (param)))26 (tag $exn (type 0))27 (func $g (throw $exn))28 (func (export "f")29 try (call $g) end)30)`31 ).exports.f()32);33assertWasmThrowsExn(() =>34 wasmEvalText(35 `(module36 (type (func (param)))37 (tag $exn (type 0))38 (func (export "f")39 try try (throw $exn) end end))`40 ).exports.f()41);42assertWasmThrowsExn(() =>43 wasmEvalText(44 `(module45 (tag $exn (param))46 (func (export "f")47 try48 try49 throw $exn50 delegate 051 end))`52 ).exports.f()53);54assertWasmThrowsExn(() =>55 wasmEvalText(56 `(module57 (tag $exn (param))58 (func (export "f")59 try60 try61 throw $exn62 delegate 163 end))`64 ).exports.f()65);66assertWasmThrowsExn(() =>67 wasmEvalText(68 `(module69 (tag $exn (param))70 (func (export "f")71 block72 try73 throw $exn74 delegate 075 end))`76 ).exports.f()77);78assertWasmThrowsExn(() =>79 wasmEvalText(80 `(module81 (tag $exn (param))82 (func (export "f")83 loop84 try85 throw $exn86 delegate 087 end))`88 ).exports.f()89);90assertWasmThrowsExn(() =>91 wasmEvalText(92 `(module93 (tag $exn (param))94 (func (export "f")95 (i32.const 1)96 if97 try98 throw $exn99 delegate 0100 end))`101 ).exports.f()102);103// Test throwing simple empty exceptions to JS.104assertWasmThrowsExn(() =>105 wasmEvalText(106 `(module107 (type (func (param)))108 (tag $exn (type 0))109 (func (export "f")110 (throw $exn)))`111 ).exports.f()112);113// Test that wasm preserves the values of non-object exceptions that pass114// through it back to JS.115assertThrowsValue(116 () =>117 wasmEvalText(118 `(module119 (tag $exn)120 (import "m" "import" (func $import))121 (func (export "f")122 try123 (call $import)124 catch $exn125 ;; this block shouldn't be reached126 end))`,127 {128 m: {129 import: () => {130 throw 42;131 },132 },133 }134 ).exports.f(),135 42136);137// Like previous test, but using a rethrow instruction instead.138assertThrowsValue(139 () =>140 wasmEvalText(141 `(module142 (import "m" "import" (func $import))143 (func (export "f")144 try145 (call $import)146 catch_all147 (rethrow 0)148 end))`,149 {150 m: {151 import: () => {152 throw 42;153 },154 },155 }156 ).exports.f(),157 42158);159// Test for throwing to JS and then back to Wasm.160{161 var wasmThrower;162 let exports = wasmEvalText(163 `(module164 (type (func (param i32)))165 (tag $exn (type 0))166 (import "m" "import" (func $import (result i32)))167 (func (export "thrower")168 (i32.const 42)169 (throw $exn))170 (func (export "catcher") (result i32)171 try (result i32)172 (call $import)173 catch $exn174 end))`,175 {176 m: {177 import: () => {178 return wasmThrower();179 },180 },181 }182 ).exports;183 wasmThrower = exports.thrower;184 assertEq(exports.catcher(), 42);185}186// Tests for checking the tags of exceptions.187{188 let exports = wasmEvalText(189 `(module190 (type (func (param i32)))191 (tag $exn (export "exn") (type 0))192 (func (export "thrower")193 (i32.const 42)194 (throw $exn)))`195 ).exports;196 let imports = {197 store: {198 throws: () => {199 return exports.thrower();200 },201 exn: exports.exn,202 },203 };204 // This passes the exception tag check and the exception is caught.205 assertEq(206 wasmEvalText(207 `(module208 (type (func (param i32)))209 (import "store" "throws" (func $thrower (result i32)))210 (import "store" "exn" (tag $exn (type 0)))211 (func (export "catches") (result i32)212 try (result i32)213 (call $thrower)214 catch $exn215 (i32.const 15)216 (i32.sub)217 end))`,218 imports219 ).exports.catches(),220 27221 );222 // This fails the exception tag check, despite the local exception having223 // a matching signature.224 assertWasmThrowsExn(() =>225 wasmEvalText(226 `(module227 (type (func (param i32)))228 (import "store" "throws" (func $thrower (result i32)))229 (tag $exn (type 0))230 (func (export "catchesFail") (result i32)231 try (result i32)232 (call $thrower)233 catch $exn ;; This should not recognise $exn, thus not unpack 42.234 end))`,235 imports236 ).exports.catchesFail()237 );238}239// Test that JS finally block executes after a Wasm throw.240assertEq(241 (() => {242 try {243 wasmEvalText(244 `(module245 (type (func (param)))246 (tag $exn (type 0))247 (func (export "f")248 (throw $exn)))`249 ).exports.f();250 } finally {251 return true;252 }253 return false;254 })(),255 true256);257// Test that a wasm trap that passes through JS cannot be caught in Wasm.258{259 let throwTrap = wasmEvalText(`(module (func (export "f") unreachable))`)260 .exports.f;261 let catcher = wasmEvalText(262 `(module263 (type (func))264 (tag $exn (type 0))265 (import "m" "f" (func $foreign (param) (result)))266 (func (export "f")267 try268 call $foreign269 catch $exn270 catch_all271 end))`,272 {273 m: {274 // JS frame that goes between the two wasm frames and just rethrows.275 f: () => {276 try {277 throwTrap();278 } catch (e) {279 throw e;280 }281 },282 },283 }284 ).exports.f;285 assertErrorMessage(286 () => catcher(),287 WebAssembly.RuntimeError,288 "unreachable executed"289 );290}291// Test delegate throwing out of function.292assertWasmThrowsExn(() =>293 wasmEvalText(294 `(module295 (tag $exn (param))296 (func (export "f") (result i32)297 try (result i32)298 throw $exn299 delegate 0))`300 ).exports.f()301);302assertWasmThrowsExn(() =>303 wasmEvalText(304 `(module305 (tag $exn (param))306 (func (export "f") (result i32)307 try (result i32)308 i32.const 0309 if310 i32.const 1311 return312 else313 throw $exn314 end315 i32.const 0316 delegate 0))`317 ).exports.f()...

Full Screen

Full Screen

worker_test_loading.js

Source:worker_test_loading.js Github

copy

Full Screen

...89 "The name of the right file appears somewhere in the stack"90 );91 is(exn.lineNumber, 13, "The error comes with the right line number");92});93function get_exn(f) {94 try {95 f();96 return undefined;97 } catch (ex) {98 return ex;99 }100}101// Test module.exports102add_test(function test_module_dot_exports() {103 let H = require(PATH + "moduleH-module-dot-exports.js");104 is(H.key, "value", "module.exports worked");105 let H2 = require(PATH + "moduleH-module-dot-exports.js");106 is(H2.key, "value", "module.exports returned the same key");107 ok(H2 === H, "module.exports returned the same module the second time");108 let exn = get_exn(() => (H.key = "this should not be accepted"));109 ok(110 exn instanceof TypeError,111 "Cannot alter value in module.exports after export"112 );113 exn = get_exn(() => (H.key2 = "this should not be accepted, either"));114 ok(115 exn instanceof TypeError,116 "Cannot add value to module.exports after export"117 );118});119self.onmessage = function(message) {120 for (let test of tests) {121 info("Entering " + test.name);122 try {123 test();124 } catch (ex) {125 ok(false, "Test " + test.name + " failed");126 info(ex);127 info(ex.stack);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3if (err) {4console.log(err);5} else {6console.log(data);7}8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org');11if (err) {12console.log(err);13} else {14console.log(data);15}16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org');19if (err) {20console.log(err);21} else {22console.log(data);23}24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org');27if (err) {28console.log(err);29} else {30console.log(data);31}32});33var wpt = require('wpt');34var wpt = new WebPageTest('www.webpagetest.org');35if (err) {36console.log(err);37} else {38console.log(data);39}40});41var wpt = require('wpt');42var wpt = new WebPageTest('www.webpagetest.org');43if (err) {44console.log(err);45} else {46console.log(data);47}48});49var wpt = require('wpt');50var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err){4 console.log(err);5 return;6 }7 console.log('Test status: ' + data.statusText);8 wpt.getTestResults(data.data.testId, function(err, data) {9 if (err){10 console.log(err);11 return;12 }13 console.log('First view: ' + data.data.average.firstView.loadTime);14 console.log('Repeat view: ' + data.data.average.repeatView.loadTime);15 });16});17{18 "dependencies": {19 }20}

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var cheerio = require('cheerio');3var page = request(url, function(err, resp, body) {4 if (err) { throw err; }5 var $ = cheerio.load(body);6 var links = $('a');7 var text = $('p');8 var title = $('title');9 var link = [];10 var text1 = [];11 var title1 = [];12 $(links).each(function(i, link){13 link[i] = $(link).text();14 });15 $(text).each(function(i, text){16 text1[i] = $(text).text();17 });18 $(title).each(function(i, title){19 title1[i] = $(title).text();20 });21 console.log(link);22 console.log(text1);23 console.log(title1);24});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const fs = require('fs');3const path = require('path');4const data = fs.readFileSync(path.resolve(__dirname, './data.json'), 'utf8');5const json = JSON.parse(data);6const exn = require('./exn.js');7const search = require('./search.js');8const get = require('./get.js');9const exnList = exn(json);10const searchList = search(exnList);11const getList = get(searchList);12console.log(getList);13const wptools = require('wptools');14const fs = require('fs');15const path = require('path');16const data = fs.readFileSync(path.resolve(__dirname, './data.json'), 'utf8');17const json = JSON.parse(data);18const exn = require('./exn.js');19const search = require('./search.js');20const get = require('./get.js');21const exnList = exn(json);22const searchList = search(exnList);23const getList = get(searchList);24console.log(getList);25const wptools = require('wptools');26const fs = require('fs');27const path = require('path');28const data = fs.readFileSync(path.resolve(__dirname, './data.json'), 'utf8');29const json = JSON.parse(data);30const exn = require('./exn.js');31const search = require('./search.js');32const get = require('./get.js');33const exnList = exn(json);34const searchList = search(exnList);35const getList = get(searchList);36console.log(getList);37const wptools = require('wptools');38const fs = require('fs');39const path = require('path');40const data = fs.readFileSync(path.resolve(__dirname, './data.json'), 'utf8');41const json = JSON.parse(data);42const exn = require('./exn.js');43const search = require('./search.js');44const get = require('./get.js');45const exnList = exn(json);46const searchList = search(exnList);47const getList = get(searchList);48console.log(getList);

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require("webpagetest");2const wpt2 = require("webpagetest");3const wpt3 = require("webpagetest");4const wpt4 = require("webpagetest");5const wpt5 = require("webpagetest");6const wpt6 = require("webpagetest");7const wpt7 = require("webpagetest");8const wpt8 = require("webpagetest");9const wpt9 = require("webpagetest");10const wpt10 = require("webpagetest");11const wpt11 = require("webpagetest");12const wpt12 = require("webpagetest");13const wpt13 = require("webpagetest");14const wpt14 = require("webpagetest");15const wpt15 = require("webpagetest");16const wpt16 = require("webpagetest");17const wpt17 = require("webpagetest");18const wpt18 = require("webpagetest");19const wpt19 = require("webpagetest");20const wpt20 = require("webpagetest");21const wpt21 = require("webpagetest");22const wpt22 = require("webpagetest");23const wpt23 = require("webpagetest");24const wpt24 = require("webpagetest");25const wpt25 = require("webpagetest");26const wpt26 = require("webpagetest");27const wpt27 = require("webpagetest");28const wpt28 = require("webpagetest");29const wpt29 = require("webpagetest");30const wpt30 = require("webpagetest");31const wpt31 = require("webpagetest");32const wpt32 = require("webpagetest");33const wpt33 = require("webpagetest");34const wpt34 = require("webpagetest");35const wpt35 = require("webpagetest");36const wpt36 = require("webpagetest");37const wpt37 = require("webpagetest");38const wpt38 = require("webpagetest");39const wpt39 = require("webpagetest");40const wpt40 = require("webpagetest");41const wpt41 = require("webpagetest");42const wpt42 = require("webpagetest");

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.4c6f7b0c8b8b7b1c9e9e9f9b8b8b7b1c');3 if (err) return console.log(err);4 console.log('Test ID: %s', data.data.testId);5 console.log('To see the test results, browse to: %sresult/%s/', wpt.testUrl, data.data.testId);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org', 'A.4c6f7b0c8b8b7b1c9e9e9f9b8b8b7b1c');9 if (err) return console.log(err);10 console.log('Test ID: %s', data.data.testId);11 console.log('To see the test results, browse to: %sresult/%s/', wpt.testUrl, data.data.testId);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org', 'A.4c6f7b0c8b8b7b1c9e9e9f9b8b8b7b1c');15 if (err) return console.log(err);16 console.log('Test ID: %s', data.data.testId);17 console.log('To see the test results, browse to: %sresult/%s/', wpt.testUrl, data.data.testId);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org', 'A.4c6f7b0c8b8b7

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful