3c7bc08aec
These are added as mjsunit tests for now since they haven't been merged to the spec repo. When that happens, the wasm-spec-tests testsuite can be updated to include these tests, and the tests in this directory can be removed. This CL also adds the test/mjsunit/wasm/bulk-memory-spec directory to a list of directories that aren't checked for copyright (since these files are auto-generated). Bug: v8:7747 Change-Id: I906f2ca45f497a6728f94afb9b3330971e1d3fd5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1600363 Commit-Queue: Ben Smith <binji@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org> Cr-Commit-Position: refs/heads/master@{#61395}
171 lines
8.2 KiB
JavaScript
171 lines
8.2 KiB
JavaScript
|
|
'use strict';
|
|
|
|
let spectest = {
|
|
print: console.log.bind(console),
|
|
print_i32: console.log.bind(console),
|
|
print_i32_f32: console.log.bind(console),
|
|
print_f64_f64: console.log.bind(console),
|
|
print_f32: console.log.bind(console),
|
|
print_f64: console.log.bind(console),
|
|
global_i32: 666,
|
|
global_f32: 666,
|
|
global_f64: 666,
|
|
table: new WebAssembly.Table({initial: 10, maximum: 20, element: 'anyfunc'}),
|
|
memory: new WebAssembly.Memory({initial: 1, maximum: 2})
|
|
};
|
|
let handler = {
|
|
get(target, prop) {
|
|
return (prop in target) ? target[prop] : {};
|
|
}
|
|
};
|
|
let registry = new Proxy({spectest}, handler);
|
|
|
|
function register(name, instance) {
|
|
registry[name] = instance.exports;
|
|
}
|
|
|
|
function module(bytes, valid = true) {
|
|
let buffer = new ArrayBuffer(bytes.length);
|
|
let view = new Uint8Array(buffer);
|
|
for (let i = 0; i < bytes.length; ++i) {
|
|
view[i] = bytes.charCodeAt(i);
|
|
}
|
|
let validated;
|
|
try {
|
|
validated = WebAssembly.validate(buffer);
|
|
} catch (e) {
|
|
throw new Error("Wasm validate throws");
|
|
}
|
|
if (validated !== valid) {
|
|
throw new Error("Wasm validate failure" + (valid ? "" : " expected"));
|
|
}
|
|
return new WebAssembly.Module(buffer);
|
|
}
|
|
|
|
function instance(bytes, imports = registry) {
|
|
return new WebAssembly.Instance(module(bytes), imports);
|
|
}
|
|
|
|
function call(instance, name, args) {
|
|
return instance.exports[name](...args);
|
|
}
|
|
|
|
function get(instance, name) {
|
|
let v = instance.exports[name];
|
|
return (v instanceof WebAssembly.Global) ? v.value : v;
|
|
}
|
|
|
|
function exports(name, instance) {
|
|
return {[name]: instance.exports};
|
|
}
|
|
|
|
function run(action) {
|
|
action();
|
|
}
|
|
|
|
function assert_malformed(bytes) {
|
|
try { module(bytes, false) } catch (e) {
|
|
if (e instanceof WebAssembly.CompileError) return;
|
|
}
|
|
throw new Error("Wasm decoding failure expected");
|
|
}
|
|
|
|
function assert_invalid(bytes) {
|
|
try { module(bytes, false) } catch (e) {
|
|
if (e instanceof WebAssembly.CompileError) return;
|
|
}
|
|
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 WebAssembly.LinkError) 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");
|
|
}
|
|
|
|
let StackOverflow;
|
|
try { (function f() { 1 + f() })() } catch (e) { StackOverflow = e.constructor }
|
|
|
|
function assert_exhaustion(action) {
|
|
try { action() } catch (e) {
|
|
if (e instanceof StackOverflow) return;
|
|
}
|
|
throw new Error("Wasm resource exhaustion 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_canonical_nan(action) {
|
|
let actual = action();
|
|
// Note that JS can't reliably distinguish different NaN values,
|
|
// so there's no good way to test that it's a canonical NaN.
|
|
if (!Number.isNaN(actual)) {
|
|
throw new Error("Wasm return value NaN expected, got " + actual);
|
|
};
|
|
}
|
|
|
|
function assert_return_arithmetic_nan(action) {
|
|
// Note that JS can't reliably distinguish different NaN values,
|
|
// so there's no good way to test for specific bitpatterns here.
|
|
let actual = action();
|
|
if (!Number.isNaN(actual)) {
|
|
throw new Error("Wasm return value NaN expected, got " + actual);
|
|
};
|
|
}
|
|
|
|
// custom.wast:1
|
|
let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x00\x24\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x6e\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64\x00\x20\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x6e\x74\x68\x69\x73\x20\x69\x73\x20\x70\x61\x79\x6c\x6f\x61\x64\x00\x11\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x6e\x00\x10\x00\x74\x68\x69\x73\x20\x69\x73\x20\x70\x61\x79\x6c\x6f\x61\x64\x00\x01\x00\x00\x24\x10\x00\x00\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x00\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64\x00\x24\x10\xef\xbb\xbf\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64\x00\x24\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\xe2\x8c\xa3\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64\x00\x1f\x16\x6d\x6f\x64\x75\x6c\x65\x20\x77\x69\x74\x68\x69\x6e\x20\x61\x20\x6d\x6f\x64\x75\x6c\x65\x00\x61\x73\x6d\x01\x00\x00\x00");
|
|
|
|
// custom.wast:14
|
|
let $2 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x01\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x02\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x03\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x04\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x05\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x06\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x07\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x09\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x0a\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x0b\x01\x00\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64\x00\x0e\x06\x63\x75\x73\x74\x6f\x6d\x70\x61\x79\x6c\x6f\x61\x64");
|
|
|
|
// custom.wast:50
|
|
let $3 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x07\x01\x60\x02\x7f\x7f\x01\x7f\x00\x1a\x06\x63\x75\x73\x74\x6f\x6d\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64\x03\x02\x01\x00\x07\x0a\x01\x06\x61\x64\x64\x54\x77\x6f\x00\x00\x0a\x09\x01\x07\x00\x20\x00\x20\x01\x6a\x0b\x00\x1b\x07\x63\x75\x73\x74\x6f\x6d\x32\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64");
|
|
|
|
// custom.wast:60
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x00");
|
|
|
|
// custom.wast:68
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x00\x00");
|
|
|
|
// custom.wast:76
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x00\x00\x00\x05\x01\x00\x07\x00\x00");
|
|
|
|
// custom.wast:84
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x00\x26\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x6e\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64");
|
|
|
|
// custom.wast:92
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x00\x25\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x6e\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64\x00\x24\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x6e\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64");
|
|
|
|
// custom.wast:101
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x07\x01\x60\x02\x7f\x7f\x01\x7f\x00\x25\x10\x61\x20\x63\x75\x73\x74\x6f\x6d\x20\x73\x65\x63\x74\x69\x6f\x6e\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64\x03\x02\x01\x00\x0a\x09\x01\x07\x00\x20\x00\x20\x01\x6a\x0b\x00\x1b\x07\x63\x75\x73\x74\x6f\x6d\x32\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x70\x61\x79\x6c\x6f\x61\x64");
|
|
|
|
// custom.wast:114
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x00\x61\x73\x6d\x01\x00\x00\x00");
|
|
|
|
// custom.wast:122
|
|
assert_malformed("\x00\x61\x73\x6d\x01\x00\x00\x00\x05\x03\x01\x00\x01\x0c\x01\x02\x0b\x06\x01\x00\x41\x00\x0b\x00");
|