• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,dedicatedworker,jsshell
2// META: script=/wasm/jsapi/wasm-module-builder.js
3
4let emptyModuleBinary;
5setup(() => {
6  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
7});
8
9test(() => {
10  const thisValues = [
11    undefined,
12    null,
13    true,
14    "",
15    Symbol(),
16    1,
17    {},
18    WebAssembly.Instance,
19    WebAssembly.Instance.prototype,
20  ];
21
22  const desc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports");
23  assert_equals(typeof desc, "object");
24
25  const getter = desc.get;
26  assert_equals(typeof getter, "function");
27
28  assert_equals(typeof desc.set, "undefined");
29
30  for (const thisValue of thisValues) {
31    assert_throws_js(TypeError, () => getter.call(thisValue), `this=${format_value(thisValue)}`);
32  }
33}, "Branding");
34
35test(() => {
36  const module = new WebAssembly.Module(emptyModuleBinary);
37  const instance = new WebAssembly.Instance(module);
38  const exports = instance.exports;
39
40  const desc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports");
41  assert_equals(typeof desc, "object");
42
43  const getter = desc.get;
44  assert_equals(typeof getter, "function");
45
46  assert_equals(getter.call(instance, {}), exports);
47}, "Stray argument");
48
49test(() => {
50  const module = new WebAssembly.Module(emptyModuleBinary);
51  const instance = new WebAssembly.Instance(module);
52  const exports = instance.exports;
53  instance.exports = {};
54  assert_equals(instance.exports, exports, "Should not change the exports");
55}, "Setting (sloppy mode)");
56
57test(() => {
58  const module = new WebAssembly.Module(emptyModuleBinary);
59  const instance = new WebAssembly.Instance(module);
60  const exports = instance.exports;
61  assert_throws_js(TypeError, () => {
62    "use strict";
63    instance.exports = {};
64  });
65  assert_equals(instance.exports, exports, "Should not change the exports");
66}, "Setting (strict mode)");
67