mirror of
https://github.com/servo/servo.git
synced 2025-08-23 06:15:35 +01:00
Update web-platform-tests to revision 2b7dace05fc1869398ee24f84fda4c0e4c0455ae
This commit is contained in:
parent
b23125d590
commit
6c901de216
844 changed files with 19802 additions and 3093 deletions
11
tests/wpt/web-platform-tests/wasm/jsapi/table/assertions.js
Normal file
11
tests/wpt/web-platform-tests/wasm/jsapi/table/assertions.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
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)`);
|
||||
for (let i = 0; i < expected.length; ++i) {
|
||||
assert_equals(table.get(i), expected[i], `${message}: table.get(${i} of ${expected.length})`);
|
||||
}
|
||||
assert_throws(new RangeError(), () => table.get(expected.length),
|
||||
`${message}: table.get(${expected.length} of ${expected.length})`);
|
||||
assert_throws(new RangeError(), () => table.get(expected.length + 1),
|
||||
`${message}: table.get(${expected.length + 1} of ${expected.length})`);
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
// META: global=jsshell
|
||||
// META: script=/wasm/jsapi/wasm-constants.js
|
||||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
// META: script=/wasm/jsapi/assertions.js
|
||||
|
||||
let emptyModuleBinary;
|
||||
setup(() => {
|
||||
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
|
||||
});
|
||||
function assert_Table(actual, expected) {
|
||||
assert_equals(Object.getPrototypeOf(actual), WebAssembly.Table.prototype,
|
||||
"prototype");
|
||||
assert_true(Object.isExtensible(actual), "extensible");
|
||||
|
||||
assert_equals(actual.length, expected.length, "length");
|
||||
for (let i = 0; i < expected.length; ++i) {
|
||||
assert_equals(actual.get(i), null, `actual.get(${i})`);
|
||||
}
|
||||
}
|
||||
|
||||
test(() => {
|
||||
assert_function_name(WebAssembly.Table, "Table", "WebAssembly.Table");
|
||||
|
@ -21,7 +25,7 @@ test(() => {
|
|||
}, "No arguments");
|
||||
|
||||
test(() => {
|
||||
const argument = { "initial": 0 };
|
||||
const argument = { "element": "anyfunc", "initial": 0 };
|
||||
assert_throws(new TypeError(), () => WebAssembly.Table(argument));
|
||||
}, "Calling");
|
||||
|
||||
|
@ -29,6 +33,26 @@ test(() => {
|
|||
assert_throws(new TypeError(), () => new WebAssembly.Table({}));
|
||||
}, "Empty descriptor");
|
||||
|
||||
test(() => {
|
||||
const invalidArguments = [
|
||||
undefined,
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
"",
|
||||
"test",
|
||||
Symbol(),
|
||||
1,
|
||||
NaN,
|
||||
{},
|
||||
];
|
||||
for (const invalidArgument of invalidArguments) {
|
||||
assert_throws(new TypeError(),
|
||||
() => new WebAssembly.Table(invalidArgument),
|
||||
`new Table(${format_value(invalidArgument)})`);
|
||||
}
|
||||
}, "Invalid descriptor argument");
|
||||
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => new WebAssembly.Table({ "element": "anyfunc", "initial": undefined }));
|
||||
}, "Undefined initial value in descriptor");
|
||||
|
@ -56,6 +80,22 @@ for (const value of outOfRangeValues) {
|
|||
}, `Out-of-range maximum value in descriptor: ${format_value(value)}`);
|
||||
}
|
||||
|
||||
test(() => {
|
||||
assert_throws(new RangeError(), () => new WebAssembly.Table({ "element": "anyfunc", "initial": 10, "maximum": 9 }));
|
||||
}, "Initial value exceeds maximum");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 0 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_Table(table, { "length": 0 });
|
||||
}, "Basic (zero)");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_Table(table, { "length": 5 });
|
||||
}, "Basic (non-zero)");
|
||||
|
||||
test(() => {
|
||||
const proxy = new Proxy({}, {
|
||||
has(o, x) {
|
||||
|
@ -73,11 +113,61 @@ test(() => {
|
|||
}
|
||||
},
|
||||
});
|
||||
new WebAssembly.Table(proxy);
|
||||
const table = new WebAssembly.Table(proxy);
|
||||
assert_Table(table, { "length": 0 });
|
||||
}, "Proxy descriptor");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 0 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equals(Object.getPrototypeOf(table), WebAssembly.Table.prototype);
|
||||
}, "Prototype");
|
||||
const table = new WebAssembly.Table({
|
||||
"element": {
|
||||
toString() { return "anyfunc"; },
|
||||
},
|
||||
"initial": 1,
|
||||
});
|
||||
assert_Table(table, { "length": 1 });
|
||||
}, "Type conversion for descriptor.element");
|
||||
|
||||
test(() => {
|
||||
const order = [];
|
||||
|
||||
new WebAssembly.Table({
|
||||
get maximum() {
|
||||
order.push("maximum");
|
||||
return {
|
||||
valueOf() {
|
||||
order.push("maximum valueOf");
|
||||
return 1;
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
get initial() {
|
||||
order.push("initial");
|
||||
return {
|
||||
valueOf() {
|
||||
order.push("initial valueOf");
|
||||
return 1;
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
get element() {
|
||||
order.push("element");
|
||||
return {
|
||||
toString() {
|
||||
order.push("element toString");
|
||||
return "anyfunc";
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
assert_array_equals(order, [
|
||||
"element",
|
||||
"element toString",
|
||||
"initial",
|
||||
"initial valueOf",
|
||||
"maximum",
|
||||
"maximum valueOf",
|
||||
]);
|
||||
}, "Order of evaluation for descriptor");
|
||||
|
|
220
tests/wpt/web-platform-tests/wasm/jsapi/table/get-set.any.js
Normal file
220
tests/wpt/web-platform-tests/wasm/jsapi/table/get-set.any.js
Normal file
|
@ -0,0 +1,220 @@
|
|||
// META: global=jsshell
|
||||
// META: script=/wasm/jsapi/wasm-constants.js
|
||||
// META: script=/wasm/jsapi/wasm-module-builder.js
|
||||
// META: script=assertions.js
|
||||
|
||||
let functions;
|
||||
setup(() => {
|
||||
const builder = new WasmModuleBuilder();
|
||||
|
||||
builder
|
||||
.addFunction("fn", kSig_v_d)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
builder
|
||||
.addFunction("fn2", kSig_v_v)
|
||||
.addBody([
|
||||
kExprEnd
|
||||
])
|
||||
.exportFunc();
|
||||
|
||||
const buffer = builder.toBuffer()
|
||||
const module = new WebAssembly.Module(buffer);
|
||||
const instance = new WebAssembly.Instance(module, {});
|
||||
functions = instance.exports;
|
||||
});
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_throws(new TypeError(), () => table.get());
|
||||
}, "Missing arguments: get");
|
||||
|
||||
test(t => {
|
||||
const thisValues = [
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
"",
|
||||
Symbol(),
|
||||
1,
|
||||
{},
|
||||
WebAssembly.Table,
|
||||
WebAssembly.Table.prototype,
|
||||
];
|
||||
|
||||
const argument = {
|
||||
valueOf: t.unreached_func("Should not touch the argument (valueOf)"),
|
||||
toString: t.unreached_func("Should not touch the argument (toString)"),
|
||||
};
|
||||
|
||||
const fn = WebAssembly.Table.prototype.get;
|
||||
|
||||
for (const thisValue of thisValues) {
|
||||
assert_throws(new TypeError(), () => fn.call(thisValue, argument), `this=${format_value(thisValue)}`);
|
||||
}
|
||||
}, "Branding: get");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_throws(new TypeError(), () => table.set());
|
||||
assert_throws(new TypeError(), () => table.set(0));
|
||||
}, "Missing arguments: set");
|
||||
|
||||
test(t => {
|
||||
const thisValues = [
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
"",
|
||||
Symbol(),
|
||||
1,
|
||||
{},
|
||||
WebAssembly.Table,
|
||||
WebAssembly.Table.prototype,
|
||||
];
|
||||
|
||||
const argument = {
|
||||
valueOf: t.unreached_func("Should not touch the argument (valueOf)"),
|
||||
toString: t.unreached_func("Should not touch the argument (toString)"),
|
||||
};
|
||||
|
||||
const fn = WebAssembly.Table.prototype.set;
|
||||
|
||||
for (const thisValue of thisValues) {
|
||||
assert_throws(new TypeError(), () => fn.call(thisValue, argument, null), `this=${format_value(thisValue)}`);
|
||||
}
|
||||
}, "Branding: set");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, [null, null, null, null, null]);
|
||||
|
||||
const {fn, fn2} = functions;
|
||||
|
||||
assert_equals(table.set(0, fn), undefined, "set() returns undefined.");
|
||||
table.set(2, fn2);
|
||||
table.set(4, fn);
|
||||
|
||||
assert_equal_to_array(table, [fn, null, fn2, null, fn]);
|
||||
|
||||
table.set(0, null);
|
||||
assert_equal_to_array(table, [null, null, fn2, null, fn]);
|
||||
}, "Basic");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, [null, null, null, null, null]);
|
||||
|
||||
const {fn, fn2} = functions;
|
||||
|
||||
table.set(0, fn);
|
||||
table.set(2, fn2);
|
||||
table.set(4, fn);
|
||||
|
||||
assert_equal_to_array(table, [fn, null, fn2, null, fn]);
|
||||
|
||||
table.grow(4);
|
||||
|
||||
assert_equal_to_array(table, [fn, null, fn2, null, fn, null, null, null, null]);
|
||||
}, "Growing");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, [null, null, null, null, null]);
|
||||
|
||||
const {fn} = functions;
|
||||
|
||||
assert_throws(new RangeError(), () => 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");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 1 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, [null]);
|
||||
|
||||
const invalidArguments = [
|
||||
undefined,
|
||||
true,
|
||||
false,
|
||||
"test",
|
||||
Symbol(),
|
||||
7,
|
||||
NaN,
|
||||
{},
|
||||
];
|
||||
for (const argument of invalidArguments) {
|
||||
assert_throws(new TypeError(), () => table.set(0, argument),
|
||||
`set(${format_value(argument)})`);
|
||||
}
|
||||
assert_equal_to_array(table, [null]);
|
||||
}, "Setting non-function");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 1 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, [null]);
|
||||
|
||||
const fn = function() {};
|
||||
assert_throws(new TypeError(), () => table.set(0, fn));
|
||||
assert_equal_to_array(table, [null]);
|
||||
}, "Setting non-wasm function");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 1 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, [null]);
|
||||
|
||||
const fn = () => {};
|
||||
assert_throws(new TypeError(), () => table.set(0, fn));
|
||||
assert_equal_to_array(table, [null]);
|
||||
}, "Setting non-wasm arrow function");
|
||||
|
||||
const outOfRangeValues = [
|
||||
undefined,
|
||||
NaN,
|
||||
Infinity,
|
||||
-Infinity,
|
||||
-1,
|
||||
0x100000000,
|
||||
0x1000000000,
|
||||
"0x100000000",
|
||||
{ valueOf() { return 0x100000000; } },
|
||||
];
|
||||
|
||||
for (const value of outOfRangeValues) {
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 1 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_throws(new TypeError(), () => table.get(value));
|
||||
}, `Getting out-of-range argument: ${format_value(value)}`);
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 1 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_throws(new TypeError(), () => table.set(value, null));
|
||||
}, `Setting out-of-range argument: ${format_value(value)}`);
|
||||
}
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 1 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
let called = 0;
|
||||
const value = {
|
||||
valueOf() {
|
||||
called++;
|
||||
return 0;
|
||||
},
|
||||
};
|
||||
assert_throws(new TypeError(), () => table.set(value, {}));
|
||||
assert_equals(called, 1);
|
||||
}, "Order of argument conversion");
|
||||
|
86
tests/wpt/web-platform-tests/wasm/jsapi/table/grow.any.js
Normal file
86
tests/wpt/web-platform-tests/wasm/jsapi/table/grow.any.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
// META: global=jsshell
|
||||
// META: script=assertions.js
|
||||
|
||||
function nulls(n) {
|
||||
return Array(n).fill(null);
|
||||
}
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_throws(new TypeError(), () => table.grow());
|
||||
}, "Missing arguments");
|
||||
|
||||
test(t => {
|
||||
const thisValues = [
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
"",
|
||||
Symbol(),
|
||||
1,
|
||||
{},
|
||||
WebAssembly.Table,
|
||||
WebAssembly.Table.prototype,
|
||||
];
|
||||
|
||||
const argument = {
|
||||
valueOf: t.unreached_func("Should not touch the argument (valueOf)"),
|
||||
toString: t.unreached_func("Should not touch the argument (toString)"),
|
||||
};
|
||||
|
||||
const fn = WebAssembly.Table.prototype.grow;
|
||||
|
||||
for (const thisValue of thisValues) {
|
||||
assert_throws(new TypeError(), () => fn.call(thisValue, argument), `this=${format_value(thisValue)}`);
|
||||
}
|
||||
}, "Branding");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, nulls(5), "before");
|
||||
|
||||
const result = table.grow(3);
|
||||
assert_equals(result, 5);
|
||||
assert_equal_to_array(table, nulls(8), "after");
|
||||
}, "Basic");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 3, "maximum": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, nulls(3), "before");
|
||||
|
||||
const result = table.grow(2);
|
||||
assert_equals(result, 3);
|
||||
assert_equal_to_array(table, nulls(5), "after");
|
||||
}, "Reached maximum");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 2, "maximum": 5 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equal_to_array(table, nulls(2), "before");
|
||||
|
||||
assert_throws(new RangeError(), () => table.grow(4));
|
||||
assert_equal_to_array(table, nulls(2), "after");
|
||||
}, "Exceeded maximum");
|
||||
|
||||
const outOfRangeValues = [
|
||||
undefined,
|
||||
NaN,
|
||||
Infinity,
|
||||
-Infinity,
|
||||
-1,
|
||||
0x100000000,
|
||||
0x1000000000,
|
||||
"0x100000000",
|
||||
{ valueOf() { return 0x100000000; } },
|
||||
];
|
||||
|
||||
for (const value of outOfRangeValues) {
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 1 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_throws(new TypeError(), () => table.grow(value));
|
||||
}, `Out-of-range argument: ${format_value(value)}`);
|
||||
}
|
46
tests/wpt/web-platform-tests/wasm/jsapi/table/length.any.js
Normal file
46
tests/wpt/web-platform-tests/wasm/jsapi/table/length.any.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
// META: global=jsshell
|
||||
|
||||
test(() => {
|
||||
const thisValues = [
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
"",
|
||||
Symbol(),
|
||||
1,
|
||||
{},
|
||||
WebAssembly.Table,
|
||||
WebAssembly.Table.prototype,
|
||||
];
|
||||
|
||||
const desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, "length");
|
||||
assert_equals(typeof desc, "object");
|
||||
|
||||
const getter = desc.get;
|
||||
assert_equals(typeof getter, "function");
|
||||
|
||||
assert_equals(typeof desc.set, "undefined");
|
||||
|
||||
for (const thisValue of thisValues) {
|
||||
assert_throws(new TypeError(), () => getter.call(thisValue), `this=${format_value(thisValue)}`);
|
||||
}
|
||||
}, "Branding");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 2 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equals(table.length, 2, "Initial length");
|
||||
table.length = 4;
|
||||
assert_equals(table.length, 2, "Should not change the length");
|
||||
}, "Setting (sloppy mode)");
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 2 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_equals(table.length, 2, "Initial length");
|
||||
assert_throws(new TypeError(), () => {
|
||||
"use strict";
|
||||
table.length = 4;
|
||||
});
|
||||
assert_equals(table.length, 2, "Should not change the length");
|
||||
}, "Setting (strict mode)");
|
|
@ -0,0 +1,7 @@
|
|||
// META: global=jsshell
|
||||
|
||||
test(() => {
|
||||
const argument = { "element": "anyfunc", "initial": 0 };
|
||||
const table = new WebAssembly.Table(argument);
|
||||
assert_class_string(table, "WebAssembly.Table");
|
||||
}, "Object.prototype.toString on an Table");
|
Loading…
Add table
Add a link
Reference in a new issue