• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,dedicatedworker,jsshell
2// META: script=/wasm/jsapi/wasm-module-builder.js
3// META: script=/wasm/jsapi/assertions.js
4
5let emptyModuleBinary;
6setup(() => {
7  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
8});
9
10test(() => {
11  assert_function_name(WebAssembly.Module, "Module", "WebAssembly.Module");
12}, "name");
13
14test(() => {
15  assert_function_length(WebAssembly.Module, 1, "WebAssembly.Module");
16}, "length");
17
18test(() => {
19  assert_throws_js(TypeError, () => new WebAssembly.Module());
20}, "No arguments");
21
22test(() => {
23  assert_throws_js(TypeError, () => WebAssembly.Module(emptyModuleBinary));
24}, "Calling");
25
26test(() => {
27  const invalidArguments = [
28    undefined,
29    null,
30    true,
31    "test",
32    Symbol(),
33    7,
34    NaN,
35    {},
36    ArrayBuffer,
37    ArrayBuffer.prototype,
38    Array.from(emptyModuleBinary),
39  ];
40  for (const argument of invalidArguments) {
41    assert_throws_js(TypeError, () => new WebAssembly.Module(argument),
42                     `new Module(${format_value(argument)})`);
43  }
44}, "Invalid arguments");
45
46test(() => {
47  const buffer = new Uint8Array();
48  assert_throws_js(WebAssembly.CompileError, () => new WebAssembly.Module(buffer));
49}, "Empty buffer");
50
51test(() => {
52  const buffer = new Uint8Array(Array.from(emptyModuleBinary).concat([0, 0]));
53  assert_throws_js(WebAssembly.CompileError, () => new WebAssembly.Module(buffer));
54}, "Invalid code");
55
56test(() => {
57  const module = new WebAssembly.Module(emptyModuleBinary);
58  assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype);
59}, "Prototype");
60
61test(() => {
62  const module = new WebAssembly.Module(emptyModuleBinary);
63  assert_true(Object.isExtensible(module));
64}, "Extensibility");
65
66test(() => {
67  const module = new WebAssembly.Module(emptyModuleBinary, {});
68  assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype);
69}, "Stray argument");
70