| /* 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\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x07\x01\x03\x66\x6f\x6f\x00\x00\x0a\x06\x01\x04\x00\x41\x00\x0b"); |
| assert_return(() => $$.exports["foo"](), 0); |
| $$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7f\x03\x02\x01\x00\x07\x07\x01\x03\x66\x6f\x6f\x00\x00\x0a\x06\x01\x04\x00\x41\x01\x0b"); |
| assert_return(() => $$.exports["foo"](), 1); |
| $$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x05\x01\x60\x00\x01\x7d\x03\x0d\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x6c\x0c\x00\x00\x00\x01\x30\x00\x01\x01\x5f\x00\x02\x01\x24\x00\x03\x01\x40\x00\x04\x21\x7e\x21\x40\x23\x24\x25\x5e\x26\x2a\x28\x29\x5f\x2b\x60\x2d\x3d\x7b\x7d\x7c\x5b\x5d\x5c\x3a\x22\x3b\x27\x3c\x3e\x3f\x2c\x2e\x2f\x20\x00\x05\x03\x4e\x61\x4e\x00\x06\x08\x49\x6e\x66\x69\x6e\x69\x74\x79\x00\x07\x02\x69\x66\x00\x08\x06\x6d\x61\x6c\x6c\x6f\x63\x00\x09\x07\x5f\x6d\x61\x6c\x6c\x6f\x63\x00\x0a\x08\x5f\x5f\x6d\x61\x6c\x6c\x6f\x63\x00\x0b\x0a\x61\x0c\x07\x00\x43\x00\x80\xc8\x40\x0b\x07\x00\x43\x00\x80\xcb\x40\x0b\x07\x00\x43\x00\x00\xcc\x40\x0b\x07\x00\x43\x00\x80\xcc\x40\x0b\x07\x00\x43\x00\x00\x00\x41\x0b\x07\x00\x43\x00\x00\xcb\x40\x0b\x07\x00\x43\x00\x40\x00\x41\x0b\x07\x00\x43\x00\x80\x00\x41\x0b\x07\x00\x43\x00\xc0\x00\x41\x0b\x07\x00\x43\x00\x00\xc9\x40\x0b\x07\x00\x43\x00\x80\xc9\x40\x0b\x07\x00\x43\x00\x00\xca\x40\x0b"); |
| assert_return(() => $$.exports[""](), f32(6.265625)); |
| assert_return(() => $$.exports["malloc"](), f32(6.28125)); |
| assert_return(() => $$.exports["_malloc"](), f32(6.296875)); |
| assert_return(() => $$.exports["__malloc"](), f32(6.3125)); |
| assert_return(() => $$.exports["~!@#$%^&*()_+`-={}|[]\x5c:\x22;'<>?,./ "](), f32(6.34375)); |
| assert_return(() => $$.exports["0"](), f32(6.359375)); |
| assert_return(() => $$.exports["_"](), f32(6.375)); |
| assert_return(() => $$.exports["$"](), f32(6.390625)); |
| assert_return(() => $$.exports["@"](), f32(8.0)); |
| assert_return(() => $$.exports["NaN"](), f32(8.015625)); |
| assert_return(() => $$.exports["Infinity"](), f32(8.03125)); |
| assert_return(() => $$.exports["if"](), f32(8.046875)); |
| $$ = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x0a\x02\x60\x01\x7f\x00\x60\x02\x7f\x7f\x00\x02\x23\x02\x08\x73\x70\x65\x63\x74\x65\x73\x74\x05\x70\x72\x69\x6e\x74\x00\x00\x08\x73\x70\x65\x63\x74\x65\x73\x74\x05\x70\x72\x69\x6e\x74\x00\x00\x03\x02\x01\x01\x07\x0b\x01\x07\x70\x72\x69\x6e\x74\x33\x32\x00\x02\x0a\x0c\x01\x0a\x00\x20\x00\x10\x00\x20\x01\x10\x01\x0b"); |
| $$.exports["print32"](42, 123); |