summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/wasm/jsapi/gc/exported-object.tentative.any.js
blob: b572f140067fda658eb18ab82c880b3697172aba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// META: global=window,dedicatedworker,jsshell
// META: script=/wasm/jsapi/wasm-module-builder.js

let functions = {};
setup(() => {
  const builder = new WasmModuleBuilder();

  const structIndex = builder.addStruct([makeField(kWasmI32, true)]);
  const arrayIndex = builder.addArray(kWasmI32, true);
  const structRef = wasmRefType(structIndex);
  const arrayRef = wasmRefType(arrayIndex);

  builder
    .addFunction("makeStruct", makeSig_r_v(structRef))
    .addBody([...wasmI32Const(42),
              ...GCInstr(kExprStructNew), structIndex])
    .exportFunc();

  builder
    .addFunction("makeArray", makeSig_r_v(arrayRef))
    .addBody([...wasmI32Const(5), ...wasmI32Const(42),
              ...GCInstr(kExprArrayNew), arrayIndex])
    .exportFunc();

  const buffer = builder.toBuffer();
  const module = new WebAssembly.Module(buffer);
  const instance = new WebAssembly.Instance(module, {});
  functions = instance.exports;
});

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_equals(struct.foo, undefined);
  assert_equals(struct[0], undefined);
  assert_equals(array.foo, undefined);
  assert_equals(array[0], undefined);
}, "property access");

test(() => {
  "use strict";
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => { struct.foo = 5; });
  assert_throws_js(TypeError, () => { array.foo = 5; });
  assert_throws_js(TypeError, () => { struct[0] = 5; });
  assert_throws_js(TypeError, () => { array[0] = 5; });
}, "property assignment (strict mode)");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => { struct.foo = 5; });
  assert_throws_js(TypeError, () => { array.foo = 5; });
  assert_throws_js(TypeError, () => { struct[0] = 5; });
  assert_throws_js(TypeError, () => { array[0] = 5; });
}, "property assignment (non-strict mode)");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_equals(Object.getOwnPropertyNames(struct).length, 0);
  assert_equals(Object.getOwnPropertyNames(array).length, 0);
}, "ownPropertyNames");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => Object.defineProperty(struct, "foo", { value: 1 }));
  assert_throws_js(TypeError, () => Object.defineProperty(array, "foo", { value: 1 }));
}, "defineProperty");

test(() => {
  "use strict";
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => delete struct.foo);
  assert_throws_js(TypeError, () => delete struct[0]);
  assert_throws_js(TypeError, () => delete array.foo);
  assert_throws_js(TypeError, () => delete array[0]);
}, "delete (strict mode)");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => delete struct.foo);
  assert_throws_js(TypeError, () => delete struct[0]);
  assert_throws_js(TypeError, () => delete array.foo);
  assert_throws_js(TypeError, () => delete array[0]);
}, "delete (non-strict mode)");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_equals(Object.getPrototypeOf(struct), null);
  assert_equals(Object.getPrototypeOf(array), null);
}, "getPrototypeOf");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => Object.setPrototypeOf(struct, {}));
  assert_throws_js(TypeError, () => Object.setPrototypeOf(array, {}));
}, "setPrototypeOf");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_false(Object.isExtensible(struct));
  assert_false(Object.isExtensible(array));
}, "isExtensible");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => Object.preventExtensions(struct));
  assert_throws_js(TypeError, () => Object.preventExtensions(array));
}, "preventExtensions");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => Object.seal(struct));
  assert_throws_js(TypeError, () => Object.seal(array));
}, "sealing");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_equals(typeof struct, "object");
  assert_equals(typeof array, "object");
}, "typeof");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => struct.toString());
  assert_equals(Object.prototype.toString.call(struct), "[object Object]");
  assert_throws_js(TypeError, () => array.toString());
  assert_equals(Object.prototype.toString.call(array), "[object Object]");
}, "toString");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  assert_throws_js(TypeError, () => struct.valueOf());
  assert_equals(Object.prototype.valueOf.call(struct), struct);
  assert_throws_js(TypeError, () => array.valueOf());
  assert_equals(Object.prototype.valueOf.call(array), array);
}, "valueOf");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  const map = new Map();
  map.set(struct, "struct");
  map.set(array, "array");
  assert_equals(map.get(struct), "struct");
  assert_equals(map.get(array), "array");
}, "GC objects as map keys");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  const set = new Set();
  set.add(struct);
  set.add(array);
  assert_true(set.has(struct));
  assert_true(set.has(array));
}, "GC objects as set element");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  const map = new WeakMap();
  map.set(struct, "struct");
  map.set(array, "array");
  assert_equals(map.get(struct), "struct");
  assert_equals(map.get(array), "array");
}, "GC objects as weak map keys");

test(() => {
  const struct = functions.makeStruct();
  const array = functions.makeArray();
  const set = new WeakSet();
  set.add(struct);
  set.add(array);
  assert_true(set.has(struct));
  assert_true(set.has(array));
}, "GC objects as weak set element");