From 6e8338865a39dceafdfd4654f39c05fc5f760c44 Mon Sep 17 00:00:00 2001 From: titzer Date: Tue, 20 Dec 2016 07:32:56 -0800 Subject: [PATCH] [wasm] Implement correct 2-level namespace for imports. R=clemensh@chromium.org CC=rossberg@chromium.org BUG=chromium:575167 Review-Url: https://codereview.chromium.org/2591753002 Cr-Commit-Position: refs/heads/master@{#41866} --- src/asmjs/asm-js.cc | 12 +++- src/runtime/runtime-compiler.cc | 4 +- src/wasm/module-decoder.cc | 3 - src/wasm/wasm-module-builder.cc | 6 +- src/wasm/wasm-module.cc | 23 +++---- test/debugger/debug/wasm/frame-inspection.js | 4 +- test/inspector/debugger/wasm-source.js | 4 +- test/inspector/debugger/wasm-stack.js | 4 +- .../wasm/compiled-module-management.js | 10 ++-- .../wasm/compiled-module-serialization.js | 8 +-- test/mjsunit/wasm/data-segments.js | 4 +- test/mjsunit/wasm/errors.js | 8 +-- test/mjsunit/wasm/exceptions.js | 14 ++--- test/mjsunit/wasm/export-table.js | 10 ++-- test/mjsunit/wasm/ffi-error.js | 13 ++-- test/mjsunit/wasm/ffi.js | 60 +++++++++---------- test/mjsunit/wasm/gc-buffer.js | 4 +- test/mjsunit/wasm/gc-frame.js | 4 +- test/mjsunit/wasm/gc-stress.js | 4 +- test/mjsunit/wasm/globals.js | 12 ++-- test/mjsunit/wasm/import-memory.js | 47 +++++++-------- test/mjsunit/wasm/import-table.js | 26 ++++---- test/mjsunit/wasm/indirect-calls.js | 12 ++-- test/mjsunit/wasm/indirect-tables.js | 40 ++++++------- .../mjsunit/wasm/instance-memory-gc-stress.js | 6 +- test/mjsunit/wasm/instantiate-module-basic.js | 14 +++-- test/mjsunit/wasm/js-api.js | 2 +- .../wasm/memory-instance-validation.js | 6 +- test/mjsunit/wasm/receiver.js | 4 +- test/mjsunit/wasm/stack.js | 4 +- test/mjsunit/wasm/stackwalk.js | 4 +- test/mjsunit/wasm/start-function.js | 6 +- test/mjsunit/wasm/table.js | 6 +- .../wasm/test-import-export-wrapper.js | 20 +++---- test/mjsunit/wasm/test-wasm-module-builder.js | 6 +- test/mjsunit/wasm/unicode-validation.js | 2 +- test/mjsunit/wasm/wasm-module-builder.js | 12 ++-- 37 files changed, 212 insertions(+), 216 deletions(-) diff --git a/src/asmjs/asm-js.cc b/src/asmjs/asm-js.cc index 4683d6d53d..c2f76952bb 100644 --- a/src/asmjs/asm-js.cc +++ b/src/asmjs/asm-js.cc @@ -257,8 +257,18 @@ MaybeHandle AsmJs::InstantiateAsmWasm(i::Isolate* isolate, ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); + // Create the ffi object for foreign functions {"": foreign}. + Handle ffi_object; + if (!foreign.is_null()) { + Handle object_function = Handle( + isolate->native_context()->object_function(), isolate); + ffi_object = isolate->factory()->NewJSObject(object_function); + JSObject::AddProperty(ffi_object, isolate->factory()->empty_string(), + foreign, NONE); + } + i::MaybeHandle maybe_module_object = - i::wasm::WasmModule::Instantiate(isolate, &thrower, module, foreign, + i::wasm::WasmModule::Instantiate(isolate, &thrower, module, ffi_object, memory); if (maybe_module_object.is_null()) { return MaybeHandle(); diff --git a/src/runtime/runtime-compiler.cc b/src/runtime/runtime-compiler.cc index 710cdb3586..9dc9659b1b 100644 --- a/src/runtime/runtime-compiler.cc +++ b/src/runtime/runtime-compiler.cc @@ -92,11 +92,11 @@ RUNTIME_FUNCTION(Runtime_InstantiateAsmJs) { } Handle foreign; if (args[2]->IsJSObject()) { - foreign = args.at(2); + foreign = args.at(2); } Handle memory; if (args[3]->IsJSArrayBuffer()) { - memory = args.at(3); + memory = args.at(3); } if (function->shared()->HasAsmWasmData() && AsmJs::IsStdlibValid(isolate, handle(function->shared()->asm_wasm_data()), diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc index af3a3f666a..fb8087da14 100644 --- a/src/wasm/module-decoder.cc +++ b/src/wasm/module-decoder.cc @@ -280,9 +280,6 @@ class ModuleDecoder : public Decoder { const byte* pos = pc_; import->module_name_offset = consume_string(&import->module_name_length, true); - if (import->module_name_length == 0) { - error(pos, "import module name cannot be NULL"); - } import->field_name_offset = consume_string(&import->field_name_length, true); diff --git a/src/wasm/wasm-module-builder.cc b/src/wasm/wasm-module-builder.cc index bf9b4ef198..eb6956c237 100644 --- a/src/wasm/wasm-module-builder.cc +++ b/src/wasm/wasm-module-builder.cc @@ -328,10 +328,10 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const { size_t start = EmitSection(kImportSectionCode, buffer); buffer.write_size(imports_.size()); for (auto import : imports_) { - buffer.write_u32v(import.name_length); // module name length - buffer.write(reinterpret_cast(import.name), // module name + buffer.write_u32v(0); // module name length + buffer.write_u32v(import.name_length); // field name length + buffer.write(reinterpret_cast(import.name), // field name import.name_length); - buffer.write_u32v(0); // field name length buffer.write_u8(kExternalFunction); buffer.write_u32v(import.sig_index); } diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc index 8ec997e4fd..9a777b20c6 100644 --- a/src/wasm/wasm-module.cc +++ b/src/wasm/wasm-module.cc @@ -1462,21 +1462,16 @@ class WasmInstanceBuilder { Handle module = result.ToHandleChecked(); - // TODO(bradnelson): Making this conditional on non-empty names violates the - // Wasm spec, but seems to be a hack intended for the asm-to-wasm pipeline. - // We need to get rid of it. - if (import_name->length() != 0) { - // Look up the value in the module. - if (!module->IsJSReceiver()) { - return ReportTypeError("module is not an object or function", index, - module_name); - } + // Look up the value in the module. + if (!module->IsJSReceiver()) { + return ReportTypeError("module is not an object or function", index, + module_name); + } - result = Object::GetPropertyOrElement(module, import_name); - if (result.is_null()) { - ReportLinkError("import not found", index, module_name, import_name); - return MaybeHandle(); - } + result = Object::GetPropertyOrElement(module, import_name); + if (result.is_null()) { + ReportLinkError("import not found", index, module_name, import_name); + return MaybeHandle(); } return result; diff --git a/test/debugger/debug/wasm/frame-inspection.js b/test/debugger/debug/wasm/frame-inspection.js index 341589a813..45c0253aa6 100644 --- a/test/debugger/debug/wasm/frame-inspection.js +++ b/test/debugger/debug/wasm/frame-inspection.js @@ -48,7 +48,7 @@ var builder = new WasmModuleBuilder(); // wasm_1 calls wasm_2 on offset 2. // wasm_2 calls call_debugger on offset 1. -builder.addImport('func', kSig_v_v); +builder.addImport("mod", 'func', kSig_v_v); builder.addFunction('wasm_1', kSig_v_v) .addBody([kExprNop, kExprCallFunction, 2]) @@ -60,7 +60,7 @@ function call_debugger() { debugger; } -var module = builder.instantiate({func: call_debugger}); +var module = builder.instantiate({mod: {func: call_debugger}}); (function testFrameInspection() { Debug.setListener(listener); diff --git a/test/inspector/debugger/wasm-source.js b/test/inspector/debugger/wasm-source.js index 0a77c19ac4..6d9d044b30 100644 --- a/test/inspector/debugger/wasm-source.js +++ b/test/inspector/debugger/wasm-source.js @@ -9,7 +9,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); var builder = new WasmModuleBuilder(); -var imported_idx = builder.addImport("func", kSig_v_v); +var imported_idx = builder.addImport("xxx", "func", kSig_v_v); var call_imported_idx = builder.addFunction("call_func", kSig_v_v) .addBody([kExprCallFunction, imported_idx]) @@ -40,7 +40,7 @@ function testFunction(bytes) { } var module = new WebAssembly.Module(buffer); - var instance = new WebAssembly.Instance(module, {func: call_debugger}); + var instance = new WebAssembly.Instance(module, {xxx: {func: call_debugger}}); instance.exports.main(); } diff --git a/test/inspector/debugger/wasm-stack.js b/test/inspector/debugger/wasm-stack.js index 56186c9568..7ac360935b 100644 --- a/test/inspector/debugger/wasm-stack.js +++ b/test/inspector/debugger/wasm-stack.js @@ -9,7 +9,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); var builder = new WasmModuleBuilder(); -var imported_idx = builder.addImport("func", kSig_v_v); +var imported_idx = builder.addImport("mode", "func", kSig_v_v); var call_imported_idx = builder.addFunction('call_func', kSig_v_v) .addBody([kExprCallFunction, imported_idx]) @@ -35,7 +35,7 @@ function testFunction(bytes) { } var module = new WebAssembly.Module(buffer); - var instance = new WebAssembly.Instance(module, {func: call_debugger}); + var instance = new WebAssembly.Instance(module, {mode: {func: call_debugger}}); instance.exports.main(); } diff --git a/test/mjsunit/wasm/compiled-module-management.js b/test/mjsunit/wasm/compiled-module-management.js index 8c4c3b32af..80a19c3b6c 100644 --- a/test/mjsunit/wasm/compiled-module-management.js +++ b/test/mjsunit/wasm/compiled-module-management.js @@ -20,7 +20,7 @@ var instance4; var builder = new WasmModuleBuilder(); builder.addMemory(1,1, true); - builder.addImport("getValue", kSig_i_v); + builder.addImport("", "getValue", kSig_i_v); builder.addFunction("f", kSig_i_v) .addBody([ kExprCallFunction, 0 @@ -29,11 +29,11 @@ var instance4; module = new WebAssembly.Module(builder.toBuffer()); %ValidateWasmModuleState(module); %ValidateWasmInstancesChain(module, 0); - instance1 = new WebAssembly.Instance(module, {getValue: () => 1}); + instance1 = new WebAssembly.Instance(module, {"": {getValue: () => 1}}); %ValidateWasmInstancesChain(module, 1); - instance2 = new WebAssembly.Instance(module, {getValue: () => 2}); + instance2 = new WebAssembly.Instance(module, {"": {getValue: () => 2}}); %ValidateWasmInstancesChain(module, 2); - instance3 = new WebAssembly.Instance(module, {getValue: () => 3}); + instance3 = new WebAssembly.Instance(module, {"": {getValue: () => 3}}); %ValidateWasmInstancesChain(module, 3); })(); @@ -62,7 +62,7 @@ gc(); %ValidateWasmModuleState(module); (function CompiledModuleInstancesInitialize4AndClearModule() { - instance4 = new WebAssembly.Instance(module, {getValue: () => 4}); + instance4 = new WebAssembly.Instance(module, {"": {getValue: () => 4}}); assertEquals(4, instance4.exports.f()); module = null; })(); diff --git a/test/mjsunit/wasm/compiled-module-serialization.js b/test/mjsunit/wasm/compiled-module-serialization.js index eb6534d0a8..2ae198949f 100644 --- a/test/mjsunit/wasm/compiled-module-serialization.js +++ b/test/mjsunit/wasm/compiled-module-serialization.js @@ -12,8 +12,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); builder.addMemory(1,1, true); var kSig_v_i = makeSig([kAstI32], []); var signature = builder.addType(kSig_v_i); - builder.addImport("some_value", kSig_i_v); - builder.addImport("writer", signature); + builder.addImport("", "some_value", kSig_i_v); + builder.addImport("", "writer", signature); builder.addFunction("main", kSig_i_i) .addBody([ @@ -48,8 +48,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); view_1[0] = 42; var outval_1; - var i1 = new WebAssembly.Instance(module, {some_value: () => 1, - writer: (x)=>outval_1 = x }, mem_1); + var i1 = new WebAssembly.Instance(module, {"": {some_value: () => 1, + writer: (x)=>outval_1 = x }}, mem_1); assertEquals(43, i1.exports.main(0)); diff --git a/test/mjsunit/wasm/data-segments.js b/test/mjsunit/wasm/data-segments.js index 8cff5e1756..b215f20857 100644 --- a/test/mjsunit/wasm/data-segments.js +++ b/test/mjsunit/wasm/data-segments.js @@ -39,7 +39,7 @@ function GlobalImportedInitTest(pad) { while (pad-- > 0) builder.addGlobal(kAstI32); // pad - var g = builder.addImportedGlobal("offset", undefined, kAstI32); + var g = builder.addImportedGlobal("mod", "offset", kAstI32); while (pad-- > 0) builder.addGlobal(kAstI32); // pad @@ -52,7 +52,7 @@ function GlobalImportedInitTest(pad) { var module = new WebAssembly.Module(buffer); for (var offset of [0, 12, 192, 1024]) { - var instance = new WebAssembly.Instance(module, {offset: offset}); + var instance = new WebAssembly.Instance(module, {mod: {offset: offset}}); for (var i = offset - 20; i < offset + 20; i += 4) { if (i < 0) continue; var expected = i == offset ? 84215045 : 0; diff --git a/test/mjsunit/wasm/errors.js b/test/mjsunit/wasm/errors.js index cf3377fbda..725abe28df 100644 --- a/test/mjsunit/wasm/errors.js +++ b/test/mjsunit/wasm/errors.js @@ -71,13 +71,13 @@ function assertConversionError(bytes, imports = {}) { let b; b = builder(); - b.addImportWithModule("foo", "bar", kSig_v_v); + b.addImport("foo", "bar", kSig_v_v); assertTypeError(b.toBuffer(), {}); b = builder(); - b.addImportWithModule("foo", "bar", kSig_v_v); + b.addImport("foo", "bar", kSig_v_v); assertLinkError(b.toBuffer(), {foo: {}}); b = builder(); - b.addImportWithModule("foo", "bar", kSig_v_v); + b.addImport("foo", "bar", kSig_v_v); assertLinkError(b.toBuffer(), {foo: {bar: 9}}); b = builder(); @@ -132,7 +132,7 @@ function assertConversionError(bytes, imports = {}) { (function TestConversionError() { let b = builder(); - b.addImportWithModule("foo", "bar", kSig_v_l); + b.addImport("foo", "bar", kSig_v_l); assertConversionError(b.addFunction("run", kSig_v_v).addBody([ kExprI64Const, 0, kExprCallFunction, 0 ]).exportFunc().end().toBuffer()); diff --git a/test/mjsunit/wasm/exceptions.js b/test/mjsunit/wasm/exceptions.js index d02e34b9d0..ef44c877ce 100644 --- a/test/mjsunit/wasm/exceptions.js +++ b/test/mjsunit/wasm/exceptions.js @@ -79,32 +79,32 @@ var test_catch = (function () { throw value; } var sig_index = builder.addType(kSig_v_i); - var kJSThrowI = builder.addImport("throw_i", sig_index); + var kJSThrowI = builder.addImport("", "throw_i", sig_index); // Helper function that throws a string. Wasm should not catch it. function throw_string() { throw "use wasm;"; } sig_index = builder.addType(kSig_v_v); - var kJSThrowString = builder.addImport("throw_string", sig_index); + var kJSThrowString = builder.addImport("", "throw_string", sig_index); // Helper function that throws undefined. Wasm should not catch it. function throw_undefined() { throw undefined; } - var kJSThrowUndefined = builder.addImport("throw_undefined", sig_index); + var kJSThrowUndefined = builder.addImport("", "throw_undefined", sig_index); // Helper function that throws an fp. Wasm should not catch it. function throw_fp() { throw 10.5; } - var kJSThrowFP = builder.addImport("throw_fp", sig_index); + var kJSThrowFP = builder.addImport("", "throw_fp", sig_index); // Helper function that throws a large number. Wasm should not catch it. function throw_large() { throw 1e+28; } - var kJSThrowLarge = builder.addImport("throw_large", sig_index); + var kJSThrowLarge = builder.addImport("", "throw_large", sig_index); // Helper function for throwing from WebAssembly. var kWasmThrowFunction = @@ -335,13 +335,13 @@ var test_catch = (function () { ]) .exportFunc(); - return builder.instantiate({ + return builder.instantiate({"": { throw_i: throw_value, throw_string: throw_string, throw_fp: throw_fp, throw_large, throw_large, throw_undefined: throw_undefined - }); + }}); })(); // Check the test_catch exists. diff --git a/test/mjsunit/wasm/export-table.js b/test/mjsunit/wasm/export-table.js index f715b20f1f..7f7c180281 100644 --- a/test/mjsunit/wasm/export-table.js +++ b/test/mjsunit/wasm/export-table.js @@ -141,11 +141,11 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function js() {} - var a = builder.addImport("a", kSig_v_v); + var a = builder.addImport("m", "a", kSig_v_v); builder.addExport("f", a); builder.addExport("g", a); - let instance = builder.instantiate({a: js}); + let instance = builder.instantiate({m: {a: js}}); let e = instance.exports; assertEquals("function", typeof e.f); assertEquals("function", typeof e.g); @@ -161,12 +161,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function js() {} - var a = builder.addImport("a", kSig_v_v); - var b = builder.addImport("b", kSig_v_v); + var a = builder.addImport("q", "a", kSig_v_v); + var b = builder.addImport("q", "b", kSig_v_v); builder.addExport("f", a); builder.addExport("g", b); - let instance = builder.instantiate({a: js, b: js}); + let instance = builder.instantiate({q: {a: js, b: js}}); let e = instance.exports; assertEquals("function", typeof e.f); assertEquals("function", typeof e.g); diff --git a/test/mjsunit/wasm/ffi-error.js b/test/mjsunit/wasm/ffi-error.js index 521f62b502..5b62bb9ec9 100644 --- a/test/mjsunit/wasm/ffi-error.js +++ b/test/mjsunit/wasm/ffi-error.js @@ -11,7 +11,7 @@ function testCallFFI(ffi) { var builder = new WasmModuleBuilder(); var sig_index = kSig_i_dd; - builder.addImport("fun", sig_index); + builder.addImport("", "fun", sig_index); builder.addFunction("main", sig_index) .addBody([ kExprGetLocal, 0, // -- @@ -25,8 +25,7 @@ function testCallFFI(ffi) { // everything is good. (function() { - var ffi = new Object(); - ffi.fun = function(a, b) { print(a, b); } + var ffi = {"": {fun: function(a, b) { print(a, b); }}} testCallFFI(ffi); })(); @@ -101,7 +100,7 @@ assertThrows(function() { var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_i_i); var sig_i64_index = builder.addType(kSig_i_l); - var index = builder.addImport("func", sig_i64_index); + var index = builder.addImport("", "func", sig_i64_index); builder.addFunction("main", sig_index) .addBody([ kExprGetLocal, 0, @@ -110,7 +109,7 @@ assertThrows(function() { ]) // -- .exportFunc(); var func = function() {return {};}; - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({"": {func: func}}).exports.main; assertThrows(function() { main(13); }, TypeError); @@ -118,11 +117,11 @@ assertThrows(function() { (function ImportSymbolToNumberThrows() { var builder = new WasmModuleBuilder(); - var index = builder.addImport("func", kSig_i_v); + var index = builder.addImport("", "func", kSig_i_v); builder.addFunction("main", kSig_i_v) .addBody([kExprCallFunction, 0]) .exportFunc(); var func = () => Symbol(); - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({"": {func: func}}).exports.main; assertThrows(() => main(), TypeError); })(); diff --git a/test/mjsunit/wasm/ffi.js b/test/mjsunit/wasm/ffi.js index 959c659d4e..8696bcf63d 100644 --- a/test/mjsunit/wasm/ffi.js +++ b/test/mjsunit/wasm/ffi.js @@ -11,7 +11,7 @@ function testCallFFI(func, check) { var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_i_dd); - builder.addImport("func", sig_index); + builder.addImport("", "func", sig_index); builder.addFunction("main", sig_index) .addBody([ kExprGetLocal, 0, // -- @@ -20,7 +20,7 @@ function testCallFFI(func, check) { ]) // -- .exportFunc(); - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({"": {func: func}}).exports.main; for (var i = 0; i < 100000; i += 10003) { var a = 22.5 + i, b = 10.5 + i; @@ -37,7 +37,7 @@ var was_called = false; var length = -1; function FOREIGN_SUB(a, b) { - print("FOREIGN_SUB(" + a + ", " + b + ")"); +// print("FOREIGN_SUB(" + a + ", " + b + ")"); was_called = true; params[0] = this; params[1] = a; @@ -75,7 +75,7 @@ print("Constructor"); var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_i_dd); - builder.addImport("func", sig_index); + builder.addImport("", "func", sig_index); builder.addFunction("main", sig_index) .addBody([ kExprGetLocal, 0, // -- @@ -84,7 +84,7 @@ print("Constructor"); ]) // -- .exportFunc(); - main_for_constructor_test = builder.instantiate({func: C}).exports.main; + main_for_constructor_test = builder.instantiate({"": {func: C}}).exports.main; assertThrows("main_for_constructor_test(12, 43)", TypeError); }) (); @@ -95,14 +95,14 @@ print("Native function"); var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_d_v); - builder.addImport("func", sig_index); + builder.addImport("", "func", sig_index); builder.addFunction("main", sig_index) .addBody([ kExprCallFunction, 0 // -- ]) // -- .exportFunc(); - var main = builder.instantiate({func: Object.prototype.toString}).exports.main; + var main = builder.instantiate({"": {func: Object.prototype.toString}}).exports.main; // The result of the call to Object.prototype.toString should be // [object Undefined]. However, we cannot test for this result because wasm // cannot return objects but converts them to float64 in this test. @@ -113,7 +113,7 @@ print("Callable JSObject"); testCallFFI(%GetCallable(), function check(r, a, b) {assertEquals(a - b, r);}); function FOREIGN_ABCD(a, b, c, d) { - print("FOREIGN_ABCD(" + a + ", " + b + ", " + c + ", " + d + ")"); +// print("FOREIGN_ABCD(" + a + ", " + b + ", " + c + ", " + d + ")"); was_called = true; params[0] = this; params[1] = a; @@ -224,7 +224,6 @@ var objWithValueOf = {valueOf: function() { return 198; }} testCallFFI(returnValue(objWithValueOf), checkReturn(198)); - function testCallBinopVoid(type, func, check) { var passed_length = -1; var passed_a = -1; @@ -232,17 +231,17 @@ function testCallBinopVoid(type, func, check) { var args_a = -1; var args_b = -1; - ffi = {func: function(a, b) { + ffi = {"": {func: function(a, b) { passed_length = arguments.length; passed_a = a; passed_b = b; args_a = arguments[0]; args_b = arguments[1]; - }}; + }}}; var builder = new WasmModuleBuilder(); - builder.addImport("func", makeSig_v_xx(type)); + builder.addImport("", "func", makeSig_v_xx(type)); builder.addFunction("main", makeSig_r_xx(kAstI32, type)) .addBody([ kExprGetLocal, 0, // -- @@ -293,13 +292,11 @@ testCallBinopVoid(kAstI32); testCallBinopVoid(kAstF32); testCallBinopVoid(kAstF64); - - (function testCallPrint() { var builder = new WasmModuleBuilder(); - builder.addImport("print", makeSig_v_x(kAstI32)); - builder.addImport("print", makeSig_v_x(kAstF64)); + builder.addImport("", "print", makeSig_v_x(kAstI32)); + builder.addImport("", "print", makeSig_v_x(kAstF64)); builder.addFunction("main", makeSig_v_x(kAstF64)) .addBody([ kExprI8Const, 97, // -- @@ -309,27 +306,29 @@ testCallBinopVoid(kAstF64); ]) // -- .exportFunc() - var main = builder.instantiate({print: print}).exports.main; + var main = builder.instantiate({"": {print: print}}).exports.main; for (var i = -9; i < 900; i += 6.125) main(i); })(); (function testImportNumbers() { + print("TestImportNumbers..."); var builder = new WasmModuleBuilder(); - builder.addImport('0', kSig_v_i); + builder.addImport("", '0', kSig_v_i); - builder.instantiate({0: print}); + builder.instantiate({"": {0: print}}); })(); (function testImportNumbers2() { + print("TestImportNumbers2..."); var builder = new WasmModuleBuilder(); - builder.addImportWithModule('foo', '0', kSig_v_i); - builder.addImportWithModule('0', 'foo', kSig_v_i); - builder.addImportWithModule('0', '0', kSig_v_i); - builder.addImportWithModule('18', '-3', kSig_v_i); - builder.addImportWithModule('-3', '18', kSig_v_i); + builder.addImport('foo', '0', kSig_v_i); + builder.addImport('0', 'foo', kSig_v_i); + builder.addImport('0', '0', kSig_v_i); + builder.addImport('18', '-3', kSig_v_i); + builder.addImport('-3', '18', kSig_v_i); builder.instantiate({ foo: {0: print}, @@ -340,21 +339,22 @@ testCallBinopVoid(kAstF64); })(); (function ImportSymbolAsVoidDoesNotThrow() { + print("ImportSymbolAsVoidDoesNotThrow..."); var builder = new WasmModuleBuilder(); // Return type is void, so there should be no ToNumber conversion. - var index = builder.addImport("func", kSig_v_v); + var index = builder.addImport("", "func", kSig_v_v); builder.addFunction("main", kSig_v_v) .addBody([kExprCallFunction, 0]) .exportFunc(); var func = () => Symbol(); - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({"": {func: func}}).exports.main; main(); })(); (function ToNumberCalledOnImport() { var builder = new WasmModuleBuilder(); // Return type is int, so there should be a ToNumber conversion. - var index = builder.addImport("func", kSig_i_v); + var index = builder.addImport("", "func", kSig_i_v); builder.addFunction("main", kSig_i_v) .addBody([kExprCallFunction, 0]) .exportFunc(); @@ -362,7 +362,7 @@ testCallBinopVoid(kAstF64); function Foo() {} Foo.prototype.valueOf = () => ++num_valueOf; var func = () => new Foo(); - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({"": {func: func}}).exports.main; main(); assertEquals(1, num_valueOf); main(); @@ -372,7 +372,7 @@ testCallBinopVoid(kAstF64); (function ToNumberNotCalledOnVoidImport() { var builder = new WasmModuleBuilder(); // Return type is void, so there should be no ToNumber conversion. - var index = builder.addImport("func", kSig_v_v); + var index = builder.addImport("", "func", kSig_v_v); builder.addFunction("main", kSig_v_v) .addBody([kExprCallFunction, 0]) .exportFunc(); @@ -380,7 +380,7 @@ testCallBinopVoid(kAstF64); function Foo() {} Foo.prototype.valueOf = () => ++num_valueOf; var func = () => new Foo(); - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({"": {func: func}}).exports.main; main(); main(); assertEquals(0, num_valueOf); diff --git a/test/mjsunit/wasm/gc-buffer.js b/test/mjsunit/wasm/gc-buffer.js index d33695532a..6bcf299d8b 100644 --- a/test/mjsunit/wasm/gc-buffer.js +++ b/test/mjsunit/wasm/gc-buffer.js @@ -12,7 +12,7 @@ function run(f) { // the module (i.e. the underlying array buffer of WASM wire bytes dies). var module = (() => { var builder = new WasmModuleBuilder(); - builder.addImport("the_name_of_my_import", kSig_i_i); + builder.addImport("mod", "the_name_of_my_import", kSig_i_i); builder.addFunction("main", kSig_i_i) .addBody([ kExprGetLocal, 0, @@ -25,7 +25,7 @@ function run(f) { gc(); for (var i = 0; i < 10; i++) { print(" instance " + i); - var instance = new WebAssembly.Instance(module, {the_name_of_my_import: f}); + var instance = new WebAssembly.Instance(module, {"mod": {the_name_of_my_import: f}}); var g = instance.exports.main; assertEquals("function", typeof g); for (var j = 0; j < 10; j++) { diff --git a/test/mjsunit/wasm/gc-frame.js b/test/mjsunit/wasm/gc-frame.js index 9e9aa98999..0c8d2ebcf8 100644 --- a/test/mjsunit/wasm/gc-frame.js +++ b/test/mjsunit/wasm/gc-frame.js @@ -11,7 +11,7 @@ function makeFFI(func, t) { var builder = new WasmModuleBuilder(); var sig_index = builder.addType(makeSig([t,t,t,t,t,t,t,t,t,t], [t])); - builder.addImport("func", sig_index); + builder.addImport("m", "func", sig_index); // Try to create a frame with lots of spilled values and parameters // on the stack to try to catch GC bugs in the reference maps for // the different parts of the stack. @@ -43,7 +43,7 @@ function makeFFI(func, t) { ]) // -- .exportFunc(); - return builder.instantiate({func: func}).exports.main; + return builder.instantiate({m: {func: func}}).exports.main; } diff --git a/test/mjsunit/wasm/gc-stress.js b/test/mjsunit/wasm/gc-stress.js index 468be105cc..2bf2f758d6 100644 --- a/test/mjsunit/wasm/gc-stress.js +++ b/test/mjsunit/wasm/gc-stress.js @@ -9,7 +9,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); function run(f) { var builder = new WasmModuleBuilder(); - builder.addImport("f", kSig_i_i); + builder.addImport("m", "f", kSig_i_i); builder.addFunction("main", kSig_i_i) .addBody([ kExprGetLocal, 0, @@ -21,7 +21,7 @@ function run(f) { for (var i = 0; i < 10; i++) { print(" instance " + i); - var instance = new WebAssembly.Instance(module, {f: f}); + var instance = new WebAssembly.Instance(module, {m: {f: f}}); var g = instance.exports.main; for (var j = 0; j < 10; j++) { assertEquals(f(j), g(j)); diff --git a/test/mjsunit/wasm/globals.js b/test/mjsunit/wasm/globals.js index 46babe3c07..d1ee960074 100644 --- a/test/mjsunit/wasm/globals.js +++ b/test/mjsunit/wasm/globals.js @@ -11,13 +11,13 @@ function TestImported(type, val, expected) { print("TestImported " + type + "(" + val +")" + " = " + expected); var builder = new WasmModuleBuilder(); var sig = makeSig([], [type]); - var g = builder.addImportedGlobal("foo", undefined, type); + var g = builder.addImportedGlobal("uuu", "foo", type); builder.addFunction("main", sig) .addBody([kExprGetGlobal, g.index]) .exportAs("main"); builder.addGlobal(kAstI32); // pad - var instance = builder.instantiate({foo: val}); + var instance = builder.instantiate({uuu: {foo: val}}); assertEquals(expected, instance.exports.main()); } @@ -49,14 +49,14 @@ function TestImportedExported(type, val, expected) { print("TestImportedExported " + type + "(" + val +")" + " = " + expected); var builder = new WasmModuleBuilder(); var sig = makeSig([type], []); - var i = builder.addImportedGlobal("foo", undefined, type); + var i = builder.addImportedGlobal("ttt", "foo", type); builder.addGlobal(kAstI32); // pad var o = builder.addGlobal(type, false) .exportAs("bar"); o.init_index = i; builder.addGlobal(kAstI32); // pad - var instance = builder.instantiate({foo: val}); + var instance = builder.instantiate({ttt: {foo: val}}); assertEquals(expected, instance.exports.bar); } @@ -67,7 +67,7 @@ TestImportedExported(kAstF64, 81347.66666, 81347.66666); function TestGlobalIndexSpace(type, val) { print("TestGlobalIndexSpace(" + val + ") = " + val); var builder = new WasmModuleBuilder(); - var im = builder.addImportedGlobal("foo", undefined, type); + var im = builder.addImportedGlobal("nnn", "foo", type); assertEquals(0, im); var def = builder.addGlobal(type, false); assertEquals(1, def.index); @@ -78,7 +78,7 @@ function TestGlobalIndexSpace(type, val) { .addBody([kExprGetGlobal, def.index]) .exportAs("main"); - var instance = builder.instantiate({foo: val}); + var instance = builder.instantiate({nnn: {foo: val}}); assertEquals(val, instance.exports.main()); } diff --git a/test/mjsunit/wasm/import-memory.js b/test/mjsunit/wasm/import-memory.js index 3f2cf1155a..6c26ef4152 100644 --- a/test/mjsunit/wasm/import-memory.js +++ b/test/mjsunit/wasm/import-memory.js @@ -13,14 +13,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(kPageSize, memory.buffer.byteLength); let i32 = new Int32Array(memory.buffer); let builder = new WasmModuleBuilder(); - builder.addImportedMemory("mine"); + builder.addImportedMemory("mod", "mine"); builder.addFunction("main", kSig_i_v) .addBody([ kExprI32Const, 0, kExprI32LoadMem, 0, 0]) .exportAs("main"); - let main = builder.instantiate({mine: memory}).exports.main; + let main = builder.instantiate({mod: {mine: memory}}).exports.main; assertEquals(0, main()); i32[0] = 993377; @@ -33,10 +33,10 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); let memory = new WebAssembly.Memory({initial: 1}); let i32 = new Int32Array(memory.buffer); let builder = new WasmModuleBuilder(); - builder.addImportedMemory("garg"); + builder.addImportedMemory("dad", "garg"); builder.exportMemoryAs("daggle"); - let instance = builder.instantiate({garg: memory}); + let instance = builder.instantiate({dad: {garg: memory}}); assertSame(memory, instance.exports.daggle); })(); @@ -59,13 +59,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); { let builder = new WasmModuleBuilder(); builder.addMemory(1, 1, false); - builder.addImportedMemory("imported_mem"); + builder.addImportedMemory("fil", "imported_mem"); builder.addFunction("bar", kSig_i_i) .addBody([ kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .exportAs("bar"); - i2 = builder.instantiate({imported_mem: i1.exports.exported_mem}); + i2 = builder.instantiate({fil: {imported_mem: i1.exports.exported_mem}}); } let i32 = new Int32Array(i1.exports.exported_mem.buffer); @@ -86,8 +86,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(kPageSize, memory.buffer.byteLength); let i32 = new Int32Array(memory.buffer); let builder = new WasmModuleBuilder(); - // builder.addImportedMemory("mine"); - builder.addImportedMemory("mine"); + builder.addImportedMemory("gaz", "mine"); builder.addFunction("load", kSig_i_i) .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .exportFunc(); @@ -96,7 +95,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); kExprGetLocal, 1]) .exportFunc(); var offset; - let instance = builder.instantiate({mine: memory}); + let instance = builder.instantiate({gaz: {mine: memory}}); function load() { return instance.exports.load(offset); } function store(value) { return instance.exports.store(offset, value); } @@ -117,7 +116,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(kPageSize, memory.buffer.byteLength); let i32 = new Int32Array(memory.buffer); let builder = new WasmModuleBuilder(); - builder.addImportedMemory("mine", "", 0, 20); + builder.addImportedMemory("mine", "dog", 0, 20); builder.addFunction("load", kSig_i_i) .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .exportFunc(); @@ -126,7 +125,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); kExprGetLocal, 1]) .exportFunc(); var offset; - let instance = builder.instantiate({mine: memory}); + let instance = builder.instantiate({mine: {dog: memory}}); function load() { return instance.exports.load(offset); } function store(value) { return instance.exports.store(offset, value); } @@ -155,7 +154,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(0, memory.buffer.byteLength); let i32 = new Int32Array(memory.buffer); let builder = new WasmModuleBuilder(); - builder.addImportedMemory("mine"); + builder.addImportedMemory("mine", "fro"); builder.addFunction("load", kSig_i_i) .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .exportFunc(); @@ -164,7 +163,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); kExprGetLocal, 1]) .exportFunc(); var offset; - let instance = builder.instantiate({mine: memory}); + let instance = builder.instantiate({mine: {fro: memory}}); function load() { return instance.exports.load(offset); } function store(value) { return instance.exports.store(offset, value); } @@ -189,8 +188,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); builder.addFunction("grow", kSig_i_i) .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) .exportFunc(); - builder.addImportedMemory("mine"); - let instance = builder.instantiate({mine: memory}); + builder.addImportedMemory("cat", "mine"); + let instance = builder.instantiate({cat: {mine: memory}}); function grow(pages) { return instance.exports.grow(pages); } assertEquals(2, grow(3)); assertEquals(5*kPageSize, memory.buffer.byteLength); @@ -212,15 +211,15 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var instance; { var builder = new WasmModuleBuilder(); - builder.addImportedMemory("imported_mem"); + builder.addImportedMemory("fur", "imported_mem"); builder.addFunction("mem_size", kSig_i_v) .addBody([kExprMemorySize, kMemoryZero]) .exportFunc(); builder.addFunction("grow", kSig_i_i) .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) .exportFunc(); - instance = builder.instantiate({ - imported_mem: exp_instance.exports.exported_mem}); + instance = builder.instantiate({fur: { + imported_mem: exp_instance.exports.exported_mem}}); } for (var i = initial_size; i < maximum_size; i++) { assertEquals(i, instance.exports.grow(1)); @@ -233,7 +232,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); print("TestMemoryGrowWebAssemblyInstances"); let memory = new WebAssembly.Memory({initial: 1, maximum: 15}); var builder = new WasmModuleBuilder(); - builder.addImportedMemory("imported_mem"); + builder.addImportedMemory("lit", "imported_mem"); builder.addFunction("mem_size", kSig_i_v) .addBody([kExprMemorySize, kMemoryZero]) .exportAs("mem_size"); @@ -243,7 +242,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var module = new WebAssembly.Module(builder.toBuffer()); var instances = []; for (var i = 0; i < 6; i++) { - instances.push(new WebAssembly.Instance(module, {imported_mem: memory})); + instances.push(new WebAssembly.Instance(module, {lit: {imported_mem: memory}})); } function verify_mem_size(expected_pages) { assertEquals(expected_pages*kPageSize, @@ -274,7 +273,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); print("TestImportMemoryMultipleInstances"); let memory = new WebAssembly.Memory({initial: 5, maximum: 100}); var builder = new WasmModuleBuilder(); - builder.addImportedMemory("imported_mem"); + builder.addImportedMemory("nob", "imported_mem"); builder.addFunction("mem_size", kSig_i_v) .addBody([kExprMemorySize, kMemoryZero]) .exportFunc(); @@ -283,7 +282,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); .exportFunc(); var instances = []; for (var i = 0; i < 5; i++) { - instances.push(builder.instantiate({imported_mem: memory})); + instances.push(builder.instantiate({nob: {imported_mem: memory}})); } function grow_instance_0(pages) { return instances[0].exports.grow(pages); } function grow_instance_1(pages) { return instances[1].exports.grow(pages); } @@ -342,7 +341,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); instance = builder.instantiate(); } var builder = new WasmModuleBuilder(); - builder.addImportedMemory("imported_mem"); + builder.addImportedMemory("doo", "imported_mem"); builder.addFunction("mem_size", kSig_i_v) .addBody([kExprMemorySize, kMemoryZero]) .exportFunc(); @@ -352,7 +351,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var instances = []; for (var i = 0; i < 10; i++) { instances.push(builder.instantiate({ - imported_mem: instance.exports.exported_mem})); + doo: {imported_mem: instance.exports.exported_mem}})); } function verify_mem_size(expected_pages) { for (var i = 0; i < 10; i++) { diff --git a/test/mjsunit/wasm/import-table.js b/test/mjsunit/wasm/import-table.js index ffb702c781..ac27e51921 100644 --- a/test/mjsunit/wasm/import-table.js +++ b/test/mjsunit/wasm/import-table.js @@ -11,7 +11,7 @@ function testCallImport(func, check) { var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_i_dd); - builder.addImport("func", sig_index); + builder.addImport("q", "func", sig_index); builder.addFunction("main", sig_index) .addBody([ kExprGetLocal, 0, // -- @@ -19,7 +19,7 @@ function testCallImport(func, check) { kExprCallFunction, 0]) // -- .exportAs("main"); - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({q: {func: func}}).exports.main; for (var i = 0; i < 100000; i += 10003) { var a = 22.5 + i, b = 10.5 + i; @@ -168,25 +168,23 @@ testCallImport(returnValue(objWithValueOf), checkReturn(198)); function testCallBinopVoid(type, func, check) { - var ffi = new Object(); - var passed_length = -1; var passed_a = -1; var passed_b = -1; var args_a = -1; var args_b = -1; - ffi.func = function(a, b) { + var ffi = {q: {func: function(a, b) { passed_length = arguments.length; passed_a = a; passed_b = b; args_a = arguments[0]; args_b = arguments[1]; - } + }}}; var builder = new WasmModuleBuilder(); - builder.addImport("func", makeSig_v_xx(type)); + builder.addImport("q", "func", makeSig_v_xx(type)); builder.addFunction("main", makeSig_r_xx(kAstI32, type)) .addBody([ kExprGetLocal, 0, // -- @@ -241,8 +239,8 @@ testCallBinopVoid(kAstF64); function testCallPrint() { var builder = new WasmModuleBuilder(); - builder.addImport("print", makeSig_v_x(kAstI32)); - builder.addImport("print", makeSig_r_x(kAstF64, kAstF64)); + builder.addImport("q", "print", makeSig_v_x(kAstI32)); + builder.addImport("q", "print", makeSig_r_x(kAstF64, kAstF64)); builder.addFunction("main", makeSig_r_x(kAstF64, kAstF64)) .addBody([ kExprI8Const, 97, // -- @@ -252,7 +250,7 @@ function testCallPrint() { ]) .exportFunc(); - var main = builder.instantiate({print: print}).exports.main; + var main = builder.instantiate({q: {print: print}}).exports.main; for (var i = -9; i < 900; i += 16.125) { main(i); @@ -266,8 +264,8 @@ testCallPrint(); function testCallImport2(foo, bar, expected) { var builder = new WasmModuleBuilder(); - builder.addImport("foo", kSig_i_v); - builder.addImport("bar", kSig_i_v); + builder.addImport("q", "foo", kSig_i_v); + builder.addImport("t", "bar", kSig_i_v); builder.addFunction("main", kSig_i_v) .addBody([ kExprCallFunction, 0, // -- @@ -276,7 +274,7 @@ function testCallImport2(foo, bar, expected) { ]) // -- .exportFunc(); - var main = builder.instantiate({foo: foo, bar: bar}).exports.main; + var main = builder.instantiate({q: {foo: foo}, t: {bar: bar}}).exports.main; assertEquals(expected, main()); } @@ -285,7 +283,7 @@ testCallImport2(function() { return 33; }, function () { return 44; }, 77); function testImportName(name) { var builder = new WasmModuleBuilder(); - builder.addImportWithModule("M", name, kSig_i_v); + builder.addImport("M", name, kSig_i_v); builder.addFunction("main", kSig_i_v) .addBody([ kExprCallFunction, 0 diff --git a/test/mjsunit/wasm/indirect-calls.js b/test/mjsunit/wasm/indirect-calls.js index ac4fa54e6d..33ea8d7729 100644 --- a/test/mjsunit/wasm/indirect-calls.js +++ b/test/mjsunit/wasm/indirect-calls.js @@ -11,7 +11,7 @@ var module = (function () { var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_i_ii); - builder.addImport("add", sig_index); + builder.addImport("q", "add", sig_index); builder.addFunction("add", sig_index) .addBody([ kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0 @@ -32,7 +32,7 @@ var module = (function () { .exportFunc() builder.appendToTable([1, 2, 3]); - return builder.instantiate({add: function(a, b) { return a + b | 0; }}); + return builder.instantiate({q: {add: function(a, b) { return a + b | 0; }}}); })(); // Check the module exists. @@ -54,7 +54,7 @@ module = (function () { var sig_i_ii = builder.addType(kSig_i_ii); var sig_i_i = builder.addType(kSig_i_i); - var mul = builder.addImport("mul", sig_i_ii); + var mul = builder.addImport("q", "mul", sig_i_ii); var add = builder.addFunction("add", sig_i_ii) .addBody([ kExprGetLocal, 0, // -- @@ -76,7 +76,7 @@ module = (function () { .exportFunc(); builder.appendToTable([mul.index, add.index, popcnt.index, main.index]); - return builder.instantiate({mul: function(a, b) { return a * b | 0; }}); + return builder.instantiate({q: {mul: function(a, b) { return a * b | 0; }}}); })(); assertEquals(-6, module.exports.main(0, -2, 3)); @@ -185,14 +185,14 @@ assertTraps(kTrapFuncInvalid, "module.exports.main(12, 3)"); .exportAs("main"); builder.setFunctionTableLength(10); - var g = builder.addImportedGlobal("base", undefined, kAstI32); + var g = builder.addImportedGlobal("fff", "base", kAstI32); builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index]); var module = new WebAssembly.Module(builder.toBuffer()); for (var i = 0; i < 5; i++) { print(" base = " + i); - var instance = new WebAssembly.Instance(module, {base: i}); + var instance = new WebAssembly.Instance(module, {fff: {base: i}}); main = instance.exports.main; for (var j = 0; j < i; j++) { assertTraps(kTrapFuncSigMismatch, "main(12, " + j + ")"); diff --git a/test/mjsunit/wasm/indirect-tables.js b/test/mjsunit/wasm/indirect-tables.js index 29e4a50031..89cdd9005c 100644 --- a/test/mjsunit/wasm/indirect-tables.js +++ b/test/mjsunit/wasm/indirect-tables.js @@ -37,7 +37,7 @@ function js_div(a, b) { return (a / b) | 0; } let builder = new WasmModuleBuilder(); - let d = builder.addImport("js_div", kSig_i_ii); + let d = builder.addImport("q", "js_div", kSig_i_ii); let f = AddFunctions(builder); builder.addFunction("main", kSig_i_ii) .addBody([ @@ -50,7 +50,7 @@ function js_div(a, b) { return (a / b) | 0; } f.add.exportAs("blarg"); builder.setFunctionTableLength(10); - let g = builder.addImportedGlobal("base", undefined, kAstI32); + let g = builder.addImportedGlobal("q", "base", kAstI32); builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index, d]); @@ -60,7 +60,7 @@ function js_div(a, b) { return (a / b) | 0; } for (let i = 0; i < 5; i++) { print(" base = " + i); - let instance = new WebAssembly.Instance(module, {base: i, js_div: js_div}); + let instance = new WebAssembly.Instance(module, {q: {base: i, js_div: js_div}}); main = instance.exports.main; let table = instance.exports.table; assertTrue(table instanceof WebAssembly.Table); @@ -107,10 +107,10 @@ function js_div(a, b) { return (a / b) | 0; } print("ImportedTableTest..."); var builder = new WasmModuleBuilder(); - let d = builder.addImport("js_div", kSig_i_ii); + let d = builder.addImport("q", "js_div", kSig_i_ii); let f = AddFunctions(builder); builder.setFunctionTableLength(kTableSize); - let g = builder.addImportedGlobal("base", undefined, kAstI32); + let g = builder.addImportedGlobal("q", "base", kAstI32); builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index, d]); @@ -120,7 +120,7 @@ function js_div(a, b) { return (a / b) | 0; } var builder = new WasmModuleBuilder(); - builder.addImportedTable("table", undefined, kTableSize, kTableSize); + builder.addImportedTable("r", "table", kTableSize, kTableSize); builder.addFunction("main", kSig_i_ii) .addBody([ kExprI32Const, 33, // -- @@ -134,10 +134,10 @@ function js_div(a, b) { return (a / b) | 0; } // Run 5 trials at different table bases. for (let i = 0; i < 5; i++) { print(" base = " + i); - let i1 = new WebAssembly.Instance(m1, {base: i, js_div: js_div}); + let i1 = new WebAssembly.Instance(m1, {q: {base: i, js_div: js_div}}); let table = i1.exports.table; assertEquals(10, table.length); - let i2 = new WebAssembly.Instance(m2, {table: table}); + let i2 = new WebAssembly.Instance(m2, {r: {table: table}}); let main = i2.exports.main; for (var j = 0; j < i; j++) { @@ -178,9 +178,9 @@ function js_div(a, b) { return (a / b) | 0; } var builder = new WasmModuleBuilder(); - let d = builder.addImport("js_div", kSig_i_ii); - builder.addImportedTable("table", undefined, kTableSize, kTableSize); - let g = builder.addImportedGlobal("base", undefined, kAstI32); + let d = builder.addImport("q", "js_div", kSig_i_ii); + builder.addImportedTable("q", "table", kTableSize, kTableSize); + let g = builder.addImportedGlobal("q", "base", kAstI32); let f = AddFunctions(builder); builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index, @@ -201,8 +201,8 @@ function js_div(a, b) { return (a / b) | 0; } let table = new WebAssembly.Table({element: "anyfunc", initial: kTableSize}); assertEquals(10, table.length); - let i2 = new WebAssembly.Instance(m2, {base: i, table: table, - js_div: js_div}); + let i2 = new WebAssembly.Instance(m2, {q: {base: i, table: table, + js_div: js_div}}); let main = i2.exports.main; for (var j = 0; j < i; j++) { @@ -246,8 +246,8 @@ function js_div(a, b) { return (a / b) | 0; } var builder = new WasmModuleBuilder(); - builder.addImportedTable("table", undefined, kTableSize, kTableSize); - let g = builder.addImportedGlobal("base", undefined, kAstI32); + builder.addImportedTable("x", "table", kTableSize, kTableSize); + let g = builder.addImportedGlobal("x", "base", kAstI32); let sig_index = builder.addType(kSig_i_v); builder.addFunction("g", sig_index) .addBody([ @@ -264,7 +264,7 @@ function js_div(a, b) { return (a / b) | 0; } for (var i = 0; i < kTableSize; i++) { print(" base = " + i); - let instance = new WebAssembly.Instance(module, {base: i, table: table}); + let instance = new WebAssembly.Instance(module, {x: {base: i, table: table}}); for (var j = 0; j < kTableSize; j++) { let func = table.get(j); @@ -319,14 +319,14 @@ function js_div(a, b) { return (a / b) | 0; } builder.setFunctionTableLength(kTableSize); builder.addFunctionTableInit(1, false, [f2.index]); - builder.addImportedTable("table", undefined, kTableSize, kTableSize); + builder.addImportedTable("z", "table", kTableSize, kTableSize); var m2 = new WebAssembly.Module(builder.toBuffer()); assertFalse(sig_index1 == sig_index2); var i1 = new WebAssembly.Instance(m1); - var i2 = new WebAssembly.Instance(m2, {table: i1.exports.table}); + var i2 = new WebAssembly.Instance(m2, {z: {table: i1.exports.table}}); assertEquals(11, i1.exports.main(0)); assertEquals(11, i2.exports.main(0)); @@ -355,7 +355,7 @@ function js_div(a, b) { return (a / b) | 0; } let m1 = new WebAssembly.Module(builder.toBuffer()); var builder = new WasmModuleBuilder(); - builder.addImportedTable("impfoo", undefined, impsize, impsize); + builder.addImportedTable("y", "impfoo", impsize, impsize); let m2 = new WebAssembly.Module(builder.toBuffer()); @@ -363,7 +363,7 @@ function js_div(a, b) { return (a / b) | 0; } // TODO(titzer): v8 currently requires import table size to match // export table size. - var ffi = {impfoo: i1.exports.expfoo}; + var ffi = {y: {impfoo: i1.exports.expfoo}}; if (expsize == impsize) { var i2 = new WebAssembly.Instance(m2, ffi); } else { diff --git a/test/mjsunit/wasm/instance-memory-gc-stress.js b/test/mjsunit/wasm/instance-memory-gc-stress.js index fc824c2af7..64909eb9df 100644 --- a/test/mjsunit/wasm/instance-memory-gc-stress.js +++ b/test/mjsunit/wasm/instance-memory-gc-stress.js @@ -13,7 +13,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); print("InstanceMemoryGcStress"); let memory = new WebAssembly.Memory({initial: 100, maximum: 1500}); var builder = new WasmModuleBuilder(); - builder.addImportedMemory("imported_mem"); + builder.addImportedMemory("mod", "imported_mem"); builder.addFunction("mem_size", kSig_i_v) .addBody([kExprMemorySize, kMemoryZero]) .exportFunc(); @@ -23,7 +23,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); var instances = []; for (var i = 0; i < 5; i++) { gc(); - instances.push(builder.instantiate({imported_mem: memory})); + instances.push(builder.instantiate({mod: {imported_mem: memory}})); } function grow_instance_0(pages) { return instances[0].exports.grow(pages); } function grow_instance_1(pages) { return instances[1].exports.grow(pages); } @@ -60,7 +60,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(800, instances[0].exports.mem_size()); // Instantiate a new instance and verify that it can be grown correctly. - instances.push(builder.instantiate({imported_mem: memory})); + instances.push(builder.instantiate({mod: {imported_mem: memory}})); function grow_instance_5(pages) { return instances[5].exports.grow(pages); } gc(); gc(); diff --git a/test/mjsunit/wasm/instantiate-module-basic.js b/test/mjsunit/wasm/instantiate-module-basic.js index d3a70dcda8..c9c6e17f35 100644 --- a/test/mjsunit/wasm/instantiate-module-basic.js +++ b/test/mjsunit/wasm/instantiate-module-basic.js @@ -120,8 +120,8 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); builder.addMemory(1,1, true); var kSig_v_i = makeSig([kAstI32], []); var signature = builder.addType(kSig_v_i); - builder.addImport("some_value", kSig_i_v); - builder.addImport("writer", signature); + builder.addImport("m", "some_value", kSig_i_v); + builder.addImport("m", "writer", signature); builder.addFunction("main", kSig_i_i) .addBody([ @@ -155,10 +155,12 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); var outval_1; var outval_2; - var i1 = new WebAssembly.Instance(module, {some_value: () => 1, - writer: (x)=>outval_1 = x }, mem_1); - var i2 = new WebAssembly.Instance(module, {some_value: () => 2, - writer: (x)=>outval_2 = x }, mem_2); + var i1 = new WebAssembly.Instance(module, {m: {some_value: () => 1, + writer: (x)=>outval_1 = x }}, + mem_1); + var i2 = new WebAssembly.Instance(module, {m: {some_value: () => 2, + writer: (x)=>outval_2 = x }}, + mem_2); assertEquals(43, i1.exports.main(0)); assertEquals(1002, i2.exports.main(0)); diff --git a/test/mjsunit/wasm/js-api.js b/test/mjsunit/wasm/js-api.js index 47965c0ffb..ea7e58d562 100644 --- a/test/mjsunit/wasm/js-api.js +++ b/test/mjsunit/wasm/js-api.js @@ -39,7 +39,7 @@ let exportingModuleBinary = (() => { let importingModuleBinary = (() => { var builder = new WasmModuleBuilder(); - builder.addImport("f", kSig_i_v); + builder.addImport("", "f", kSig_i_v); return new Int8Array(builder.toBuffer()); })(); diff --git a/test/mjsunit/wasm/memory-instance-validation.js b/test/mjsunit/wasm/memory-instance-validation.js index 3457ff7c89..e0220e6ee9 100644 --- a/test/mjsunit/wasm/memory-instance-validation.js +++ b/test/mjsunit/wasm/memory-instance-validation.js @@ -13,7 +13,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); print("ValidateSharedInstanceMemory"); let memory = new WebAssembly.Memory({initial: 5, maximum: 100}); var builder = new WasmModuleBuilder(); - builder.addImportedMemory("imported_mem"); + builder.addImportedMemory("mod", "imported_mem"); builder.addFunction("mem_size", kSig_i_v) .addBody([kExprMemorySize, kMemoryZero]) .exportFunc(); @@ -22,7 +22,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); .exportFunc(); var instances = []; for (var i = 0; i < 5; i++) { - instances.push(builder.instantiate({imported_mem: memory})); + instances.push(builder.instantiate({mod: {imported_mem: memory}})); } function grow_instance_0(pages) { return instances[0].exports.grow(pages); } function grow_instance_1(pages) { return instances[1].exports.grow(pages); } @@ -82,7 +82,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); assertEquals(28, instances[3].exports.mem_size()); // Instantiate a new instance and verify that it can be grown correctly. - instances.push(builder.instantiate({imported_mem: memory})); + instances.push(builder.instantiate({mod: {imported_mem: memory}})); function grow_instance_5(pages) { return instances[5].exports.grow(pages); } // i[2] - i[3] - i[5] diff --git a/test/mjsunit/wasm/receiver.js b/test/mjsunit/wasm/receiver.js index 97a6d94c9b..b3373c11ec 100644 --- a/test/mjsunit/wasm/receiver.js +++ b/test/mjsunit/wasm/receiver.js @@ -11,7 +11,7 @@ function testCallImport(func, expected, a, b) { var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_i_dd); - builder.addImport("func", sig_index); + builder.addImport("mod", "func", sig_index); builder.addFunction("main", sig_index) .addBody([ kExprGetLocal, 0, // -- @@ -19,7 +19,7 @@ function testCallImport(func, expected, a, b) { kExprCallFunction, 0]) // -- .exportAs("main"); - var main = builder.instantiate({func: func}).exports.main; + var main = builder.instantiate({mod: {func: func}}).exports.main; assertEquals(expected, main(a, b)); } diff --git a/test/mjsunit/wasm/stack.js b/test/mjsunit/wasm/stack.js index d7c399dc03..538c10e543 100644 --- a/test/mjsunit/wasm/stack.js +++ b/test/mjsunit/wasm/stack.js @@ -42,7 +42,7 @@ function STACK() { var builder = new WasmModuleBuilder(); -builder.addImport("func", kSig_v_v); +builder.addImport("mod", "func", kSig_v_v); builder.addFunction("main", kSig_v_v) .addBody([kExprCallFunction, 0]) @@ -63,7 +63,7 @@ builder.addFunction("call_mem_out_of_bounds", kSig_i_v) .addBody([kExprCallFunction, mem_oob_func.index]) .exportAs("call_mem_out_of_bounds"); -var module = builder.instantiate({func: STACK}); +var module = builder.instantiate({mod: {func: STACK}}); (function testSimpleStack() { var expected_string = "Error\n" + diff --git a/test/mjsunit/wasm/stackwalk.js b/test/mjsunit/wasm/stackwalk.js index cd560ec62b..d2810fce45 100644 --- a/test/mjsunit/wasm/stackwalk.js +++ b/test/mjsunit/wasm/stackwalk.js @@ -11,7 +11,7 @@ function makeFFI(func) { var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_i_dd); - builder.addImport("func", sig_index); + builder.addImport("mom", "func", sig_index); builder.addFunction("main", sig_index) .addBody([ kExprGetLocal, 0, // -- @@ -20,7 +20,7 @@ function makeFFI(func) { ]) .exportFunc() - return builder.instantiate({func: func}).exports.main; + return builder.instantiate({mom: {func: func}}).exports.main; } diff --git a/test/mjsunit/wasm/start-function.js b/test/mjsunit/wasm/start-function.js index da1c7c37c4..a9d512adcd 100644 --- a/test/mjsunit/wasm/start-function.js +++ b/test/mjsunit/wasm/start-function.js @@ -99,15 +99,15 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);}); (function testStartFFI() { print("testStartFFI"); var ranned = false; - var ffi = { foo : function() { + var ffi = {gak: {foo : function() { print("we ranned at stert!"); ranned = true; - }}; + }}}; var builder = new WasmModuleBuilder(); var sig_index = builder.addType(kSig_v_v); - builder.addImport("foo", sig_index); + builder.addImport("gak", "foo", sig_index); var func = builder.addFunction("", sig_index) .addBody([kExprCallFunction, 0]); diff --git a/test/mjsunit/wasm/table.js b/test/mjsunit/wasm/table.js index 5484720622..2eca796af2 100644 --- a/test/mjsunit/wasm/table.js +++ b/test/mjsunit/wasm/table.js @@ -153,7 +153,7 @@ function assertTableIsValid(table) { (function TestSet() { let builder = new WasmModuleBuilder; builder.addExport("wasm", builder.addFunction("", kSig_v_v)); - builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v)); + builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); @@ -201,7 +201,7 @@ function assertTableIsValid(table) { (function TestIndexing() { let builder = new WasmModuleBuilder; builder.addExport("wasm", builder.addFunction("", kSig_v_v)); - builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v)); + builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); @@ -224,7 +224,7 @@ function assertTableIsValid(table) { (function TestGrow() { let builder = new WasmModuleBuilder; builder.addExport("wasm", builder.addFunction("", kSig_v_v)); - builder.addExport("host", builder.addImportWithModule("test", "f", kSig_v_v)); + builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; function init(table) { diff --git a/test/mjsunit/wasm/test-import-export-wrapper.js b/test/mjsunit/wasm/test-import-export-wrapper.js index e84881667d..e16a7af26a 100644 --- a/test/mjsunit/wasm/test-import-export-wrapper.js +++ b/test/mjsunit/wasm/test-import-export-wrapper.js @@ -21,7 +21,7 @@ var expect_no_elison = 1; var second_module = new WasmModuleBuilder(); var sig_index = second_module.addType(kSig_i_i); second_module - .addImportWithModule("import_module_2", "import_name_2", sig_index); + .addImport("import_module_2", "import_name_2", sig_index); second_module .addFunction("second_export", sig_index) .addBody([ @@ -34,7 +34,7 @@ var expect_no_elison = 1; var first_module = new WasmModuleBuilder(); var sig_index = first_module.addType(kSig_i_i); first_module - .addImportWithModule("import_module_1", "import_name_1", sig_index); + .addImport("import_module_1", "import_name_1", sig_index); first_module .addFunction("first_export", sig_index) .addBody([ @@ -81,7 +81,7 @@ var expect_no_elison = 1; var sig_index1 = second_module.addType(kSig_i_i); var sig_index_ll = second_module.addType(kSig_l_l); second_module - .addImportWithModule("import_module_2", "import_name_2", sig_index1); + .addImport("import_module_2", "import_name_2", sig_index1); second_module .addFunction("second_export", sig_index_ll) .addBody([ @@ -97,7 +97,7 @@ var expect_no_elison = 1; var sig_index = first_module.addType(kSig_i_v); var sig_index_ll = first_module.addType(kSig_l_l); first_module - .addImportWithModule("import_module_1", "import_name_1", sig_index_ll); + .addImport("import_module_1", "import_name_1", sig_index_ll); first_module .addFunction("first_export", sig_index) .addBody([ @@ -138,7 +138,7 @@ assertThrows(function TestWasmWrapperNoElisionLessParams() { var second_module = new WasmModuleBuilder(); var sig_index_1 = second_module.addType(kSig_i_i); second_module - .addImportWithModule("import_module_2", "import_name_2", sig_index_1); + .addImport("import_module_2", "import_name_2", sig_index_1); second_module .addFunction("second_export", sig_index_1) .addBody([ @@ -151,7 +151,7 @@ assertThrows(function TestWasmWrapperNoElisionLessParams() { var first_module = new WasmModuleBuilder(); var sig_index_2 = first_module.addType(kSig_i_ii); first_module - .addImportWithModule("import_module_1", "import_name_1", sig_index_2); + .addImport("import_module_1", "import_name_1", sig_index_2); first_module .addFunction("first_export", sig_index_2) .addBody([ @@ -195,7 +195,7 @@ assertThrows(function TestWasmWrapperNoElisionMoreParams() { var second_module = new WasmModuleBuilder(); var sig_index_3 = second_module.addType(kSig_i_iii); second_module - .addImportWithModule("import_module_2", "import_name_2", sig_index_3); + .addImport("import_module_2", "import_name_2", sig_index_3); second_module .addFunction("second_export", sig_index_3) .addBody([ @@ -210,7 +210,7 @@ assertThrows(function TestWasmWrapperNoElisionMoreParams() { var first_module = new WasmModuleBuilder(); var sig_index_2 = first_module.addType(kSig_i_ii); first_module - .addImportWithModule("import_module_1", "import_name_1", sig_index_2); + .addImport("import_module_1", "import_name_1", sig_index_2); first_module .addFunction("first_export", sig_index_2) .addBody([ @@ -254,7 +254,7 @@ assertThrows(function TestWasmWrapperNoElisionTypeMismatch() { var second_module = new WasmModuleBuilder(); var sig_index_2 = second_module.addType(kSig_d_dd); second_module - .addImportWithModule("import_module_2", "import_name_2", sig_index_2); + .addImport("import_module_2", "import_name_2", sig_index_2); second_module .addFunction("second_export", sig_index_2) .addBody([ @@ -268,7 +268,7 @@ assertThrows(function TestWasmWrapperNoElisionTypeMismatch() { var first_module = new WasmModuleBuilder(); var sig_index_2 = first_module.addType(kSig_i_ii); first_module - .addImportWithModule("import_module_1", "import_name_1", sig_index_2); + .addImport("import_module_1", "import_name_1", sig_index_2); first_module .addFunction("first_export", sig_index_2) .addBody([ diff --git a/test/mjsunit/wasm/test-wasm-module-builder.js b/test/mjsunit/wasm/test-wasm-module-builder.js index 30bbe4ac93..f673bec32f 100644 --- a/test/mjsunit/wasm/test-wasm-module-builder.js +++ b/test/mjsunit/wasm/test-wasm-module-builder.js @@ -27,13 +27,13 @@ function instantiate(buffer, ffi) { (function ImportTest() { let builder = new WasmModuleBuilder(); - var index = builder.addImport("print", makeSig_v_x(kAstI32)); + var index = builder.addImport("", "print", makeSig_v_x(kAstI32)); builder.addFunction("foo", kSig_v_v) .addBody([kExprI8Const, 13, kExprCallFunction, index]) .exportAs("main"); var buffer = builder.toBuffer(debug); - var instance = instantiate(buffer, {print: print}); + var instance = instantiate(buffer, {"": {print: print}}); print("should print 13! "); instance.exports.main(); })(); @@ -145,7 +145,7 @@ function instantiate(buffer, ffi) { (function ImportTestTwoLevel() { let builder = new WasmModuleBuilder(); - var index = builder.addImportWithModule("mod", "print", makeSig_v_x(kAstI32)); + var index = builder.addImport("mod", "print", makeSig_v_x(kAstI32)); builder.addFunction("foo", kSig_v_v) .addBody([kExprI8Const, 19, kExprCallFunction, index]) .exportAs("main"); diff --git a/test/mjsunit/wasm/unicode-validation.js b/test/mjsunit/wasm/unicode-validation.js index 29d1f73d94..2dd2d00bce 100644 --- a/test/mjsunit/wasm/unicode-validation.js +++ b/test/mjsunit/wasm/unicode-validation.js @@ -45,7 +45,7 @@ function checkImportsAndExports(imported_module_name, imported_function_name, internal_function_name, exported_function_name, shouldThrow) { var builder = new WasmModuleBuilder(); - builder.addImportWithModule(imported_module_name, imported_function_name, + builder.addImport(imported_module_name, imported_function_name, kSig_v_v); builder.addFunction(internal_function_name, kSig_v_v) diff --git a/test/mjsunit/wasm/wasm-module-builder.js b/test/mjsunit/wasm/wasm-module-builder.js index 900198d7d0..edacb38062 100644 --- a/test/mjsunit/wasm/wasm-module-builder.js +++ b/test/mjsunit/wasm/wasm-module-builder.js @@ -179,32 +179,28 @@ class WasmModuleBuilder { return func; } - addImportWithModule(module, name, type) { + addImport(module = "", name, type) { let type_index = (typeof type) == "number" ? type : this.addType(type); this.imports.push({module: module, name: name, kind: kExternalFunction, type: type_index}); return this.num_imported_funcs++; } - addImport(name, type) { - return this.addImportWithModule(name, undefined, type); - } - - addImportedGlobal(module, name, type) { + addImportedGlobal(module = "", name, type) { let o = {module: module, name: name, kind: kExternalGlobal, type: type, mutable: false} this.imports.push(o); return this.num_imported_globals++; } - addImportedMemory(module, name, initial = 0, maximum) { + addImportedMemory(module = "", name, initial = 0, maximum) { let o = {module: module, name: name, kind: kExternalMemory, initial: initial, maximum: maximum}; this.imports.push(o); return this; } - addImportedTable(module, name, initial, maximum) { + addImportedTable(module = "", name, initial, maximum) { let o = {module: module, name: name, kind: kExternalTable, initial: initial, maximum: maximum}; this.imports.push(o);