Update web-platform-tests to revision 9a5d71b326166e12784bdd9d161772e20f87c1fd

This commit is contained in:
WPT Sync Bot 2018-09-07 21:37:42 -04:00
parent f7630dad87
commit 4ae3d09ff3
86 changed files with 2739 additions and 640 deletions

View file

@ -15,3 +15,59 @@ function assert_function_length(fn, length, description) {
assert_true(propdesc.configurable, "configurable", `${description} length should be configurable`);
assert_equals(propdesc.value, length, `${description} length should be ${length}`);
}
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;
}
}
}

View file

@ -0,0 +1,77 @@
// META: global=jsshell
// META: script=/wasm/jsapi/wasm-constants.js
// META: script=/wasm/jsapi/wasm-module-builder.js
function assert_Module(module) {
assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype,
"Prototype");
assert_true(Object.isExtensible(module), "Extensibility");
}
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
promise_test(t => {
return promise_rejects(t, new TypeError(), WebAssembly.compile());
}, "Missing argument");
promise_test(t => {
const invalidArguments = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
ArrayBuffer,
ArrayBuffer.prototype,
Array.from(emptyModuleBinary),
];
return Promise.all(invalidArguments.map(argument => {
return promise_rejects(t, new TypeError(), WebAssembly.compile(argument),
`compile(${format_value(argument)})`);
}));
}, "Invalid arguments");
promise_test(() => {
const fn = WebAssembly.compile;
const thisValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly,
];
return Promise.all(thisValues.map(thisValue => {
return fn.call(thisValue, emptyModuleBinary).then(assert_Module);
}));
}, "Branding");
test(() => {
const promise = WebAssembly.compile(emptyModuleBinary);
assert_equals(Object.getPrototypeOf(promise), Promise.prototype, "prototype");
assert_true(Object.isExtensible(promise), "extensibility");
}, "Promise type");
promise_test(t => {
const buffer = new Uint8Array();
return promise_rejects(t, new WebAssembly.CompileError(), WebAssembly.compile(buffer));
}, "Invalid code");
promise_test(() => {
return WebAssembly.compile(emptyModuleBinary).then(assert_Module);
}, "Result type");
promise_test(() => {
const buffer = new WasmModuleBuilder().toBuffer();
assert_equals(buffer[0], 0);
const promise = WebAssembly.compile(buffer);
buffer[0] = 1;
return promise.then(assert_Module);
}, "Changing the buffer");

View file

@ -0,0 +1,196 @@
// META: global=jsshell
// META: script=/wasm/jsapi/wasm-constants.js
// META: script=/wasm/jsapi/wasm-module-builder.js
// META: script=/wasm/jsapi/assertions.js
function assert_WebAssemblyInstantiatedSource(actual, expected_exports={}) {
assert_equals(Object.getPrototypeOf(actual), Object.prototype,
"Prototype");
assert_true(Object.isExtensible(actual), "Extensibility");
const module = Object.getOwnPropertyDescriptor(actual, "module");
assert_equals(typeof module, "object", "module: type of descriptor");
assert_true(module.writable, "module: writable");
assert_true(module.enumerable, "module: enumerable");
assert_true(module.configurable, "module: configurable");
assert_equals(Object.getPrototypeOf(module.value), WebAssembly.Module.prototype,
"module: prototype");
const instance = Object.getOwnPropertyDescriptor(actual, "instance");
assert_equals(typeof instance, "object", "instance: type of descriptor");
assert_true(instance.writable, "instance: writable");
assert_true(instance.enumerable, "instance: enumerable");
assert_true(instance.configurable, "instance: configurable");
assert_Instance(instance.value, expected_exports);
}
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
promise_test(t => {
return promise_rejects(t, new TypeError(), WebAssembly.instantiate());
}, "Missing arguments");
promise_test(() => {
const fn = WebAssembly.instantiate;
const thisValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly,
];
return Promise.all(thisValues.map(thisValue => {
return fn.call(thisValue, emptyModuleBinary).then(assert_WebAssemblyInstantiatedSource);
}));
}, "Branding");
promise_test(t => {
const invalidArguments = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly.Module,
WebAssembly.Module.prototype,
ArrayBuffer,
ArrayBuffer.prototype,
Array.from(emptyModuleBinary),
];
return Promise.all(invalidArguments.map(argument => {
return promise_rejects(t, new TypeError(), WebAssembly.instantiate(argument),
`instantiate(${format_value(argument)})`);
}));
}, "Invalid arguments");
test(() => {
const promise = WebAssembly.instantiate(emptyModuleBinary);
assert_equals(Object.getPrototypeOf(promise), Promise.prototype, "prototype");
assert_true(Object.isExtensible(promise), "extensibility");
}, "Promise type");
const createModule = () => {
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, exports];
}
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));
}, "Invalid code");
promise_test(() => {
const buffer = new WasmModuleBuilder().toBuffer();
assert_equals(buffer[0], 0);
const promise = WebAssembly.instantiate(buffer);
buffer[0] = 1;
return promise.then(assert_WebAssemblyInstantiatedSource);
}, "Changing the buffer");

View file

@ -0,0 +1,96 @@
// META: global=jsshell
// META: script=/wasm/jsapi/wasm-constants.js
// META: script=/wasm/jsapi/wasm-module-builder.js
let emptyModuleBinary;
setup(() => {
emptyModuleBinary = new WasmModuleBuilder().toBuffer();
});
test(() => {
assert_throws(new TypeError(), () => WebAssembly.validate());
}, "Missing argument");
test(() => {
const invalidArguments = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
ArrayBuffer,
ArrayBuffer.prototype,
Array.from(emptyModuleBinary),
];
for (const argument of invalidArguments) {
assert_throws(new TypeError(), () => WebAssembly.validate(argument),
`validate(${format_value(argument)})`);
}
}, "Invalid arguments");
test(() => {
const fn = WebAssembly.validate;
const thisValues = [
undefined,
null,
true,
"",
Symbol(),
1,
{},
WebAssembly,
];
for (const thisValue of thisValues) {
assert_true(fn.call(thisValue, emptyModuleBinary), `this=${format_value(thisValue)}`);
}
}, "Branding");
const modules = [
// Incomplete header.
[[], false],
[[0x00], false],
[[0x00, 0x61], false],
[[0x00, 0x61, 0x73], false],
[[0x00, 0x61, 0x73, 0x6d], false],
[[0x00, 0x61, 0x73, 0x6d, 0x01], false],
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00], false],
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00], false],
// Complete header.
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00], true],
// Invalid version.
[[0x00, 0x61, 0x73, 0x6d, 0x00, 0x00, 0x00, 0x00], false],
[[0x00, 0x61, 0x73, 0x6d, 0x02, 0x00, 0x00, 0x00], false],
// Nameless custom section.
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], false],
// Custom section with empty name.
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00], true],
// Custom section with name "a".
[[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x61], true],
];
const bufferTypes = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
];
for (const [module, expected] of modules) {
const name = module.map(n => n.toString(16)).join(" ");
for (const bufferType of bufferTypes) {
if (module.length % bufferType.BYTES_PER_ELEMENT === 0) {
test(() => {
const bytes = new Uint8Array(module);
const moduleBuffer = new bufferType(bytes.buffer);
assert_equals(WebAssembly.validate(moduleBuffer), expected);
}, `Validating module [${name}] in ${bufferType.name}`);
}
}
}

View file

@ -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");