blob: 9df3ec023ed681347ed9e35eddd6468f47db082b [file] [log] [blame]
/* Copied from *
* 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\x08\x02\x60\x00\x00\x60\x00\x01\x7f\x03\x27\x26\x00\x00\x01\x00\x01\x01\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x07\xf5\x07\x26\x1a\x66\x75\x6e\x63\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x00\x11\x66\x75\x6e\x63\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x00\x01\x17\x66\x75\x6e\x63\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x2d\x76\x61\x6c\x75\x65\x00\x02\x17\x66\x75\x6e\x63\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x03\x1d\x66\x75\x6e\x63\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x2d\x76\x61\x6c\x75\x65\x00\x04\x15\x66\x75\x6e\x63\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x72\x65\x74\x75\x72\x6e\x00\x05\x1b\x62\x6c\x6f\x63\x6b\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x06\x12\x62\x6c\x6f\x63\x6b\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x00\x07\x18\x62\x6c\x6f\x63\x6b\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x2d\x76\x61\x6c\x75\x65\x00\x08\x18\x62\x6c\x6f\x63\x6b\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x09\x1e\x62\x6c\x6f\x63\x6b\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x2d\x76\x61\x6c\x75\x65\x00\x0a\x16\x62\x6c\x6f\x63\x6b\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x72\x65\x74\x75\x72\x6e\x00\x0b\x22\x62\x6c\x6f\x63\x6b\x2d\x6e\x65\x73\x74\x65\x64\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x0c\x19\x62\x6c\x6f\x63\x6b\x2d\x6e\x65\x73\x74\x65\x64\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x00\x0d\x1f\x62\x6c\x6f\x63\x6b\x2d\x6e\x65\x73\x74\x65\x64\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x2d\x76\x61\x6c\x75\x65\x00\x0e\x1f\x62\x6c\x6f\x63\x6b\x2d\x6e\x65\x73\x74\x65\x64\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x0f\x25\x62\x6c\x6f\x63\x6b\x2d\x6e\x65\x73\x74\x65\x64\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x2d\x76\x61\x6c\x75\x65\x00\x10\x1d\x62\x6c\x6f\x63\x6b\x2d\x6e\x65\x73\x74\x65\x64\x2d\x75\x6e\x77\x69\x6e\x64\x2d\x62\x79\x2d\x72\x65\x74\x75\x72\x6e\x00\x11\x17\x75\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x12\x0e\x75\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x00\x13\x14\x75\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x14\x12\x75\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x72\x65\x74\x75\x72\x6e\x00\x15\x18\x62\x69\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x16\x0f\x62\x69\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x00\x17\x15\x62\x69\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x18\x13\x62\x69\x6e\x61\x72\x79\x2d\x61\x66\x74\x65\x72\x2d\x72\x65\x74\x75\x72\x6e\x00\x19\x18\x73\x65\x6c\x65\x63\x74\x2d\x61\x66\x74\x65\x72\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x1a\x0f\x73\x65\x6c\x65\x63\x74\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x00\x1b\x15\x73\x65\x6c\x65\x63\x74\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x1c\x13\x73\x65\x6c\x65\x63\x74\x2d\x61\x66\x74\x65\x72\x2d\x72\x65\x74\x75\x72\x6e\x00\x1d\x1d\x62\x6c\x6f\x63\x6b\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x1e\x14\x62\x6c\x6f\x63\x6b\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x00\x1f\x1a\x62\x6c\x6f\x63\x6b\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x20\x18\x62\x6c\x6f\x63\x6b\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x72\x65\x74\x75\x72\x6e\x00\x21\x1c\x6c\x6f\x6f\x70\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x75\x6e\x72\x65\x61\x63\x68\x61\x62\x6c\x65\x00\x22\x13\x6c\x6f\x6f\x70\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x00\x23\x19\x6c\x6f\x6f\x70\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x62\x72\x5f\x74\x61\x62\x6c\x65\x00\x24\x17\x6c\x6f\x6f\x70\x2d\x76\x61\x6c\x75\x65\x2d\x61\x66\x74\x65\x72\x2d\x72\x65\x74\x75\x72\x6e\x00\x25\x0a\xfb\x04\x26\x07\x00\x41\x03\x42\x01\x00\x0b\x08\x00\x41\x03\x42\x01\x0c\x00\x0b\x0a\x00\x41\x03\x42\x01\x41\x09\x0c\x00\x0b\x0b\x00\x41\x03\x42\x01\x41\x00\x0e\x00\x00\x0b\x0d\x00\x41\x03\x42\x01\x41\x09\x41\x00\x0e\x00\x00\x0b\x09\x00\x41\x03\x42\x01\x41\x09\x0f\x0b\x0a\x00\x02\x40\x41\x03\x42\x01\x00\x0b\x0b\x0d\x00\x02\x40\x41\x03\x42\x01\x0c\x00\x0b\x41\x09\x0b\x0d\x00\x02\x7f\x41\x03\x42\x01\x41\x09\x0c\x00\x0b\x0b\x10\x00\x02\x40\x41\x03\x42\x01\x41\x00\x0e\x00\x00\x0b\x41\x09\x0b\x10\x00\x02\x7f\x41\x03\x42\x01\x41\x09\x41\x00\x0e\x00\x00\x0b\x0b\x0c\x00\x02\x7f\x41\x03\x42\x01\x41\x09\x0f\x0b\x0b\x0d\x00\x02\x7f\x41\x03\x02\x40\x42\x01\x00\x0b\x0b\x0b\x11\x00\x02\x40\x41\x03\x02\x40\x42\x01\x0c\x01\x0b\x1a\x0b\x41\x09\x0b\x10\x00\x02\x7f\x41\x03\x02\x40\x42\x01\x41\x09\x0c\x01\x0b\x0b\x0b\x14\x00\x02\x40\x41\x03\x02\x40\x42\x01\x41\x01\x0e\x00\x01\x0b\x1a\x0b\x41\x09\x0b\x13\x00\x02\x7f\x41\x03\x02\x40\x42\x01\x41\x09\x41\x01\x0e\x00\x01\x0b\x0b\x0b\x0f\x00\x02\x7f\x41\x03\x02\x40\x42\x01\x41\x09\x0f\x0b\x0b\x0b\x09\x00\x43\x00\x00\x00\x00\x00\x50\x0b\x0f\x00\x02\x7f\x43\x00\x00\x00\x00\x41\x09\x0c\x00\x50\x0b\x0b\x13\x00\x02\x7f\x43\x00\x00\x00\x00\x41\x09\x41\x00\x0e\x01\x00\x00\x50\x0b\x0b\x0b\x00\x43\x00\x00\x00\x00\x41\x09\x0f\x50\x0b\x12\x00\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x00\x51\x0b\x18\x00\x02\x7f\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x41\x09\x0c\x00\x51\x0b\x0b\x1b\x00\x02\x7f\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x41\x09\x41\x00\x0e\x00\x00\x51\x0b\x0b\x14\x00\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x41\x09\x0f\x51\x0b\x14\x00\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x42\x00\x00\x1b\x0b\x1a\x00\x02\x7f\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x42\x00\x41\x09\x0c\x00\x1b\x0b\x0b\x1d\x00\x02\x7f\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x42\x00\x41\x09\x41\x00\x0e\x00\x00\x1b\x0b\x0b\x16\x00\x43\x00\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\xf0\x3f\x42\x01\x41\x09\x0f\x1b\x0b\x0b\x00\x02\x7f\x43\x00\x00\x00\x00\x00\x0b\x0b\x0e\x00\x02\x7f\x43\x00\x00\x00\x00\x41\x09\x0c\x00\x0b\x0b\x12\x00\x02\x7f\x43\x00\x00\x00\x00\x41\x09\x41\x00\x0e\x01\x00\x00\x0b\x0b\x0d\x00\x02\x7f\x43\x00\x00\x00\x00\x41\x09\x0f\x0b\x0b\x0b\x00\x03\x7f\x43\x00\x00\x00\x00\x00\x0b\x0b\x11\x00\x02\x7f\x03\x7f\x43\x00\x00\x00\x00\x41\x09\x0c\x01\x0b\x0b\x0b\x15\x00\x02\x7f\x03\x7f\x43\x00\x00\x00\x00\x41\x09\x41\x00\x0e\x01\x01\x01\x0b\x0b\x0b\x0d\x00\x03\x7f\x43\x00\x00\x00\x00\x41\x09\x0f\x0b\x0b");
assert_trap(() => $$.exports["func-unwind-by-unreachable"]());
assert_return(() => $$.exports["func-unwind-by-br"]());
assert_return(() => $$.exports["func-unwind-by-br-value"](), 9);
assert_return(() => $$.exports["func-unwind-by-br_table"]());
assert_return(() => $$.exports["func-unwind-by-br_table-value"](), 9);
assert_return(() => $$.exports["func-unwind-by-return"](), 9);
assert_trap(() => $$.exports["block-unwind-by-unreachable"]());
assert_return(() => $$.exports["block-unwind-by-br"](), 9);
assert_return(() => $$.exports["block-unwind-by-br-value"](), 9);
assert_return(() => $$.exports["block-unwind-by-br_table"](), 9);
assert_return(() => $$.exports["block-unwind-by-br_table-value"](), 9);
assert_return(() => $$.exports["block-unwind-by-return"](), 9);
assert_trap(() => $$.exports["block-nested-unwind-by-unreachable"]());
assert_return(() => $$.exports["block-nested-unwind-by-br"](), 9);
assert_return(() => $$.exports["block-nested-unwind-by-br-value"](), 9);
assert_return(() => $$.exports["block-nested-unwind-by-br_table"](), 9);
assert_return(() => $$.exports["block-nested-unwind-by-br_table-value"](), 9);
assert_return(() => $$.exports["block-nested-unwind-by-return"](), 9);
assert_trap(() => $$.exports["unary-after-unreachable"]());
assert_return(() => $$.exports["unary-after-br"](), 9);
assert_return(() => $$.exports["unary-after-br_table"](), 9);
assert_return(() => $$.exports["unary-after-return"](), 9);
assert_trap(() => $$.exports["binary-after-unreachable"]());
assert_return(() => $$.exports["binary-after-br"](), 9);
assert_return(() => $$.exports["binary-after-br_table"](), 9);
assert_return(() => $$.exports["binary-after-return"](), 9);
assert_trap(() => $$.exports["select-after-unreachable"]());
assert_return(() => $$.exports["select-after-br"](), 9);
assert_return(() => $$.exports["select-after-br_table"](), 9);
assert_return(() => $$.exports["select-after-return"](), 9);
assert_trap(() => $$.exports["block-value-after-unreachable"]());
assert_return(() => $$.exports["block-value-after-br"](), 9);
assert_return(() => $$.exports["block-value-after-br_table"](), 9);
assert_return(() => $$.exports["block-value-after-return"](), 9);
assert_trap(() => $$.exports["loop-value-after-unreachable"]());
assert_return(() => $$.exports["loop-value-after-br"](), 9);
assert_return(() => $$.exports["loop-value-after-br_table"](), 9);
assert_return(() => $$.exports["loop-value-after-return"](), 9);