2016-12-19 17:19:56 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-03-01 15:09:12 +00:00
|
|
|
// Flags: --expose-wasm
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2021-06-01 12:46:36 +00:00
|
|
|
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
|
2017-04-06 09:49:38 +00:00
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
function assertEq(val, expected) {
|
2017-10-06 14:09:29 +00:00
|
|
|
assertSame(expected, val);
|
2016-12-19 17:19:56 +00:00
|
|
|
}
|
2017-01-24 15:23:02 +00:00
|
|
|
function assertArrayBuffer(val, expected) {
|
|
|
|
assertTrue(val instanceof ArrayBuffer);
|
|
|
|
assertEq(expected.length, val.byteLength);
|
|
|
|
var input = new Int8Array(val);
|
|
|
|
for (var i = 0; i < expected.length; i++) {
|
|
|
|
assertEq(expected[i], input[i]);
|
|
|
|
}
|
|
|
|
}
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2019-12-04 12:59:36 +00:00
|
|
|
function isConstructor(value) {
|
|
|
|
var p = new Proxy(value, { construct: () => ({}) });
|
|
|
|
try {
|
|
|
|
return new p, true;
|
|
|
|
} catch(e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
let emptyModuleBinary = (() => {
|
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
|
|
|
|
let exportingModuleBinary = (() => {
|
|
|
|
var builder = new WasmModuleBuilder();
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 42]).exportAs('f');
|
2016-12-19 17:19:56 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
|
|
|
|
let importingModuleBinary = (() => {
|
|
|
|
var builder = new WasmModuleBuilder();
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addImport('', 'f', kSig_i_v);
|
2016-12-19 17:19:56 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
|
2017-01-13 20:47:44 +00:00
|
|
|
let memoryImportingModuleBinary = (() => {
|
|
|
|
var builder = new WasmModuleBuilder();
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addImportedMemory('', 'my_memory');
|
2017-01-13 20:47:44 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
|
2017-01-11 00:25:09 +00:00
|
|
|
let moduleBinaryImporting2Memories = (() => {
|
|
|
|
var builder = new WasmModuleBuilder();
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addImportedMemory('', 'memory1');
|
|
|
|
builder.addImportedMemory('', 'memory2');
|
2017-01-11 00:25:09 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
|
2017-01-12 16:48:09 +00:00
|
|
|
let moduleBinaryWithMemSectionAndMemImport = (() => {
|
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
builder.addMemory(1, 1, false);
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addImportedMemory('', 'memory1');
|
2017-01-12 16:48:09 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
// 'WebAssembly' data property on global object
|
|
|
|
let wasmDesc = Object.getOwnPropertyDescriptor(this, 'WebAssembly');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof wasmDesc.value, 'object');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(wasmDesc.writable);
|
|
|
|
assertFalse(wasmDesc.enumerable);
|
|
|
|
assertTrue(wasmDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly' object
|
|
|
|
assertEq(WebAssembly, wasmDesc.value);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(String(WebAssembly), '[object WebAssembly]');
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2016-12-21 09:03:35 +00:00
|
|
|
// 'WebAssembly.CompileError'
|
2017-04-06 09:49:38 +00:00
|
|
|
let compileErrorDesc =
|
|
|
|
Object.getOwnPropertyDescriptor(WebAssembly, 'CompileError');
|
|
|
|
assertEq(typeof compileErrorDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(compileErrorDesc.writable);
|
|
|
|
assertFalse(compileErrorDesc.enumerable);
|
|
|
|
assertTrue(compileErrorDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
let CompileError = WebAssembly.CompileError;
|
|
|
|
assertEq(CompileError, compileErrorDesc.value);
|
|
|
|
assertEq(CompileError.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(CompileError.name, 'CompileError');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertTrue(isConstructor(CompileError));
|
2016-12-19 17:19:56 +00:00
|
|
|
let compileError = new CompileError;
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(compileError instanceof CompileError);
|
|
|
|
assertTrue(compileError instanceof Error);
|
|
|
|
assertFalse(compileError instanceof TypeError);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(compileError.message, '');
|
|
|
|
assertEq(new CompileError('hi').message, 'hi');
|
2016-12-21 09:03:35 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.RuntimeError'
|
2017-04-06 09:49:38 +00:00
|
|
|
let runtimeErrorDesc =
|
|
|
|
Object.getOwnPropertyDescriptor(WebAssembly, 'RuntimeError');
|
|
|
|
assertEq(typeof runtimeErrorDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(runtimeErrorDesc.writable);
|
|
|
|
assertFalse(runtimeErrorDesc.enumerable);
|
|
|
|
assertTrue(runtimeErrorDesc.configurable);
|
2016-12-21 09:03:35 +00:00
|
|
|
let RuntimeError = WebAssembly.RuntimeError;
|
|
|
|
assertEq(RuntimeError, runtimeErrorDesc.value);
|
|
|
|
assertEq(RuntimeError.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(RuntimeError.name, 'RuntimeError');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertTrue(isConstructor(RuntimeError));
|
2016-12-21 09:03:35 +00:00
|
|
|
let runtimeError = new RuntimeError;
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(runtimeError instanceof RuntimeError);
|
|
|
|
assertTrue(runtimeError instanceof Error);
|
|
|
|
assertFalse(runtimeError instanceof TypeError);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(runtimeError.message, '');
|
|
|
|
assertEq(new RuntimeError('hi').message, 'hi');
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2016-12-21 09:03:35 +00:00
|
|
|
// 'WebAssembly.LinkError'
|
|
|
|
let linkErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'LinkError');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof linkErrorDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(linkErrorDesc.writable);
|
|
|
|
assertFalse(linkErrorDesc.enumerable);
|
|
|
|
assertTrue(linkErrorDesc.configurable);
|
2016-12-21 09:03:35 +00:00
|
|
|
let LinkError = WebAssembly.LinkError;
|
|
|
|
assertEq(LinkError, linkErrorDesc.value);
|
|
|
|
assertEq(LinkError.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(LinkError.name, 'LinkError');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertTrue(isConstructor(LinkError));
|
2016-12-21 09:03:35 +00:00
|
|
|
let linkError = new LinkError;
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(linkError instanceof LinkError);
|
|
|
|
assertTrue(linkError instanceof Error);
|
|
|
|
assertFalse(linkError instanceof TypeError);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(linkError.message, '');
|
|
|
|
assertEq(new LinkError('hi').message, 'hi');
|
2016-12-21 09:03:35 +00:00
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
// 'WebAssembly.Module' data property
|
|
|
|
let moduleDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Module');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof moduleDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(moduleDesc.writable);
|
|
|
|
assertFalse(moduleDesc.enumerable);
|
|
|
|
assertTrue(moduleDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Module' constructor function
|
|
|
|
let Module = WebAssembly.Module;
|
|
|
|
assertEq(Module, moduleDesc.value);
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(Module.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(Module.name, 'Module');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertTrue(isConstructor(Module));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => Module(), TypeError, /must be invoked with 'new'/);
|
|
|
|
assertThrows(
|
|
|
|
() => new Module(), TypeError, /Argument 0 must be a buffer source/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Module(undefined), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Module(): Argument 0 must be a buffer source');
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Module(1), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Module(): Argument 0 must be a buffer source');
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Module({}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Module(): Argument 0 must be a buffer source');
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Module(new Uint8Array()), CompileError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/BufferSource argument is empty/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Module(new ArrayBuffer()), CompileError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/BufferSource argument is empty/);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(new Module(emptyModuleBinary) instanceof Module);
|
|
|
|
assertTrue(new Module(emptyModuleBinary.buffer) instanceof Module);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Module.prototype' data property
|
|
|
|
let moduleProtoDesc = Object.getOwnPropertyDescriptor(Module, 'prototype');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof moduleProtoDesc.value, 'object');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertFalse(moduleProtoDesc.writable);
|
|
|
|
assertFalse(moduleProtoDesc.enumerable);
|
|
|
|
assertFalse(moduleProtoDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Module.prototype' object
|
|
|
|
let moduleProto = Module.prototype;
|
|
|
|
assertEq(moduleProto, moduleProtoDesc.value);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(String(moduleProto), '[object WebAssembly.Module]');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Object.getPrototypeOf(moduleProto), Object.prototype);
|
|
|
|
|
|
|
|
// 'WebAssembly.Module' instance objects
|
|
|
|
let emptyModule = new Module(emptyModuleBinary);
|
|
|
|
let importingModule = new Module(importingModuleBinary);
|
|
|
|
let exportingModule = new Module(exportingModuleBinary);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof emptyModule, 'object');
|
|
|
|
assertEq(String(emptyModule), '[object WebAssembly.Module]');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Object.getPrototypeOf(emptyModule), moduleProto);
|
|
|
|
|
|
|
|
// 'WebAssembly.Module.imports' data property
|
|
|
|
let moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof moduleImportsDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(moduleImportsDesc.writable);
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(moduleImportsDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(moduleImportsDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Module.imports' method
|
|
|
|
let moduleImports = moduleImportsDesc.value;
|
|
|
|
assertEq(moduleImports.length, 1);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(moduleImports));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => moduleImports(), TypeError, /Argument 0 must be a WebAssembly.Module/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => moduleImports(undefined), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a WebAssembly.Module/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => moduleImports({}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a WebAssembly.Module/);
|
2017-01-11 14:17:54 +00:00
|
|
|
var arr = moduleImports(new Module(emptyModuleBinary));
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(arr instanceof Array);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(arr.length, 0);
|
2017-01-11 14:17:54 +00:00
|
|
|
let importingModuleBinary2 = (() => {
|
2017-04-06 09:49:38 +00:00
|
|
|
var text =
|
|
|
|
'(module (func (import "a" "b")) (memory (import "c" "d") 1) (table (import "e" "f") 1 anyfunc) (global (import "g" "⚡") i32))'
|
2017-01-11 14:17:54 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addImport('a', 'b', kSig_i_i);
|
|
|
|
builder.addImportedMemory('c', 'd');
|
|
|
|
builder.addImportedTable('e', 'f');
|
|
|
|
builder.addImportedGlobal('g', 'x', kWasmI32);
|
2017-01-11 14:17:54 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
var arr = moduleImports(new Module(importingModuleBinary2));
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(arr instanceof Array);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(arr.length, 4);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(arr[0].kind, 'function');
|
|
|
|
assertEq(arr[0].module, 'a');
|
|
|
|
assertEq(arr[0].name, 'b');
|
|
|
|
assertEq(arr[1].kind, 'memory');
|
|
|
|
assertEq(arr[1].module, 'c');
|
|
|
|
assertEq(arr[1].name, 'd');
|
|
|
|
assertEq(arr[2].kind, 'table');
|
|
|
|
assertEq(arr[2].module, 'e');
|
|
|
|
assertEq(arr[2].name, 'f');
|
|
|
|
assertEq(arr[3].kind, 'global');
|
|
|
|
assertEq(arr[3].module, 'g');
|
|
|
|
assertEq(arr[3].name, 'x');
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Module.exports' data property
|
|
|
|
let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof moduleExportsDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(moduleExportsDesc.writable);
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(moduleExportsDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(moduleExportsDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Module.exports' method
|
|
|
|
let moduleExports = moduleExportsDesc.value;
|
|
|
|
assertEq(moduleExports.length, 1);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(moduleExports));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => moduleExports(), TypeError, /Argument 0 must be a WebAssembly.Module/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => moduleExports(undefined), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a WebAssembly.Module/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => moduleExports({}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a WebAssembly.Module/);
|
2016-12-19 17:19:56 +00:00
|
|
|
var arr = moduleExports(emptyModule);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(arr instanceof Array);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(arr.length, 0);
|
2017-01-11 14:40:25 +00:00
|
|
|
let exportingModuleBinary2 = (() => {
|
|
|
|
var text =
|
2017-04-06 09:49:38 +00:00
|
|
|
'(module (func (export "a")) (memory (export "b") 1) (table (export "c") 1 anyfunc) (global (export "⚡") i32 (i32.const 0)))';
|
2017-01-11 14:40:25 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addFunction('foo', kSig_v_v).addBody([]).exportAs('a');
|
2017-01-11 14:40:25 +00:00
|
|
|
builder.addMemory(1, 1, false);
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.exportMemoryAs('b');
|
2018-10-10 22:05:40 +00:00
|
|
|
builder.setTableBounds(1, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
builder.addExportOfKind('c', kExternalTable, 0);
|
|
|
|
var o = builder.addGlobal(kWasmI32, false).exportAs('x');
|
2017-01-11 14:40:25 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
var arr = moduleExports(new Module(exportingModuleBinary2));
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(arr instanceof Array);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(arr.length, 4);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(arr[0].kind, 'function');
|
|
|
|
assertEq(arr[0].name, 'a');
|
|
|
|
assertEq(arr[1].kind, 'memory');
|
|
|
|
assertEq(arr[1].name, 'b');
|
|
|
|
assertEq(arr[2].kind, 'table');
|
|
|
|
assertEq(arr[2].name, 'c');
|
|
|
|
assertEq(arr[3].kind, 'global');
|
|
|
|
assertEq(arr[3].name, 'x');
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2017-01-24 15:23:02 +00:00
|
|
|
// 'WebAssembly.Module.customSections' data property
|
|
|
|
let moduleCustomSectionsDesc =
|
|
|
|
Object.getOwnPropertyDescriptor(Module, 'customSections');
|
|
|
|
assertEq(typeof moduleCustomSectionsDesc.value, 'function');
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(moduleCustomSectionsDesc.writable);
|
|
|
|
assertTrue(moduleCustomSectionsDesc.enumerable);
|
|
|
|
assertTrue(moduleCustomSectionsDesc.configurable);
|
2017-01-24 15:23:02 +00:00
|
|
|
|
2019-12-04 12:59:36 +00:00
|
|
|
// 'WebAssembly.Module.customSections' method
|
2017-01-24 15:23:02 +00:00
|
|
|
let moduleCustomSections = moduleCustomSectionsDesc.value;
|
|
|
|
assertEq(moduleCustomSections.length, 2);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(moduleCustomSections));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => moduleCustomSections(), TypeError, /Argument 0 must be a WebAssembly.Module/);
|
|
|
|
assertThrows(
|
2017-01-24 15:23:02 +00:00
|
|
|
() => moduleCustomSections(undefined), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a WebAssembly.Module/);
|
|
|
|
assertThrows(
|
2017-01-24 15:23:02 +00:00
|
|
|
() => moduleCustomSections({}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a WebAssembly.Module/);
|
2017-01-24 15:23:02 +00:00
|
|
|
var arr = moduleCustomSections(emptyModule, 'x');
|
|
|
|
assertEq(arr instanceof Array, true);
|
|
|
|
assertEq(arr.length, 0);
|
|
|
|
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2017-01-24 15:23:02 +00:00
|
|
|
() => moduleCustomSections(1), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Module.customSections(): Argument 0 must be a WebAssembly.Module');
|
2017-01-24 15:23:02 +00:00
|
|
|
|
|
|
|
let customSectionModuleBinary2 = (() => {
|
|
|
|
let builder = new WasmModuleBuilder();
|
2017-01-25 11:53:09 +00:00
|
|
|
builder.addCustomSection('x', [2]);
|
|
|
|
builder.addCustomSection('foo', [66, 77]);
|
|
|
|
builder.addCustomSection('foo', [91, 92, 93]);
|
|
|
|
builder.addCustomSection('fox', [99, 99, 99]);
|
2017-01-24 15:23:02 +00:00
|
|
|
return new Int8Array(builder.toBuffer());
|
|
|
|
})();
|
|
|
|
var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'x');
|
|
|
|
assertEq(arr instanceof Array, true);
|
|
|
|
assertEq(arr.length, 1);
|
|
|
|
assertArrayBuffer(arr[0], [2]);
|
|
|
|
var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'foo');
|
|
|
|
assertEq(arr instanceof Array, true);
|
|
|
|
assertEq(arr.length, 2);
|
|
|
|
assertArrayBuffer(arr[0], [66, 77]);
|
|
|
|
assertArrayBuffer(arr[1], [91, 92, 93]);
|
|
|
|
var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'bar');
|
|
|
|
assertEq(arr instanceof Array, true);
|
|
|
|
assertEq(arr.length, 0);
|
2017-08-03 14:13:18 +00:00
|
|
|
var o = {toString() { return "foo" }}
|
|
|
|
var arr = moduleCustomSections(new Module(customSectionModuleBinary2), o);
|
|
|
|
assertEq(arr instanceof Array, true);
|
|
|
|
assertEq(arr.length, 2);
|
|
|
|
assertArrayBuffer(arr[0], [66, 77]);
|
|
|
|
assertArrayBuffer(arr[1], [91, 92, 93]);
|
|
|
|
var o = {toString() { throw "boo!" }}
|
|
|
|
assertThrows(
|
|
|
|
() => moduleCustomSections(new Module(customSectionModuleBinary2), o));
|
2017-01-24 15:23:02 +00:00
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
// 'WebAssembly.Instance' data property
|
|
|
|
let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof instanceDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(instanceDesc.writable);
|
|
|
|
assertFalse(instanceDesc.enumerable);
|
|
|
|
assertTrue(instanceDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Instance' constructor function
|
|
|
|
let Instance = WebAssembly.Instance;
|
|
|
|
assertEq(Instance, instanceDesc.value);
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(Instance.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(Instance.name, 'Instance');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertTrue(isConstructor(Instance));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => Instance(), TypeError, /must be invoked with 'new'/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Instance(1), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Instance(): Argument 0 must be a WebAssembly.Module');
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Instance({}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Instance(): Argument 0 must be a WebAssembly.Module');
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Instance(emptyModule, null), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Instance(): Argument 1 must be an object');
|
|
|
|
assertThrows(() => new Instance(importingModule, null), TypeError);
|
|
|
|
assertThrows(
|
|
|
|
() => new Instance(importingModule, undefined), TypeError);
|
|
|
|
assertThrows(
|
|
|
|
() => new Instance(importingModule, {'': {g: () => {}}}), LinkError);
|
|
|
|
assertThrows(
|
|
|
|
() => new Instance(importingModule, {t: {f: () => {}}}), TypeError);
|
2017-01-13 20:47:44 +00:00
|
|
|
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(new Instance(emptyModule) instanceof Instance);
|
|
|
|
assertTrue(new Instance(emptyModule, {}) instanceof Instance);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Instance.prototype' data property
|
|
|
|
let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof instanceProtoDesc.value, 'object');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertFalse(instanceProtoDesc.writable);
|
|
|
|
assertFalse(instanceProtoDesc.enumerable);
|
|
|
|
assertFalse(instanceProtoDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Instance.prototype' object
|
|
|
|
let instanceProto = Instance.prototype;
|
|
|
|
assertEq(instanceProto, instanceProtoDesc.value);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(String(instanceProto), '[object WebAssembly.Instance]');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Object.getPrototypeOf(instanceProto), Object.prototype);
|
|
|
|
|
|
|
|
// 'WebAssembly.Instance' instance objects
|
|
|
|
let exportingInstance = new Instance(exportingModule);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof exportingInstance, 'object');
|
|
|
|
assertEq(String(exportingInstance), '[object WebAssembly.Instance]');
|
2017-01-16 15:31:40 +00:00
|
|
|
assertEq(Object.getPrototypeOf(exportingInstance), instanceProto);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2017-08-03 16:13:47 +00:00
|
|
|
// 'WebAssembly.Instance' 'exports' getter property
|
2017-04-06 09:49:38 +00:00
|
|
|
let instanceExportsDesc =
|
2017-08-03 16:13:47 +00:00
|
|
|
Object.getOwnPropertyDescriptor(instanceProto, 'exports');
|
|
|
|
assertEq(typeof instanceExportsDesc.get, 'function');
|
2019-11-29 14:17:27 +00:00
|
|
|
assertEq(instanceExportsDesc.get.name, 'get exports');
|
|
|
|
assertEq(instanceExportsDesc.get.length, 0);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(instanceExportsDesc.get));
|
2019-11-29 14:17:27 +00:00
|
|
|
assertFalse('prototype' in instanceExportsDesc.get);
|
2017-08-03 16:13:47 +00:00
|
|
|
assertEq(instanceExportsDesc.set, undefined);
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(instanceExportsDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(instanceExportsDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2017-01-24 19:00:36 +00:00
|
|
|
exportsObj = exportingInstance.exports;
|
|
|
|
assertEq(typeof exportsObj, 'object');
|
|
|
|
assertFalse(Object.isExtensible(exportsObj));
|
|
|
|
assertEq(Object.getPrototypeOf(exportsObj), null);
|
|
|
|
assertEq(Object.keys(exportsObj).join(), 'f');
|
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
// Exported WebAssembly functions
|
|
|
|
let f = exportingInstance.exports.f;
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(f instanceof Function);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(f.length, 0);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue('name' in f);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Function.prototype.call.call(f), 42);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(() => new f(), TypeError, /is not a constructor/);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Memory' data property
|
|
|
|
let memoryDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Memory');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof memoryDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(memoryDesc.writable);
|
|
|
|
assertFalse(memoryDesc.enumerable);
|
|
|
|
assertTrue(memoryDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Memory' constructor function
|
|
|
|
let Memory = WebAssembly.Memory;
|
|
|
|
assertEq(Memory, memoryDesc.value);
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(Memory.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(Memory.name, 'Memory');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertTrue(isConstructor(Memory));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => Memory(), TypeError, /must be invoked with 'new'/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Memory(1), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
'WebAssembly.Memory(): Argument 0 must be a memory descriptor');
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Memory({initial: {valueOf() { throw new Error('here') }}}), Error,
|
|
|
|
'here');
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => new Memory({initial: -1}), TypeError, /must be non-negative/);
|
|
|
|
assertThrows(
|
2018-12-08 09:58:18 +00:00
|
|
|
() => new Memory({initial: Math.pow(2, 32)}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be in the unsigned long range/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Memory({initial: 1, maximum: Math.pow(2, 32) / Math.pow(2, 14)}),
|
2019-03-01 15:09:12 +00:00
|
|
|
RangeError, /is above the upper bound/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Memory({initial: 2, maximum: 1}), RangeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/is below the lower bound/);
|
|
|
|
assertThrows(
|
|
|
|
() => new Memory({maximum: -1}), TypeError, /'initial' is required/);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(new Memory({initial: 1}) instanceof Memory);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(new Memory({initial: 1.5}).buffer.byteLength, kPageSize);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Memory.prototype' data property
|
|
|
|
let memoryProtoDesc = Object.getOwnPropertyDescriptor(Memory, 'prototype');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof memoryProtoDesc.value, 'object');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertFalse(memoryProtoDesc.writable);
|
|
|
|
assertFalse(memoryProtoDesc.enumerable);
|
|
|
|
assertFalse(memoryProtoDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Memory.prototype' object
|
|
|
|
let memoryProto = Memory.prototype;
|
|
|
|
assertEq(memoryProto, memoryProtoDesc.value);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(String(memoryProto), '[object WebAssembly.Memory]');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Object.getPrototypeOf(memoryProto), Object.prototype);
|
|
|
|
|
|
|
|
// 'WebAssembly.Memory' instance objects
|
2017-04-06 09:49:38 +00:00
|
|
|
let mem1 = new Memory({initial: 1});
|
|
|
|
assertEq(typeof mem1, 'object');
|
|
|
|
assertEq(String(mem1), '[object WebAssembly.Memory]');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Object.getPrototypeOf(mem1), memoryProto);
|
|
|
|
|
|
|
|
// 'WebAssembly.Memory.prototype.buffer' accessor property
|
|
|
|
let bufferDesc = Object.getOwnPropertyDescriptor(memoryProto, 'buffer');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof bufferDesc.get, 'function');
|
2019-11-29 14:17:27 +00:00
|
|
|
assertEq(bufferDesc.get.name, 'get buffer');
|
|
|
|
assertEq(bufferDesc.get.length, 0);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(bufferDesc.get));
|
2019-11-29 14:17:27 +00:00
|
|
|
assertFalse('prototype' in bufferDesc.get);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(bufferDesc.set, undefined);
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(bufferDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(bufferDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Memory.prototype.buffer' getter
|
|
|
|
let bufferGetter = bufferDesc.get;
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => bufferGetter.call(), TypeError, /Receiver is not a WebAssembly.Memory/);
|
|
|
|
assertThrows(
|
|
|
|
() => bufferGetter.call({}), TypeError, /Receiver is not a WebAssembly.Memory/);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(bufferGetter.call(mem1) instanceof ArrayBuffer);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(bufferGetter.call(mem1).byteLength, kPageSize);
|
|
|
|
|
|
|
|
// 'WebAssembly.Memory.prototype.grow' data property
|
|
|
|
let memGrowDesc = Object.getOwnPropertyDescriptor(memoryProto, 'grow');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof memGrowDesc.value, 'function');
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(memGrowDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(memGrowDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Memory.prototype.grow' method
|
|
|
|
let memGrow = memGrowDesc.value;
|
|
|
|
assertEq(memGrow.length, 1);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(memGrow));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => memGrow.call(), TypeError, /Receiver is not a WebAssembly.Memory/);
|
|
|
|
assertThrows(
|
|
|
|
() => memGrow.call({}), TypeError, /Receiver is not a WebAssembly.Memory/);
|
|
|
|
assertThrows(
|
2018-11-28 17:39:02 +00:00
|
|
|
() => memGrow.call(mem1, -1), TypeError, /must be non-negative/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2018-11-28 17:39:02 +00:00
|
|
|
() => memGrow.call(mem1, Math.pow(2, 32)), TypeError,
|
|
|
|
/must be in the unsigned long range/);
|
2017-04-06 09:49:38 +00:00
|
|
|
var mem = new Memory({initial: 1, maximum: 2});
|
2016-12-19 17:19:56 +00:00
|
|
|
var buf = mem.buffer;
|
|
|
|
assertEq(buf.byteLength, kPageSize);
|
|
|
|
assertEq(mem.grow(0), 1);
|
2017-01-26 22:15:59 +00:00
|
|
|
assertTrue(buf !== mem.buffer);
|
|
|
|
assertEq(buf.byteLength, 0);
|
2016-12-19 17:19:56 +00:00
|
|
|
buf = mem.buffer;
|
|
|
|
assertEq(buf.byteLength, kPageSize);
|
2017-10-06 14:09:29 +00:00
|
|
|
assertEq(mem.grow(1, 23), 1);
|
|
|
|
assertTrue(buf !== mem.buffer);
|
|
|
|
assertEq(buf.byteLength, 0);
|
|
|
|
buf = mem.buffer;
|
|
|
|
assertEq(buf.byteLength, 2 * kPageSize);
|
2018-11-28 17:39:02 +00:00
|
|
|
assertEq(mem.grow(0), 2);
|
2017-01-26 22:15:59 +00:00
|
|
|
assertTrue(buf !== mem.buffer);
|
|
|
|
assertEq(buf.byteLength, 0);
|
2016-12-19 17:19:56 +00:00
|
|
|
buf = mem.buffer;
|
|
|
|
assertEq(buf.byteLength, 2 * kPageSize);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(() => mem.grow(1), Error, /Maximum memory size exceeded/);
|
|
|
|
assertThrows(() => mem.grow(Infinity), Error, /must be convertible to a valid number/);
|
|
|
|
assertThrows(() => mem.grow(-Infinity), Error, /must be convertible to a valid number/);
|
2017-10-06 14:09:29 +00:00
|
|
|
assertEq(buf, mem.buffer);
|
|
|
|
let throwOnValueOf = {
|
|
|
|
valueOf: function() {
|
|
|
|
throw Error('throwOnValueOf')
|
|
|
|
}
|
|
|
|
};
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(() => mem.grow(throwOnValueOf), Error, /throwOnValueOf/);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(buf, mem.buffer);
|
2017-10-06 14:09:29 +00:00
|
|
|
let zero_wrapper = {
|
|
|
|
valueOf: function() {
|
|
|
|
++this.call_counter;
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
call_counter: 0
|
|
|
|
};
|
|
|
|
assertEq(mem.grow(zero_wrapper), 2);
|
|
|
|
assertEq(zero_wrapper.call_counter, 1);
|
|
|
|
assertTrue(buf !== mem.buffer);
|
|
|
|
assertEq(buf.byteLength, 0);
|
|
|
|
buf = mem.buffer;
|
|
|
|
assertEq(buf.byteLength, 2 * kPageSize);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2017-08-02 17:30:58 +00:00
|
|
|
let empty_mem = new Memory({initial: 0, maximum: 5});
|
|
|
|
let empty_buf = empty_mem.buffer;
|
|
|
|
assertEq(empty_buf.byteLength, 0);
|
|
|
|
assertEq(empty_mem.grow(0), 0);
|
|
|
|
assertEq(empty_mem.buffer.byteLength, 0);
|
|
|
|
assertTrue(empty_buf !== empty_mem.buffer);
|
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
// 'WebAssembly.Table' data property
|
|
|
|
let tableDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Table');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof tableDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(tableDesc.writable);
|
|
|
|
assertFalse(tableDesc.enumerable);
|
|
|
|
assertTrue(tableDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table' constructor function
|
|
|
|
let Table = WebAssembly.Table;
|
|
|
|
assertEq(Table, tableDesc.value);
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(Table.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(Table.name, 'Table');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertTrue(isConstructor(Table));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => Table(), TypeError, /must be invoked with 'new'/);
|
|
|
|
assertThrows(
|
2021-02-01 12:13:06 +00:00
|
|
|
() => new Table(1), TypeError, 'WebAssembly.Table(): Argument 0 must be a table descriptor');
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2020-06-16 13:53:59 +00:00
|
|
|
() => new Table({initial: 1, element: 1}), TypeError, /must be a WebAssembly reference type/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Table({initial: 1, element: 'any'}), TypeError,
|
2020-06-16 13:53:59 +00:00
|
|
|
/must be a WebAssembly reference type/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Table({initial: 1, element: {valueOf() { return 'anyfunc' }}}),
|
2020-06-16 13:53:59 +00:00
|
|
|
TypeError, /must be a WebAssembly reference type/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Table(
|
|
|
|
{initial: {valueOf() { throw new Error('here') }}, element: 'anyfunc'}),
|
|
|
|
Error, 'here');
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2018-12-08 09:58:18 +00:00
|
|
|
() => new Table({initial: -1, element: 'anyfunc'}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be non-negative/);
|
|
|
|
assertThrows(
|
2018-12-08 09:58:18 +00:00
|
|
|
() => new Table({initial: Math.pow(2, 32), element: 'anyfunc'}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be in the unsigned long range/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Table({initial: 2, maximum: 1, element: 'anyfunc'}), RangeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/is below the lower bound/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => new Table({initial: 2, maximum: Math.pow(2, 32), element: 'anyfunc'}),
|
2019-03-01 15:09:12 +00:00
|
|
|
TypeError, /must be in the unsigned long range/);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(new Table({initial: 1, element: 'anyfunc'}) instanceof Table);
|
|
|
|
assertTrue(new Table({initial: 1.5, element: 'anyfunc'}) instanceof Table);
|
|
|
|
assertTrue(
|
|
|
|
new Table({initial: 1, maximum: 1.5, element: 'anyfunc'}) instanceof Table);
|
2020-08-06 10:14:12 +00:00
|
|
|
assertTrue(
|
|
|
|
new Table({initial: 1, maximum: Math.pow(2, 32) - 1, element: 'anyfunc'})
|
|
|
|
instanceof Table);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype' data property
|
|
|
|
let tableProtoDesc = Object.getOwnPropertyDescriptor(Table, 'prototype');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof tableProtoDesc.value, 'object');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertFalse(tableProtoDesc.writable);
|
|
|
|
assertFalse(tableProtoDesc.enumerable);
|
|
|
|
assertFalse(tableProtoDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype' object
|
|
|
|
let tableProto = Table.prototype;
|
|
|
|
assertEq(tableProto, tableProtoDesc.value);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(String(tableProto), '[object WebAssembly.Table]');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Object.getPrototypeOf(tableProto), Object.prototype);
|
|
|
|
|
|
|
|
// 'WebAssembly.Table' instance objects
|
2017-04-06 09:49:38 +00:00
|
|
|
let tbl1 = new Table({initial: 2, element: 'anyfunc'});
|
|
|
|
assertEq(typeof tbl1, 'object');
|
|
|
|
assertEq(String(tbl1), '[object WebAssembly.Table]');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(Object.getPrototypeOf(tbl1), tableProto);
|
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.length' accessor data property
|
|
|
|
let lengthDesc = Object.getOwnPropertyDescriptor(tableProto, 'length');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof lengthDesc.get, 'function');
|
2019-11-29 14:17:27 +00:00
|
|
|
assertEq(lengthDesc.get.name, 'get length');
|
|
|
|
assertEq(lengthDesc.get.length, 0);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(lengthDesc.get));
|
2019-11-29 14:17:27 +00:00
|
|
|
assertFalse('prototype' in lengthDesc.get);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(lengthDesc.set, undefined);
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(lengthDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(lengthDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.length' getter
|
|
|
|
let lengthGetter = lengthDesc.get;
|
|
|
|
assertEq(lengthGetter.length, 0);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => lengthGetter.call(), TypeError, /Receiver is not a WebAssembly.Table/);
|
|
|
|
assertThrows(
|
|
|
|
() => lengthGetter.call({}), TypeError, /Receiver is not a WebAssembly.Table/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof lengthGetter.call(tbl1), 'number');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(lengthGetter.call(tbl1), 2);
|
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.get' data property
|
|
|
|
let getDesc = Object.getOwnPropertyDescriptor(tableProto, 'get');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof getDesc.value, 'function');
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(getDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(getDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.get' method
|
|
|
|
let get = getDesc.value;
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(get.length, 1);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(get));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => get.call(), TypeError, /Receiver is not a WebAssembly.Table/);
|
|
|
|
assertThrows(
|
|
|
|
() => get.call({}), TypeError, /Receiver is not a WebAssembly.Table/);
|
|
|
|
assertThrows(
|
2019-01-16 14:07:49 +00:00
|
|
|
() => get.call(tbl1), TypeError, /must be convertible to a valid number/);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(get.call(tbl1, 0), null);
|
2017-10-06 14:09:29 +00:00
|
|
|
assertEq(get.call(tbl1, 0, Infinity), null);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(get.call(tbl1, 1), null);
|
|
|
|
assertEq(get.call(tbl1, 1.5), null);
|
2019-03-12 15:45:13 +00:00
|
|
|
assertThrows(() => get.call(tbl1, 2), RangeError, /invalid index \d+ into function table/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2019-03-12 15:45:13 +00:00
|
|
|
() => get.call(tbl1, 2.5), RangeError, /invalid index \d+ into function table/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(() => get.call(tbl1, -1), TypeError, /must be non-negative/);
|
|
|
|
assertThrows(
|
|
|
|
() => get.call(tbl1, Math.pow(2, 33)), TypeError,
|
|
|
|
/must be in the unsigned long range/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => get.call(tbl1, {valueOf() { throw new Error('hi') }}), Error, 'hi');
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.set' data property
|
|
|
|
let setDesc = Object.getOwnPropertyDescriptor(tableProto, 'set');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof setDesc.value, 'function');
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(setDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(setDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.set' method
|
|
|
|
let set = setDesc.value;
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(set.length, 2);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(set));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => set.call(), TypeError, /Receiver is not a WebAssembly.Table/);
|
|
|
|
assertThrows(
|
|
|
|
() => set.call({}), TypeError, /Receiver is not a WebAssembly.Table/);
|
|
|
|
assertThrows(
|
|
|
|
() => set.call(tbl1, 0), TypeError, /must be null or a WebAssembly function/);
|
|
|
|
assertThrows(
|
2017-10-06 14:09:29 +00:00
|
|
|
() => set.call(tbl1, undefined), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be convertible to a valid number/);
|
|
|
|
assertThrows(
|
2019-03-12 15:45:13 +00:00
|
|
|
() => set.call(tbl1, 2, null), RangeError, /invalid index \d+ into function table/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => set.call(tbl1, -1, null), TypeError, /must be non-negative/);
|
|
|
|
assertThrows(
|
2019-01-16 14:07:49 +00:00
|
|
|
() => set.call(tbl1, Math.pow(2, 33), null), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be in the unsigned long range/);
|
|
|
|
assertThrows(
|
|
|
|
() => set.call(tbl1, Infinity, null), TypeError,
|
|
|
|
/must be convertible to a valid number/);
|
|
|
|
assertThrows(
|
|
|
|
() => set.call(tbl1, -Infinity, null), TypeError,
|
|
|
|
/must be convertible to a valid number/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => set.call(tbl1, 0, undefined), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be null or a WebAssembly function/);
|
|
|
|
assertThrows(
|
2017-10-06 14:09:29 +00:00
|
|
|
() => set.call(tbl1, undefined, undefined), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be convertible to a valid number/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => set.call(tbl1, 0, {}), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be null or a WebAssembly function/);
|
|
|
|
assertThrows(() => set.call(tbl1, 0, function() {
|
|
|
|
}), TypeError, /must be null or a WebAssembly function/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => set.call(tbl1, 0, Math.sin), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be null or a WebAssembly function/);
|
|
|
|
assertThrows(
|
2017-04-06 09:49:38 +00:00
|
|
|
() => set.call(tbl1, {valueOf() { throw Error('hai') }}, null), Error,
|
|
|
|
'hai');
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(set.call(tbl1, 0, null), undefined);
|
|
|
|
assertEq(set.call(tbl1, 1, null), undefined);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
2019-01-16 14:07:49 +00:00
|
|
|
() => set.call(tbl1, undefined, null), TypeError,
|
|
|
|
/must be convertible to a valid number/);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.grow' data property
|
|
|
|
let tblGrowDesc = Object.getOwnPropertyDescriptor(tableProto, 'grow');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof tblGrowDesc.value, 'function');
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(tblGrowDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(tblGrowDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.Table.prototype.grow' method
|
|
|
|
let tblGrow = tblGrowDesc.value;
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(tblGrow.length, 1);
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(tblGrow));
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => tblGrow.call(), TypeError, /Receiver is not a WebAssembly.Table/);
|
|
|
|
assertThrows(
|
|
|
|
() => tblGrow.call({}), TypeError, /Receiver is not a WebAssembly.Table/);
|
|
|
|
assertThrows(
|
|
|
|
() => tblGrow.call(tbl1, -1), TypeError, /must be non-negative/);
|
|
|
|
assertThrows(
|
2018-12-19 15:11:06 +00:00
|
|
|
() => tblGrow.call(tbl1, Math.pow(2, 32)), TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/must be in the unsigned long range/);
|
2017-04-06 09:49:38 +00:00
|
|
|
var tbl = new Table({element: 'anyfunc', initial: 1, maximum: 2});
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(tbl.length, 1);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => tbl.grow(Infinity), TypeError, /must be convertible to a valid number/);
|
|
|
|
assertThrows(
|
|
|
|
() => tbl.grow(-Infinity), TypeError, /must be convertible to a valid number/);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(tbl.grow(0), 1);
|
|
|
|
assertEq(tbl.length, 1);
|
2017-10-06 14:09:29 +00:00
|
|
|
assertEq(tbl.grow(1, 4), 1);
|
|
|
|
assertEq(tbl.length, 2);
|
2016-12-19 17:19:56 +00:00
|
|
|
assertEq(tbl.length, 2);
|
2019-04-29 15:42:33 +00:00
|
|
|
assertThrows(() => tbl.grow(1), Error, /failed to grow table by \d+/);
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(
|
|
|
|
() => tbl.grow(Infinity), TypeError, /must be convertible to a valid number/);
|
|
|
|
assertThrows(
|
|
|
|
() => tbl.grow(-Infinity), TypeError, /must be convertible to a valid number/);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
2017-01-11 00:25:09 +00:00
|
|
|
// 'WebAssembly.validate' function
|
2019-03-01 15:09:12 +00:00
|
|
|
assertThrows(() => WebAssembly.validate(), TypeError);
|
|
|
|
assertThrows(() => WebAssembly.validate('hi'), TypeError);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(WebAssembly.validate(emptyModuleBinary));
|
2017-01-11 00:25:09 +00:00
|
|
|
// TODO: other ways for validate to return false.
|
2017-01-20 18:46:44 +00:00
|
|
|
assertFalse(WebAssembly.validate(moduleBinaryImporting2Memories));
|
|
|
|
assertFalse(WebAssembly.validate(moduleBinaryWithMemSectionAndMemImport));
|
2017-01-11 00:25:09 +00:00
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
// 'WebAssembly.compile' data property
|
|
|
|
let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile');
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(typeof compileDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(compileDesc.writable);
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(compileDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(compileDesc.configurable);
|
2016-12-19 17:19:56 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.compile' function
|
|
|
|
let compile = WebAssembly.compile;
|
|
|
|
assertEq(compile, compileDesc.value);
|
2016-12-21 09:03:35 +00:00
|
|
|
assertEq(compile.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(compile.name, 'compile');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(compile));
|
2016-12-19 17:19:56 +00:00
|
|
|
function assertCompileError(args, err, msg) {
|
2019-02-06 13:09:43 +00:00
|
|
|
assertThrowsAsync(compile(...args), err /* TODO , msg */);
|
2016-12-19 17:19:56 +00:00
|
|
|
}
|
|
|
|
assertCompileError([], TypeError, /requires more than 0 arguments/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertCompileError(
|
|
|
|
[undefined], TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a buffer source/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertCompileError(
|
|
|
|
[1], TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a buffer source/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertCompileError(
|
|
|
|
[{}], TypeError,
|
2019-03-01 15:09:12 +00:00
|
|
|
/Argument 0 must be a buffer source/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertCompileError(
|
|
|
|
[new Uint8Array()], CompileError, /BufferSource argument is empty/);
|
|
|
|
assertCompileError(
|
|
|
|
[new ArrayBuffer()], CompileError, /BufferSource argument is empty/);
|
|
|
|
assertCompileError(
|
|
|
|
[new Uint8Array('hi!')], CompileError, /failed to match magic number/);
|
|
|
|
assertCompileError(
|
|
|
|
[new ArrayBuffer('hi!')], CompileError, /failed to match magic number/);
|
2017-01-12 21:30:39 +00:00
|
|
|
|
2016-12-19 17:19:56 +00:00
|
|
|
function assertCompileSuccess(bytes) {
|
2017-04-06 09:49:38 +00:00
|
|
|
var module = null;
|
2017-10-25 14:12:49 +00:00
|
|
|
assertPromiseResult(compile(bytes), m => assertTrue(m instanceof Module));
|
2016-12-19 17:19:56 +00:00
|
|
|
}
|
|
|
|
assertCompileSuccess(emptyModuleBinary);
|
|
|
|
assertCompileSuccess(emptyModuleBinary.buffer);
|
|
|
|
|
2017-01-13 20:47:44 +00:00
|
|
|
// 'WebAssembly.instantiate' data property
|
2017-04-06 09:49:38 +00:00
|
|
|
let instantiateDesc =
|
|
|
|
Object.getOwnPropertyDescriptor(WebAssembly, 'instantiate');
|
|
|
|
assertEq(typeof instantiateDesc.value, 'function');
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(instantiateDesc.writable);
|
2018-12-05 13:37:51 +00:00
|
|
|
assertTrue(instantiateDesc.enumerable);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertTrue(instantiateDesc.configurable);
|
2017-01-13 20:47:44 +00:00
|
|
|
|
|
|
|
// 'WebAssembly.instantiate' function
|
|
|
|
let instantiate = WebAssembly.instantiate;
|
|
|
|
assertEq(instantiate, instantiateDesc.value);
|
|
|
|
assertEq(instantiate.length, 1);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertEq(instantiate.name, 'instantiate');
|
2019-12-04 12:59:36 +00:00
|
|
|
assertFalse(isConstructor(instantiate));
|
2017-01-13 20:47:44 +00:00
|
|
|
function assertInstantiateError(args, err, msg) {
|
2019-02-06 13:09:43 +00:00
|
|
|
assertThrowsAsync(instantiate(...args), err /* TODO , msg */);
|
2017-01-13 20:47:44 +00:00
|
|
|
}
|
2018-12-08 09:58:18 +00:00
|
|
|
var scratch_memory = new WebAssembly.Memory({ initial: 0 });
|
2017-01-13 20:47:44 +00:00
|
|
|
assertInstantiateError([], TypeError, /requires more than 0 arguments/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertInstantiateError(
|
|
|
|
[undefined], TypeError, /first argument must be a BufferSource/);
|
2017-01-13 20:47:44 +00:00
|
|
|
assertInstantiateError([1], TypeError, /first argument must be a BufferSource/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertInstantiateError(
|
|
|
|
[{}], TypeError, /first argument must be a BufferSource/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[new Uint8Array()], CompileError, /failed to match magic number/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[new ArrayBuffer()], CompileError, /failed to match magic number/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[new Uint8Array('hi!')], CompileError, /failed to match magic number/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[new ArrayBuffer('hi!')], CompileError, /failed to match magic number/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[importingModule], TypeError, /second argument must be an object/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[importingModule, null], TypeError, /second argument must be an object/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[importingModuleBinary, null], TypeError,
|
|
|
|
/second argument must be an object/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[emptyModule, null], TypeError, /first argument must be a BufferSource/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[importingModuleBinary, null], TypeError, /TODO: error messages?/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[importingModuleBinary, undefined], TypeError, /TODO: error messages?/);
|
|
|
|
assertInstantiateError(
|
2017-04-11 20:09:20 +00:00
|
|
|
[importingModuleBinary, {}], TypeError, /TODO: error messages?/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertInstantiateError(
|
|
|
|
[importingModuleBinary, {'': {g: () => {}}}], LinkError,
|
|
|
|
/TODO: error messages?/);
|
|
|
|
assertInstantiateError(
|
2017-04-11 20:09:20 +00:00
|
|
|
[importingModuleBinary, {t: {f: () => {}}}], TypeError,
|
2017-04-06 09:49:38 +00:00
|
|
|
/TODO: error messages?/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[memoryImportingModuleBinary, null], TypeError, /TODO: error messages?/);
|
|
|
|
assertInstantiateError(
|
|
|
|
[memoryImportingModuleBinary, undefined], TypeError,
|
|
|
|
/TODO: error messages?/);
|
|
|
|
assertInstantiateError(
|
2017-04-11 20:09:20 +00:00
|
|
|
[memoryImportingModuleBinary, {}], TypeError, /TODO: error messages?/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertInstantiateError(
|
|
|
|
[memoryImportingModuleBinary, {'mod': {'my_memory': scratch_memory}}],
|
2017-04-11 20:09:20 +00:00
|
|
|
TypeError, /TODO: error messages?/);
|
2017-04-06 09:49:38 +00:00
|
|
|
assertInstantiateError(
|
|
|
|
[memoryImportingModuleBinary, {'': {'memory': scratch_memory}}], LinkError,
|
|
|
|
/TODO: error messages?/);
|
2017-01-13 20:47:44 +00:00
|
|
|
|
2017-01-20 18:46:44 +00:00
|
|
|
function assertInstantiateSuccess(module_or_bytes, imports) {
|
2017-01-13 20:47:44 +00:00
|
|
|
var result = null;
|
2017-10-25 14:12:49 +00:00
|
|
|
assertPromiseResult(instantiate(module_or_bytes, imports), result => {
|
|
|
|
if (module_or_bytes instanceof Module) {
|
|
|
|
assertTrue(result instanceof Instance);
|
|
|
|
} else {
|
|
|
|
assertTrue(result.module instanceof Module);
|
|
|
|
assertTrue(result.instance instanceof Instance);
|
|
|
|
}
|
|
|
|
});
|
2016-12-19 17:19:56 +00:00
|
|
|
}
|
2017-01-20 18:46:44 +00:00
|
|
|
assertInstantiateSuccess(emptyModule);
|
2017-01-13 20:47:44 +00:00
|
|
|
assertInstantiateSuccess(emptyModuleBinary);
|
|
|
|
assertInstantiateSuccess(emptyModuleBinary.buffer);
|
2017-01-20 18:46:44 +00:00
|
|
|
assertInstantiateSuccess(importingModule, {'': {f: () => {}}});
|
2017-04-06 09:49:38 +00:00
|
|
|
assertInstantiateSuccess(importingModuleBinary, {'': {f: () => {}}});
|
|
|
|
assertInstantiateSuccess(importingModuleBinary.buffer, {'': {f: () => {}}});
|
|
|
|
assertInstantiateSuccess(
|
|
|
|
memoryImportingModuleBinary, {'': {'my_memory': scratch_memory}});
|
2017-10-23 12:24:53 +00:00
|
|
|
|
|
|
|
(function TestSubclassing() {
|
|
|
|
class M extends WebAssembly.Module { }
|
|
|
|
assertThrows(() => new M());
|
|
|
|
|
|
|
|
class I extends WebAssembly.Instance { }
|
|
|
|
assertThrows(() => new I());
|
|
|
|
|
|
|
|
class T extends WebAssembly.Table { }
|
|
|
|
assertThrows(() => new T());
|
|
|
|
|
|
|
|
class Y extends WebAssembly.Memory { }
|
|
|
|
assertThrows(() => new Y());
|
|
|
|
})();
|
2017-11-18 23:20:09 +00:00
|
|
|
|
|
|
|
(function TestCallWithoutNew() {
|
|
|
|
var bytes = Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x1, 0x00, 0x00, 0x00);
|
|
|
|
assertThrows(() => WebAssembly.Module(bytes), TypeError);
|
|
|
|
assertThrows(() => WebAssembly.Instance(new WebAssembly.Module(bytes)),
|
|
|
|
TypeError);
|
|
|
|
assertThrows(() => WebAssembly.Table({size: 10, element: 'anyfunc'}),
|
|
|
|
TypeError);
|
|
|
|
assertThrows(() => WebAssembly.Memory({size: 10}), TypeError);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestTinyModule() {
|
|
|
|
var bytes = Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x1, 0x00, 0x00, 0x00);
|
|
|
|
var module = new WebAssembly.Module(bytes);
|
|
|
|
assertTrue(module instanceof Module);
|
|
|
|
var instance = new WebAssembly.Instance(module);
|
|
|
|
assertTrue(instance instanceof Instance);
|
|
|
|
})();
|
2018-12-19 15:50:34 +00:00
|
|
|
|
2019-11-29 14:17:27 +00:00
|
|
|
(function TestAccessorFunctions() {
|
|
|
|
function testAccessorFunction(obj, prop, accessor) {
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(obj, prop);
|
|
|
|
assertSame('function', typeof desc[accessor]);
|
|
|
|
assertFalse(desc[accessor].hasOwnProperty('prototype'));
|
|
|
|
assertFalse(isConstructor(desc[accessor]));
|
|
|
|
}
|
|
|
|
testAccessorFunction(WebAssembly.Global.prototype, "value", "get");
|
|
|
|
testAccessorFunction(WebAssembly.Global.prototype, "value", "set");
|
|
|
|
testAccessorFunction(WebAssembly.Instance.prototype, "exports", "get");
|
|
|
|
testAccessorFunction(WebAssembly.Memory.prototype, "buffer", "get");
|
|
|
|
testAccessorFunction(WebAssembly.Table.prototype, "length", "get");
|
|
|
|
})();
|