fune/testing/web-platform/tests/wasm/jsapi/module/constructor.any.js
Ms2ger 26bdc1fe3c Bug 1545584 [wpt PR 16326] - Merge wasm-constants.js and wasm-module-builder.js., a=testonly
Automatic update from web-platform-tests
Merge wasm-constants.js and wasm-module-builder.js.

Reviewed upstream: https://github.com/WebAssembly/spec/pull/963.

--

wpt-commits: b0af23eb48e143a53505155ae0f85ca3a1355c0f
wpt-pr: 16326
2019-06-05 10:25:58 +01:00

69 lines
1.8 KiB
JavaScript

// META: global=jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
test(() => {
assert_function_name(WebAssembly.Module, "Module", "WebAssembly.Module");
}, "name");
test(() => {
assert_function_length(WebAssembly.Module, 1, "WebAssembly.Module");
}, "length");
test(() => {
assert_throws(new TypeError(), () => new WebAssembly.Module());
}, "No arguments");
test(() => {
assert_throws(new TypeError(), () => WebAssembly.Module(emptyModuleBinary));
}, "Calling");
test(() => {
const invalidArguments = [
undefined,
null,
true,
"test",
Symbol(),
7,
NaN,
{},
ArrayBuffer,
ArrayBuffer.prototype,
Array.from(emptyModuleBinary),
];
for (const argument of invalidArguments) {
assert_throws(new TypeError(), () => new WebAssembly.Module(argument),
`new Module(${format_value(argument)})`);
}
}, "Invalid arguments");
test(() => {
const buffer = new Uint8Array();
assert_throws(new WebAssembly.CompileError(), () => new WebAssembly.Module(buffer));
}, "Empty buffer");
test(() => {
const buffer = new Uint8Array(Array.from(emptyModuleBinary).concat([0, 0]));
assert_throws(new WebAssembly.CompileError(), () => new WebAssembly.Module(buffer));
}, "Invalid code");
test(() => {
const module = new WebAssembly.Module(emptyModuleBinary);
assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype);
}, "Prototype");
test(() => {
const module = new WebAssembly.Module(emptyModuleBinary);
assert_true(Object.isExtensible(module));
}, "Extensibility");
test(() => {
const module = new WebAssembly.Module(emptyModuleBinary, {});
assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype);
}, "Stray argument");