mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Update web-platform-tests to revision 3d117ae1266e6bd039a3a1ab92b27e82c3ccc92d
This commit is contained in:
parent
647796ede6
commit
20a08918d9
132 changed files with 3012 additions and 689 deletions
|
@ -2,6 +2,7 @@
|
|||
// META: script=/wasm/jsapi/wasm-constants.js
|
||||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
// META: script=/wasm/jsapi/assertions.js
|
||||
// META: script=/wasm/jsapi/instanceTestFactory.js
|
||||
|
||||
function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) {
|
||||
assert_equals(Object.getPrototypeOf(actual), Object.prototype,
|
||||
|
@ -77,111 +78,25 @@ test(() => {
|
|||
assert_true(Object.isExtensible(promise), "extensibility");
|
||||
}, "Promise type");
|
||||
|
||||
const createModule = () => {
|
||||
const builder = new WasmModuleBuilder();
|
||||
for (const [name, fn] of instanceTestFactory) {
|
||||
promise_test(() => {
|
||||
const { buffer, args, exports, verify } = fn();
|
||||
return WebAssembly.instantiate(buffer, ...args).then(result => {
|
||||
assert_WebAssemblyInstantiatedSource(result, exports);
|
||||
verify(result.instance);
|
||||
});
|
||||
}, `${name}: BufferSource argument`);
|
||||
|
||||
builder
|
||||
.addFunction("fn", kSig_v_d)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
builder
|
||||
.addFunction("fn2", kSig_v_v)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
|
||||
builder.setFunctionTableLength(1);
|
||||
builder.addExportOfKind("table", kExternalTable, 0);
|
||||
|
||||
builder.addGlobal(kWasmI32, true)
|
||||
.exportAs("global")
|
||||
.init = 7;
|
||||
builder.addGlobal(kWasmF64, true)
|
||||
.exportAs("global2")
|
||||
.init = 1.2;
|
||||
|
||||
builder.addMemory(4, 8, true);
|
||||
|
||||
const buffer = builder.toBuffer();
|
||||
|
||||
const exports = {
|
||||
"fn": { "kind": "function", "name": "0", "length": 1 },
|
||||
"fn2": { "kind": "function", "name": "1", "length": 0 },
|
||||
"table": { "kind": "table", "length": 1 },
|
||||
"global": { "kind": "global", "value": 7 },
|
||||
"global2": { "kind": "global", "value": 1.2 },
|
||||
"memory": { "kind": "memory", "size": 4 },
|
||||
};
|
||||
|
||||
return [buffer, exports];
|
||||
promise_test(() => {
|
||||
const { buffer, args, exports, verify } = fn();
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
return WebAssembly.instantiate(module, ...args).then(instance => {
|
||||
assert_Instance(instance, exports);
|
||||
verify(instance);
|
||||
});
|
||||
}, `${name}: Module argument`);
|
||||
}
|
||||
|
||||
promise_test(() => {
|
||||
const [buffer, expected] = createModule();
|
||||
return WebAssembly.instantiate(buffer).then(result => assert_WebAssemblyInstantiatedSource(result, expected));
|
||||
}, "BufferSource argument");
|
||||
|
||||
promise_test(() => {
|
||||
const [buffer, expected] = createModule();
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
return WebAssembly.instantiate(module).then(instance => assert_Instance(instance, expected));
|
||||
}, "Module argument");
|
||||
|
||||
const createModuleWithImports = () => {
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
const index = builder.addImportedGlobal("module", "global", kWasmI32);
|
||||
builder
|
||||
.addFunction("fn", kSig_i_v)
|
||||
.addBody([
|
||||
kExprGetGlobal,
|
||||
index,
|
||||
kExprReturn,
|
||||
kExprEnd,
|
||||
])
|
||||
.exportFunc();
|
||||
|
||||
const buffer = builder.toBuffer();
|
||||
|
||||
const expected = {
|
||||
"fn": { "kind": "function", "name": "0", "length": 0 },
|
||||
};
|
||||
|
||||
return [buffer, expected];
|
||||
};
|
||||
|
||||
promise_test(() => {
|
||||
const [buffer, expected] = createModuleWithImports();
|
||||
|
||||
const value = 102;
|
||||
return WebAssembly.instantiate(buffer, {
|
||||
"module": {
|
||||
"global": value,
|
||||
},
|
||||
}).then(result => {
|
||||
assert_WebAssemblyInstantiatedSource(result, expected)
|
||||
assert_equals(result.instance.exports.fn(), value);
|
||||
});
|
||||
}, "exports and imports: buffer argument");
|
||||
|
||||
promise_test(() => {
|
||||
const [buffer, expected] = createModuleWithImports();
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
|
||||
const value = 102;
|
||||
return WebAssembly.instantiate(module, {
|
||||
"module": {
|
||||
"global": value,
|
||||
},
|
||||
}).then(instance => {
|
||||
assert_Instance(instance, expected)
|
||||
assert_equals(instance.exports.fn(), value);
|
||||
});
|
||||
}, "exports and imports: Module argument");
|
||||
|
||||
promise_test(t => {
|
||||
const buffer = new Uint8Array();
|
||||
return promise_rejects(t, new WebAssembly.CompileError(), WebAssembly.instantiate(buffer));
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// META: script=/wasm/jsapi/wasm-constants.js
|
||||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
// META: script=/wasm/jsapi/assertions.js
|
||||
// META: script=/wasm/jsapi/instanceTestFactory.js
|
||||
|
||||
let emptyModuleBinary;
|
||||
setup(() => {
|
||||
|
@ -38,184 +39,17 @@ test(() => {
|
|||
}
|
||||
}, "Non-Module arguments");
|
||||
|
||||
test(() => {
|
||||
const module = new WebAssembly.Module(emptyModuleBinary);
|
||||
const invalidArguments = [
|
||||
null,
|
||||
true,
|
||||
"",
|
||||
Symbol(),
|
||||
1,
|
||||
];
|
||||
for (const argument of invalidArguments) {
|
||||
assert_throws(new TypeError(), () => new WebAssembly.Instance(module, argument),
|
||||
`new Instance(module, ${format_value(argument)})`);
|
||||
}
|
||||
}, "Non-object imports");
|
||||
|
||||
test(() => {
|
||||
const module = new WebAssembly.Module(emptyModuleBinary);
|
||||
assert_throws(new TypeError(), () => WebAssembly.Instance(module));
|
||||
}, "Calling");
|
||||
|
||||
test(() => {
|
||||
const module = new WebAssembly.Module(emptyModuleBinary);
|
||||
const arguments = [
|
||||
[],
|
||||
[undefined],
|
||||
[{}],
|
||||
];
|
||||
for (const value of arguments) {
|
||||
const instance = new WebAssembly.Instance(module, ...arguments);
|
||||
assert_Instance(instance, {});
|
||||
}
|
||||
}, "Empty module");
|
||||
|
||||
test(() => {
|
||||
const builder = new WasmModuleBuilder();
|
||||
builder.addImportedGlobal("module", "global1", kWasmI32);
|
||||
builder.addImportedGlobal("module2", "global3", kWasmI32);
|
||||
builder.addImportedMemory("module", "memory", 0, 128);
|
||||
builder.addImportedGlobal("module", "global2", kWasmI32);
|
||||
const buffer = builder.toBuffer();
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
const order = [];
|
||||
const imports = {
|
||||
get module() {
|
||||
order.push("module getter");
|
||||
return {
|
||||
get global1() {
|
||||
order.push("global1 getter");
|
||||
return 0;
|
||||
},
|
||||
get global2() {
|
||||
order.push("global2 getter");
|
||||
return 0;
|
||||
},
|
||||
get memory() {
|
||||
order.push("memory getter");
|
||||
return new WebAssembly.Memory({ "initial": 64, maximum: 128 });
|
||||
},
|
||||
}
|
||||
},
|
||||
get module2() {
|
||||
order.push("module2 getter");
|
||||
return {
|
||||
get global3() {
|
||||
order.push("global3 getter");
|
||||
return 0;
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
new WebAssembly.Instance(module, imports);
|
||||
const expected = [
|
||||
"module getter",
|
||||
"global1 getter",
|
||||
"module2 getter",
|
||||
"global3 getter",
|
||||
"module getter",
|
||||
"memory getter",
|
||||
"module getter",
|
||||
"global2 getter",
|
||||
];
|
||||
assert_array_equals(order, expected);
|
||||
}, "getter order for imports object");
|
||||
|
||||
test(() => {
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
builder.addImport("module", "fn", kSig_v_v);
|
||||
builder.addImportedGlobal("module", "global", kWasmI32);
|
||||
builder.addImportedMemory("module", "memory", 0, 128);
|
||||
builder.addImportedTable("module", "table", 0, 128);
|
||||
|
||||
const buffer = builder.toBuffer();
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
const instance = new WebAssembly.Instance(module, {
|
||||
"module": {
|
||||
"fn": function() {},
|
||||
"global": 0,
|
||||
"memory": new WebAssembly.Memory({ "initial": 64, maximum: 128 }),
|
||||
"table": new WebAssembly.Table({ "element": "anyfunc", "initial": 64, maximum: 128 }),
|
||||
},
|
||||
get "module2"() {
|
||||
assert_unreached("Should not get modules that are not imported");
|
||||
},
|
||||
});
|
||||
assert_Instance(instance, {});
|
||||
}, "imports");
|
||||
|
||||
test(() => {
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
builder
|
||||
.addFunction("fn", kSig_v_d)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
builder
|
||||
.addFunction("fn2", kSig_v_v)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
|
||||
builder.setFunctionTableLength(1);
|
||||
builder.addExportOfKind("table", kExternalTable, 0);
|
||||
|
||||
builder.addGlobal(kWasmI32, true)
|
||||
.exportAs("global")
|
||||
.init = 7;
|
||||
builder.addGlobal(kWasmF64, true)
|
||||
.exportAs("global2")
|
||||
.init = 1.2;
|
||||
|
||||
builder.addMemory(4, 8, true);
|
||||
|
||||
const buffer = builder.toBuffer()
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
|
||||
const instance = new WebAssembly.Instance(module, {});
|
||||
const expected = {
|
||||
"fn": { "kind": "function", "name": "0", "length": 1 },
|
||||
"fn2": { "kind": "function", "name": "1", "length": 0 },
|
||||
"table": { "kind": "table", "length": 1 },
|
||||
"global": { "kind": "global", "value": 7 },
|
||||
"global2": { "kind": "global", "value": 1.2 },
|
||||
"memory": { "kind": "memory", "size": 4 },
|
||||
};
|
||||
assert_Instance(instance, expected);
|
||||
}, "exports");
|
||||
|
||||
test(() => {
|
||||
const value = 102;
|
||||
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
builder.addImportedGlobal("module", "global", kWasmI32);
|
||||
builder
|
||||
.addFunction("fn", kSig_i_v)
|
||||
.addBody([
|
||||
kExprGetGlobal,
|
||||
0,
|
||||
kExprReturn,
|
||||
kExprEnd,
|
||||
])
|
||||
.exportFunc();
|
||||
|
||||
const buffer = builder.toBuffer();
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
const instance = new WebAssembly.Instance(module, {
|
||||
"module": {
|
||||
"global": value,
|
||||
},
|
||||
});
|
||||
const expected = {
|
||||
"fn": { "kind": "function", "name": "0", "length": 0 },
|
||||
};
|
||||
assert_Instance(instance, expected);
|
||||
|
||||
assert_equals(instance.exports.fn(), value);
|
||||
}, "exports and imports");
|
||||
for (const [name, fn] of instanceTestFactory) {
|
||||
test(() => {
|
||||
const { buffer, args, exports, verify } = fn();
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
const instance = new WebAssembly.Instance(module, ...args);
|
||||
assert_Instance(instance, exports);
|
||||
verify(instance);
|
||||
}, name);
|
||||
}
|
||||
|
|
217
tests/wpt/web-platform-tests/wasm/jsapi/instanceTestFactory.js
Normal file
217
tests/wpt/web-platform-tests/wasm/jsapi/instanceTestFactory.js
Normal file
|
@ -0,0 +1,217 @@
|
|||
const instanceTestFactory = [
|
||||
[
|
||||
"Empty module without imports argument",
|
||||
function() {
|
||||
return {
|
||||
buffer: emptyModuleBinary,
|
||||
args: [],
|
||||
exports: {},
|
||||
verify: () => {},
|
||||
};
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
"Empty module with undefined imports argument",
|
||||
function() {
|
||||
return {
|
||||
buffer: emptyModuleBinary,
|
||||
args: [undefined],
|
||||
exports: {},
|
||||
verify: () => {},
|
||||
};
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
"Empty module with empty imports argument",
|
||||
function() {
|
||||
return {
|
||||
buffer: emptyModuleBinary,
|
||||
args: [{}],
|
||||
exports: {},
|
||||
verify: () => {},
|
||||
};
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
"getter order for imports object",
|
||||
function() {
|
||||
const builder = new WasmModuleBuilder();
|
||||
builder.addImportedGlobal("module", "global1", kWasmI32);
|
||||
builder.addImportedGlobal("module2", "global3", kWasmI32);
|
||||
builder.addImportedMemory("module", "memory", 0, 128);
|
||||
builder.addImportedGlobal("module", "global2", kWasmI32);
|
||||
const buffer = builder.toBuffer();
|
||||
const order = [];
|
||||
|
||||
const imports = {
|
||||
get module() {
|
||||
order.push("module getter");
|
||||
return {
|
||||
get global1() {
|
||||
order.push("global1 getter");
|
||||
return 0;
|
||||
},
|
||||
get global2() {
|
||||
order.push("global2 getter");
|
||||
return 0;
|
||||
},
|
||||
get memory() {
|
||||
order.push("memory getter");
|
||||
return new WebAssembly.Memory({ "initial": 64, maximum: 128 });
|
||||
},
|
||||
}
|
||||
},
|
||||
get module2() {
|
||||
order.push("module2 getter");
|
||||
return {
|
||||
get global3() {
|
||||
order.push("global3 getter");
|
||||
return 0;
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const expected = [
|
||||
"module getter",
|
||||
"global1 getter",
|
||||
"module2 getter",
|
||||
"global3 getter",
|
||||
"module getter",
|
||||
"memory getter",
|
||||
"module getter",
|
||||
"global2 getter",
|
||||
];
|
||||
return {
|
||||
buffer,
|
||||
args: [imports],
|
||||
exports: {},
|
||||
verify: () => assert_array_equals(order, expected),
|
||||
};
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
"imports",
|
||||
function() {
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
builder.addImport("module", "fn", kSig_v_v);
|
||||
builder.addImportedGlobal("module", "global", kWasmI32);
|
||||
builder.addImportedMemory("module", "memory", 0, 128);
|
||||
builder.addImportedTable("module", "table", 0, 128);
|
||||
|
||||
const buffer = builder.toBuffer();
|
||||
const imports = {
|
||||
"module": {
|
||||
"fn": function() {},
|
||||
"global": 0,
|
||||
"memory": new WebAssembly.Memory({ "initial": 64, maximum: 128 }),
|
||||
"table": new WebAssembly.Table({ "element": "anyfunc", "initial": 64, maximum: 128 }),
|
||||
},
|
||||
get "module2"() {
|
||||
assert_unreached("Should not get modules that are not imported");
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
buffer,
|
||||
args: [imports],
|
||||
exports: {},
|
||||
verify: () => {},
|
||||
};
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
"No imports",
|
||||
function() {
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
builder
|
||||
.addFunction("fn", kSig_v_d)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
builder
|
||||
.addFunction("fn2", kSig_v_v)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
|
||||
builder.setFunctionTableLength(1);
|
||||
builder.addExportOfKind("table", kExternalTable, 0);
|
||||
|
||||
builder.addGlobal(kWasmI32, true)
|
||||
.exportAs("global")
|
||||
.init = 7;
|
||||
builder.addGlobal(kWasmF64, true)
|
||||
.exportAs("global2")
|
||||
.init = 1.2;
|
||||
|
||||
builder.addMemory(4, 8, true);
|
||||
|
||||
const buffer = builder.toBuffer();
|
||||
|
||||
const exports = {
|
||||
"fn": { "kind": "function", "name": "0", "length": 1 },
|
||||
"fn2": { "kind": "function", "name": "1", "length": 0 },
|
||||
"table": { "kind": "table", "length": 1 },
|
||||
"global": { "kind": "global", "value": 7 },
|
||||
"global2": { "kind": "global", "value": 1.2 },
|
||||
"memory": { "kind": "memory", "size": 4 },
|
||||
};
|
||||
|
||||
return {
|
||||
buffer,
|
||||
args: [],
|
||||
exports,
|
||||
verify: () => {},
|
||||
};
|
||||
}
|
||||
],
|
||||
|
||||
[
|
||||
"exports and imports",
|
||||
function() {
|
||||
const value = 102;
|
||||
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
const index = builder.addImportedGlobal("module", "global", kWasmI32);
|
||||
builder
|
||||
.addFunction("fn", kSig_i_v)
|
||||
.addBody([
|
||||
kExprGetGlobal,
|
||||
index,
|
||||
kExprReturn,
|
||||
kExprEnd,
|
||||
])
|
||||
.exportFunc();
|
||||
|
||||
const buffer = builder.toBuffer();
|
||||
|
||||
const imports = {
|
||||
"module": {
|
||||
"global": value,
|
||||
},
|
||||
};
|
||||
|
||||
const exports = {
|
||||
"fn": { "kind": "function", "name": "0", "length": 0 },
|
||||
};
|
||||
|
||||
return {
|
||||
buffer,
|
||||
args: [imports],
|
||||
exports,
|
||||
verify: instance => assert_equals(instance.exports.fn(), value)
|
||||
};
|
||||
}
|
||||
],
|
||||
];
|
|
@ -9,7 +9,7 @@ function test_operations(object, object_name, operations) {
|
|||
assert_true(propdesc.writable, "writable");
|
||||
assert_true(propdesc.enumerable, "enumerable");
|
||||
assert_true(propdesc.configurable, "configurable");
|
||||
assert_equals(propdesc.value, WebAssembly[name]);
|
||||
assert_equals(propdesc.value, object[name]);
|
||||
}, `${object_name}.${name}`);
|
||||
|
||||
test(() => {
|
||||
|
|
|
@ -79,6 +79,10 @@ for (const value of outOfRangeValues) {
|
|||
}, `Out-of-range maximum value in descriptor: ${format_value(value)}`);
|
||||
}
|
||||
|
||||
test(() => {
|
||||
assert_throws(new RangeError(), () => new WebAssembly.Memory({ "element": "anyfunc", "initial": 10, "maximum": 9 }));
|
||||
}, "Initial value exceeds maximum");
|
||||
|
||||
test(() => {
|
||||
const proxy = new Proxy({}, {
|
||||
has(o, x) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
function assert_equal_to_array(table, expected, message) {
|
||||
assert_equals(table.length, expected.length, `${message}: length`);
|
||||
assert_throws(new RangeError(), () => table.get(-1), `${message}: table.get(-1)`);
|
||||
// The argument check in get() happens before the range check, and negative numbers
|
||||
// are illegal, hence will throw TypeError per spec.
|
||||
assert_throws(new TypeError(), () => table.get(-1), `${message}: table.get(-1)`);
|
||||
for (let i = 0; i < expected.length; ++i) {
|
||||
assert_equals(table.get(i), expected[i], `${message}: table.get(${i} of ${expected.length})`);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,9 @@ test(() => {
|
|||
|
||||
const {fn} = functions;
|
||||
|
||||
assert_throws(new RangeError(), () => table.set(-1, fn));
|
||||
// -1 is the wrong type hence the type check on entry gets this
|
||||
// before the range check does.
|
||||
assert_throws(new TypeError(), () => table.set(-1, fn));
|
||||
assert_throws(new RangeError(), () => table.set(5, fn));
|
||||
assert_equal_to_array(table, [null, null, null, null, null]);
|
||||
}, "Setting out-of-bounds");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue