mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
Update web-platform-tests to revision 9a5d71b326166e12784bdd9d161772e20f87c1fd
This commit is contained in:
parent
f7630dad87
commit
4ae3d09ff3
86 changed files with 2739 additions and 640 deletions
|
@ -3,62 +3,6 @@
|
|||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
// META: script=/wasm/jsapi/assertions.js
|
||||
|
||||
function assert_exported_function(fn, { name, length }, description) {
|
||||
assert_equals(Object.getPrototypeOf(fn), Function.prototype,
|
||||
`${description}: prototype`);
|
||||
|
||||
assert_function_name(fn, name, description);
|
||||
assert_function_length(fn, length, description);
|
||||
}
|
||||
|
||||
function assert_Instance(instance, expected_exports) {
|
||||
assert_equals(Object.getPrototypeOf(instance), WebAssembly.Instance.prototype,
|
||||
"prototype");
|
||||
assert_true(Object.isExtensible(instance), "extensible");
|
||||
|
||||
assert_equals(instance.exports, instance.exports, "exports should be idempotent");
|
||||
const exports = instance.exports;
|
||||
|
||||
assert_equals(Object.getPrototypeOf(exports), null, "exports prototype");
|
||||
assert_false(Object.isExtensible(exports), "extensible exports");
|
||||
for (const [key, expected] of Object.entries(expected_exports)) {
|
||||
const property = Object.getOwnPropertyDescriptor(exports, key);
|
||||
assert_equals(typeof property, "object", `${key} should be present`);
|
||||
assert_false(property.writable, `${key}: writable`);
|
||||
assert_true(property.enumerable, `${key}: enumerable`);
|
||||
assert_false(property.configurable, `${key}: configurable`);
|
||||
const actual = property.value;
|
||||
assert_true(Object.isExtensible(actual), `${key}: extensible`);
|
||||
|
||||
switch (expected.kind) {
|
||||
case "function":
|
||||
assert_exported_function(actual, expected, `value of ${key}`);
|
||||
break;
|
||||
case "global":
|
||||
assert_equals(Object.getPrototypeOf(actual), WebAssembly.Global.prototype,
|
||||
`value of ${key}: prototype`);
|
||||
assert_equals(actual.value, expected.value, `value of ${key}: value`);
|
||||
assert_equals(actual.valueOf(), expected.value, `value of ${key}: valueOf()`);
|
||||
break;
|
||||
case "memory":
|
||||
assert_equals(Object.getPrototypeOf(actual), WebAssembly.Memory.prototype,
|
||||
`value of ${key}: prototype`);
|
||||
assert_equals(Object.getPrototypeOf(actual.buffer), ArrayBuffer.prototype,
|
||||
`value of ${key}: prototype of buffer`);
|
||||
assert_equals(actual.buffer.byteLength, 0x10000 * expected.size, `value of ${key}: size of buffer`);
|
||||
const array = new Uint8Array(actual.buffer);
|
||||
assert_equals(array[0], 0, `value of ${key}: first element of buffer`);
|
||||
assert_equals(array[array.byteLength - 1], 0, `value of ${key}: last element of buffer`);
|
||||
break;
|
||||
case "table":
|
||||
assert_equals(Object.getPrototypeOf(actual), WebAssembly.Table.prototype,
|
||||
`value of ${key}: prototype`);
|
||||
assert_equals(actual.length, expected.length, `value of ${key}: length of table`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let emptyModuleBinary;
|
||||
setup(() => {
|
||||
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
|
||||
|
@ -130,6 +74,8 @@ test(() => {
|
|||
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);
|
||||
|
@ -146,6 +92,19 @@ test(() => {
|
|||
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;
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -153,6 +112,10 @@ test(() => {
|
|||
const expected = [
|
||||
"module getter",
|
||||
"global1 getter",
|
||||
"module2 getter",
|
||||
"global3 getter",
|
||||
"module getter",
|
||||
"memory getter",
|
||||
"module getter",
|
||||
"global2 getter",
|
||||
];
|
||||
|
@ -225,3 +188,34 @@ test(() => {
|
|||
};
|
||||
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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue