| /* Lovingly generated by gen-spec-js.py based on the wonderful content of * |
| * https://github.com/WebAssembly/spec/blob/master/interpreter/host/js.ml */ |
| 'use strict'; |
| |
| let soft_validate = true; |
| |
| let spectest = { |
| print: print || ((...xs) => console.log(...xs)), |
| global: 666, |
| table: new WebAssembly.Table({initial: 10, maximum: 20, element: 'anyfunc'}), |
| memory: new WebAssembly.Memory({initial: 1, maximum: 2}),}; |
| |
| let registry = {spectest}; |
| let $$; |
| |
| function register(name, instance) { |
| registry[name] = instance.exports; |
| } |
| |
| function module(bytes) { |
| let buffer = new ArrayBuffer(bytes.length); |
| let view = new Uint8Array(buffer); |
| for (let i = 0; i < bytes.length; ++i) { |
| view[i] = bytes.charCodeAt(i); |
| } |
| return new WebAssembly.Module(buffer); |
| } |
| |
| function instance(bytes, imports = registry) { |
| return new WebAssembly.Instance(module(bytes), imports); |
| } |
| |
| function assert_malformed(bytes) { |
| try { module(bytes) } catch (e) { |
| if (e instanceof WebAssembly.CompileError) return; |
| } |
| throw new Error("Wasm decoding failure expected"); |
| } |
| |
| function assert_invalid(bytes) { |
| try { module(bytes) } catch (e) { |
| if (e instanceof WebAssembly.CompileError) return; |
| } |
| throw new Error("Wasm validation failure expected"); |
| } |
| |
| function assert_soft_invalid(bytes) { |
| try { module(bytes) } catch (e) { |
| if (e instanceof WebAssembly.CompileError) return; |
| throw new Error("Wasm validation failure expected"); |
| } |
| if (soft_validate) |
| throw new Error("Wasm validation failure expected"); |
| } |
| |
| function assert_unlinkable(bytes) { |
| let mod = module(bytes); |
| try { new WebAssembly.Instance(mod, registry) } catch (e) { |
| if (e instanceof TypeError) return; |
| } |
| throw new Error("Wasm linking failure expected"); |
| } |
| |
| function assert_uninstantiable(bytes) { |
| let mod = module(bytes); |
| try { new WebAssembly.Instance(mod, registry) } catch (e) { |
| if (e instanceof WebAssembly.RuntimeError) return; |
| } |
| throw new Error("Wasm trap expected"); |
| } |
| |
| function assert_trap(action) { |
| try { action() } catch (e) { |
| if (e instanceof WebAssembly.RuntimeError) return; |
| } |
| throw new Error("Wasm trap expected"); |
| } |
| |
| function assert_return(action, expected) { |
| let actual = action(); |
| if (!Object.is(actual, expected)) { |
| throw new Error("Wasm return value " + expected + " expected, got " + actual); |
| }; |
| } |
| |
| function assert_return_nan(action) { |
| let actual = action(); |
| if (!Number.isNaN(actual)) { |
| throw new Error("Wasm return value NaN expected, got " + actual); |
| }; |
| } |
| |
| let f32 = Math.fround; |
| |
| $$ = instance("\x00\x61\x73\x6d\x0d\x00\x00\x00\x01\x28\x08\x60\x00\x00\x60\x00\x01\x7c\x60\x00\x01\x7f\x60\x00\x01\x7e\x60\x02\x7f\x7f\x01\x7f\x60\x03\x7f\x7f\x7f\x01\x7f\x60\x03\x7f\x7f\x7f\x01\x7f\x60\x00\x01\x7d\x03\x3c\x3b\x00\x00\x00\x00\x00\x00\x01\x02\x02\x00\x02\x00\x00\x00\x02\x02\x02\x02\x02\x00\x02\x02\x03\x02\x02\x03\x02\x04\x04\x04\x04\x02\x05\x02\x02\x02\x02\x02\x02\x02\x02\x07\x03\x02\x02\x02\x02\x07\x02\x03\x02\x02\x02\x02\x02\x00\x00\x00\x00\x04\x05\x01\x70\x01\x01\x01\x05\x03\x01\x00\x01\x07\xb5\x07\x39\x08\x74\x79\x70\x65\x2d\x69\x33\x32\x00\x01\x08\x74\x79\x70\x65\x2d\x69\x36\x34\x00\x02\x08\x74\x79\x70\x65\x2d\x66\x33\x32\x00\x03\x08\x74\x79\x70\x65\x2d\x66\x36\x34\x00\x04\x07\x6e\x75\x6c\x6c\x61\x72\x79\x00\x05\x05\x75\x6e\x61\x72\x79\x00\x06\x0d\x61\x73\x2d\x66\x75\x6e\x63\x2d\x66\x69\x72\x73\x74\x00\x07\x0b\x61\x73\x2d\x66\x75\x6e\x63\x2d\x6d\x69\x64\x00\x08\x0c\x61\x73\x2d\x66\x75\x6e\x63\x2d\x6c\x61\x73\x74\x00\x09\x0d\x61\x73\x2d\x66\x75\x6e\x63\x2d\x76\x61\x6c\x75\x65\x00\x0a\x0e\x61\x73\x2d\x62\x6c\x6f\x63\x6b\x2d\x66\x69\x72\x73\x74\x00\x0b\x0c\x61\x73\x2d\x62\x6c\x6f\x63\x6b\x2d\x6d\x69\x64\x00\x0c\x0d\x61\x73\x2d\x62\x6c\x6f\x63\x6b\x2d\x6c\x61\x73\x74\x00\x0d\x0e\x61\x73\x2d\x62\x6c\x6f\x63\x6b\x2d\x76\x61\x6c\x75\x65\x00\x0e\x0d\x61\x73\x2d\x6c\x6f\x6f\x70\x2d\x66\x69\x72\x73\x74\x00\x0f\x0b\x61\x73\x2d\x6c\x6f\x6f\x70\x2d\x6d\x69\x64\x00\x10\x0c\x61\x73\x2d\x6c\x6f\x6f\x70\x2d\x6c\x61\x73\x74\x00\x11\x0b\x61\x73\x2d\x62\x72\x2d\x76\x61\x6c\x75\x65\x00\x12\x0d\x61\x73\x2d\x62\x72\x5f\x69\x66\x2d\x63\x6f\x6e\x64\x00\x13\x0e\x61\x73\x2d\x62\x72\x5f\x69\x66\x2d\x76\x61\x6c\x75\x65\x00\x14\x13\x61\x73\x2d\x62\x72\x5f\x69\x66\x2d\x76\x61\x6c\x75\x65\x2d\x63\x6f\x6e\x64\x00\x15\x11\x61\x73\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x2d\x69\x6e\x64\x65\x78\x00\x16\x11\x61\x73\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x2d\x76\x61\x6c\x75\x65\x00\x17\x17\x61\x73\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x2d\x76\x61\x6c\x75\x65\x2d\x69\x6e\x64\x65\x78\x00\x18\x0f\x61\x73\x2d\x72\x65\x74\x75\x72\x6e\x2d\x76\x61\x6c\x75\x65\x00\x19\x0a\x61\x73\x2d\x69\x66\x2d\x63\x6f\x6e\x64\x00\x1a\x0a\x61\x73\x2d\x69\x66\x2d\x74\x68\x65\x6e\x00\x1b\x0a\x61\x73\x2d\x69\x66\x2d\x65\x6c\x73\x65\x00\x1c\x0f\x61\x73\x2d\x73\x65\x6c\x65\x63\x74\x2d\x66\x69\x72\x73\x74\x00\x1d\x10\x61\x73\x2d\x73\x65\x6c\x65\x63\x74\x2d\x73\x65\x63\x6f\x6e\x64\x00\x1e\x0e\x61\x73\x2d\x73\x65\x6c\x65\x63\x74\x2d\x63\x6f\x6e\x64\x00\x1f\x0d\x61\x73\x2d\x63\x61\x6c\x6c\x2d\x66\x69\x72\x73\x74\x00\x21\x0b\x61\x73\x2d\x63\x61\x6c\x6c\x2d\x6d\x69\x64\x00\x22\x0c\x61\x73\x2d\x63\x61\x6c\x6c\x2d\x6c\x61\x73\x74\x00\x23\x15\x61\x73\x2d\x63\x61\x6c\x6c\x5f\x69\x6e\x64\x69\x72\x65\x63\x74\x2d\x66\x75\x6e\x63\x00\x24\x16\x61\x73\x2d\x63\x61\x6c\x6c\x5f\x69\x6e\x64\x69\x72\x65\x63\x74\x2d\x66\x69\x72\x73\x74\x00\x25\x14\x61\x73\x2d\x63\x61\x6c\x6c\x5f\x69\x6e\x64\x69\x72\x65\x63\x74\x2d\x6d\x69\x64\x00\x26\x15\x61\x73\x2d\x63\x61\x6c\x6c\x5f\x69\x6e\x64\x69\x72\x65\x63\x74\x2d\x6c\x61\x73\x74\x00\x27\x12\x61\x73\x2d\x73\x65\x74\x5f\x6c\x6f\x63\x61\x6c\x2d\x76\x61\x6c\x75\x65\x00\x28\x0f\x61\x73\x2d\x6c\x6f\x61\x64\x2d\x61\x64\x64\x72\x65\x73\x73\x00\x29\x10\x61\x73\x2d\x6c\x6f\x61\x64\x4e\x2d\x61\x64\x64\x72\x65\x73\x73\x00\x2a\x10\x61\x73\x2d\x73\x74\x6f\x72\x65\x2d\x61\x64\x64\x72\x65\x73\x73\x00\x2b\x0e\x61\x73\x2d\x73\x74\x6f\x72\x65\x2d\x76\x61\x6c\x75\x65\x00\x2c\x11\x61\x73\x2d\x73\x74\x6f\x72\x65\x4e\x2d\x61\x64\x64\x72\x65\x73\x73\x00\x2d\x0f\x61\x73\x2d\x73\x74\x6f\x72\x65\x4e\x2d\x76\x61\x6c\x75\x65\x00\x2e\x10\x61\x73\x2d\x75\x6e\x61\x72\x79\x2d\x6f\x70\x65\x72\x61\x6e\x64\x00\x2f\x0e\x61\x73\x2d\x62\x69\x6e\x61\x72\x79\x2d\x6c\x65\x66\x74\x00\x30\x0f\x61\x73\x2d\x62\x69\x6e\x61\x72\x79\x2d\x72\x69\x67\x68\x74\x00\x31\x0f\x61\x73\x2d\x74\x65\x73\x74\x2d\x6f\x70\x65\x72\x61\x6e\x64\x00\x32\x0f\x61\x73\x2d\x63\x6f\x6d\x70\x61\x72\x65\x2d\x6c\x65\x66\x74\x00\x33\x10\x61\x73\x2d\x63\x6f\x6d\x70\x61\x72\x65\x2d\x72\x69\x67\x68\x74\x00\x34\x12\x61\x73\x2d\x63\x6f\x6e\x76\x65\x72\x74\x2d\x6f\x70\x65\x72\x61\x6e\x64\x00\x35\x13\x61\x73\x2d\x67\x72\x6f\x77\x5f\x6d\x65\x6d\x6f\x72\x79\x2d\x73\x69\x7a\x65\x00\x36\x08\x61\x73\x73\x65\x72\x74\x5f\x30\x00\x37\x08\x61\x73\x73\x65\x72\x74\x5f\x31\x00\x38\x08\x61\x73\x73\x65\x72\x74\x5f\x32\x00\x39\x08\x61\x73\x73\x65\x72\x74\x5f\x33\x00\x3a\x09\x07\x01\x00\x41\x00\x0b\x01\x20\x0a\xa5\x05\x3b\x02\x00\x0b\x05\x00\x0f\x68\x1a\x0b\x05\x00\x0f\x7a\x1a\x0b\x05\x00\x0f\x8c\x1a\x0b\x05\x00\x0f\x9a\x1a\x0b\x03\x00\x0f\x0b\x0c\x00\x44\x00\x00\x00\x00\x00\x00\x08\x40\x0f\x0b\x07\x00\x41\x01\x0f\x41\x02\x0b\x09\x00\x10\x00\x41\x02\x0f\x41\x03\x0b\x06\x00\x01\x10\x00\x0f\x0b\x08\x00\x01\x10\x00\x41\x03\x0f\x0b\x08\x00\x02\x40\x0f\x10\x00\x0b\x0b\x0a\x00\x02\x40\x10\x00\x0f\x10\x00\x0b\x0b\x09\x00\x02\x40\x01\x10\x00\x0f\x0b\x0b\x0b\x00\x02\x7f\x01\x10\x00\x41\x02\x0f\x0b\x0b\x0a\x00\x03\x7f\x41\x03\x0f\x41\x02\x0b\x0b\x0c\x00\x03\x7f\x10\x00\x41\x04\x0f\x41\x02\x0b\x0b\x0b\x00\x03\x7f\x01\x10\x00\x41\x05\x0f\x0b\x0b\x0a\x00\x02\x7f\x41\x09\x0f\x0c\x00\x0b\x0b\x08\x00\x02\x40\x0f\x0d\x00\x0b\x0b\x0f\x00\x02\x7f\x41\x08\x0f\x41\x01\x0d\x00\x1a\x41\x07\x0b\x0b\x0f\x00\x02\x7f\x41\x06\x41\x09\x0f\x0d\x00\x1a\x41\x07\x0b\x0b\x0f\x00\x02\x40\x42\x09\x0f\x0e\x02\x00\x00\x00\x0b\x42\x7f\x0b\x11\x00\x02\x7f\x41\x0a\x0f\x41\x01\x0e\x02\x00\x00\x00\x41\x07\x0b\x0b\x10\x00\x02\x7f\x41\x06\x41\x0b\x0f\x0e\x01\x00\x00\x41\x07\x0b\x0b\x06\x00\x42\x07\x0f\x0f\x0b\x0d\x00\x41\x02\x0f\x04\x7f\x41\x00\x05\x41\x01\x0b\x0b\x0d\x00\x20\x00\x04\x7f\x41\x03\x0f\x05\x20\x01\x0b\x0b\x0d\x00\x20\x00\x04\x7f\x20\x01\x05\x41\x04\x0f\x0b\x0b\x0a\x00\x41\x05\x0f\x20\x00\x20\x01\x1b\x0b\x0a\x00\x20\x00\x41\x06\x0f\x20\x01\x1b\x0b\x0a\x00\x41\x00\x41\x01\x41\x07\x0f\x1b\x0b\x04\x00\x41\x7f\x0b\x0b\x00\x41\x0c\x0f\x41\x02\x41\x03\x10\x20\x0b\x0b\x00\x41\x01\x41\x0d\x0f\x41\x03\x10\x20\x0b\x0b\x00\x41\x01\x41\x02\x41\x0e\x0f\x10\x20\x0b\x0e\x00\x41\x14\x0f\x41\x01\x41\x02\x41\x03\x11\x06\x00\x0b\x0e\x00\x41\x00\x41\x15\x0f\x41\x02\x41\x03\x11\x06\x00\x0b\x0e\x00\x41\x00\x41\x01\x41\x16\x0f\x41\x03\x11\x06\x00\x0b\x0e\x00\x41\x00\x41\x01\x41\x02\x41\x17\x0f\x11\x06\x00\x0b\x0b\x01\x01\x7d\x41\x11\x0f\x21\x00\x41\x7f\x0b\x0b\x00\x43\x9a\x99\xd9\x3f\x0f\x2a\x02\x00\x0b\x08\x00\x42\x1e\x0f\x30\x00\x00\x0b\x13\x00\x41\x1e\x0f\x44\x00\x00\x00\x00\x00\x00\x1c\x40\x39\x03\x00\x41\x7f\x0b\x0c\x00\x41\x02\x41\x1f\x0f\x37\x03\x00\x41\x7f\x0b\x0c\x00\x41\x20\x0f\x41\x07\x3a\x00\x00\x41\x7f\x0b\x0c\x00\x41\x02\x41\x21\x0f\x3d\x01\x00\x41\x7f\x0b\x09\x00\x43\x9a\x99\x59\x40\x0f\x8c\x0b\x08\x00\x41\x03\x0f\x41\x0a\x6a\x0b\x08\x00\x42\x0a\x42\x2d\x0f\x7d\x0b\x06\x00\x41\x2c\x0f\x45\x0b\x0f\x00\x41\x2b\x0f\x44\x00\x00\x00\x00\x00\x00\x24\x40\x65\x0b\x0b\x00\x43\x00\x00\x20\x41\x41\x2a\x0f\x5c\x0b\x06\x00\x41\x29\x0f\xa7\x0b\x07\x00\x41\x28\x0f\x40\x00\x0b\x0f\x00\x02\x40\x10\x16\x42\x09\x51\x45\x0d\x00\x0f\x0b\x00\x0b\x0f\x00\x02\x40\x10\x19\x42\x07\x51\x45\x0d\x00\x0f\x0b\x00\x0b\x0f\x00\x02\x40\x10\x2a\x42\x1e\x51\x45\x0d\x00\x0f\x0b\x00\x0b\x0f\x00\x02\x40\x10\x31\x42\x2d\x51\x45\x0d\x00\x0f\x0b\x00\x0b"); |
| assert_return(() => $$.exports["type-i32"]()); |
| assert_return(() => $$.exports["type-i64"]()); |
| assert_return(() => $$.exports["type-f32"]()); |
| assert_return(() => $$.exports["type-f64"]()); |
| assert_return(() => $$.exports["nullary"]()); |
| assert_return(() => $$.exports["unary"](), 3.0); |
| assert_return(() => $$.exports["as-func-first"](), 1); |
| assert_return(() => $$.exports["as-func-mid"](), 2); |
| assert_return(() => $$.exports["as-func-last"]()); |
| assert_return(() => $$.exports["as-func-value"](), 3); |
| assert_return(() => $$.exports["as-block-first"]()); |
| assert_return(() => $$.exports["as-block-mid"]()); |
| assert_return(() => $$.exports["as-block-last"]()); |
| assert_return(() => $$.exports["as-block-value"](), 2); |
| assert_return(() => $$.exports["as-loop-first"](), 3); |
| assert_return(() => $$.exports["as-loop-mid"](), 4); |
| assert_return(() => $$.exports["as-loop-last"](), 5); |
| assert_return(() => $$.exports["as-br-value"](), 9); |
| assert_return(() => $$.exports["as-br_if-cond"]()); |
| assert_return(() => $$.exports["as-br_if-value"](), 8); |
| assert_return(() => $$.exports["as-br_if-value-cond"](), 9); |
| assert_return(() => $$.exports["assert_0"]()); |
| assert_return(() => $$.exports["as-br_table-value"](), 10); |
| assert_return(() => $$.exports["as-br_table-value-index"](), 11); |
| assert_return(() => $$.exports["assert_1"]()); |
| assert_return(() => $$.exports["as-if-cond"](), 2); |
| assert_return(() => $$.exports["as-if-then"](1, 6), 3); |
| assert_return(() => $$.exports["as-if-then"](0, 6), 6); |
| assert_return(() => $$.exports["as-if-else"](0, 6), 4); |
| assert_return(() => $$.exports["as-if-else"](1, 6), 6); |
| assert_return(() => $$.exports["as-select-first"](0, 6), 5); |
| assert_return(() => $$.exports["as-select-first"](1, 6), 5); |
| assert_return(() => $$.exports["as-select-second"](0, 6), 6); |
| assert_return(() => $$.exports["as-select-second"](1, 6), 6); |
| assert_return(() => $$.exports["as-select-cond"](), 7); |
| assert_return(() => $$.exports["as-call-first"](), 12); |
| assert_return(() => $$.exports["as-call-mid"](), 13); |
| assert_return(() => $$.exports["as-call-last"](), 14); |
| assert_return(() => $$.exports["as-call_indirect-func"](), 20); |
| assert_return(() => $$.exports["as-call_indirect-first"](), 21); |
| assert_return(() => $$.exports["as-call_indirect-mid"](), 22); |
| assert_return(() => $$.exports["as-call_indirect-last"](), 23); |
| assert_return(() => $$.exports["as-set_local-value"](), 17); |
| assert_return(() => $$.exports["as-load-address"](), f32(1.70000004768)); |
| assert_return(() => $$.exports["assert_2"]()); |
| assert_return(() => $$.exports["as-store-address"](), 30); |
| assert_return(() => $$.exports["as-store-value"](), 31); |
| assert_return(() => $$.exports["as-storeN-address"](), 32); |
| assert_return(() => $$.exports["as-storeN-value"](), 33); |
| assert_return(() => $$.exports["as-unary-operand"](), f32(3.40000009537)); |
| assert_return(() => $$.exports["as-binary-left"](), 3); |
| assert_return(() => $$.exports["assert_3"]()); |
| assert_return(() => $$.exports["as-test-operand"](), 44); |
| assert_return(() => $$.exports["as-compare-left"](), 43); |
| assert_return(() => $$.exports["as-compare-right"](), 42); |
| assert_return(() => $$.exports["as-convert-operand"](), 41); |
| assert_return(() => $$.exports["as-grow_memory-size"](), 40); |
| assert_invalid("\x00\x61\x73\x6d\x0d\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7c\x03\x02\x01\x00\x0a\x05\x01\x03\x00\x0f\x0b"); |
| assert_invalid("\x00\x61\x73\x6d\x0d\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7c\x03\x02\x01\x00\x0a\x06\x01\x04\x00\x01\x0f\x0b"); |
| assert_invalid("\x00\x61\x73\x6d\x0d\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7c\x03\x02\x01\x00\x0a\x07\x01\x05\x00\x42\x01\x0f\x0b"); |