How to use assertErrorMessage method in Testcafe

Best JavaScript code snippet using testcafe

testAtomics.js

Source:testAtomics.js Github

copy

Full Screen

...253 assertEq(i32m.cas2_i(size*100), -1);254 assertEq(i32a[100], 0x5A5A5A5A);255 // Out-of-bounds accesses.256 var oob = (heap.byteLength * 2) & ~7;257 assertErrorMessage(() => i32m.cas1_i(oob), RangeError, /out-of-range index/);258 assertErrorMessage(() => i32m.cas2_i(oob), RangeError, /out-of-range index/);259 assertErrorMessage(() => i32m.or_i(oob), RangeError, /out-of-range index/);260 assertErrorMessage(() => i32m.xor_i(oob), RangeError, /out-of-range index/);261 assertErrorMessage(() => i32m.and_i(oob), RangeError, /out-of-range index/);262 assertErrorMessage(() => i32m.add_i(oob), RangeError, /out-of-range index/);263 assertErrorMessage(() => i32m.sub_i(oob), RangeError, /out-of-range index/);264 assertErrorMessage(() => i32m.load_i(oob), RangeError, /out-of-range index/);265 assertErrorMessage(() => i32m.store_i(oob), RangeError, /out-of-range index/);266 assertErrorMessage(() => i32m.xchg_i(oob), RangeError, /out-of-range index/);267 // Edge cases268 assertErrorMessage(() => i32m.load_i(i32a.length*4), RangeError, /out-of-range index/);269 assertErrorMessage(() => i32m.store_i(i32a.length*4), RangeError, /out-of-range index/);270 assertErrorMessage(() => i32m.add_i(i32a.length*4), RangeError, /out-of-range index/);271 i32a[i32a.length-1] = 88;272 assertEq(i32m.load_i((i32a.length-1)*4), 88);273 assertEq(i32m.store_i((i32a.length-1)*4), 37);274 assertEq(i32m.add_i((i32a.length-1)*4), 37);275 assertEq(i32m.load_i((i32a.length-1)*4), 37+37);276 i32a[i32a.length-1] = 0;277}278var loadModule_uint32_code =279 USE_ASM + `280 var atomic_fence = stdlib.Atomics.fence;281 var atomic_load = stdlib.Atomics.load;282 var atomic_store = stdlib.Atomics.store;283 var atomic_cmpxchg = stdlib.Atomics.compareExchange;284 var atomic_exchange = stdlib.Atomics.exchange;285 var atomic_add = stdlib.Atomics.add;286 var atomic_sub = stdlib.Atomics.sub;287 var atomic_and = stdlib.Atomics.and;288 var atomic_or = stdlib.Atomics.or;289 var atomic_xor = stdlib.Atomics.xor;290 var i32a = new stdlib.SharedUint32Array(heap);291 // Load element 0292 function do_load() {293 var v = 0;294 v = atomic_load(i32a, 0);295 return +(v>>>0);296 }297 // Load element i298 function do_load_i(i) {299 i = i|0;300 var v = 0;301 v = atomic_load(i32a, i>>2);302 return +(v>>>0);303 }304 // Store 37 in element 0305 function do_store() {306 var v = 0;307 v = atomic_store(i32a, 0, 37);308 return +(v>>>0);309 }310 // Store 37 in element i311 function do_store_i(i) {312 i = i|0;313 var v = 0;314 v = atomic_store(i32a, i>>2, 37);315 return +(v>>>0);316 }317 // Exchange 37 into element 200318 function do_xchg() {319 var v = 0;320 v = atomic_exchange(i32a, 200, 37);321 return v|0;322 }323 // Exchange 42 into element i324 function do_xchg_i(i) {325 i = i|0;326 var v = 0;327 v = atomic_exchange(i32a, i>>2, 42);328 return v|0;329 }330 // Add 37 to element 10331 function do_add() {332 var v = 0;333 v = atomic_add(i32a, 10, 37);334 return +(v>>>0);335 }336 // Add 37 to element i337 function do_add_i(i) {338 i = i|0;339 var v = 0;340 v = atomic_add(i32a, i>>2, 37);341 return +(v>>>0);342 }343 // Subtract 148 from element 20344 function do_sub() {345 var v = 0;346 v = atomic_sub(i32a, 20, 148);347 return +(v>>>0);348 }349 // Subtract 148 from element i350 function do_sub_i(i) {351 i = i|0;352 var v = 0;353 v = atomic_sub(i32a, i>>2, 148);354 return +(v>>>0);355 }356 // AND 0x33333333 into element 30357 function do_and() {358 var v = 0;359 v = atomic_and(i32a, 30, 0x33333333);360 return +(v>>>0);361 }362 // AND 0x33333333 into element i363 function do_and_i(i) {364 i = i|0;365 var v = 0;366 v = atomic_and(i32a, i>>2, 0x33333333);367 return +(v>>>0);368 }369 // OR 0x33333333 into element 40370 function do_or() {371 var v = 0;372 v = atomic_or(i32a, 40, 0x33333333);373 return +(v>>>0);374 }375 // OR 0x33333333 into element i376 function do_or_i(i) {377 i = i|0;378 var v = 0;379 v = atomic_or(i32a, i>>2, 0x33333333);380 return +(v>>>0);381 }382 // XOR 0x33333333 into element 50383 function do_xor() {384 var v = 0;385 v = atomic_xor(i32a, 50, 0x33333333);386 return +(v>>>0);387 }388 // XOR 0x33333333 into element i389 function do_xor_i(i) {390 i = i|0;391 var v = 0;392 v = atomic_xor(i32a, i>>2, 0x33333333);393 return +(v>>>0);394 }395 // CAS element 100: 0 -> -1396 function do_cas1() {397 var v = 0;398 v = atomic_cmpxchg(i32a, 100, 0, -1);399 return +(v>>>0);400 }401 // CAS element 100: -1 -> 0x5A5A5A5A402 function do_cas2() {403 var v = 0;404 v = atomic_cmpxchg(i32a, 100, -1, 0x5A5A5A5A);405 return +(v>>>0);406 }407 // CAS element i: 0 -> -1408 function do_cas1_i(i) {409 i = i|0;410 var v = 0;411 v = atomic_cmpxchg(i32a, i>>2, 0, -1);412 return +(v>>>0);413 }414 // CAS element i: -1 -> 0x5A5A5A5A415 function do_cas2_i(i) {416 i = i|0;417 var v = 0;418 v = atomic_cmpxchg(i32a, i>>2, -1, 0x5A5A5A5A);419 return +(v>>>0);420 }421 return { load: do_load,422 load_i: do_load_i,423 store: do_store,424 store_i: do_store_i,425 xchg: do_xchg,426 xchg_i: do_xchg_i,427 add: do_add,428 add_i: do_add_i,429 sub: do_sub,430 sub_i: do_sub_i,431 and: do_and,432 and_i: do_and_i,433 or: do_or,434 or_i: do_or_i,435 xor: do_xor,436 xor_i: do_xor_i,437 cas1: do_cas1,438 cas2: do_cas2,439 cas1_i: do_cas1_i,440 cas2_i: do_cas2_i };441`;442var loadModule_uint32 = asmCompile('stdlib', 'foreign', 'heap', loadModule_uint32_code);443function test_uint32(heap) {444 var i32a = new SharedUint32Array(heap);445 var i32m = loadModule_uint32(this, {}, heap);446 var size = SharedUint32Array.BYTES_PER_ELEMENT;447 i32a[0] = 12345;448 assertEq(i32m.load(), 12345);449 assertEq(i32m.load_i(size*0), 12345);450 assertEq(i32m.store(), 37);451 assertEq(i32a[0], 37);452 assertEq(i32m.store_i(size*0), 37);453 i32a[200] = 78;454 assertEq(i32m.xchg(), 78); // 37 into #200455 assertEq(i32a[0], 37);456 assertEq(i32m.xchg_i(size*200), 37); // 42 into #200457 assertEq(i32a[200], 42);458 i32a[10] = 18;459 assertEq(i32m.add(), 18);460 assertEq(i32a[10], 18+37);461 assertEq(i32m.add_i(size*10), 18+37);462 assertEq(i32a[10], 18+37+37);463 i32a[20] = 4972;464 assertEq(i32m.sub(), 4972);465 assertEq(i32a[20], 4972 - 148);466 assertEq(i32m.sub_i(size*20), 4972 - 148);467 assertEq(i32a[20], 4972 - 148 - 148);468 i32a[30] = 0x66666666;469 assertEq(i32m.and(), 0x66666666);470 assertEq(i32a[30], 0x22222222);471 i32a[30] = 0x66666666;472 assertEq(i32m.and_i(size*30), 0x66666666);473 assertEq(i32a[30], 0x22222222);474 i32a[40] = 0x22222222;475 assertEq(i32m.or(), 0x22222222);476 assertEq(i32a[40], 0x33333333);477 i32a[40] = 0x22222222;478 assertEq(i32m.or_i(size*40), 0x22222222);479 assertEq(i32a[40], 0x33333333);480 i32a[50] = 0x22222222;481 assertEq(i32m.xor(), 0x22222222);482 assertEq(i32a[50], 0x11111111);483 i32a[50] = 0x22222222;484 assertEq(i32m.xor_i(size*50), 0x22222222);485 assertEq(i32a[50], 0x11111111);486 i32a[100] = 0;487 assertEq(i32m.cas1(), 0);488 assertEq(i32m.cas2(), 0xFFFFFFFF);489 assertEq(i32a[100], 0x5A5A5A5A);490 i32a[100] = 0;491 assertEq(i32m.cas1_i(size*100), 0);492 assertEq(i32m.cas2_i(size*100), 0xFFFFFFFF);493 assertEq(i32a[100], 0x5A5A5A5A);494 // Out-of-bounds accesses.495 var oob = (heap.byteLength * 2) & ~7;496 assertErrorMessage(() => i32m.cas1_i(oob), RangeError, /out-of-range index/);497 assertErrorMessage(() => i32m.cas2_i(oob), RangeError, /out-of-range index/);498 assertErrorMessage(() => i32m.or_i(oob), RangeError, /out-of-range index/);499 assertErrorMessage(() => i32m.xor_i(oob), RangeError, /out-of-range index/);500 assertErrorMessage(() => i32m.and_i(oob), RangeError, /out-of-range index/);501 assertErrorMessage(() => i32m.add_i(oob), RangeError, /out-of-range index/);502 assertErrorMessage(() => i32m.sub_i(oob), RangeError, /out-of-range index/);503 assertErrorMessage(() => i32m.load_i(oob), RangeError, /out-of-range index/);504 assertErrorMessage(() => i32m.store_i(oob), RangeError, /out-of-range index/);505 assertErrorMessage(() => i32m.xchg_i(oob), RangeError, /out-of-range index/);506 // Edge cases507 assertErrorMessage(() => i32m.load_i(i32a.length*4), RangeError, /out-of-range index/);508 assertErrorMessage(() => i32m.store_i(i32a.length*4), RangeError, /out-of-range index/);509 assertErrorMessage(() => i32m.add_i(i32a.length*4), RangeError, /out-of-range index/);510 i32a[i32a.length-1] = 88;511 assertEq(i32m.load_i((i32a.length-1)*4), 88);512 assertEq(i32m.store_i((i32a.length-1)*4), 37);513 assertEq(i32m.add_i((i32a.length-1)*4), 37);514 assertEq(i32m.load_i((i32a.length-1)*4), 37+37);515 i32a[i32a.length-1] = 0;516}517var loadModule_int16_code =518 USE_ASM + `519 var atomic_fence = stdlib.Atomics.fence;520 var atomic_load = stdlib.Atomics.load;521 var atomic_store = stdlib.Atomics.store;522 var atomic_cmpxchg = stdlib.Atomics.compareExchange;523 var atomic_exchange = stdlib.Atomics.exchange;524 var atomic_add = stdlib.Atomics.add;525 var atomic_sub = stdlib.Atomics.sub;526 var atomic_and = stdlib.Atomics.and;527 var atomic_or = stdlib.Atomics.or;528 var atomic_xor = stdlib.Atomics.xor;529 var i16a = new stdlib.SharedInt16Array(heap);530 function do_fence() {531 atomic_fence();532 }533 // Load element 0534 function do_load() {535 var v = 0;536 v = atomic_load(i16a, 0);537 return v|0;538 }539 // Load element i540 function do_load_i(i) {541 i = i|0;542 var v = 0;543 v = atomic_load(i16a, i>>1);544 return v|0;545 }546 // Store 37 in element 0547 function do_store() {548 var v = 0;549 v = atomic_store(i16a, 0, 37);550 return v|0;551 }552 // Store 37 in element i553 function do_store_i(i) {554 i = i|0;555 var v = 0;556 v = atomic_store(i16a, i>>1, 37);557 return v|0;558 }559 // Exchange 37 into element 200560 function do_xchg() {561 var v = 0;562 v = atomic_exchange(i16a, 200, 37);563 return v|0;564 }565 // Exchange 42 into element i566 function do_xchg_i(i) {567 i = i|0;568 var v = 0;569 v = atomic_exchange(i16a, i>>1, 42);570 return v|0;571 }572 // Add 37 to element 10573 function do_add() {574 var v = 0;575 v = atomic_add(i16a, 10, 37);576 return v|0;577 }578 // Add 37 to element i579 function do_add_i(i) {580 i = i|0;581 var v = 0;582 v = atomic_add(i16a, i>>1, 37);583 return v|0;584 }585 // Subtract 148 from element 20586 function do_sub() {587 var v = 0;588 v = atomic_sub(i16a, 20, 148);589 return v|0;590 }591 // Subtract 148 from element i592 function do_sub_i(i) {593 i = i|0;594 var v = 0;595 v = atomic_sub(i16a, i>>1, 148);596 return v|0;597 }598 // AND 0x3333 into element 30599 function do_and() {600 var v = 0;601 v = atomic_and(i16a, 30, 0x3333);602 return v|0;603 }604 // AND 0x3333 into element i605 function do_and_i(i) {606 i = i|0;607 var v = 0;608 v = atomic_and(i16a, i>>1, 0x3333);609 return v|0;610 }611 // OR 0x3333 into element 40612 function do_or() {613 var v = 0;614 v = atomic_or(i16a, 40, 0x3333);615 return v|0;616 }617 // OR 0x3333 into element i618 function do_or_i(i) {619 i = i|0;620 var v = 0;621 v = atomic_or(i16a, i>>1, 0x3333);622 return v|0;623 }624 // XOR 0x3333 into element 50625 function do_xor() {626 var v = 0;627 v = atomic_xor(i16a, 50, 0x3333);628 return v|0;629 }630 // XOR 0x3333 into element i631 function do_xor_i(i) {632 i = i|0;633 var v = 0;634 v = atomic_xor(i16a, i>>1, 0x3333);635 return v|0;636 }637 // CAS element 100: 0 -> -1638 function do_cas1() {639 var v = 0;640 v = atomic_cmpxchg(i16a, 100, 0, -1);641 return v|0;642 }643 // CAS element 100: -1 -> 0x5A5A644 function do_cas2() {645 var v = 0;646 v = atomic_cmpxchg(i16a, 100, -1, 0x5A5A);647 return v|0;648 }649 // CAS element i: 0 -> -1650 function do_cas1_i(i) {651 i = i|0;652 var v = 0;653 v = atomic_cmpxchg(i16a, i>>1, 0, -1);654 return v|0;655 }656 // CAS element i: -1 -> 0x5A5A657 function do_cas2_i(i) {658 i = i|0;659 var v = 0;660 v = atomic_cmpxchg(i16a, i>>1, -1, 0x5A5A);661 return v|0;662 }663 return { fence: do_fence,664 load: do_load,665 load_i: do_load_i,666 store: do_store,667 store_i: do_store_i,668 xchg: do_xchg,669 xchg_i: do_xchg_i,670 add: do_add,671 add_i: do_add_i,672 sub: do_sub,673 sub_i: do_sub_i,674 and: do_and,675 and_i: do_and_i,676 or: do_or,677 or_i: do_or_i,678 xor: do_xor,679 xor_i: do_xor_i,680 cas1: do_cas1,681 cas2: do_cas2,682 cas1_i: do_cas1_i,683 cas2_i: do_cas2_i };684`685var loadModule_int16 = asmCompile('stdlib', 'foreign', 'heap', loadModule_int16_code);686function test_int16(heap) {687 var i16a = new SharedInt16Array(heap);688 var i16m = loadModule_int16(this, {}, heap);689 var size = SharedInt16Array.BYTES_PER_ELEMENT;690 i16m.fence();691 i16a[0] = 12345;692 assertEq(i16m.load(), 12345);693 assertEq(i16m.load_i(size*0), 12345);694 i16a[0] = -38;695 assertEq(i16m.load(), -38);696 assertEq(i16m.load_i(size*0), -38);697 assertEq(i16m.store(), 37);698 assertEq(i16a[0], 37);699 assertEq(i16m.store_i(size*0), 37);700 i16a[200] = 78;701 assertEq(i16m.xchg(), 78); // 37 into #200702 assertEq(i16a[0], 37);703 assertEq(i16m.xchg_i(size*200), 37); // 42 into #200704 assertEq(i16a[200], 42);705 i16a[10] = 18;706 assertEq(i16m.add(), 18);707 assertEq(i16a[10], 18+37);708 assertEq(i16m.add_i(size*10), 18+37);709 assertEq(i16a[10], 18+37+37);710 i16a[10] = -38;711 assertEq(i16m.add(), -38);712 assertEq(i16a[10], -38+37);713 assertEq(i16m.add_i(size*10), -38+37);714 assertEq(i16a[10], -38+37+37);715 i16a[20] = 4972;716 assertEq(i16m.sub(), 4972);717 assertEq(i16a[20], 4972 - 148);718 assertEq(i16m.sub_i(size*20), 4972 - 148);719 assertEq(i16a[20], 4972 - 148 - 148);720 i16a[30] = 0x6666;721 assertEq(i16m.and(), 0x6666);722 assertEq(i16a[30], 0x2222);723 i16a[30] = 0x6666;724 assertEq(i16m.and_i(size*30), 0x6666);725 assertEq(i16a[30], 0x2222);726 i16a[40] = 0x2222;727 assertEq(i16m.or(), 0x2222);728 assertEq(i16a[40], 0x3333);729 i16a[40] = 0x2222;730 assertEq(i16m.or_i(size*40), 0x2222);731 assertEq(i16a[40], 0x3333);732 i16a[50] = 0x2222;733 assertEq(i16m.xor(), 0x2222);734 assertEq(i16a[50], 0x1111);735 i16a[50] = 0x2222;736 assertEq(i16m.xor_i(size*50), 0x2222);737 assertEq(i16a[50], 0x1111);738 i16a[100] = 0;739 assertEq(i16m.cas1(), 0);740 assertEq(i16m.cas2(), -1);741 assertEq(i16a[100], 0x5A5A);742 i16a[100] = 0;743 assertEq(i16m.cas1_i(size*100), 0);744 assertEq(i16m.cas2_i(size*100), -1);745 assertEq(i16a[100], 0x5A5A);746 var oob = (heap.byteLength * 2) & ~7;747 assertErrorMessage(() => i16m.cas1_i(oob), RangeError, /out-of-range index/);748 assertErrorMessage(() => i16m.cas2_i(oob), RangeError, /out-of-range index/);749 assertErrorMessage(() => i16m.or_i(oob), RangeError, /out-of-range index/);750 assertErrorMessage(() => i16m.xor_i(oob), RangeError, /out-of-range index/);751 assertErrorMessage(() => i16m.and_i(oob), RangeError, /out-of-range index/);752 assertErrorMessage(() => i16m.add_i(oob), RangeError, /out-of-range index/);753 assertErrorMessage(() => i16m.sub_i(oob), RangeError, /out-of-range index/);754 assertErrorMessage(() => i16m.load_i(oob), RangeError, /out-of-range index/);755 assertErrorMessage(() => i16m.store_i(oob), RangeError, /out-of-range index/);756 assertErrorMessage(() => i16m.xchg_i(oob), RangeError, /out-of-range index/);757 // Edge cases758 assertErrorMessage(() => i16m.load_i(i16a.length*2), RangeError, /out-of-range index/);759 assertErrorMessage(() => i16m.store_i(i16a.length*2), RangeError, /out-of-range index/);760 assertErrorMessage(() => i16m.add_i(i16a.length*2), RangeError, /out-of-range index/);761 i16a[i16a.length-1] = 88;762 assertEq(i16m.load_i((i16a.length-1)*2), 88);763 assertEq(i16m.store_i((i16a.length-1)*2), 37);764 assertEq(i16m.add_i((i16a.length-1)*2), 37);765 assertEq(i16m.load_i((i16a.length-1)*2), 37+37);766 i16a[i16a.length-1] = 0;767}768var loadModule_uint16_code =769 USE_ASM + `770 var atomic_load = stdlib.Atomics.load;771 var atomic_store = stdlib.Atomics.store;772 var atomic_cmpxchg = stdlib.Atomics.compareExchange;773 var atomic_exchange = stdlib.Atomics.exchange;774 var atomic_add = stdlib.Atomics.add;775 var atomic_sub = stdlib.Atomics.sub;776 var atomic_and = stdlib.Atomics.and;777 var atomic_or = stdlib.Atomics.or;778 var atomic_xor = stdlib.Atomics.xor;779 var i16a = new stdlib.SharedUint16Array(heap);780 // Load element 0781 function do_load() {782 var v = 0;783 v = atomic_load(i16a, 0);784 return v|0;785 }786 // Load element i787 function do_load_i(i) {788 i = i|0;789 var v = 0;790 v = atomic_load(i16a, i>>1);791 return v|0;792 }793 // Store 37 in element 0794 function do_store() {795 var v = 0;796 v = atomic_store(i16a, 0, 37);797 return v|0;798 }799 // Store 37 in element i800 function do_store_i(i) {801 i = i|0;802 var v = 0;803 v = atomic_store(i16a, i>>1, 37);804 return v|0;805 }806 // Exchange 37 into element 200807 function do_xchg() {808 var v = 0;809 v = atomic_exchange(i16a, 200, 37);810 return v|0;811 }812 // Exchange 42 into element i813 function do_xchg_i(i) {814 i = i|0;815 var v = 0;816 v = atomic_exchange(i16a, i>>1, 42);817 return v|0;818 }819 // Add 37 to element 10820 function do_add() {821 var v = 0;822 v = atomic_add(i16a, 10, 37);823 return v|0;824 }825 // Add 37 to element i826 function do_add_i(i) {827 i = i|0;828 var v = 0;829 v = atomic_add(i16a, i>>1, 37);830 return v|0;831 }832 // Subtract 148 from element 20833 function do_sub() {834 var v = 0;835 v = atomic_sub(i16a, 20, 148);836 return v|0;837 }838 // Subtract 148 from element i839 function do_sub_i(i) {840 i = i|0;841 var v = 0;842 v = atomic_sub(i16a, i>>1, 148);843 return v|0;844 }845 // AND 0x3333 into element 30846 function do_and() {847 var v = 0;848 v = atomic_and(i16a, 30, 0x3333);849 return v|0;850 }851 // AND 0x3333 into element i852 function do_and_i(i) {853 i = i|0;854 var v = 0;855 v = atomic_and(i16a, i>>1, 0x3333);856 return v|0;857 }858 // OR 0x3333 into element 40859 function do_or() {860 var v = 0;861 v = atomic_or(i16a, 40, 0x3333);862 return v|0;863 }864 // OR 0x3333 into element i865 function do_or_i(i) {866 i = i|0;867 var v = 0;868 v = atomic_or(i16a, i>>1, 0x3333);869 return v|0;870 }871 // XOR 0x3333 into element 50872 function do_xor() {873 var v = 0;874 v = atomic_xor(i16a, 50, 0x3333);875 return v|0;876 }877 // XOR 0x3333 into element i878 function do_xor_i(i) {879 i = i|0;880 var v = 0;881 v = atomic_xor(i16a, i>>1, 0x3333);882 return v|0;883 }884 // CAS element 100: 0 -> -1885 function do_cas1() {886 var v = 0;887 v = atomic_cmpxchg(i16a, 100, 0, -1);888 return v|0;889 }890 // CAS element 100: -1 -> 0x5A5A891 function do_cas2() {892 var v = 0;893 v = atomic_cmpxchg(i16a, 100, -1, 0x5A5A);894 return v|0;895 }896 // CAS element i: 0 -> -1897 function do_cas1_i(i) {898 i = i|0;899 var v = 0;900 v = atomic_cmpxchg(i16a, i>>1, 0, -1);901 return v|0;902 }903 // CAS element i: -1 -> 0x5A5A904 function do_cas2_i(i) {905 i = i|0;906 var v = 0;907 v = atomic_cmpxchg(i16a, i>>1, -1, 0x5A5A);908 return v|0;909 }910 return { load: do_load,911 load_i: do_load_i,912 store: do_store,913 store_i: do_store_i,914 xchg: do_xchg,915 xchg_i: do_xchg_i,916 add: do_add,917 add_i: do_add_i,918 sub: do_sub,919 sub_i: do_sub_i,920 and: do_and,921 and_i: do_and_i,922 or: do_or,923 or_i: do_or_i,924 xor: do_xor,925 xor_i: do_xor_i,926 cas1: do_cas1,927 cas2: do_cas2,928 cas1_i: do_cas1_i,929 cas2_i: do_cas2_i };930`931var loadModule_uint16 = asmCompile('stdlib', 'foreign', 'heap', loadModule_uint16_code);932function test_uint16(heap) {933 var i16a = new SharedUint16Array(heap);934 var i16m = loadModule_uint16(this, {}, heap);935 var size = SharedUint16Array.BYTES_PER_ELEMENT;936 i16a[0] = 12345;937 assertEq(i16m.load(), 12345);938 assertEq(i16m.load_i(size*0), 12345);939 i16a[0] = -38;940 assertEq(i16m.load(), (0x10000-38));941 assertEq(i16m.load_i(size*0), (0x10000-38));942 assertEq(i16m.store(), 37);943 assertEq(i16a[0], 37);944 assertEq(i16m.store_i(size*0), 37);945 i16a[200] = 78;946 assertEq(i16m.xchg(), 78); // 37 into #200947 assertEq(i16a[0], 37);948 assertEq(i16m.xchg_i(size*200), 37); // 42 into #200949 assertEq(i16a[200], 42);950 i16a[10] = 18;951 assertEq(i16m.add(), 18);952 assertEq(i16a[10], 18+37);953 assertEq(i16m.add_i(size*10), 18+37);954 assertEq(i16a[10], 18+37+37);955 i16a[10] = -38;956 assertEq(i16m.add(), (0x10000-38));957 assertEq(i16a[10], (0x10000-38)+37);958 assertEq(i16m.add_i(size*10), (0x10000-38)+37);959 assertEq(i16a[10], ((0x10000-38)+37+37) & 0xFFFF);960 i16a[20] = 4972;961 assertEq(i16m.sub(), 4972);962 assertEq(i16a[20], 4972 - 148);963 assertEq(i16m.sub_i(size*20), 4972 - 148);964 assertEq(i16a[20], 4972 - 148 - 148);965 i16a[30] = 0x6666;966 assertEq(i16m.and(), 0x6666);967 assertEq(i16a[30], 0x2222);968 i16a[30] = 0x6666;969 assertEq(i16m.and_i(size*30), 0x6666);970 assertEq(i16a[30], 0x2222);971 i16a[40] = 0x2222;972 assertEq(i16m.or(), 0x2222);973 assertEq(i16a[40], 0x3333);974 i16a[40] = 0x2222;975 assertEq(i16m.or_i(size*40), 0x2222);976 assertEq(i16a[40], 0x3333);977 i16a[50] = 0x2222;978 assertEq(i16m.xor(), 0x2222);979 assertEq(i16a[50], 0x1111);980 i16a[50] = 0x2222;981 assertEq(i16m.xor_i(size*50), 0x2222);982 assertEq(i16a[50], 0x1111);983 i16a[100] = 0;984 assertEq(i16m.cas1(), 0);985 assertEq(i16m.cas2(), -1 & 0xFFFF);986 assertEq(i16a[100], 0x5A5A);987 i16a[100] = 0;988 assertEq(i16m.cas1_i(size*100), 0);989 assertEq(i16m.cas2_i(size*100), -1 & 0xFFFF);990 assertEq(i16a[100], 0x5A5A);991 var oob = (heap.byteLength * 2) & ~7;992 assertErrorMessage(() => i16m.cas1_i(oob), RangeError, /out-of-range index/);993 assertErrorMessage(() => i16m.cas2_i(oob), RangeError, /out-of-range index/);994 assertErrorMessage(() => i16m.or_i(oob), RangeError, /out-of-range index/);995 assertErrorMessage(() => i16m.xor_i(oob), RangeError, /out-of-range index/);996 assertErrorMessage(() => i16m.and_i(oob), RangeError, /out-of-range index/);997 assertErrorMessage(() => i16m.add_i(oob), RangeError, /out-of-range index/);998 assertErrorMessage(() => i16m.sub_i(oob), RangeError, /out-of-range index/);999 assertErrorMessage(() => i16m.load_i(oob), RangeError, /out-of-range index/);1000 assertErrorMessage(() => i16m.store_i(oob), RangeError, /out-of-range index/);1001 assertErrorMessage(() => i16m.xchg_i(oob), RangeError, /out-of-range index/);1002 // Edge cases1003 assertErrorMessage(() => i16m.load_i(i16a.length*2), RangeError, /out-of-range index/);1004 assertErrorMessage(() => i16m.store_i(i16a.length*2), RangeError, /out-of-range index/);1005 assertErrorMessage(() => i16m.add_i(i16a.length*2), RangeError, /out-of-range index/);1006 i16a[i16a.length-1] = 88;1007 assertEq(i16m.load_i((i16a.length-1)*2), 88);1008 assertEq(i16m.store_i((i16a.length-1)*2), 37);1009 assertEq(i16m.add_i((i16a.length-1)*2), 37);1010 assertEq(i16m.load_i((i16a.length-1)*2), 37+37);1011 i16a[i16a.length-1] = 0;1012}1013var loadModule_int8_code =1014 USE_ASM + `1015 var atomic_load = stdlib.Atomics.load;1016 var atomic_store = stdlib.Atomics.store;1017 var atomic_cmpxchg = stdlib.Atomics.compareExchange;1018 var atomic_exchange = stdlib.Atomics.exchange;1019 var atomic_add = stdlib.Atomics.add;1020 var atomic_sub = stdlib.Atomics.sub;1021 var atomic_and = stdlib.Atomics.and;1022 var atomic_or = stdlib.Atomics.or;1023 var atomic_xor = stdlib.Atomics.xor;1024 var i8a = new stdlib.SharedInt8Array(heap);1025 // Load element 01026 function do_load() {1027 var v = 0;1028 v = atomic_load(i8a, 0);1029 return v|0;1030 }1031 // Load element i1032 function do_load_i(i) {1033 i = i|0;1034 var v = 0;1035 v = atomic_load(i8a, i);1036 return v|0;1037 }1038 // Store 37 in element 01039 function do_store() {1040 var v = 0;1041 v = atomic_store(i8a, 0, 37);1042 return v|0;1043 }1044 // Store 37 in element i1045 function do_store_i(i) {1046 i = i|0;1047 var v = 0;1048 v = atomic_store(i8a, i, 37);1049 return v|0;1050 }1051 // Exchange 37 into element 2001052 function do_xchg() {1053 var v = 0;1054 v = atomic_exchange(i8a, 200, 37);1055 return v|0;1056 }1057 // Exchange 42 into element i1058 function do_xchg_i(i) {1059 i = i|0;1060 var v = 0;1061 v = atomic_exchange(i8a, i, 42);1062 return v|0;1063 }1064 // Add 37 to element 101065 function do_add() {1066 var v = 0;1067 v = atomic_add(i8a, 10, 37);1068 return v|0;1069 }1070 // Add 37 to element i1071 function do_add_i(i) {1072 i = i|0;1073 var v = 0;1074 v = atomic_add(i8a, i, 37);1075 return v|0;1076 }1077 // Subtract 108 from element 201078 function do_sub() {1079 var v = 0;1080 v = atomic_sub(i8a, 20, 108);1081 return v|0;1082 }1083 // Subtract 108 from element i1084 function do_sub_i(i) {1085 i = i|0;1086 var v = 0;1087 v = atomic_sub(i8a, i, 108);1088 return v|0;1089 }1090 // AND 0x33 into element 301091 function do_and() {1092 var v = 0;1093 v = atomic_and(i8a, 30, 0x33);1094 return v|0;1095 }1096 // AND 0x33 into element i1097 function do_and_i(i) {1098 i = i|0;1099 var v = 0;1100 v = atomic_and(i8a, i, 0x33);1101 return v|0;1102 }1103 // OR 0x33 into element 401104 function do_or() {1105 var v = 0;1106 v = atomic_or(i8a, 40, 0x33);1107 return v|0;1108 }1109 // OR 0x33 into element i1110 function do_or_i(i) {1111 i = i|0;1112 var v = 0;1113 v = atomic_or(i8a, i, 0x33);1114 return v|0;1115 }1116 // XOR 0x33 into element 501117 function do_xor() {1118 var v = 0;1119 v = atomic_xor(i8a, 50, 0x33);1120 return v|0;1121 }1122 // XOR 0x33 into element i1123 function do_xor_i(i) {1124 i = i|0;1125 var v = 0;1126 v = atomic_xor(i8a, i, 0x33);1127 return v|0;1128 }1129 // CAS element 100: 0 -> -11130 function do_cas1() {1131 var v = 0;1132 v = atomic_cmpxchg(i8a, 100, 0, -1);1133 return v|0;1134 }1135 // CAS element 100: -1 -> 0x5A1136 function do_cas2() {1137 var v = 0;1138 v = atomic_cmpxchg(i8a, 100, -1, 0x5A);1139 return v|0;1140 }1141 // CAS element i: 0 -> -11142 function do_cas1_i(i) {1143 i = i|0;1144 var v = 0;1145 v = atomic_cmpxchg(i8a, i, 0, -1);1146 return v|0;1147 }1148 // CAS element i: -1 -> 0x5A1149 function do_cas2_i(i) {1150 i = i|0;1151 var v = 0;1152 v = atomic_cmpxchg(i8a, i, -1, 0x5A);1153 return v|0;1154 }1155 return { load: do_load,1156 load_i: do_load_i,1157 store: do_store,1158 store_i: do_store_i,1159 xchg: do_xchg,1160 xchg_i: do_xchg_i,1161 add: do_add,1162 add_i: do_add_i,1163 sub: do_sub,1164 sub_i: do_sub_i,1165 and: do_and,1166 and_i: do_and_i,1167 or: do_or,1168 or_i: do_or_i,1169 xor: do_xor,1170 xor_i: do_xor_i,1171 cas1: do_cas1,1172 cas2: do_cas2,1173 cas1_i: do_cas1_i,1174 cas2_i: do_cas2_i };1175`1176var loadModule_int8 = asmCompile('stdlib', 'foreign', 'heap', loadModule_int8_code);1177function test_int8(heap) {1178 var i8a = new SharedInt8Array(heap);1179 var i8m = loadModule_int8(this, {}, heap);1180 for ( var i=0 ; i < i8a.length ; i++ )1181 i8a[i] = 0;1182 var size = SharedInt8Array.BYTES_PER_ELEMENT;1183 i8a[0] = 123;1184 assertEq(i8m.load(), 123);1185 assertEq(i8m.load_i(0), 123);1186 assertEq(i8m.store(), 37);1187 assertEq(i8a[0], 37);1188 assertEq(i8m.store_i(0), 37);1189 i8a[200] = 78;1190 assertEq(i8m.xchg(), 78); // 37 into #2001191 assertEq(i8a[0], 37);1192 assertEq(i8m.xchg_i(size*200), 37); // 42 into #2001193 assertEq(i8a[200], 42);1194 i8a[10] = 18;1195 assertEq(i8m.add(), 18);1196 assertEq(i8a[10], 18+37);1197 assertEq(i8m.add_i(10), 18+37);1198 assertEq(i8a[10], 18+37+37);1199 i8a[20] = 49;1200 assertEq(i8m.sub(), 49);1201 assertEq(i8a[20], 49 - 108);1202 assertEq(i8m.sub_i(20), 49 - 108);1203 assertEq(i8a[20], ((49 - 108 - 108) << 24) >> 24); // Byte, sign extended1204 i8a[30] = 0x66;1205 assertEq(i8m.and(), 0x66);1206 assertEq(i8a[30], 0x22);1207 i8a[30] = 0x66;1208 assertEq(i8m.and_i(30), 0x66);1209 assertEq(i8a[30], 0x22);1210 i8a[40] = 0x22;1211 assertEq(i8m.or(), 0x22);1212 assertEq(i8a[40], 0x33);1213 i8a[40] = 0x22;1214 assertEq(i8m.or_i(40), 0x22);1215 assertEq(i8a[40], 0x33);1216 i8a[50] = 0x22;1217 assertEq(i8m.xor(), 0x22);1218 assertEq(i8a[50], 0x11);1219 i8a[50] = 0x22;1220 assertEq(i8m.xor_i(50), 0x22);1221 assertEq(i8a[50], 0x11);1222 i8a[100] = 0;1223 assertEq(i8m.cas1(), 0);1224 assertEq(i8m.cas2(), -1);1225 assertEq(i8a[100], 0x5A);1226 i8a[100] = 0;1227 assertEq(i8m.cas1_i(100), 0);1228 assertEq(i8m.cas2_i(100), -1);1229 assertEq(i8a[100], 0x5A);1230 var oob = (heap.byteLength * 2) & ~7;1231 assertErrorMessage(() => i8m.cas1_i(oob), RangeError, /out-of-range index/);1232 assertErrorMessage(() => i8m.cas2_i(oob), RangeError, /out-of-range index/);1233 assertErrorMessage(() => i8m.or_i(oob), RangeError, /out-of-range index/);1234 assertErrorMessage(() => i8m.xor_i(oob), RangeError, /out-of-range index/);1235 assertErrorMessage(() => i8m.and_i(oob), RangeError, /out-of-range index/);1236 assertErrorMessage(() => i8m.add_i(oob), RangeError, /out-of-range index/);1237 assertErrorMessage(() => i8m.sub_i(oob), RangeError, /out-of-range index/);1238 assertErrorMessage(() => i8m.load_i(oob), RangeError, /out-of-range index/);1239 assertErrorMessage(() => i8m.store_i(oob), RangeError, /out-of-range index/);1240 assertErrorMessage(() => i8m.xchg_i(oob), RangeError, /out-of-range index/);1241 // Edge cases1242 assertErrorMessage(() => i8m.load_i(i8a.length), RangeError, /out-of-range index/);1243 assertErrorMessage(() => i8m.store_i(i8a.length), RangeError, /out-of-range index/);1244 assertErrorMessage(() => i8m.add_i(i8a.length), RangeError, /out-of-range index/);1245 i8a[i8a.length-1] = 88;1246 assertEq(i8m.load_i(i8a.length-1), 88);1247 assertEq(i8m.store_i(i8a.length-1), 37);1248 assertEq(i8m.add_i(i8a.length-1), 37);1249 assertEq(i8m.load_i(i8a.length-1), 37+37);1250 i8a[i8a.length-1] = 0;1251}1252var loadModule_uint8_code =1253 USE_ASM + `1254 var atomic_load = stdlib.Atomics.load;1255 var atomic_store = stdlib.Atomics.store;1256 var atomic_cmpxchg = stdlib.Atomics.compareExchange;1257 var atomic_exchange = stdlib.Atomics.exchange;1258 var atomic_add = stdlib.Atomics.add;1259 var atomic_sub = stdlib.Atomics.sub;1260 var atomic_and = stdlib.Atomics.and;1261 var atomic_or = stdlib.Atomics.or;1262 var atomic_xor = stdlib.Atomics.xor;1263 var i8a = new stdlib.SharedUint8Array(heap);1264 // Load element 01265 function do_load() {1266 var v = 0;1267 v = atomic_load(i8a, 0);1268 return v|0;1269 }1270 // Load element i1271 function do_load_i(i) {1272 i = i|0;1273 var v = 0;1274 v = atomic_load(i8a, i);1275 return v|0;1276 }1277 // Store 37 in element 01278 function do_store() {1279 var v = 0;1280 v = atomic_store(i8a, 0, 37);1281 return v|0;1282 }1283 // Store 37 in element i1284 function do_store_i(i) {1285 i = i|0;1286 var v = 0;1287 v = atomic_store(i8a, i, 37);1288 return v|0;1289 }1290 // Exchange 37 into element 2001291 function do_xchg() {1292 var v = 0;1293 v = atomic_exchange(i8a, 200, 37);1294 return v|0;1295 }1296 // Exchange 42 into element i1297 function do_xchg_i(i) {1298 i = i|0;1299 var v = 0;1300 v = atomic_exchange(i8a, i, 42);1301 return v|0;1302 }1303 // Add 37 to element 101304 function do_add() {1305 var v = 0;1306 v = atomic_add(i8a, 10, 37);1307 return v|0;1308 }1309 // Add 37 to element i1310 function do_add_i(i) {1311 i = i|0;1312 var v = 0;1313 v = atomic_add(i8a, i, 37);1314 return v|0;1315 }1316 // Subtract 108 from element 201317 function do_sub() {1318 var v = 0;1319 v = atomic_sub(i8a, 20, 108);1320 return v|0;1321 }1322 // Subtract 108 from element i1323 function do_sub_i(i) {1324 i = i|0;1325 var v = 0;1326 v = atomic_sub(i8a, i, 108);1327 return v|0;1328 }1329 // AND 0x33 into element 301330 function do_and() {1331 var v = 0;1332 v = atomic_and(i8a, 30, 0x33);1333 return v|0;1334 }1335 // AND 0x33 into element i1336 function do_and_i(i) {1337 i = i|0;1338 var v = 0;1339 v = atomic_and(i8a, i, 0x33);1340 return v|0;1341 }1342 // OR 0x33 into element 401343 function do_or() {1344 var v = 0;1345 v = atomic_or(i8a, 40, 0x33);1346 return v|0;1347 }1348 // OR 0x33 into element i1349 function do_or_i(i) {1350 i = i|0;1351 var v = 0;1352 v = atomic_or(i8a, i, 0x33);1353 return v|0;1354 }1355 // XOR 0x33 into element 501356 function do_xor() {1357 var v = 0;1358 v = atomic_xor(i8a, 50, 0x33);1359 return v|0;1360 }1361 // XOR 0x33 into element i1362 function do_xor_i(i) {1363 i = i|0;1364 var v = 0;1365 v = atomic_xor(i8a, i, 0x33);1366 return v|0;1367 }1368 // CAS element 100: 0 -> -11369 function do_cas1() {1370 var v = 0;1371 v = atomic_cmpxchg(i8a, 100, 0, -1);1372 return v|0;1373 }1374 // CAS element 100: -1 -> 0x5A1375 function do_cas2() {1376 var v = 0;1377 v = atomic_cmpxchg(i8a, 100, -1, 0x5A);1378 return v|0;1379 }1380 // CAS element i: 0 -> -11381 function do_cas1_i(i) {1382 i = i|0;1383 var v = 0;1384 v = atomic_cmpxchg(i8a, i, 0, -1);1385 return v|0;1386 }1387 // CAS element i: -1 -> 0x5A1388 function do_cas2_i(i) {1389 i = i|0;1390 var v = 0;1391 v = atomic_cmpxchg(i8a, i, -1, 0x5A);1392 return v|0;1393 }1394 return { load: do_load,1395 load_i: do_load_i,1396 store: do_store,1397 store_i: do_store_i,1398 xchg: do_xchg,1399 xchg_i: do_xchg_i,1400 add: do_add,1401 add_i: do_add_i,1402 sub: do_sub,1403 sub_i: do_sub_i,1404 and: do_and,1405 and_i: do_and_i,1406 or: do_or,1407 or_i: do_or_i,1408 xor: do_xor,1409 xor_i: do_xor_i,1410 cas1: do_cas1,1411 cas2: do_cas2,1412 cas1_i: do_cas1_i,1413 cas2_i: do_cas2_i };1414`1415var loadModule_uint8 = asmCompile('stdlib', 'foreign', 'heap', loadModule_uint8_code);1416function test_uint8(heap) {1417 var i8a = new SharedUint8Array(heap);1418 var i8m = loadModule_uint8(this, {}, heap);1419 for ( var i=0 ; i < i8a.length ; i++ )1420 i8a[i] = 0;1421 var size = SharedUint8Array.BYTES_PER_ELEMENT;1422 i8a[0] = 123;1423 assertEq(i8m.load(), 123);1424 assertEq(i8m.load_i(0), 123);1425 i8a[0] = -38;1426 assertEq(i8m.load(), (0x100-38));1427 assertEq(i8m.load_i(size*0), (0x100-38));1428 assertEq(i8m.store(), 37);1429 assertEq(i8a[0], 37);1430 assertEq(i8m.store_i(0), 37);1431 i8a[200] = 78;1432 assertEq(i8m.xchg(), 78); // 37 into #2001433 assertEq(i8a[0], 37);1434 assertEq(i8m.xchg_i(size*200), 37); // 42 into #2001435 assertEq(i8a[200], 42);1436 i8a[10] = 18;1437 assertEq(i8m.add(), 18);1438 assertEq(i8a[10], 18+37);1439 assertEq(i8m.add_i(10), 18+37);1440 assertEq(i8a[10], 18+37+37);1441 i8a[10] = -38;1442 assertEq(i8m.add(), (0x100-38));1443 assertEq(i8a[10], (0x100-38)+37);1444 assertEq(i8m.add_i(size*10), (0x100-38)+37);1445 assertEq(i8a[10], ((0x100-38)+37+37) & 0xFF);1446 i8a[20] = 49;1447 assertEq(i8m.sub(), 49);1448 assertEq(i8a[20], (49 - 108) & 255);1449 assertEq(i8m.sub_i(20), (49 - 108) & 255);1450 assertEq(i8a[20], (49 - 108 - 108) & 255); // Byte, zero extended1451 i8a[30] = 0x66;1452 assertEq(i8m.and(), 0x66);1453 assertEq(i8a[30], 0x22);1454 i8a[30] = 0x66;1455 assertEq(i8m.and_i(30), 0x66);1456 assertEq(i8a[30], 0x22);1457 i8a[40] = 0x22;1458 assertEq(i8m.or(), 0x22);1459 assertEq(i8a[40], 0x33);1460 i8a[40] = 0x22;1461 assertEq(i8m.or_i(40), 0x22);1462 assertEq(i8a[40], 0x33);1463 i8a[50] = 0x22;1464 assertEq(i8m.xor(), 0x22);1465 assertEq(i8a[50], 0x11);1466 i8a[50] = 0x22;1467 assertEq(i8m.xor_i(50), 0x22);1468 assertEq(i8a[50], 0x11);1469 i8a[100] = 0;1470 assertEq(i8m.cas1(), 0);1471 assertEq(i8m.cas2(), 255);1472 assertEq(i8a[100], 0x5A);1473 i8a[100] = 0;1474 assertEq(i8m.cas1_i(100), 0);1475 assertEq(i8m.cas2_i(100), 255);1476 assertEq(i8a[100], 0x5A);1477 var oob = (heap.byteLength * 2) & ~7;1478 assertErrorMessage(() => i8m.cas1_i(oob), RangeError, /out-of-range index/);1479 assertErrorMessage(() => i8m.cas2_i(oob), RangeError, /out-of-range index/);1480 assertErrorMessage(() => i8m.or_i(oob), RangeError, /out-of-range index/);1481 assertErrorMessage(() => i8m.xor_i(oob), RangeError, /out-of-range index/);1482 assertErrorMessage(() => i8m.and_i(oob), RangeError, /out-of-range index/);1483 assertErrorMessage(() => i8m.add_i(oob), RangeError, /out-of-range index/);1484 assertErrorMessage(() => i8m.sub_i(oob), RangeError, /out-of-range index/);1485 assertErrorMessage(() => i8m.load_i(oob), RangeError, /out-of-range index/);1486 assertErrorMessage(() => i8m.store_i(oob), RangeError, /out-of-range index/);1487 assertErrorMessage(() => i8m.xchg_i(oob), RangeError, /out-of-range index/);1488 // Edge cases1489 assertErrorMessage(() => i8m.load_i(i8a.length), RangeError, /out-of-range index/);1490 assertErrorMessage(() => i8m.store_i(i8a.length), RangeError, /out-of-range index/);1491 assertErrorMessage(() => i8m.add_i(i8a.length), RangeError, /out-of-range index/);1492 i8a[i8a.length-1] = 88;1493 assertEq(i8m.load_i(i8a.length-1), 88);1494 assertEq(i8m.store_i(i8a.length-1), 37);1495 assertEq(i8m.add_i(i8a.length-1), 37);1496 assertEq(i8m.load_i(i8a.length-1), 37+37);1497 i8a[i8a.length-1] = 0;1498}1499var loadModule_misc_code =1500 USE_ASM + `1501 var atomic_isLockFree = stdlib.Atomics.isLockFree;1502 function ilf1() {1503 return atomic_isLockFree(1)|0;1504 }1505 function ilf2() {...

Full Screen

Full Screen

js-api.js

Source:js-api.js Github

copy

Full Screen

...23}24function wasmIsSupported() {25 return (typeof WebAssembly.Module) == 'function';26}27function assertErrorMessage(func, type, msg) {28 // TODO assertThrows(func, type, msg);29 assertThrows(func, type);30}31let emptyModuleBinary = (() => {32 var builder = new WasmModuleBuilder();33 return new Int8Array(builder.toBuffer());34})();35let exportingModuleBinary = (() => {36 var builder = new WasmModuleBuilder();37 builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 42]).exportAs('f');38 return new Int8Array(builder.toBuffer());39})();40let importingModuleBinary = (() => {41 var builder = new WasmModuleBuilder();42 builder.addImport('', 'f', kSig_i_v);43 return new Int8Array(builder.toBuffer());44})();45let memoryImportingModuleBinary = (() => {46 var builder = new WasmModuleBuilder();47 builder.addImportedMemory('', 'my_memory');48 return new Int8Array(builder.toBuffer());49})();50let moduleBinaryImporting2Memories = (() => {51 var builder = new WasmModuleBuilder();52 builder.addImportedMemory('', 'memory1');53 builder.addImportedMemory('', 'memory2');54 return new Int8Array(builder.toBuffer());55})();56let moduleBinaryWithMemSectionAndMemImport = (() => {57 var builder = new WasmModuleBuilder();58 builder.addMemory(1, 1, false);59 builder.addImportedMemory('', 'memory1');60 return new Int8Array(builder.toBuffer());61})();62// 'WebAssembly' data property on global object63let wasmDesc = Object.getOwnPropertyDescriptor(this, 'WebAssembly');64assertEq(typeof wasmDesc.value, 'object');65assertTrue(wasmDesc.writable);66assertFalse(wasmDesc.enumerable);67assertTrue(wasmDesc.configurable);68// 'WebAssembly' object69assertEq(WebAssembly, wasmDesc.value);70assertEq(String(WebAssembly), '[object WebAssembly]');71// 'WebAssembly.CompileError'72let compileErrorDesc =73 Object.getOwnPropertyDescriptor(WebAssembly, 'CompileError');74assertEq(typeof compileErrorDesc.value, 'function');75assertTrue(compileErrorDesc.writable);76assertFalse(compileErrorDesc.enumerable);77assertTrue(compileErrorDesc.configurable);78let CompileError = WebAssembly.CompileError;79assertEq(CompileError, compileErrorDesc.value);80assertEq(CompileError.length, 1);81assertEq(CompileError.name, 'CompileError');82let compileError = new CompileError;83assertTrue(compileError instanceof CompileError);84assertTrue(compileError instanceof Error);85assertFalse(compileError instanceof TypeError);86assertEq(compileError.message, '');87assertEq(new CompileError('hi').message, 'hi');88// 'WebAssembly.RuntimeError'89let runtimeErrorDesc =90 Object.getOwnPropertyDescriptor(WebAssembly, 'RuntimeError');91assertEq(typeof runtimeErrorDesc.value, 'function');92assertTrue(runtimeErrorDesc.writable);93assertFalse(runtimeErrorDesc.enumerable);94assertTrue(runtimeErrorDesc.configurable);95let RuntimeError = WebAssembly.RuntimeError;96assertEq(RuntimeError, runtimeErrorDesc.value);97assertEq(RuntimeError.length, 1);98assertEq(RuntimeError.name, 'RuntimeError');99let runtimeError = new RuntimeError;100assertTrue(runtimeError instanceof RuntimeError);101assertTrue(runtimeError instanceof Error);102assertFalse(runtimeError instanceof TypeError);103assertEq(runtimeError.message, '');104assertEq(new RuntimeError('hi').message, 'hi');105// 'WebAssembly.LinkError'106let linkErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'LinkError');107assertEq(typeof linkErrorDesc.value, 'function');108assertTrue(linkErrorDesc.writable);109assertFalse(linkErrorDesc.enumerable);110assertTrue(linkErrorDesc.configurable);111let LinkError = WebAssembly.LinkError;112assertEq(LinkError, linkErrorDesc.value);113assertEq(LinkError.length, 1);114assertEq(LinkError.name, 'LinkError');115let linkError = new LinkError;116assertTrue(linkError instanceof LinkError);117assertTrue(linkError instanceof Error);118assertFalse(linkError instanceof TypeError);119assertEq(linkError.message, '');120assertEq(new LinkError('hi').message, 'hi');121// 'WebAssembly.Module' data property122let moduleDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Module');123assertEq(typeof moduleDesc.value, 'function');124assertTrue(moduleDesc.writable);125assertFalse(moduleDesc.enumerable);126assertTrue(moduleDesc.configurable);127// 'WebAssembly.Module' constructor function128let Module = WebAssembly.Module;129assertEq(Module, moduleDesc.value);130assertEq(Module.length, 1);131assertEq(Module.name, 'Module');132assertErrorMessage(133 () => Module(), TypeError, /constructor without new is forbidden/);134assertErrorMessage(135 () => new Module(), TypeError, /requires more than 0 arguments/);136assertErrorMessage(137 () => new Module(undefined), TypeError,138 'first argument must be an ArrayBuffer or typed array object');139assertErrorMessage(140 () => new Module(1), TypeError,141 'first argument must be an ArrayBuffer or typed array object');142assertErrorMessage(143 () => new Module({}), TypeError,144 'first argument must be an ArrayBuffer or typed array object');145assertErrorMessage(146 () => new Module(new Uint8Array()), CompileError,147 /failed to match magic number/);148assertErrorMessage(149 () => new Module(new ArrayBuffer()), CompileError,150 /failed to match magic number/);151assertTrue(new Module(emptyModuleBinary) instanceof Module);152assertTrue(new Module(emptyModuleBinary.buffer) instanceof Module);153// 'WebAssembly.Module.prototype' data property154let moduleProtoDesc = Object.getOwnPropertyDescriptor(Module, 'prototype');155assertEq(typeof moduleProtoDesc.value, 'object');156assertFalse(moduleProtoDesc.writable);157assertFalse(moduleProtoDesc.enumerable);158assertFalse(moduleProtoDesc.configurable);159// 'WebAssembly.Module.prototype' object160let moduleProto = Module.prototype;161assertEq(moduleProto, moduleProtoDesc.value);162assertEq(String(moduleProto), '[object WebAssembly.Module]');163assertEq(Object.getPrototypeOf(moduleProto), Object.prototype);164// 'WebAssembly.Module' instance objects165let emptyModule = new Module(emptyModuleBinary);166let importingModule = new Module(importingModuleBinary);167let exportingModule = new Module(exportingModuleBinary);168assertEq(typeof emptyModule, 'object');169assertEq(String(emptyModule), '[object WebAssembly.Module]');170assertEq(Object.getPrototypeOf(emptyModule), moduleProto);171// 'WebAssembly.Module.imports' data property172let moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports');173assertEq(typeof moduleImportsDesc.value, 'function');174assertTrue(moduleImportsDesc.writable);175assertFalse(moduleImportsDesc.enumerable);176assertTrue(moduleImportsDesc.configurable);177// 'WebAssembly.Module.imports' method178let moduleImports = moduleImportsDesc.value;179assertEq(moduleImports.length, 1);180assertErrorMessage(181 () => moduleImports(), TypeError, /requires more than 0 arguments/);182assertErrorMessage(183 () => moduleImports(undefined), TypeError,184 /first argument must be a WebAssembly.Module/);185assertErrorMessage(186 () => moduleImports({}), TypeError,187 /first argument must be a WebAssembly.Module/);188var arr = moduleImports(new Module(emptyModuleBinary));189assertTrue(arr instanceof Array);190assertEq(arr.length, 0);191let importingModuleBinary2 = (() => {192 var text =193 '(module (func (import "a" "b")) (memory (import "c" "d") 1) (table (import "e" "f") 1 anyfunc) (global (import "g" "⚡") i32))'194 let builder = new WasmModuleBuilder();195 builder.addImport('a', 'b', kSig_i_i);196 builder.addImportedMemory('c', 'd');197 builder.addImportedTable('e', 'f');198 builder.addImportedGlobal('g', 'x', kWasmI32);199 return new Int8Array(builder.toBuffer());200})();201var arr = moduleImports(new Module(importingModuleBinary2));202assertTrue(arr instanceof Array);203assertEq(arr.length, 4);204assertEq(arr[0].kind, 'function');205assertEq(arr[0].module, 'a');206assertEq(arr[0].name, 'b');207assertEq(arr[1].kind, 'memory');208assertEq(arr[1].module, 'c');209assertEq(arr[1].name, 'd');210assertEq(arr[2].kind, 'table');211assertEq(arr[2].module, 'e');212assertEq(arr[2].name, 'f');213assertEq(arr[3].kind, 'global');214assertEq(arr[3].module, 'g');215assertEq(arr[3].name, 'x');216// 'WebAssembly.Module.exports' data property217let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports');218assertEq(typeof moduleExportsDesc.value, 'function');219assertTrue(moduleExportsDesc.writable);220assertFalse(moduleExportsDesc.enumerable);221assertTrue(moduleExportsDesc.configurable);222// 'WebAssembly.Module.exports' method223let moduleExports = moduleExportsDesc.value;224assertEq(moduleExports.length, 1);225assertErrorMessage(226 () => moduleExports(), TypeError, /requires more than 0 arguments/);227assertErrorMessage(228 () => moduleExports(undefined), TypeError,229 /first argument must be a WebAssembly.Module/);230assertErrorMessage(231 () => moduleExports({}), TypeError,232 /first argument must be a WebAssembly.Module/);233var arr = moduleExports(emptyModule);234assertTrue(arr instanceof Array);235assertEq(arr.length, 0);236let exportingModuleBinary2 = (() => {237 var text =238 '(module (func (export "a")) (memory (export "b") 1) (table (export "c") 1 anyfunc) (global (export "⚡") i32 (i32.const 0)))';239 let builder = new WasmModuleBuilder();240 builder.addFunction('foo', kSig_v_v).addBody([]).exportAs('a');241 builder.addMemory(1, 1, false);242 builder.exportMemoryAs('b');243 builder.setFunctionTableBounds(1, 1);244 builder.addExportOfKind('c', kExternalTable, 0);245 var o = builder.addGlobal(kWasmI32, false).exportAs('x');246 return new Int8Array(builder.toBuffer());247})();248var arr = moduleExports(new Module(exportingModuleBinary2));249assertTrue(arr instanceof Array);250assertEq(arr.length, 4);251assertEq(arr[0].kind, 'function');252assertEq(arr[0].name, 'a');253assertEq(arr[1].kind, 'memory');254assertEq(arr[1].name, 'b');255assertEq(arr[2].kind, 'table');256assertEq(arr[2].name, 'c');257assertEq(arr[3].kind, 'global');258assertEq(arr[3].name, 'x');259// 'WebAssembly.Module.customSections' data property260let moduleCustomSectionsDesc =261 Object.getOwnPropertyDescriptor(Module, 'customSections');262assertEq(typeof moduleCustomSectionsDesc.value, 'function');263assertEq(moduleCustomSectionsDesc.writable, true);264assertEq(moduleCustomSectionsDesc.enumerable, false);265assertEq(moduleCustomSectionsDesc.configurable, true);266let moduleCustomSections = moduleCustomSectionsDesc.value;267assertEq(moduleCustomSections.length, 2);268assertErrorMessage(269 () => moduleCustomSections(), TypeError, /requires more than 0 arguments/);270assertErrorMessage(271 () => moduleCustomSections(undefined), TypeError,272 /first argument must be a WebAssembly.Module/);273assertErrorMessage(274 () => moduleCustomSections({}), TypeError,275 /first argument must be a WebAssembly.Module/);276var arr = moduleCustomSections(emptyModule, 'x');277assertEq(arr instanceof Array, true);278assertEq(arr.length, 0);279assertErrorMessage(280 () => moduleCustomSections(1), TypeError,281 'first argument must be a WebAssembly.Module');282let customSectionModuleBinary2 = (() => {283 let builder = new WasmModuleBuilder();284 builder.addCustomSection('x', [2]);285 builder.addCustomSection('foo', [66, 77]);286 builder.addCustomSection('foo', [91, 92, 93]);287 builder.addCustomSection('fox', [99, 99, 99]);288 return new Int8Array(builder.toBuffer());289})();290var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'x');291assertEq(arr instanceof Array, true);292assertEq(arr.length, 1);293assertArrayBuffer(arr[0], [2]);294var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'foo');295assertEq(arr instanceof Array, true);296assertEq(arr.length, 2);297assertArrayBuffer(arr[0], [66, 77]);298assertArrayBuffer(arr[1], [91, 92, 93]);299var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'bar');300assertEq(arr instanceof Array, true);301assertEq(arr.length, 0);302var o = {toString() { return "foo" }}303var arr = moduleCustomSections(new Module(customSectionModuleBinary2), o);304assertEq(arr instanceof Array, true);305assertEq(arr.length, 2);306assertArrayBuffer(arr[0], [66, 77]);307assertArrayBuffer(arr[1], [91, 92, 93]);308var o = {toString() { throw "boo!" }}309assertThrows(310 () => moduleCustomSections(new Module(customSectionModuleBinary2), o));311// 'WebAssembly.Instance' data property312let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance');313assertEq(typeof instanceDesc.value, 'function');314assertTrue(instanceDesc.writable);315assertFalse(instanceDesc.enumerable);316assertTrue(instanceDesc.configurable);317// 'WebAssembly.Instance' constructor function318let Instance = WebAssembly.Instance;319assertEq(Instance, instanceDesc.value);320assertEq(Instance.length, 1);321assertEq(Instance.name, 'Instance');322assertErrorMessage(323 () => Instance(), TypeError, /constructor without new is forbidden/);324assertErrorMessage(325 () => new Instance(1), TypeError,326 'first argument must be a WebAssembly.Module');327assertErrorMessage(328 () => new Instance({}), TypeError,329 'first argument must be a WebAssembly.Module');330assertErrorMessage(331 () => new Instance(emptyModule, null), TypeError,332 'second argument must be an object');333assertErrorMessage(() => new Instance(importingModule, null), TypeError, '');334assertErrorMessage(335 () => new Instance(importingModule, undefined), TypeError, '');336assertErrorMessage(337 () => new Instance(importingModule, {'': {g: () => {}}}), LinkError, '');338assertErrorMessage(339 () => new Instance(importingModule, {t: {f: () => {}}}), TypeError, '');340assertTrue(new Instance(emptyModule) instanceof Instance);341assertTrue(new Instance(emptyModule, {}) instanceof Instance);342// 'WebAssembly.Instance.prototype' data property343let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype');344assertEq(typeof instanceProtoDesc.value, 'object');345assertFalse(instanceProtoDesc.writable);346assertFalse(instanceProtoDesc.enumerable);347assertFalse(instanceProtoDesc.configurable);348// 'WebAssembly.Instance.prototype' object349let instanceProto = Instance.prototype;350assertEq(instanceProto, instanceProtoDesc.value);351assertEq(String(instanceProto), '[object WebAssembly.Instance]');352assertEq(Object.getPrototypeOf(instanceProto), Object.prototype);353// 'WebAssembly.Instance' instance objects354let exportingInstance = new Instance(exportingModule);355assertEq(typeof exportingInstance, 'object');356assertEq(String(exportingInstance), '[object WebAssembly.Instance]');357assertEq(Object.getPrototypeOf(exportingInstance), instanceProto);358// 'WebAssembly.Instance' 'exports' getter property359let instanceExportsDesc =360 Object.getOwnPropertyDescriptor(instanceProto, 'exports');361assertEq(typeof instanceExportsDesc.get, 'function');362assertEq(instanceExportsDesc.set, undefined);363assertFalse(instanceExportsDesc.enumerable);364assertTrue(instanceExportsDesc.configurable);365exportsObj = exportingInstance.exports;366assertEq(typeof exportsObj, 'object');367assertFalse(Object.isExtensible(exportsObj));368assertEq(Object.getPrototypeOf(exportsObj), null);369assertEq(Object.keys(exportsObj).join(), 'f');370// Exported WebAssembly functions371let f = exportingInstance.exports.f;372assertTrue(f instanceof Function);373assertEq(f.length, 0);374assertTrue('name' in f);375assertEq(Function.prototype.call.call(f), 42);376assertErrorMessage(() => new f(), TypeError, /is not a constructor/);377// 'WebAssembly.Memory' data property378let memoryDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Memory');379assertEq(typeof memoryDesc.value, 'function');380assertTrue(memoryDesc.writable);381assertFalse(memoryDesc.enumerable);382assertTrue(memoryDesc.configurable);383// 'WebAssembly.Memory' constructor function384let Memory = WebAssembly.Memory;385assertEq(Memory, memoryDesc.value);386assertEq(Memory.length, 1);387assertEq(Memory.name, 'Memory');388assertErrorMessage(389 () => Memory(), TypeError, /constructor without new is forbidden/);390assertErrorMessage(391 () => new Memory(1), TypeError,392 'first argument must be a memory descriptor');393assertErrorMessage(394 () => new Memory({initial: {valueOf() { throw new Error('here') }}}), Error,395 'here');396assertErrorMessage(397 () => new Memory({initial: -1}), RangeError, /bad Memory initial size/);398assertErrorMessage(399 () => new Memory({initial: Math.pow(2, 32)}), RangeError,400 /bad Memory initial size/);401assertErrorMessage(402 () => new Memory({initial: 1, maximum: Math.pow(2, 32) / Math.pow(2, 14)}),403 RangeError, /bad Memory maximum size/);404assertErrorMessage(405 () => new Memory({initial: 2, maximum: 1}), RangeError,406 /bad Memory maximum size/);407assertErrorMessage(408 () => new Memory({maximum: -1}), RangeError, /bad Memory maximum size/);409assertTrue(new Memory({initial: 1}) instanceof Memory);410assertEq(new Memory({initial: 1.5}).buffer.byteLength, kPageSize);411// 'WebAssembly.Memory.prototype' data property412let memoryProtoDesc = Object.getOwnPropertyDescriptor(Memory, 'prototype');413assertEq(typeof memoryProtoDesc.value, 'object');414assertFalse(memoryProtoDesc.writable);415assertFalse(memoryProtoDesc.enumerable);416assertFalse(memoryProtoDesc.configurable);417// 'WebAssembly.Memory.prototype' object418let memoryProto = Memory.prototype;419assertEq(memoryProto, memoryProtoDesc.value);420assertEq(String(memoryProto), '[object WebAssembly.Memory]');421assertEq(Object.getPrototypeOf(memoryProto), Object.prototype);422// 'WebAssembly.Memory' instance objects423let mem1 = new Memory({initial: 1});424assertEq(typeof mem1, 'object');425assertEq(String(mem1), '[object WebAssembly.Memory]');426assertEq(Object.getPrototypeOf(mem1), memoryProto);427// 'WebAssembly.Memory.prototype.buffer' accessor property428let bufferDesc = Object.getOwnPropertyDescriptor(memoryProto, 'buffer');429assertEq(typeof bufferDesc.get, 'function');430assertEq(bufferDesc.set, undefined);431assertFalse(bufferDesc.enumerable);432assertTrue(bufferDesc.configurable);433// 'WebAssembly.Memory.prototype.buffer' getter434let bufferGetter = bufferDesc.get;435assertErrorMessage(436 () => bufferGetter.call(), TypeError, /called on incompatible undefined/);437assertErrorMessage(438 () => bufferGetter.call({}), TypeError, /called on incompatible Object/);439assertTrue(bufferGetter.call(mem1) instanceof ArrayBuffer);440assertEq(bufferGetter.call(mem1).byteLength, kPageSize);441// 'WebAssembly.Memory.prototype.grow' data property442let memGrowDesc = Object.getOwnPropertyDescriptor(memoryProto, 'grow');443assertEq(typeof memGrowDesc.value, 'function');444assertFalse(memGrowDesc.enumerable);445assertTrue(memGrowDesc.configurable);446// 'WebAssembly.Memory.prototype.grow' method447let memGrow = memGrowDesc.value;448assertEq(memGrow.length, 1);449assertErrorMessage(450 () => memGrow.call(), TypeError, /called on incompatible undefined/);451assertErrorMessage(452 () => memGrow.call({}), TypeError, /called on incompatible Object/);453assertErrorMessage(454 () => memGrow.call(mem1, -1), RangeError, /bad Memory grow delta/);455assertErrorMessage(456 () => memGrow.call(mem1, Math.pow(2, 32)), RangeError,457 /bad Memory grow delta/);458var mem = new Memory({initial: 1, maximum: 2});459var buf = mem.buffer;460assertEq(buf.byteLength, kPageSize);461assertEq(mem.grow(0), 1);462assertTrue(buf !== mem.buffer);463assertEq(buf.byteLength, 0);464buf = mem.buffer;465assertEq(buf.byteLength, kPageSize);466assertEq(mem.grow(1, 23), 1);467assertTrue(buf !== mem.buffer);468assertEq(buf.byteLength, 0);469buf = mem.buffer;470assertEq(buf.byteLength, 2 * kPageSize);471assertEq(mem.grow(), 2);472assertTrue(buf !== mem.buffer);473assertEq(buf.byteLength, 0);474buf = mem.buffer;475assertEq(buf.byteLength, 2 * kPageSize);476assertErrorMessage(() => mem.grow(1), Error, /failed to grow memory/);477assertErrorMessage(() => mem.grow(Infinity), Error, /failed to grow memory/);478assertErrorMessage(() => mem.grow(-Infinity), Error, /failed to grow memory/);479assertEq(buf, mem.buffer);480let throwOnValueOf = {481 valueOf: function() {482 throw Error('throwOnValueOf')483 }484};485assertErrorMessage(() => mem.grow(throwOnValueOf), Error, /throwOnValueOf/);486assertEq(buf, mem.buffer);487let zero_wrapper = {488 valueOf: function() {489 ++this.call_counter;490 return 0;491 },492 call_counter: 0493};494assertEq(mem.grow(zero_wrapper), 2);495assertEq(zero_wrapper.call_counter, 1);496assertTrue(buf !== mem.buffer);497assertEq(buf.byteLength, 0);498buf = mem.buffer;499assertEq(buf.byteLength, 2 * kPageSize);500let empty_mem = new Memory({initial: 0, maximum: 5});501let empty_buf = empty_mem.buffer;502assertEq(empty_buf.byteLength, 0);503assertEq(empty_mem.grow(0), 0);504assertEq(empty_mem.buffer.byteLength, 0);505assertTrue(empty_buf !== empty_mem.buffer);506// 'WebAssembly.Table' data property507let tableDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Table');508assertEq(typeof tableDesc.value, 'function');509assertTrue(tableDesc.writable);510assertFalse(tableDesc.enumerable);511assertTrue(tableDesc.configurable);512// 'WebAssembly.Table' constructor function513let Table = WebAssembly.Table;514assertEq(Table, tableDesc.value);515assertEq(Table.length, 1);516assertEq(Table.name, 'Table');517assertErrorMessage(518 () => Table(), TypeError, /constructor without new is forbidden/);519assertErrorMessage(520 () => new Table(1), TypeError, 'first argument must be a table descriptor');521assertErrorMessage(522 () => new Table({initial: 1, element: 1}), TypeError, /must be "anyfunc"/);523assertErrorMessage(524 () => new Table({initial: 1, element: 'any'}), TypeError,525 /must be "anyfunc"/);526assertErrorMessage(527 () => new Table({initial: 1, element: {valueOf() { return 'anyfunc' }}}),528 TypeError, /must be "anyfunc"/);529assertErrorMessage(530 () => new Table(531 {initial: {valueOf() { throw new Error('here') }}, element: 'anyfunc'}),532 Error, 'here');533assertErrorMessage(534 () => new Table({initial: -1, element: 'anyfunc'}), RangeError,535 /bad Table initial size/);536assertErrorMessage(537 () => new Table({initial: Math.pow(2, 32), element: 'anyfunc'}), RangeError,538 /bad Table initial size/);539assertErrorMessage(540 () => new Table({initial: 2, maximum: 1, element: 'anyfunc'}), RangeError,541 /bad Table maximum size/);542assertErrorMessage(543 () => new Table({initial: 2, maximum: Math.pow(2, 32), element: 'anyfunc'}),544 RangeError, /bad Table maximum size/);545assertTrue(new Table({initial: 1, element: 'anyfunc'}) instanceof Table);546assertTrue(new Table({initial: 1.5, element: 'anyfunc'}) instanceof Table);547assertTrue(548 new Table({initial: 1, maximum: 1.5, element: 'anyfunc'}) instanceof Table);549assertTrue(550 new Table({initial: 1, maximum: Math.pow(2, 32) - 1, element: 'anyfunc'})551 instanceof Table);552// 'WebAssembly.Table.prototype' data property553let tableProtoDesc = Object.getOwnPropertyDescriptor(Table, 'prototype');554assertEq(typeof tableProtoDesc.value, 'object');555assertFalse(tableProtoDesc.writable);556assertFalse(tableProtoDesc.enumerable);557assertFalse(tableProtoDesc.configurable);558// 'WebAssembly.Table.prototype' object559let tableProto = Table.prototype;560assertEq(tableProto, tableProtoDesc.value);561assertEq(String(tableProto), '[object WebAssembly.Table]');562assertEq(Object.getPrototypeOf(tableProto), Object.prototype);563// 'WebAssembly.Table' instance objects564let tbl1 = new Table({initial: 2, element: 'anyfunc'});565assertEq(typeof tbl1, 'object');566assertEq(String(tbl1), '[object WebAssembly.Table]');567assertEq(Object.getPrototypeOf(tbl1), tableProto);568// 'WebAssembly.Table.prototype.length' accessor data property569let lengthDesc = Object.getOwnPropertyDescriptor(tableProto, 'length');570assertEq(typeof lengthDesc.get, 'function');571assertEq(lengthDesc.set, undefined);572assertFalse(lengthDesc.enumerable);573assertTrue(lengthDesc.configurable);574// 'WebAssembly.Table.prototype.length' getter575let lengthGetter = lengthDesc.get;576assertEq(lengthGetter.length, 0);577assertErrorMessage(578 () => lengthGetter.call(), TypeError, /called on incompatible undefined/);579assertErrorMessage(580 () => lengthGetter.call({}), TypeError, /called on incompatible Object/);581assertEq(typeof lengthGetter.call(tbl1), 'number');582assertEq(lengthGetter.call(tbl1), 2);583// 'WebAssembly.Table.prototype.get' data property584let getDesc = Object.getOwnPropertyDescriptor(tableProto, 'get');585assertEq(typeof getDesc.value, 'function');586assertFalse(getDesc.enumerable);587assertTrue(getDesc.configurable);588// 'WebAssembly.Table.prototype.get' method589let get = getDesc.value;590assertEq(get.length, 1);591assertErrorMessage(592 () => get.call(), TypeError, /called on incompatible undefined/);593assertErrorMessage(594 () => get.call({}), TypeError, /called on incompatible Object/);595assertEq(get.call(tbl1), null);596assertEq(get.call(tbl1, 0), null);597assertEq(get.call(tbl1, 0, Infinity), null);598assertEq(get.call(tbl1, 1), null);599assertEq(get.call(tbl1, 1.5), null);600assertErrorMessage(() => get.call(tbl1, 2), RangeError, /bad Table get index/);601assertErrorMessage(602 () => get.call(tbl1, 2.5), RangeError, /bad Table get index/);603assertErrorMessage(() => get.call(tbl1, -1), RangeError, /bad Table get index/);604assertErrorMessage(605 () => get.call(tbl1, Math.pow(2, 33)), RangeError, /bad Table get index/);606assertErrorMessage(607 () => get.call(tbl1, {valueOf() { throw new Error('hi') }}), Error, 'hi');608// 'WebAssembly.Table.prototype.set' data property609let setDesc = Object.getOwnPropertyDescriptor(tableProto, 'set');610assertEq(typeof setDesc.value, 'function');611assertFalse(setDesc.enumerable);612assertTrue(setDesc.configurable);613// 'WebAssembly.Table.prototype.set' method614let set = setDesc.value;615assertEq(set.length, 2);616assertErrorMessage(617 () => set.call(), TypeError, /called on incompatible undefined/);618assertErrorMessage(619 () => set.call({}), TypeError, /called on incompatible Object/);620assertErrorMessage(621 () => set.call(tbl1, 0), TypeError, /requires more than 1 argument/);622assertErrorMessage(623 () => set.call(tbl1, undefined), TypeError,624 /requires more than 1 argument/);625assertErrorMessage(626 () => set.call(tbl1, 2, null), RangeError, /bad Table set index/);627assertErrorMessage(628 () => set.call(tbl1, -1, null), RangeError, /bad Table set index/);629assertErrorMessage(630 () => set.call(tbl1, Math.pow(2, 33), null), RangeError,631 /bad Table set index/);632assertErrorMessage(633 () => set.call(tbl1, Infinity, null), RangeError, /bad Table set index/);634assertErrorMessage(635 () => set.call(tbl1, -Infinity, null), RangeError, /bad Table set index/);636assertErrorMessage(637 () => set.call(tbl1, 0, undefined), TypeError,638 /can only assign WebAssembly exported functions to Table/);639assertErrorMessage(640 () => set.call(tbl1, undefined, undefined), TypeError,641 /can only assign WebAssembly exported functions to Table/);642assertErrorMessage(643 () => set.call(tbl1, 0, {}), TypeError,644 /can only assign WebAssembly exported functions to Table/);645assertErrorMessage(() => set.call(tbl1, 0, function() {646}), TypeError, /can only assign WebAssembly exported functions to Table/);647assertErrorMessage(648 () => set.call(tbl1, 0, Math.sin), TypeError,649 /can only assign WebAssembly exported functions to Table/);650assertErrorMessage(651 () => set.call(tbl1, {valueOf() { throw Error('hai') }}, null), Error,652 'hai');653assertEq(set.call(tbl1, 0, null), undefined);654assertEq(set.call(tbl1, 1, null), undefined);655assertEq(set.call(tbl1, undefined, null), undefined);656// 'WebAssembly.Table.prototype.grow' data property657let tblGrowDesc = Object.getOwnPropertyDescriptor(tableProto, 'grow');658assertEq(typeof tblGrowDesc.value, 'function');659assertFalse(tblGrowDesc.enumerable);660assertTrue(tblGrowDesc.configurable);661// 'WebAssembly.Table.prototype.grow' method662let tblGrow = tblGrowDesc.value;663assertEq(tblGrow.length, 1);664assertErrorMessage(665 () => tblGrow.call(), TypeError, /called on incompatible undefined/);666assertErrorMessage(667 () => tblGrow.call({}), TypeError, /called on incompatible Object/);668assertErrorMessage(669 () => tblGrow.call(tbl1, -1), RangeError, /bad Table grow delta/);670assertErrorMessage(671 () => tblGrow.call(tbl1, Math.pow(2, 32)), RangeError,672 /bad Table grow delta/);673var tbl = new Table({element: 'anyfunc', initial: 1, maximum: 2});674assertEq(tbl.length, 1);675assertErrorMessage(676 () => tbl.grow(Infinity), RangeError, /failed to grow table/);677assertErrorMessage(678 () => tbl.grow(-Infinity), RangeError, /failed to grow table/);679assertEq(tbl.grow(0), 1);680assertEq(tbl.length, 1);681assertEq(tbl.grow(1, 4), 1);682assertEq(tbl.length, 2);683assertEq(tbl.grow(), 2);684assertEq(tbl.length, 2);685assertErrorMessage(() => tbl.grow(1), Error, /failed to grow table/);686assertErrorMessage(687 () => tbl.grow(Infinity), RangeError, /failed to grow table/);688assertErrorMessage(689 () => tbl.grow(-Infinity), RangeError, /failed to grow table/);690// 'WebAssembly.validate' function691assertErrorMessage(() => WebAssembly.validate(), TypeError);692assertErrorMessage(() => WebAssembly.validate('hi'), TypeError);693assertTrue(WebAssembly.validate(emptyModuleBinary));694// TODO: other ways for validate to return false.695assertFalse(WebAssembly.validate(moduleBinaryImporting2Memories));696assertFalse(WebAssembly.validate(moduleBinaryWithMemSectionAndMemImport));697// 'WebAssembly.compile' data property698let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile');699assertEq(typeof compileDesc.value, 'function');700assertTrue(compileDesc.writable);701assertFalse(compileDesc.enumerable);702assertTrue(compileDesc.configurable);703// 'WebAssembly.compile' function704let compile = WebAssembly.compile;705assertEq(compile, compileDesc.value);706assertEq(compile.length, 1);...

Full Screen

Full Screen

basic.js

Source:basic.js Github

copy

Full Screen

...40wasmEvalText('(module (func) (func) (export "a" 0))');41wasmEvalText('(module (func) (func) (export "a" 1))');42wasmEvalText('(module (func $a) (func $b) (export "a" $a) (export "b" $b))');43wasmEvalText('(module (func $a) (func $b) (export "a" $a) (export "b" $b))');44assertErrorMessage(() => wasmEvalText('(module (func) (export "a" 1))'), TypeError, /export function index out of range/);45assertErrorMessage(() => wasmEvalText('(module (func) (func) (export "a" 2))'), TypeError, /export function index out of range/);46var o = wasmEvalText('(module (func) (export "a" 0) (export "b" 0))');47assertEq(Object.getOwnPropertyNames(o).sort().toString(), "a,b");48assertEq(o.a.name, "wasm-function[0]");49assertEq(o.b.name, "wasm-function[0]");50assertEq(o.a === o.b, true);51var o = wasmEvalText('(module (func) (func) (export "a" 0) (export "b" 1))');52assertEq(Object.getOwnPropertyNames(o).sort().toString(), "a,b");53assertEq(o.a.name, "wasm-function[0]");54assertEq(o.b.name, "wasm-function[1]");55assertEq(o.a === o.b, false);56var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" 0) (export "b" 1))');57assertEq(o.a(), 1);58assertEq(o.b(), 2);59var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" 1) (export "b" 0))');60assertEq(o.a(), 2);61assertEq(o.b(), 1);62assertErrorMessage(() => wasmEvalText('(module (func) (export "a" 0) (export "a" 0))'), TypeError, /duplicate export/);63assertErrorMessage(() => wasmEvalText('(module (func) (func) (export "a" 0) (export "a" 1))'), TypeError, /duplicate export/);64// ----------------------------------------------------------------------------65// signatures66assertErrorMessage(() => wasmEvalText('(module (func (result i32)))'), TypeError, mismatchError("void", "i32"));67assertErrorMessage(() => wasmEvalText('(module (func (result i32) (nop)))'), TypeError, mismatchError("void", "i32"));68wasmEvalText('(module (func (nop)))');69wasmEvalText('(module (func (result i32) (i32.const 42)))');70wasmEvalText('(module (func (param i32)))');71wasmEvalText('(module (func (param i32) (result i32) (i32.const 42)))');72wasmEvalText('(module (func (result i32) (param i32) (i32.const 42)))');73wasmEvalText('(module (func (param f32)))');74wasmEvalText('(module (func (param f64)))');75var hasI64 = getBuildConfiguration().x64;76if (!hasI64) {77 assertErrorMessage(() => wasmEvalText('(module (func (param i64)))'), TypeError, /NYI/);78 assertErrorMessage(() => wasmEvalText('(module (func (result i64)))'), TypeError, /NYI/);79}80// ----------------------------------------------------------------------------81// imports82assertErrorMessage(() => wasmEvalText('(module (import "a" "b"))', 1), Error, /second argument, if present, must be an object/);83assertErrorMessage(() => wasmEvalText('(module (import "a" "b"))', null), Error, /second argument, if present, must be an object/);84const noImportObj = /no import object given/;85const notObject = /import object field is not an Object/;86const notFunction = /import object field is not a Function/;87var code = '(module (import "a" "b"))';88assertErrorMessage(() => wasmEvalText(code), TypeError, noImportObj);89assertErrorMessage(() => wasmEvalText(code, {}), TypeError, notObject);90assertErrorMessage(() => wasmEvalText(code, {a:1}), TypeError, notObject);91assertErrorMessage(() => wasmEvalText(code, {a:{}}), TypeError, notFunction);92assertErrorMessage(() => wasmEvalText(code, {a:{b:1}}), TypeError, notFunction);93wasmEvalText(code, {a:{b:()=>{}}});94var code = '(module (import "" "b"))';95assertErrorMessage(() => wasmEvalText(code), TypeError, /module name cannot be empty/);96var code = '(module (import "a" ""))';97assertErrorMessage(() => wasmEvalText(code), TypeError, noImportObj);98assertErrorMessage(() => wasmEvalText(code, {}), TypeError, notFunction);99assertErrorMessage(() => wasmEvalText(code, {a:1}), TypeError, notFunction);100wasmEvalText(code, {a:()=>{}});101var code = '(module (import "a" "") (import "b" "c") (import "c" ""))';102assertErrorMessage(() => wasmEvalText(code, {a:()=>{}, b:{c:()=>{}}, c:{}}), TypeError, notFunction);103wasmEvalText(code, {a:()=>{}, b:{c:()=>{}}, c:()=>{}});104wasmEvalText('(module (import "a" "" (result i32)))', {a: ()=> {}});105wasmEvalText('(module (import "a" "" (result f32)))', {a: ()=> {}});106wasmEvalText('(module (import "a" "" (result f64)))', {a: ()=> {}});107wasmEvalText('(module (import $foo "a" "" (result f64)))', {a: ()=> {}});108// ----------------------------------------------------------------------------109// memory110wasmEvalText('(module (memory 0))');111wasmEvalText('(module (memory 1))');112assertErrorMessage(() => wasmEvalText('(module (memory 65536))'), TypeError, /initial memory size too big/);113assertErrorMessage(() => wasmEvalText('(module (memory 32768))'), TypeError, /initial memory size too big/);114// May OOM, but must not crash:115try {116 wasmEvalText('(module (memory 32767))');117} catch (e) {118 print(e);119 assertEq(String(e).indexOf("out of memory") != -1, true);120}121// Tests to reinstate pending a switch back to "real" memory exports:122//123//assertErrorMessage(() => wasmEvalText('(module (export "" memory))'), TypeError, /no memory section/);124//125//var buf = wasmEvalText('(module (memory 1) (export "" memory))');126//assertEq(buf instanceof ArrayBuffer, true);127//assertEq(buf.byteLength, 65536);128//129//assertErrorMessage(() => wasmEvalText('(module (memory 1) (export "a" memory) (export "a" memory))'), TypeError, /duplicate export/);130//assertErrorMessage(() => wasmEvalText('(module (memory 1) (func) (export "a" memory) (export "a" 0))'), TypeError, /duplicate export/);131//var {a, b} = wasmEvalText('(module (memory 1) (export "a" memory) (export "b" memory))');132//assertEq(a instanceof ArrayBuffer, true);133//assertEq(a, b);134//135//var obj = wasmEvalText('(module (memory 1) (func (result i32) (i32.const 42)) (func (nop)) (export "a" memory) (export "b" 0) (export "c" 1))');136//assertEq(obj.a instanceof ArrayBuffer, true);137//assertEq(obj.b instanceof Function, true);138//assertEq(obj.c instanceof Function, true);139//assertEq(obj.a.byteLength, 65536);140//assertEq(obj.b(), 42);141//assertEq(obj.c(), undefined);142//143//var obj = wasmEvalText('(module (memory 1) (func (result i32) (i32.const 42)) (export "" memory) (export "a" 0) (export "b" 0))');144//assertEq(obj instanceof ArrayBuffer, true);145//assertEq(obj.a instanceof Function, true);146//assertEq(obj.b instanceof Function, true);147//assertEq(obj.a, obj.b);148//assertEq(obj.byteLength, 65536);149//assertEq(obj.a(), 42);150//151//var buf = wasmEvalText('(module (memory 1 (segment 0 "")) (export "" memory))');152//assertEq(new Uint8Array(buf)[0], 0);153//154//var buf = wasmEvalText('(module (memory 1 (segment 65536 "")) (export "" memory))');155//assertEq(new Uint8Array(buf)[0], 0);156//157//var buf = wasmEvalText('(module (memory 1 (segment 0 "a")) (export "" memory))');158//assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));159//160//var buf = wasmEvalText('(module (memory 1 (segment 0 "a") (segment 2 "b")) (export "" memory))');161//assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));162//assertEq(new Uint8Array(buf)[1], 0);163//assertEq(new Uint8Array(buf)[2], 'b'.charCodeAt(0));164//165//var buf = wasmEvalText('(module (memory 1 (segment 65535 "c")) (export "" memory))');166//assertEq(new Uint8Array(buf)[0], 0);167//assertEq(new Uint8Array(buf)[65535], 'c'.charCodeAt(0));168//169//assertErrorMessage(() => wasmEvalText('(module (memory 1 (segment 65536 "a")) (export "" memory))'), TypeError, /data segment does not fit/);170//assertErrorMessage(() => wasmEvalText('(module (memory 1 (segment 65535 "ab")) (export "" memory))'), TypeError, /data segment does not fit/);171var buf = wasmEvalText('(module (memory 1) (export "memory" memory))').memory;172assertEq(buf instanceof ArrayBuffer, true);173assertEq(buf.byteLength, 65536);174var obj = wasmEvalText('(module (memory 1) (func (result i32) (i32.const 42)) (func (nop)) (export "memory" memory) (export "b" 0) (export "c" 1))');175assertEq(obj.memory instanceof ArrayBuffer, true);176assertEq(obj.b instanceof Function, true);177assertEq(obj.c instanceof Function, true);178assertEq(obj.memory.byteLength, 65536);179assertEq(obj.b(), 42);180assertEq(obj.c(), undefined);181var buf = wasmEvalText('(module (memory 1 (segment 0 "")) (export "memory" memory))').memory;182assertEq(new Uint8Array(buf)[0], 0);183var buf = wasmEvalText('(module (memory 1 (segment 65536 "")) (export "memory" memory))').memory;184assertEq(new Uint8Array(buf)[0], 0);185var buf = wasmEvalText('(module (memory 1 (segment 0 "a")) (export "memory" memory))').memory;186assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));187var buf = wasmEvalText('(module (memory 1 (segment 0 "a") (segment 2 "b")) (export "memory" memory))').memory;188assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));189assertEq(new Uint8Array(buf)[1], 0);190assertEq(new Uint8Array(buf)[2], 'b'.charCodeAt(0));191var buf = wasmEvalText('(module (memory 1 (segment 65535 "c")) (export "memory" memory))').memory;192assertEq(new Uint8Array(buf)[0], 0);193assertEq(new Uint8Array(buf)[65535], 'c'.charCodeAt(0));194assertErrorMessage(() => wasmEvalText('(module (memory 1 (segment 65536 "a")) (export "memory" memory))'), TypeError, /data segment does not fit/);195assertErrorMessage(() => wasmEvalText('(module (memory 1 (segment 65535 "ab")) (export "memory" memory))'), TypeError, /data segment does not fit/);196// ----------------------------------------------------------------------------197// locals198assertEq(wasmEvalText('(module (func (param i32) (result i32) (get_local 0)) (export "" 0))')(), 0);199assertEq(wasmEvalText('(module (func (param i32) (result i32) (get_local 0)) (export "" 0))')(42), 42);200assertEq(wasmEvalText('(module (func (param i32) (param i32) (result i32) (get_local 0)) (export "" 0))')(42, 43), 42);201assertEq(wasmEvalText('(module (func (param i32) (param i32) (result i32) (get_local 1)) (export "" 0))')(42, 43), 43);202assertErrorMessage(() => wasmEvalText('(module (func (get_local 0)))'), TypeError, /get_local index out of range/);203wasmEvalText('(module (func (local i32)))');204wasmEvalText('(module (func (local i32) (local f32)))');205assertEq(wasmEvalText('(module (func (result i32) (local i32) (get_local 0)) (export "" 0))')(), 0);206assertErrorMessage(() => wasmEvalText('(module (func (result f32) (local i32) (get_local 0)))'), TypeError, mismatchError("i32", "f32"));207assertErrorMessage(() => wasmEvalText('(module (func (result i32) (local f32) (get_local 0)))'), TypeError, mismatchError("f32", "i32"));208assertEq(wasmEvalText('(module (func (result i32) (param i32) (local f32) (get_local 0)) (export "" 0))')(), 0);209assertEq(wasmEvalText('(module (func (result f32) (param i32) (local f32) (get_local 1)) (export "" 0))')(), 0);210assertErrorMessage(() => wasmEvalText('(module (func (result f32) (param i32) (local f32) (get_local 0)))'), TypeError, mismatchError("i32", "f32"));211assertErrorMessage(() => wasmEvalText('(module (func (result i32) (param i32) (local f32) (get_local 1)))'), TypeError, mismatchError("f32", "i32"));212assertErrorMessage(() => wasmEvalText('(module (func (set_local 0 (i32.const 0))))'), TypeError, /set_local index out of range/);213wasmEvalText('(module (func (local i32) (set_local 0 (i32.const 0))))');214assertErrorMessage(() => wasmEvalText('(module (func (local f32) (set_local 0 (i32.const 0))))'), TypeError, mismatchError("i32", "f32"));215assertErrorMessage(() => wasmEvalText('(module (func (local f32) (set_local 0 (nop))))'), TypeError, mismatchError("void", "f32"));216assertErrorMessage(() => wasmEvalText('(module (func (local i32) (local f32) (set_local 0 (get_local 1))))'), TypeError, mismatchError("f32", "i32"));217assertErrorMessage(() => wasmEvalText('(module (func (local i32) (local f32) (set_local 1 (get_local 0))))'), TypeError, mismatchError("i32", "f32"));218wasmEvalText('(module (func (local i32) (local f32) (set_local 0 (get_local 0))))');219wasmEvalText('(module (func (local i32) (local f32) (set_local 1 (get_local 1))))');220assertEq(wasmEvalText('(module (func (result i32) (local i32) (set_local 0 (i32.const 42))) (export "" 0))')(), 42);221assertEq(wasmEvalText('(module (func (result i32) (local i32) (set_local 0 (get_local 0))) (export "" 0))')(), 0);222if (!hasI64)223 assertErrorMessage(() => wasmEvalText('(module (func (local i64)))'), TypeError, /NYI/);224assertEq(wasmEvalText('(module (func (param $a i32) (result i32) (get_local $a)) (export "" 0))')(), 0);225assertEq(wasmEvalText('(module (func (param $a i32) (local $b i32) (result i32) (block (set_local $b (get_local $a)) (get_local $b))) (export "" 0))')(42), 42);226wasmEvalText('(module (func (local i32) (local $a f32) (set_local 0 (i32.const 1)) (set_local $a (f32.const nan))))');227// ----------------------------------------------------------------------------228// blocks229assertEq(wasmEvalText('(module (func (block)) (export "" 0))')(), undefined);230assertErrorMessage(() => wasmEvalText('(module (func (result i32) (block)))'), TypeError, mismatchError("void", "i32"));231assertErrorMessage(() => wasmEvalText('(module (func (result i32) (block (block))))'), TypeError, mismatchError("void", "i32"));232assertErrorMessage(() => wasmEvalText('(module (func (local i32) (set_local 0 (block))))'), TypeError, mismatchError("void", "i32"));233assertEq(wasmEvalText('(module (func (block (block))) (export "" 0))')(), undefined);234assertEq(wasmEvalText('(module (func (result i32) (block (i32.const 42))) (export "" 0))')(), 42);235assertEq(wasmEvalText('(module (func (result i32) (block (block (i32.const 42)))) (export "" 0))')(), 42);236assertErrorMessage(() => wasmEvalText('(module (func (result f32) (block (i32.const 0))))'), TypeError, mismatchError("i32", "f32"));237assertEq(wasmEvalText('(module (func (result i32) (block (i32.const 13) (block (i32.const 42)))) (export "" 0))')(), 42);238assertErrorMessage(() => wasmEvalText('(module (func (result f32) (param f32) (block (get_local 0) (i32.const 0))))'), TypeError, mismatchError("i32", "f32"));239assertEq(wasmEvalText('(module (func (result i32) (local i32) (set_local 0 (i32.const 42)) (get_local 0)) (export "" 0))')(), 42);240// ----------------------------------------------------------------------------241// calls242// TODO: Reenable when syntactic arities are added for calls243//assertThrowsInstanceOf(() => wasmEvalText('(module (func (nop)) (func (call 0 (i32.const 0))))'), TypeError);244assertThrowsInstanceOf(() => wasmEvalText('(module (func (param i32) (nop)) (func (call 0)))'), TypeError);245assertThrowsInstanceOf(() => wasmEvalText('(module (func (param f32) (nop)) (func (call 0 (i32.const 0))))'), TypeError);246assertErrorMessage(() => wasmEvalText('(module (func (nop)) (func (call 3)))'), TypeError, /callee index out of range/);247wasmEvalText('(module (func (nop)) (func (call 0)))');248wasmEvalText('(module (func (param i32) (nop)) (func (call 0 (i32.const 0))))');249assertEq(wasmEvalText('(module (func (result i32) (i32.const 42)) (func (result i32) (call 0)) (export "" 1))')(), 42);250assertThrowsInstanceOf(() => wasmEvalText('(module (func (call 0)) (export "" 0))')(), InternalError);251assertThrowsInstanceOf(() => wasmEvalText('(module (func (call 1)) (func (call 0)) (export "" 0))')(), InternalError);252wasmEvalText('(module (func (param i32 f32)) (func (call 0 (i32.const 0) (f32.const nan))))');253assertErrorMessage(() => wasmEvalText('(module (func (param i32 f32)) (func (call 0 (i32.const 0) (i32.const 0))))'), TypeError, mismatchError("i32", "f32"));254// TODO: Reenable when syntactic arities are added for calls255//assertThrowsInstanceOf(() => wasmEvalText('(module (import "a" "") (func (call_import 0 (i32.const 0))))', {a:()=>{}}), TypeError);256assertThrowsInstanceOf(() => wasmEvalText('(module (import "a" "" (param i32)) (func (call_import 0)))', {a:()=>{}}), TypeError);257assertThrowsInstanceOf(() => wasmEvalText('(module (import "a" "" (param f32)) (func (call_import 0 (i32.const 0))))', {a:()=>{}}), TypeError);258assertErrorMessage(() => wasmEvalText('(module (import "a" "") (func (call_import 1)))'), TypeError, /import index out of range/);259wasmEvalText('(module (import "a" "") (func (call_import 0)))', {a:()=>{}});260wasmEvalText('(module (import "a" "" (param i32)) (func (call_import 0 (i32.const 0))))', {a:()=>{}});261function checkF32CallImport(v) {262 assertEq(wasmEvalText('(module (import "a" "" (result f32)) (func (result f32) (call_import 0)) (export "" 0))', {a:()=>{ return v; }})(), Math.fround(v));263}264checkF32CallImport(13.37);265checkF32CallImport(NaN);266checkF32CallImport(-Infinity);267checkF32CallImport(-0);268checkF32CallImport(Math.pow(2, 32) - 1);269var f = wasmEvalText('(module (import "inc" "") (func (call_import 0)) (export "" 0))', {inc:()=>counter++});270var g = wasmEvalText('(module (import "f" "") (func (block (call_import 0) (call_import 0))) (export "" 0))', {f});271var counter = 0;272f();273assertEq(counter, 1);274g();275assertEq(counter, 3);276var f = wasmEvalText('(module (import "callf" "") (func (call_import 0)) (export "" 0))', {callf:()=>f()});277assertThrowsInstanceOf(() => f(), InternalError);278var f = wasmEvalText('(module (import "callg" "") (func (call_import 0)) (export "" 0))', {callg:()=>g()});279var g = wasmEvalText('(module (import "callf" "") (func (call_import 0)) (export "" 0))', {callf:()=>f()});280assertThrowsInstanceOf(() => f(), InternalError);281var code = '(module (import "one" "" (result i32)) (import "two" "" (result i32)) (func (result i32) (i32.const 3)) (func (result i32) (i32.const 4)) (func (result i32) BODY) (export "" 2))';282var imports = {one:()=>1, two:()=>2};283assertEq(wasmEvalText(code.replace('BODY', '(call_import 0)'), imports)(), 1);284assertEq(wasmEvalText(code.replace('BODY', '(call_import 1)'), imports)(), 2);285assertEq(wasmEvalText(code.replace('BODY', '(call 0)'), imports)(), 3);286assertEq(wasmEvalText(code.replace('BODY', '(call 1)'), imports)(), 4);287var {v2i, i2i, i2v} = wasmEvalText(`(module288 (type (func (result i32)))289 (type (func (param i32) (result i32)))290 (type (func (param i32)))291 (func (type 0) (i32.const 13))292 (func (type 0) (i32.const 42))293 (func (type 1) (i32.add (get_local 0) (i32.const 1)))294 (func (type 1) (i32.add (get_local 0) (i32.const 2)))295 (func (type 1) (i32.add (get_local 0) (i32.const 3)))296 (func (type 1) (i32.add (get_local 0) (i32.const 4)))297 (table 0 1 2 3 4 5)298 (func (param i32) (result i32) (call_indirect 0 (get_local 0)))299 (func (param i32) (param i32) (result i32) (call_indirect 1 (get_local 0) (get_local 1)))300 (func (param i32) (call_indirect 2 (get_local 0) (i32.const 0)))301 (export "v2i" 6)302 (export "i2i" 7)303 (export "i2v" 8)304)`);305const badIndirectCall = /wasm indirect call signature mismatch/;306assertEq(v2i(0), 13);307assertEq(v2i(1), 42);308assertErrorMessage(() => v2i(2), Error, badIndirectCall);309assertErrorMessage(() => v2i(3), Error, badIndirectCall);310assertErrorMessage(() => v2i(4), Error, badIndirectCall);311assertErrorMessage(() => v2i(5), Error, badIndirectCall);312assertErrorMessage(() => i2i(0), Error, badIndirectCall);313assertErrorMessage(() => i2i(1), Error, badIndirectCall);314assertEq(i2i(2, 100), 101);315assertEq(i2i(3, 100), 102);316assertEq(i2i(4, 100), 103);317assertEq(i2i(5, 100), 104);318assertErrorMessage(() => i2v(0), Error, badIndirectCall);319assertErrorMessage(() => i2v(1), Error, badIndirectCall);320assertErrorMessage(() => i2v(2), Error, badIndirectCall);321assertErrorMessage(() => i2v(3), Error, badIndirectCall);322assertErrorMessage(() => i2v(4), Error, badIndirectCall);323assertErrorMessage(() => i2v(5), Error, badIndirectCall);324{325 enableSPSProfiling();326 wasmEvalText(`(327 module328 (func (result i32) (i32.const 0))329 (func)330 (table 1 0)331 (export "" 0)332 )`)();333 disableSPSProfiling();334}335for (bad of [6, 7, 100, Math.pow(2,31)-1, Math.pow(2,31), Math.pow(2,31)+1, Math.pow(2,32)-2, Math.pow(2,32)-1]) {336 assertThrowsInstanceOf(() => v2i(bad), RangeError);337 assertThrowsInstanceOf(() => i2i(bad, 0), RangeError);338 assertThrowsInstanceOf(() => i2v(bad, 0), RangeError);339}340if (hasI64) {341 assertErrorMessage(() => wasmEvalText('(module (func (param i64) (result i32) (i32.const 123)) (export "" 0))'), TypeError, /i64 argument/);342 assertErrorMessage(() => wasmEvalText('(module (func (param i32) (result i64) (i64.const 123)) (export "" 0))'), TypeError, /i64 return type/);343 assertErrorMessage(() => wasmEvalText('(module (import "a" "" (param i64) (result i32)))'), TypeError, /i64 argument/);344 assertErrorMessage(() => wasmEvalText('(module (import "a" "" (result i64)))'), TypeError, /i64 return type/);345}346var {v2i, i2i, i2v} = wasmEvalText(`(module347 (type $a (func (result i32)))348 (type $b (func (param i32) (result i32)))349 (type $c (func (param i32)))350 (func $a (type $a) (i32.const 13))351 (func $b (type $a) (i32.const 42))352 (func $c (type $b) (i32.add (get_local 0) (i32.const 1)))353 (func $d (type $b) (i32.add (get_local 0) (i32.const 2)))354 (func $e (type $b) (i32.add (get_local 0) (i32.const 3)))355 (func $f (type $b) (i32.add (get_local 0) (i32.const 4)))356 (table $a $b $c $d $e $f)357 (func (param i32) (result i32) (call_indirect $a (get_local 0)))358 (func (param i32) (param i32) (result i32) (call_indirect $b (get_local 0) (get_local 1)))359 (func (param i32) (call_indirect $c (get_local 0) (i32.const 0)))360 (export "v2i" 6)361 (export "i2i" 7)362 (export "i2v" 8)363)`);364wasmEvalText('(module (func $foo (nop)) (func (call $foo)))');365wasmEvalText('(module (func (call $foo)) (func $foo (nop)))');366wasmEvalText('(module (import $bar "a" "") (func (call_import $bar)) (func $foo (nop)))', {a:()=>{}});...

Full Screen

Full Screen

test-run-error-formatting-test.js

Source:test-run-error-formatting-test.js Github

copy

Full Screen

...106}107describe('Error formatting', function () {108 describe('Errors', function () {109 it('Should format "actionIntegerOptionError" message', function () {110 assertErrorMessage('action-integer-option-error', new ActionIntegerOptionError('offsetX', '1.01'));111 });112 it('Should format "actionPositiveIntegerOptionError" message', function () {113 assertErrorMessage('action-positive-integer-option-error', new ActionPositiveIntegerOptionError('caretPos', '-1'));114 });115 it('Should format "actionIntegerArgumentError" message', function () {116 assertErrorMessage('action-integer-argument-error', new ActionIntegerArgumentError('dragOffsetX', 'NaN'));117 });118 it('Should format "actionPositiveIntegerArgumentError" message', function () {119 assertErrorMessage('action-positive-integer-argument-error', new ActionPositiveIntegerArgumentError('startPos', '-1'));120 });121 it('Should format "actionBooleanOptionError" message', function () {122 assertErrorMessage('action-boolean-option-error', new ActionBooleanOptionError('modifier.ctrl', 'object'));123 });124 it('Should format "actionSpeedOptionError" message', function () {125 assertErrorMessage('action-speed-option-error', new ActionSpeedOptionError('speed', 'object'));126 });127 it('Should format "pageLoadError" message', function () {128 assertErrorMessage('page-load-error', new PageLoadError('Failed to find a DNS-record for the resource'));129 });130 it('Should format "uncaughtErrorOnPage" message', function () {131 assertErrorMessage('uncaught-js-error-on-page', new UncaughtErrorOnPage('Custom script error', 'http://example.org'));132 });133 it('Should format "uncaughtErrorInTestCode" message', function () {134 assertErrorMessage('uncaught-js-error-in-test-code', new UncaughtErrorInTestCode(new Error('Custom script error'), testCallsite));135 });136 it('Should format "uncaughtNonErrorObjectInTestCode" message', function () {137 assertErrorMessage('uncaught-non-error-object-in-test-code', new UncaughtNonErrorObjectInTestCode('Hey ya!'));138 });139 it('Should format "uncaughtErrorInAddCustomDOMProperties" message', function () {140 assertErrorMessage('uncaught-error-in-add-custom-dom-properties-code', new UncaughtErrorInCustomDOMPropertyCode(testCallsite, new Error('Custom script error'), 'prop'));141 });142 it('Should format "actionElementNotFoundError" message', function () {143 assertErrorMessage('action-element-not-found-error', new ActionElementNotFoundError());144 });145 it('Should format "actionElementIsInvisibleError" message', function () {146 assertErrorMessage('action-element-is-invisible-error', new ActionElementIsInvisibleError());147 });148 it('Should format "actionSelectorMatchesWrongNodeTypeError" message', function () {149 assertErrorMessage('action-selector-matches-wrong-node-type-error', new ActionSelectorMatchesWrongNodeTypeError('text'));150 });151 it('Should format "actionElementNonEditableError" message', function () {152 assertErrorMessage('action-element-non-editable-error', new ActionElementNonEditableError());153 });154 it('Should format "actionRootContainerNotFoundError" message', function () {155 assertErrorMessage('action-root-container-not-found-error', new ActionRootContainerNotFoundError());156 });157 it('Should format "actionElementNonContentEditableError" message', function () {158 assertErrorMessage('action-element-non-content-editable-error', new ActionElementNonContentEditableError('startSelector'));159 });160 it('Should format "actionElementNotTextAreaError" message', function () {161 assertErrorMessage('action-element-not-text-area-error', new ActionElementNotTextAreaError());162 });163 it('Should format "actionElementNotIframeError" message', function () {164 assertErrorMessage('action-element-not-iframe-error', new ActionElementNotIframeError());165 });166 it('Should format "actionSelectorError" message', function () {167 assertErrorMessage('action-selector-error', new ActionSelectorError('selector', 'Yo!'));168 });169 it('Should format "actionOptionsTypeError" message', function () {170 assertErrorMessage('action-options-type-error', new ActionOptionsTypeError(typeof 1));171 });172 it('Should format "actionAdditionalElementNotFoundError" message', function () {173 assertErrorMessage('action-additional-element-not-found-error', new ActionAdditionalElementNotFoundError('startSelector'));174 });175 it('Should format "actionAdditionalElementIsInvisibleError" message', function () {176 assertErrorMessage('action-additional-element-is-invisible-error', new ActionAdditionalElementIsInvisibleError('startSelector'));177 });178 it('Should format "actionAdditionalSelectorMatchesWrongNodeTypeError" message', function () {179 assertErrorMessage('action-additional-selector-matches-wrong-node-type-error', new ActionAdditionalSelectorMatchesWrongNodeTypeError('startSelector', 'text'));180 });181 it('Should format "actionStringArgumentError" message', function () {182 assertErrorMessage('action-string-argument-error', new ActionStringArgumentError('text', typeof 1));183 });184 it('Should format "actionNullableStringArgumentError" message', function () {185 assertErrorMessage('action-nullable-string-argument-error', new ActionNullableStringArgumentError('text', typeof 1));186 });187 it('Should format "actionIncorrectKeysError" message', function () {188 assertErrorMessage('action-incorrect-keys-error', new ActionIncorrectKeysError('keys'));189 });190 it('Should format "actionNonEmptyStringArrayArgumentError" message', function () {191 assertErrorMessage('action-non-empty-string-array-argument-error', new ActionStringOrStringArrayArgumentError('array', null));192 });193 it('Should format "actionStringArrayElementError" message', function () {194 assertErrorMessage('action-string-array-element-error', new ActionStringArrayElementError('array', 'number', 1));195 });196 it('Should format "actionElementIsNotFileInputError" message', function () {197 assertErrorMessage('action-element-is-not-file-input-error', new ActionElementIsNotFileInputError());198 });199 it('Should format "actionCanNotFindFileToUploadError" message', function () {200 assertErrorMessage('action-can-not-find-file-to-upload-error', new ActionCanNotFindFileToUploadError(['/path/1', '/path/2']));201 });202 it('Should format "actionUnsupportedDeviceTypeError" message', function () {203 assertErrorMessage('action-unsupported-device-type-error', new ActionUnsupportedDeviceTypeError('device', 'iPhone 555'));204 });205 it('Should format "actionIframeIsNotLoadedError" message', function () {206 assertErrorMessage('action-iframe-is-not-loaded-error', new ActionIframeIsNotLoadedError());207 });208 it('Should format "currentIframeIsNotLoadedError" message', function () {209 assertErrorMessage('current-iframe-is-not-loaded-error', new CurrentIframeIsNotLoadedError());210 });211 it('Should format "currentIframeNotFoundError" message', function () {212 assertErrorMessage('current-iframe-not-found-error', new CurrentIframeNotFoundError());213 });214 it('Should format "currentIframeIsInvisibleError" message', function () {215 assertErrorMessage('current-iframe-is-invisible-error', new CurrentIframeIsInvisibleError());216 });217 it('Should format "missingAwaitError', function () {218 assertErrorMessage('missing-await-error', new MissingAwaitError(testCallsite));219 });220 it('Should format "externalAssertionLibraryError', function () {221 assertErrorMessage('external-assertion-library-error', new ExternalAssertionLibraryError(testAssertionError, testCallsite));222 });223 it('Should format "uncaughtErrorInClientFunctionCode"', function () {224 assertErrorMessage('uncaught-error-in-client-function-code', new UncaughtErrorInClientFunctionCode('Selector', new Error('Some error.')));225 });226 it('Should format "clientFunctionExecutionInterruptionError"', function () {227 assertErrorMessage('client-function-execution-interruption-error', new ClientFunctionExecutionInterruptionError('eval'));228 });229 it('Should format "domNodeClientFunctionResultError"', function () {230 assertErrorMessage('dom-node-client-function-result-error', new DomNodeClientFunctionResultError('ClientFunction'));231 });232 it('Should format "invalidSelectorResultError"', function () {233 assertErrorMessage('invalid-selector-result-error', new InvalidSelectorResultError());234 });235 it('Should format "nativeDialogNotHandledError"', function () {236 assertErrorMessage('native-dialog-not-handled-error', new NativeDialogNotHandledError('alert', 'http://example.org'));237 });238 it('Should format "uncaughtErrorInNativeDialogHandler"', function () {239 assertErrorMessage('uncaught-error-in-native-dialog-handler', new UncaughtErrorInNativeDialogHandler('alert', 'error message', 'http://example.org'));240 });241 it('Should format "setNativeDialogHandlerCodeWrongTypeError"', function () {242 assertErrorMessage('set-native-dialog-handler-code-wrong-type-error', new SetNativeDialogHandlerCodeWrongTypeError('number'));243 });244 it('Should format "cantObtainInfoForElementSpecifiedBySelectorError"', function () {245 assertErrorMessage('cant-obtain-info-for-element-specified-by-selector-error', new CantObtainInfoForElementSpecifiedBySelectorError(testCallsite));246 });247 it('Should format "windowDimensionsOverflowError"', function () {248 assertErrorMessage('window-dimensions-overflow-error', new WindowDimensionsOverflowError());249 });250 it('Should format "setTestSpeedArgumentError"', function () {251 assertErrorMessage('set-test-speed-argument-error', new SetTestSpeedArgumentError('speed', 'string'));252 });253 it('Should format "roleSwitchInRoleInitializerError"', function () {254 assertErrorMessage('role-switch-in-role-initializer-error', new RoleSwitchInRoleInitializerError(testCallsite));255 });256 it('Should format "actionRoleArgumentError"', function () {257 assertErrorMessage('action-role-argument-error', new ActionRoleArgumentError('role', 'number'));258 });259 it('Should format "assertionExecutableArgumentError"', function () {260 assertErrorMessage('assertion-executable-argument-error', new AssertionExecutableArgumentError('actual', '1 + temp', 'Unexpected identifier'));261 });262 });263 describe('Test coverage', function () {264 it('Should test messages for all error codes', function () {265 expect(untestedErrorTypes).to.be.empty;266 });267 });...

Full Screen

Full Screen

error-formatter-test.js

Source:error-formatter-test.js Github

copy

Full Screen

...65 isStrings: true,66 diffIndex: 067 }68 };69 assertErrorMessage('eq-assertion', err);70 });71 it('Should format "notEq" assertion message', function () {72 var err = {73 stepName: 'Step',74 relatedSourceCode: 'notEq("test", "test")',75 actual: '"test"',76 expected: '"test"',77 code: TYPE.notEqAssertion,78 userAgent: userAgentMock79 };80 assertErrorMessage('not-eq-assertion', err);81 });82 it('Should format "ok" assertion message', function () {83 var err = {84 stepName: 'Step',85 relatedSourceCode: 'ok(false)',86 actual: 'false',87 code: TYPE.okAssertion,88 userAgent: userAgentMock89 };90 assertErrorMessage('ok-assertion', err);91 });92 it('Should format "notOk" assertion message', function () {93 var err = {94 stepName: 'Step',95 relatedSourceCode: 'notOk("test")',96 actual: '"test"',97 code: TYPE.notOkAssertion,98 userAgent: userAgentMock99 };100 assertErrorMessage('not-ok-assertion', err);101 });102 });103 describe('Errors', function () {104 it('Should format "iframeLoadingTimeout" error message', function () {105 var err = {106 code: TYPE.iframeLoadingTimeout,107 userAgent: userAgentMock108 };109 assertErrorMessage('iframe-loading-timeout', err);110 });111 it('Should format "inIFrameTargetLoadingTimeout" error message', function () {112 var err = {113 code: TYPE.inIFrameTargetLoadingTimeout,114 stepName: 'Step',115 userAgent: userAgentMock116 };117 assertErrorMessage('in-iframe-target-loading-timeout', err);118 });119 it('Should format "uncaughtJSError" error message', function () {120 var err = {121 code: TYPE.uncaughtJSError,122 scriptErr: 'test-error',123 pageUrl: 'http://page',124 userAgent: userAgentMock125 };126 assertErrorMessage('uncaught-js-error', err);127 });128 it('Should format "uncaughtJSErrorInTestCodeStep" error message', function () {129 var err = {130 code: TYPE.uncaughtJSErrorInTestCodeStep,131 stepName: 'Step',132 scriptErr: 'error',133 userAgent: userAgentMock134 };135 assertErrorMessage('uncaught-js-error-in-test-code-step', err);136 });137 it('Should format "storeDomNodeOrJqueryObject" error message', function () {138 var err = {139 code: TYPE.storeDomNodeOrJqueryObject,140 stepName: 'Step',141 userAgent: userAgentMock142 };143 assertErrorMessage('store-dom-node-or-jquery-object', err);144 });145 it('Should format "emptyFirstArgument" error message', function () {146 var err = {147 code: TYPE.emptyFirstArgument,148 stepName: 'Step',149 relatedSourceCode: 'code',150 action: 'testAction',151 userAgent: userAgentMock152 };153 assertErrorMessage('empty-first-argument', err);154 });155 it('Should format "invisibleActionElement" error message', function () {156 var err = {157 code: TYPE.invisibleActionElement,158 stepName: 'Step',159 relatedSourceCode: 'code',160 action: 'test-action',161 element: 'element',162 userAgent: userAgentMock163 };164 assertErrorMessage('invisible-action-element', err);165 });166 it('Should format "incorrectDraggingSecondArgument" error message', function () {167 var err = {168 code: TYPE.incorrectDraggingSecondArgument,169 stepName: 'Step',170 relatedSourceCode: 'code',171 userAgent: userAgentMock172 };173 assertErrorMessage('incorrect-dragging-second-argument', err);174 });175 it('Should format "incorrectPressActionArgument" error message', function () {176 var err = {177 code: TYPE.incorrectPressActionArgument,178 stepName: 'Step',179 relatedSourceCode: 'code',180 userAgent: userAgentMock181 };182 assertErrorMessage('incorrect-press-action-argument', err);183 });184 it('Should format "emptyTypeActionArgument" error message', function () {185 var err = {186 code: TYPE.emptyTypeActionArgument,187 stepName: 'Step',188 relatedSourceCode: 'code',189 userAgent: userAgentMock190 };191 assertErrorMessage('empty-type-action-argument', err);192 });193 it('Should format "unexpectedDialog" error message', function () {194 var err = {195 code: TYPE.unexpectedDialog,196 stepName: 'Step',197 dialog: 'test-dialog',198 message: 'message',199 userAgent: userAgentMock200 };201 assertErrorMessage('unexpected-dialog', err);202 });203 it('Should format "expectedDialogDoesntAppear" error message', function () {204 var err = {205 code: TYPE.expectedDialogDoesntAppear,206 stepName: 'Step',207 dialog: 'test-dialog',208 userAgent: userAgentMock209 };210 assertErrorMessage('expected-dialog-doesnt-appear', err);211 });212 it('Should format "incorrectSelectActionArguments" error message', function () {213 var err = {214 code: TYPE.incorrectSelectActionArguments,215 stepName: 'Step',216 relatedSourceCode: 'code',217 userAgent: userAgentMock218 };219 assertErrorMessage('incorrect-select-action-arguments', err);220 });221 it('Should format "incorrectWaitActionMillisecondsArgument" error message', function () {222 var err = {223 code: TYPE.incorrectWaitActionMillisecondsArgument,224 stepName: 'Step',225 relatedSourceCode: 'code',226 userAgent: userAgentMock227 };228 assertErrorMessage('incorrect-wait-action-milliseconds-arguments', err);229 });230 it('Should format "incorrectWaitForActionEventArgument" error message', function () {231 var err = {232 code: TYPE.incorrectWaitForActionEventArgument,233 stepName: 'Step',234 relatedSourceCode: 'code',235 userAgent: userAgentMock236 };237 assertErrorMessage('incorrect-wait-for-action-event-argument', err);238 });239 it('Should format "incorrectWaitForActionTimeoutArgument" error message', function () {240 var err = {241 code: TYPE.incorrectWaitForActionTimeoutArgument,242 stepName: 'Step',243 relatedSourceCode: 'code',244 userAgent: userAgentMock245 };246 assertErrorMessage('incorrect-wait-for-action-timeout-argument', err);247 });248 it('Should format "waitForActionTimeoutExceeded" error message', function () {249 var err = {250 code: TYPE.waitForActionTimeoutExceeded,251 stepName: 'Step',252 relatedSourceCode: 'code',253 userAgent: userAgentMock254 };255 assertErrorMessage('wait-for-action-timeout-exceeded', err);256 });257 it('Should format "emptyIFrameArgument" error message', function () {258 var err = {259 code: TYPE.emptyIFrameArgument,260 stepName: 'Step',261 relatedSourceCode: 'code',262 userAgent: userAgentMock263 };264 assertErrorMessage('empty-iframe-argument', err);265 });266 it('Should format "iframeArgumentIsNotIFrame" error message', function () {267 var err = {268 code: TYPE.iframeArgumentIsNotIFrame,269 stepName: 'Step',270 relatedSourceCode: 'code',271 userAgent: userAgentMock272 };273 assertErrorMessage('iframe-argument-is-not-iframe', err);274 });275 it('Should format "multipleIFrameArgument" error message', function () {276 var err = {277 code: TYPE.multipleIFrameArgument,278 stepName: 'Step',279 relatedSourceCode: 'code',280 userAgent: userAgentMock281 };282 assertErrorMessage('multiple-iframe-argument', err);283 });284 it('Should format "incorrectIFrameArgument" error message', function () {285 var err = {286 code: TYPE.incorrectIFrameArgument,287 stepName: 'Step',288 relatedSourceCode: 'code',289 userAgent: userAgentMock290 };291 assertErrorMessage('incorrect-iframe-argument', err);292 });293 it('Should format "uploadCanNotFindFileToUpload" error message', function () {294 var err = {295 code: TYPE.uploadCanNotFindFileToUpload,296 stepName: 'Step',297 relatedSourceCode: 'code',298 filePaths: ['path1', 'path2'],299 userAgent: userAgentMock300 };301 assertErrorMessage('upload-can-not-find-file-to-upload', err);302 });303 it('Should format "uploadElementIsNotFileInput" error message', function () {304 var err = {305 code: TYPE.uploadElementIsNotFileInput,306 stepName: 'Step',307 relatedSourceCode: 'code',308 filePath: 'path',309 userAgent: userAgentMock310 };311 assertErrorMessage('upload-element-is-not-file-input', err);312 });313 it('Should format "uploadInvalidFilePathArgument" error message', function () {314 var err = {315 code: TYPE.uploadInvalidFilePathArgument,316 stepName: 'Step',317 relatedSourceCode: 'code',318 userAgent: userAgentMock319 };320 assertErrorMessage('upload-invalid-file-path-argument', err);321 });322 it('Should format "pageNotLoaded" error message', function () {323 var err = {324 code: TYPE.pageNotLoaded,325 message: 'Failed to find a DNS-record for the resource at <a href="example.org">example.org</a>.',326 userAgent: userAgentMock327 };328 assertErrorMessage('page-not-loaded', err);329 });330 });331 describe('Test coverage', function () {332 it('Should test messages for all error codes', function () {333 expect(untestedErrorCodes).to.be.empty;334 });335 });...

Full Screen

Full Screen

legacy-test-run-error-formatting-test.js

Source:legacy-test-run-error-formatting-test.js Github

copy

Full Screen

...52 isStrings: true,53 diffIndex: 154 }55 };56 assertErrorMessage('eq-assertion', err, 'eq({"<tag>": "<some-tag>"}, {"<tag>": "<another-tag>"})');57 });58 it('Should format "notEq" assertion message', function () {59 var err = {60 stepName: 'Step with <tag>',61 actual: '"<test>"',62 expected: '"<test>"',63 type: TEST_RUN_ERROR_TYPE.notEqAssertion,64 message: '<tagged> message'65 };66 assertErrorMessage('not-eq-assertion', err, 'notEq("<test>", "<test>")');67 });68 it('Should format "ok" assertion message', function () {69 var err = {70 stepName: 'Step with <tag>',71 actual: 'false',72 type: TEST_RUN_ERROR_TYPE.okAssertion,73 message: '<tagged> message'74 };75 assertErrorMessage('ok-assertion', err, 'ok("<test>" === "<best>")');76 });77 it('Should format "notOk" assertion message', function () {78 var err = {79 stepName: 'Step with <tag>',80 actual: '"<test>"',81 type: TEST_RUN_ERROR_TYPE.notOkAssertion,82 message: '<tagged> message'83 };84 assertErrorMessage('not-ok-assertion', err, 'notOk("<test>")');85 });86 });87 describe('Errors', function () {88 it('Should format "iframeLoadingTimeout" error message', function () {89 var err = {90 type: TEST_RUN_ERROR_TYPE.iframeLoadingTimeout91 };92 assertErrorMessage('iframe-loading-timeout', err);93 });94 it('Should format "inIFrameTargetLoadingTimeout" error message', function () {95 var err = {96 type: TEST_RUN_ERROR_TYPE.inIFrameTargetLoadingTimeout,97 stepName: 'Step with <tag>'98 };99 assertErrorMessage('in-iframe-target-loading-timeout', err);100 });101 it('Should format "uncaughtJSError" error message', function () {102 var err = {103 type: TEST_RUN_ERROR_TYPE.uncaughtJSError,104 scriptErr: 'test-error-with-<tag>',105 pageDestUrl: 'http://page'106 };107 assertErrorMessage('uncaught-js-error', err);108 });109 it('Should format "uncaughtJSErrorInTestCodeStep" error message', function () {110 var err = {111 type: TEST_RUN_ERROR_TYPE.uncaughtJSErrorInTestCodeStep,112 stepName: 'Step with <tag>',113 scriptErr: 'error with <tag>'114 };115 assertErrorMessage('uncaught-js-error-in-test-code-step', err);116 });117 it('Should format "storeDomNodeOrJqueryObject" error message', function () {118 var err = {119 type: TEST_RUN_ERROR_TYPE.storeDomNodeOrJqueryObject,120 stepName: 'Step with <tag>'121 };122 assertErrorMessage('store-dom-node-or-jquery-object', err);123 });124 it('Should format "emptyFirstArgument" error message', function () {125 var err = {126 type: TEST_RUN_ERROR_TYPE.emptyFirstArgument,127 stepName: 'Step with <tag>',128 action: 'testAction'129 };130 assertErrorMessage('empty-first-argument', err, 'code and <tag>');131 });132 it('Should format "invisibleActionElement" error message', function () {133 var err = {134 type: TEST_RUN_ERROR_TYPE.invisibleActionElement,135 stepName: 'Step with <tag>',136 action: 'test-action',137 element: '<element>'138 };139 assertErrorMessage('invisible-action-element', err, 'code and <tag>');140 });141 it('Should format "incorrectDraggingSecondArgument" error message', function () {142 var err = {143 type: TEST_RUN_ERROR_TYPE.incorrectDraggingSecondArgument,144 stepName: 'Step with <tag>'145 };146 assertErrorMessage('incorrect-dragging-second-argument', err, 'code and <tag>');147 });148 it('Should format "incorrectPressActionArgument" error message', function () {149 var err = {150 type: TEST_RUN_ERROR_TYPE.incorrectPressActionArgument,151 stepName: 'Step with <tag>'152 };153 assertErrorMessage('incorrect-press-action-argument', err, 'code and <tag>');154 });155 it('Should format "emptyTypeActionArgument" error message', function () {156 var err = {157 type: TEST_RUN_ERROR_TYPE.emptyTypeActionArgument,158 stepName: 'Step with <tag>'159 };160 assertErrorMessage('empty-type-action-argument', err, 'code and <tag>');161 });162 it('Should format "unexpectedDialog" error message', function () {163 var err = {164 type: TEST_RUN_ERROR_TYPE.unexpectedDialog,165 stepName: 'Step with <tag>',166 dialog: 'test-dialog',167 message: 'message with <tag>'168 };169 assertErrorMessage('unexpected-dialog', err);170 });171 it('Should format "expectedDialogDoesntAppear" error message', function () {172 var err = {173 type: TEST_RUN_ERROR_TYPE.expectedDialogDoesntAppear,174 stepName: 'Step with <tag>',175 dialog: 'test-dialog'176 };177 assertErrorMessage('expected-dialog-doesnt-appear', err);178 });179 it('Should format "incorrectSelectActionArguments" error message', function () {180 var err = {181 type: TEST_RUN_ERROR_TYPE.incorrectSelectActionArguments,182 stepName: 'Step with <tag>'183 };184 assertErrorMessage('incorrect-select-action-arguments', err, 'code and <tag>');185 });186 it('Should format "incorrectWaitActionMillisecondsArgument" error message', function () {187 var err = {188 type: TEST_RUN_ERROR_TYPE.incorrectWaitActionMillisecondsArgument,189 stepName: 'Step with <tag>'190 };191 assertErrorMessage('incorrect-wait-action-milliseconds-arguments', err, 'code and <tag>');192 });193 it('Should format "incorrectWaitForActionEventArgument" error message', function () {194 var err = {195 type: TEST_RUN_ERROR_TYPE.incorrectWaitForActionEventArgument,196 stepName: 'Step with <tag>'197 };198 assertErrorMessage('incorrect-wait-for-action-event-argument', err, 'code and <tag>');199 });200 it('Should format "incorrectWaitForActionTimeoutArgument" error message', function () {201 var err = {202 type: TEST_RUN_ERROR_TYPE.incorrectWaitForActionTimeoutArgument,203 stepName: 'Step with <tag>'204 };205 assertErrorMessage('incorrect-wait-for-action-timeout-argument', err, 'code and <tag>');206 });207 it('Should format "waitForActionTimeoutExceeded" error message', function () {208 var err = {209 type: TEST_RUN_ERROR_TYPE.waitForActionTimeoutExceeded,210 stepName: 'Step with <tag>'211 };212 assertErrorMessage('wait-for-action-timeout-exceeded', err, 'act.waitFor(function(cb) {\n $("<iframe>");\n cb();\n}, 1000);');213 });214 it('Should format "emptyIFrameArgument" error message', function () {215 var err = {216 type: TEST_RUN_ERROR_TYPE.emptyIFrameArgument,217 stepName: 'Step with <tag>'218 };219 assertErrorMessage('empty-iframe-argument', err);220 });221 it('Should format "iframeArgumentIsNotIFrame" error message', function () {222 var err = {223 type: TEST_RUN_ERROR_TYPE.iframeArgumentIsNotIFrame,224 stepName: 'Step with <tag>'225 };226 assertErrorMessage('iframe-argument-is-not-iframe', err);227 });228 it('Should format "multipleIFrameArgument" error message', function () {229 var err = {230 type: TEST_RUN_ERROR_TYPE.multipleIFrameArgument,231 stepName: 'Step with <tag>'232 };233 assertErrorMessage('multiple-iframe-argument', err);234 });235 it('Should format "incorrectIFrameArgument" error message', function () {236 var err = {237 type: TEST_RUN_ERROR_TYPE.incorrectIFrameArgument,238 stepName: 'Step with <tag>'239 };240 assertErrorMessage('incorrect-iframe-argument', err);241 });242 it('Should format "uploadCanNotFindFileToUpload" error message', function () {243 var err = {244 type: TEST_RUN_ERROR_TYPE.uploadCanNotFindFileToUpload,245 stepName: 'Step with <tag>',246 filePaths: ['/unix/path/with/<tag>', 'path2']247 };248 assertErrorMessage('upload-can-not-find-file-to-upload', err, 'code and <tag>');249 });250 it('Should format "uploadElementIsNotFileInput" error message', function () {251 var err = {252 type: TEST_RUN_ERROR_TYPE.uploadElementIsNotFileInput,253 stepName: 'Step with <tag>'254 };255 assertErrorMessage('upload-element-is-not-file-input', err, 'code and <tag>');256 });257 it('Should format "uploadInvalidFilePathArgument" error message', function () {258 var err = {259 type: TEST_RUN_ERROR_TYPE.uploadInvalidFilePathArgument,260 stepName: 'Step with <tag>'261 };262 assertErrorMessage('upload-invalid-file-path-argument', err, 'code and <tag>');263 });264 it('Should format "pageNotLoaded" error message', function () {265 var err = {266 type: TEST_RUN_ERROR_TYPE.pageNotLoaded,267 message: 'Failed to find a DNS-record for the resource at <a href="example.org">example.org</a>.'268 };269 assertErrorMessage('page-not-loaded', err);270 });271 it('Should format "incorrectGlobalWaitForActionEventArgument" error message', function () {272 var err = {273 type: TEST_RUN_ERROR_TYPE.incorrectGlobalWaitForActionEventArgument,274 stepName: 'Step with <tag>'275 };276 assertErrorMessage('incorrect-global-wait-for-action-event-argument', err);277 });278 it('Should format "incorrectGlobalWaitForActionTimeoutArgument" error message', function () {279 var err = {280 type: TEST_RUN_ERROR_TYPE.incorrectGlobalWaitForActionTimeoutArgument,281 stepName: 'Step with <tag>'282 };283 assertErrorMessage('incorrect-global-wait-for-action-timeout-argument', err);284 });285 it('Should format "globalWaitForActionTimeoutExceeded" error message', function () {286 var err = {287 type: TEST_RUN_ERROR_TYPE.globalWaitForActionTimeoutExceeded,288 stepName: 'Step with <tag>'289 };290 assertErrorMessage('global-wait-for-action-timeout-exceed', err);291 });292 });293 describe('Test coverage', function () {294 it('Should test messages for all error codes', function () {295 expect(untestedErrorTypes).to.be.empty;296 });297 });...

Full Screen

Full Screen

mjsunit-assertion-error.js

Source:mjsunit-assertion-error.js Github

copy

Full Screen

...7 frameExpectations.unshift('assertTrue.*mjsunit.js');8 // Frist frame is the top-level script.9 frameExpectations.push(fileName);10}11function assertErrorMessage(frameExpectations, error) {12 let stack = error.stack.split("\n");13 let title = stack.shift();14 assertContains('MjsUnitAssertionError', title);15 addDefaultFrames(frameExpectations);16 // Add default frames to the expectations.17 assertEquals(frameExpectations.length, stack.length);18 for (let i = 0; i < stack.length; i++) {19 let frame = stack[i];20 let expectation = frameExpectations[i];21 assertTrue(frame.search(expectation) != -1,22 `Frame ${i}: Did not find '${expectation}' in '${frame}'`);23 }24}25// Toplevel26try {27 assertTrue(false);28} catch(e) {29 assertErrorMessage([], e);30}31// Single function.32function throwError() {33 assertTrue(false);34}35try {36 throwError();37 assertUnreachable();38} catch(e) {39 assertErrorMessage(['throwError'], e);40}41// Nested function.42function outer() {43 throwError();44}45try {46 outer();47 assertUnreachable();48} catch(e) {49 assertErrorMessage(['throwError', 'outer'], e);50}51// Test Array helper nesting52try {53 [1].map(throwError);54 assertUnreachable();55} catch(e) {56 assertErrorMessage(['throwError', 'Array.map'], e);57}58try {59 Array.prototype.map.call([1], throwError);60 assertUnreachable();61} catch(e) {62 assertErrorMessage(['throwError', 'Array.map'], e);63}64// Test eval65try {66 eval("assertTrue(false);");67 assertUnreachable();68} catch(e) {69 assertErrorMessage(['eval'], e);70}71(function testNestedEval() {72 try {73 eval("assertTrue(false);");74 assertUnreachable();75 } catch(e) {76 assertErrorMessage(['eval', 'testNestedEval'], e);77 }78})();79(function testConstructor() {80 class Failer {81 constructor() {82 assertTrue(false);83 }84 }85 try {86 new Failer();87 assertUnreachable();88 } catch(e) {89 assertErrorMessage(['new Failer', 'testConstructor'], e);90 }...

Full Screen

Full Screen

text.js

Source:text.js Github

copy

Full Screen

1load(libdir + "wasm.js");2var parsingError = /parsing wasm text at/;3assertErrorMessage(() => wasmEvalText(''), SyntaxError, parsingError);4assertErrorMessage(() => wasmEvalText('('), SyntaxError, parsingError);5assertErrorMessage(() => wasmEvalText('(m'), SyntaxError, parsingError);6assertErrorMessage(() => wasmEvalText('(module'), SyntaxError, parsingError);7assertErrorMessage(() => wasmEvalText('(moduler'), SyntaxError, parsingError);8assertErrorMessage(() => wasmEvalText('(module (func) (export "a'), SyntaxError, parsingError);9assertErrorMessage(() => wasmEvalText('(module (func (local $a i32) (param $b f32)))'), SyntaxError, parsingError);10assertErrorMessage(() => wasmEvalText('(module (func $a) (func) (export "a" $a) (export "b" $b))'), SyntaxError, /function not found/);11assertErrorMessage(() => wasmEvalText('(module (import $foo "a" "b") (import $foo "a" "b"))'), SyntaxError, /duplicate import/);12assertErrorMessage(() => wasmEvalText('(module (func $foo) (func $foo))'), SyntaxError, /duplicate function/);13assertErrorMessage(() => wasmEvalText('(module (func (param $a i32) (local $a i32)))'), SyntaxError, /duplicate var/);14assertErrorMessage(() => wasmEvalText('(module (func (get_local $a)))'), SyntaxError, /local not found/);15assertErrorMessage(() => wasmEvalText('(module (type $a (func)) (type $a (func (param i32))))'), SyntaxError, /duplicate signature/);16assertErrorMessage(() => wasmEvalText('(module (import "a" "") (func (call_import $abc)))'), SyntaxError, /import not found/);17assertErrorMessage(() => wasmEvalText('(module (type $a (func)) (func (type $b) (i32.const 13)))'), SyntaxError, /signature not found/);18assertErrorMessage(() => wasmEvalText('(module (type $a (func)) (func (call_indirect $c (get_local 0) (i32.const 0))))'), SyntaxError, /signature not found/);19assertErrorMessage(() => wasmEvalText('(module (func (br $a)))'), SyntaxError, /label not found/);20assertErrorMessage(() => wasmEvalText('(module (func (block $a) (br $a)))'), SyntaxError, /label not found/);21// Note: the s-expression text format is temporary, this file is mostly just to...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 let headerText = await articleHeader.innerText;7 .expect(headerText).eql('Thank you, John Smith!')8 .expect(articleHeader.innerText).contains('Thank you, John Smith!');9});10import { Selector } from 'testcafe';11test('My first test', async t => {12 .typeText('#developer-name', 'John Smith')13 .click('#submit-button');14 const articleHeader = await Selector('.result-content').find('h1');15 let headerText = await articleHeader.innerText;16 .expect(headerText).eql('Thank you, John Smith!')17 .expect(articleHeader.innerText).contains('Thank you, John Smith!');18});19import { Selector } from 'testcafe';20export default async function assertErrorMessage(t, selector, expectedMessage) {21 const actualMessage = await Selector(selector).innerText;22 await t.expect(actualMessage).contains(expectedMessage);23}24import { Selector } from 'testcafe';25import assertErrorMessage from './assertion';26test('My first test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button');29 const articleHeader = await Selector('.result-content').find('h1');30 let headerText = await articleHeader.innerText;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});7import { Selector } from 'testcafe';8test('My first test', async t => {9 .typeText('#developer-name', 'John Smith')10 .click('#submit-button')11 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');12});13const assertErrorMessage = async (t, selector, errorMessage) => {14 await t.expect(selector.hasAttribute('aria-invalid')).ok();15 await t.expect(selector.getAttribute('aria-invalid')).eql('true');16 await t.expect(selector.getAttribute('aria-describedby')).ok();17 const id = selector.getAttribute('aria-describedby');18 await t.expect(Selector(`#${id}`).innerText).eql(errorMessage);19};20test('My first test', async t => {21 .typeText('#developer-name', 'John Smith')22 .click('#submit-button')23 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');24});25test('My first test', async t => {26 .typeText('#developer-name', 'John Smith')27 .click('#submit-button')28 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');29});30test('My first test', async t => {31 .typeText('#developer-name', 'John Smith')32 .click('#submit-button')

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector, ClientFunction } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6test('My second test', async t => {7 .typeText('#developer-name', 'John Smith')8 .click('#submit-button')9 .assertErrorMessage('You have successfully submitted the form')10});11test('My third test', async t => {12 .typeText('#developer-name', 'John Smith')13 .click('#submit-button')14 .assertErrorMessage('You have successfully submitted the form', 'You have successfully submitted the form')15});16test('My fourth test', async t => {17 .typeText('#developer-name', 'John Smith')18 .click('#submit-button')19 .assertErrorMessage('You have successfully submitted the form', 'You have successfully submitted the form', 'You have successfully submitted the form')20});21test('My fifth test', async t => {22 .typeText('#developer-name', 'John Smith')23 .click('#submit-button')24 .assertErrorMessage('You have successfully submitted the form', 'You have successfully submitted the form', 'You have successfully submitted the form', 'You have successfully submitted the form')25});26test('My sixth test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button')29 .assertErrorMessage('You have successfully submitted the form', 'You ha

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2fixture `Getting Started`;3test('My first test', async t => {4 .typeText('#developer-name', 'John Smith')5 .click('#submit-button');6 const articleHeader = await Selector('.result-content').find('h1');7 let headerText = await articleHeader.innerText;8 let id = await articleHeader.id;9 .expect(headerText).eql('Thank you, John Smith!')10 .expect(id).contains('article-header');11});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ClientFunction, Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6 const getLocation = ClientFunction(() => document.location.href);7 await t.expect(getLocation()).contains('example/thank-you.html');8});9test('My second test', async t => {10 .typeText('#developer-name', 'John Smith')11 .click('#submit-button')12 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');13 const getLocation = ClientFunction(() => document.location.href);14 await t.expect(getLocation()).contains('example/thank-you.html');15});16test('My third test', async t => {17 .typeText('#developer-name', 'John Smith')18 .click('#submit-button')19 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');20 const getLocation = ClientFunction(() => document.location.href);21 await t.expect(getLocation()).contains('example/thank-you.html');22});23test('My fourth test', async t => {24 .typeText('#developer-name', 'John Smith')25 .click('#submit-button')26 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');27 const getLocation = ClientFunction(() => document.location.href);28 await t.expect(getLocation()).contains('example/thank-you.html');29});30test('My fifth test', async t => {31 .typeText('#developer-name', 'John Smith')32 .click('#submit-button')33 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');34 const getLocation = ClientFunction(() => document.location.href);35 await t.expect(getLocation()).contains('example/thank-you.html');36});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('Check for the error message', async t => {3 const name = Selector('#developer-name');4 .typeText(name, 'Peter')5 .click('#submit-button')6 .expect(Selector('.result-content').innerText).contains('Peter', 'This message is displayed when the assertion fails.');7});8import { Selector } from 'testcafe';9test('Check for the error message', async t => {10 const name = Selector('#developer-name');11 .typeText(name, 'Peter')12 .click('#submit-button')13 .expect(Selector('.result-content').innerText).contains('Peter', 'This message is displayed when the assertion fails.');14});15import { Selector } from 'testcafe';16test('Check for the error message', async t => {17 const name = Selector('#developer-name');18 .typeText(name, 'Peter')19 .click('#submit-button')20 .expect(Selector('.result-content').innerText).contains('Peter', 'This message is displayed when the assertion fails.');21});22import { Selector } from 'testcafe';23test('Check for the error message', async t => {24 const name = Selector('#developer-name');25 .typeText(name, 'Peter')26 .click('#submit-button')27 .expect(Selector('.result-content').innerText).contains('Peter', 'This message is displayed when the assertion fails.');28});29import { Selector } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ClientFunction } from 'testcafe';2const assertErrorMessage = ClientFunction((selector) => {3 const element = document.querySelector(selector);4 const error = element.getAttribute('data-error');5 if (error) {6 return error;7 }8 return '';9});10test('My first test', async t => {11 .typeText('#developer-name', 'John Smith')12 .click('#submit-button')13 .expect(assertErrorMessage('#developer-name')).eql('name is required');14});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector, ClientFunction } from 'testcafe';2const assertErrorMessage = ClientFunction(() => {3 return window.assertErrorMessage;4});5test('test', async t => {6 .typeText('#username', 'test')7 .typeText('#password', 'test')8 .click('#login');9 const errorMessage = await assertErrorMessage();10 await t.expect(errorMessage).eql('Invalid credentials');11});12import { Selector, ClientFunction } from 'testcafe';13const assertErrorMessage = ClientFunction(() => {14 return window.assertErrorMessage;15});16test('test', async t => {17 .typeText('#username', 'test')18 .typeText('#password', 'test')19 .click('#login');20 const errorMessage = await assertErrorMessage();21 await t.expect(errorMessage).eql('Invalid credentials');22});23import { Selector, ClientFunction } from 'testcafe';24const assertErrorMessage = ClientFunction(() => {25 return window.assertErrorMessage;26});27test('test', async t => {28 .typeText('#username', 'test')29 .typeText('#password', 'test')30 .click('#login');31 const errorMessage = await assertErrorMessage();32 await t.expect(errorMessage).e

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 Testcafe 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