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

@ -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}`);
}
}
}