Skip to content

Commit e6bee70

Browse files
committed
[test] Sync with wpt.
1 parent 994ee7c commit e6bee70

12 files changed

Lines changed: 434 additions & 27 deletions

File tree

‎test/js-api/assertions.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ function assert_function_length(fn, length, description) {
1717
}
1818

1919
function assert_exported_function(fn, { name, length }, description) {
20-
assert_equals(Object.getPrototypeOf(fn), Function.prototype,
21-
`${description}: prototype`);
20+
if (WebAssembly.Function === undefined) {
21+
assert_equals(Object.getPrototypeOf(fn), Function.prototype,
22+
`${description}: prototype`);
23+
} else {
24+
assert_equals(Object.getPrototypeOf(fn), WebAssembly.Function.prototype,
25+
`${description}: prototype`);
26+
}
2227

2328
assert_function_name(fn, name, description);
2429
assert_function_length(fn, length, description);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// META: global=window,dedicatedworker,jsshell
2+
3+
"use strict";
4+
// https://heycam.github.io/webidl/#es-namespaces
5+
// https://webassembly.github.io/spec/js-api/#namespacedef-webassembly
6+
7+
test(() => {
8+
assert_own_property(WebAssembly, Symbol.toStringTag);
9+
10+
const propDesc = Object.getOwnPropertyDescriptor(WebAssembly, Symbol.toStringTag);
11+
assert_equals(propDesc.value, "WebAssembly", "value");
12+
assert_equals(propDesc.writable, false, "writable");
13+
assert_equals(propDesc.enumerable, false, "enumerable");
14+
assert_equals(propDesc.configurable, true, "configurable");
15+
}, "@@toStringTag exists on the namespace object with the appropriate descriptor");
16+
17+
test(() => {
18+
assert_equals(WebAssembly.toString(), "[object WebAssembly]");
19+
assert_equals(Object.prototype.toString.call(WebAssembly), "[object WebAssembly]");
20+
}, "Object.prototype.toString applied to the namespace object");
21+
22+
test(t => {
23+
assert_own_property(WebAssembly, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
24+
t.add_cleanup(() => {
25+
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "WebAssembly" });
26+
});
27+
28+
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "Test" });
29+
assert_equals(WebAssembly.toString(), "[object Test]");
30+
assert_equals(Object.prototype.toString.call(WebAssembly), "[object Test]");
31+
}, "Object.prototype.toString applied after modifying the namespace object's @@toStringTag");
32+
33+
test(t => {
34+
assert_own_property(WebAssembly, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
35+
t.add_cleanup(() => {
36+
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "WebAssembly" });
37+
});
38+
39+
assert_true(delete WebAssembly[Symbol.toStringTag]);
40+
assert_equals(WebAssembly.toString(), "[object Object]");
41+
assert_equals(Object.prototype.toString.call(WebAssembly), "[object Object]");
42+
}, "Object.prototype.toString applied after deleting @@toStringTag");

‎test/js-api/functions/helper.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function call_later(f) {
2+
const builder = new WasmModuleBuilder();
3+
const functionIndex = builder.addImport("module", "imported", kSig_v_v);
4+
builder.addStart(functionIndex);
5+
const buffer = builder.toBuffer();
6+
7+
WebAssembly.instantiate(buffer, {
8+
"module": {
9+
"imported": f,
10+
}
11+
});
12+
}

‎test/js-api/instanceTestFactory.js‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,134 @@ const instanceTestFactory = [
126126
}
127127
],
128128

129+
[
130+
"imports with empty module names",
131+
function() {
132+
const builder = new WasmModuleBuilder();
133+
134+
builder.addImport("", "fn", kSig_v_v);
135+
builder.addImportedGlobal("", "global", kWasmI32);
136+
builder.addImportedMemory("", "memory", 0, 128);
137+
builder.addImportedTable("", "table", 0, 128);
138+
139+
const buffer = builder.toBuffer();
140+
const imports = {
141+
"": {
142+
"fn": function() {},
143+
"global": 0,
144+
"memory": new WebAssembly.Memory({ "initial": 64, maximum: 128 }),
145+
"table": new WebAssembly.Table({ "element": "anyfunc", "initial": 64, maximum: 128 }),
146+
},
147+
};
148+
149+
return {
150+
buffer,
151+
args: [imports],
152+
exports: {},
153+
verify: () => {},
154+
};
155+
}
156+
],
157+
158+
[
159+
"imports with empty names",
160+
function() {
161+
const builder = new WasmModuleBuilder();
162+
163+
builder.addImport("a", "", kSig_v_v);
164+
builder.addImportedGlobal("b", "", kWasmI32);
165+
builder.addImportedMemory("c", "", 0, 128);
166+
builder.addImportedTable("d", "", 0, 128);
167+
168+
const buffer = builder.toBuffer();
169+
const imports = {
170+
"a": { "": function() {} },
171+
"b": { "": 0 },
172+
"c": { "": new WebAssembly.Memory({ "initial": 64, maximum: 128 }) },
173+
"d": { "": new WebAssembly.Table({ "element": "anyfunc", "initial": 64, maximum: 128 }) },
174+
};
175+
176+
return {
177+
buffer,
178+
args: [imports],
179+
exports: {},
180+
verify: () => {},
181+
};
182+
}
183+
],
184+
185+
[
186+
"exports with empty name: function",
187+
function() {
188+
const builder = new WasmModuleBuilder();
189+
190+
builder
191+
.addFunction("", kSig_v_d)
192+
.addBody([])
193+
.exportFunc();
194+
195+
const buffer = builder.toBuffer();
196+
197+
const exports = {
198+
"": { "kind": "function", "name": "0", "length": 1 },
199+
};
200+
201+
return {
202+
buffer,
203+
args: [],
204+
exports,
205+
verify: () => {},
206+
};
207+
}
208+
],
209+
210+
[
211+
"exports with empty name: table",
212+
function() {
213+
const builder = new WasmModuleBuilder();
214+
215+
builder.setTableBounds(1);
216+
builder.addExportOfKind("", kExternalTable, 0);
217+
218+
const buffer = builder.toBuffer();
219+
220+
const exports = {
221+
"": { "kind": "table", "length": 1 },
222+
};
223+
224+
return {
225+
buffer,
226+
args: [],
227+
exports,
228+
verify: () => {},
229+
};
230+
}
231+
],
232+
233+
[
234+
"exports with empty name: global",
235+
function() {
236+
const builder = new WasmModuleBuilder();
237+
238+
builder.addGlobal(kWasmI32, true)
239+
.exportAs("")
240+
.init = 7;
241+
242+
const buffer = builder.toBuffer();
243+
244+
const exports = {
245+
"": { "kind": "global", "value": 7 },
246+
};
247+
248+
return {
249+
buffer,
250+
args: [],
251+
exports,
252+
verify: () => {},
253+
};
254+
}
255+
],
256+
129257
[
130258
"No imports",
131259
function() {

‎test/js-api/memory/constructor.any.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ test(() => {
7272
assert_unreached(`Should not call [[HasProperty]] with ${x}`);
7373
},
7474
get(o, x) {
75-
return 0;
75+
// Due to the requirement not to supply both minimum and initial, we need to ignore one of them.
76+
switch (x) {
77+
case "shared":
78+
return false;
79+
case "initial":
80+
case "maximum":
81+
return 0;
82+
default:
83+
return undefined;
84+
}
7685
},
7786
});
7887
new WebAssembly.Memory(proxy);

‎test/js-api/module/exports.any.js‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ test(() => {
7575
}
7676
}, "Branding");
7777

78+
test(() => {
79+
const module = new WebAssembly.Module(emptyModuleBinary);
80+
const exports = WebAssembly.Module.exports(module);
81+
assert_true(Array.isArray(exports));
82+
}, "Return type");
83+
7884
test(() => {
7985
const module = new WebAssembly.Module(emptyModuleBinary);
8086
const exports = WebAssembly.Module.exports(module);
@@ -124,6 +130,54 @@ test(() => {
124130
assert_exports(exports, expected);
125131
}, "exports");
126132

133+
test(() => {
134+
const builder = new WasmModuleBuilder();
135+
136+
builder
137+
.addFunction("", kSig_v_v)
138+
.addBody([])
139+
.exportFunc();
140+
141+
const buffer = builder.toBuffer()
142+
const module = new WebAssembly.Module(buffer);
143+
const exports = WebAssembly.Module.exports(module);
144+
const expected = [
145+
{ "kind": "function", "name": "" },
146+
];
147+
assert_exports(exports, expected);
148+
}, "exports with empty name: function");
149+
150+
test(() => {
151+
const builder = new WasmModuleBuilder();
152+
153+
builder.setTableBounds(1);
154+
builder.addExportOfKind("", kExternalTable, 0);
155+
156+
const buffer = builder.toBuffer()
157+
const module = new WebAssembly.Module(buffer);
158+
const exports = WebAssembly.Module.exports(module);
159+
const expected = [
160+
{ "kind": "table", "name": "" },
161+
];
162+
assert_exports(exports, expected);
163+
}, "exports with empty name: table");
164+
165+
test(() => {
166+
const builder = new WasmModuleBuilder();
167+
168+
builder.addGlobal(kWasmI32, true)
169+
.exportAs("")
170+
.init = 7;
171+
172+
const buffer = builder.toBuffer()
173+
const module = new WebAssembly.Module(buffer);
174+
const exports = WebAssembly.Module.exports(module);
175+
const expected = [
176+
{ "kind": "global", "name": "" },
177+
];
178+
assert_exports(exports, expected);
179+
}, "exports with empty name: global");
180+
127181
test(() => {
128182
const module = new WebAssembly.Module(emptyModuleBinary);
129183
const exports = WebAssembly.Module.exports(module, {});

‎test/js-api/module/imports.any.js‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,66 @@ test(() => {
118118
assert_imports(imports, expected);
119119
}, "imports");
120120

121+
test(() => {
122+
const builder = new WasmModuleBuilder();
123+
124+
builder.addImport("", "fn", kSig_v_v);
125+
builder.addImportedGlobal("", "global", kWasmI32);
126+
builder.addImportedMemory("", "memory", 0, 128);
127+
builder.addImportedTable("", "table", 0, 128);
128+
129+
const buffer = builder.toBuffer()
130+
const module = new WebAssembly.Module(buffer);
131+
const imports = WebAssembly.Module.imports(module);
132+
const expected = [
133+
{ "module": "", "kind": "function", "name": "fn" },
134+
{ "module": "", "kind": "global", "name": "global" },
135+
{ "module": "", "kind": "memory", "name": "memory" },
136+
{ "module": "", "kind": "table", "name": "table" },
137+
];
138+
assert_imports(imports, expected);
139+
}, "imports with empty module name");
140+
141+
test(() => {
142+
const builder = new WasmModuleBuilder();
143+
144+
builder.addImport("a", "", kSig_v_v);
145+
builder.addImportedGlobal("b", "", kWasmI32);
146+
builder.addImportedMemory("c", "", 0, 128);
147+
builder.addImportedTable("d", "", 0, 128);
148+
149+
const buffer = builder.toBuffer()
150+
const module = new WebAssembly.Module(buffer);
151+
const imports = WebAssembly.Module.imports(module);
152+
const expected = [
153+
{ "module": "a", "kind": "function", "name": "" },
154+
{ "module": "b", "kind": "global", "name": "" },
155+
{ "module": "c", "kind": "memory", "name": "" },
156+
{ "module": "d", "kind": "table", "name": "" },
157+
];
158+
assert_imports(imports, expected);
159+
}, "imports with empty names");
160+
161+
test(() => {
162+
const builder = new WasmModuleBuilder();
163+
164+
builder.addImport("", "", kSig_v_v);
165+
builder.addImportedGlobal("", "", kWasmI32);
166+
builder.addImportedMemory("", "", 0, 128);
167+
builder.addImportedTable("", "", 0, 128);
168+
169+
const buffer = builder.toBuffer()
170+
const module = new WebAssembly.Module(buffer);
171+
const imports = WebAssembly.Module.imports(module);
172+
const expected = [
173+
{ "module": "", "kind": "function", "name": "" },
174+
{ "module": "", "kind": "global", "name": "" },
175+
{ "module": "", "kind": "memory", "name": "" },
176+
{ "module": "", "kind": "table", "name": "" },
177+
];
178+
assert_imports(imports, expected);
179+
}, "imports with empty module names and names");
180+
121181
test(() => {
122182
const module = new WebAssembly.Module(emptyModuleBinary);
123183
const imports = WebAssembly.Module.imports(module, {});

‎test/js-api/table/assertions.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ function assert_equal_to_array(table, expected, message) {
1111
assert_throws_js(RangeError, () => table.get(expected.length + 1),
1212
`${message}: table.get(${expected.length + 1} of ${expected.length})`);
1313
}
14+
15+
function assert_Table(actual, expected) {
16+
assert_equals(Object.getPrototypeOf(actual), WebAssembly.Table.prototype,
17+
"prototype");
18+
assert_true(Object.isExtensible(actual), "extensible");
19+
20+
assert_equals(actual.length, expected.length, "length");
21+
for (let i = 0; i < expected.length; ++i) {
22+
assert_equals(actual.get(i), null, `actual.get(${i})`);
23+
}
24+
}

0 commit comments

Comments
 (0)