Commit 6e833886 authored by titzer's avatar titzer Committed by Commit bot

[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}
parent a1c917ca
...@@ -257,8 +257,18 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate, ...@@ -257,8 +257,18 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate,
ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation");
// Create the ffi object for foreign functions {"": foreign}.
Handle<JSObject> ffi_object;
if (!foreign.is_null()) {
Handle<JSFunction> object_function = Handle<JSFunction>(
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<i::JSObject> maybe_module_object = i::MaybeHandle<i::JSObject> maybe_module_object =
i::wasm::WasmModule::Instantiate(isolate, &thrower, module, foreign, i::wasm::WasmModule::Instantiate(isolate, &thrower, module, ffi_object,
memory); memory);
if (maybe_module_object.is_null()) { if (maybe_module_object.is_null()) {
return MaybeHandle<Object>(); return MaybeHandle<Object>();
......
...@@ -92,11 +92,11 @@ RUNTIME_FUNCTION(Runtime_InstantiateAsmJs) { ...@@ -92,11 +92,11 @@ RUNTIME_FUNCTION(Runtime_InstantiateAsmJs) {
} }
Handle<JSObject> foreign; Handle<JSObject> foreign;
if (args[2]->IsJSObject()) { if (args[2]->IsJSObject()) {
foreign = args.at<i::JSObject>(2); foreign = args.at<JSObject>(2);
} }
Handle<JSArrayBuffer> memory; Handle<JSArrayBuffer> memory;
if (args[3]->IsJSArrayBuffer()) { if (args[3]->IsJSArrayBuffer()) {
memory = args.at<i::JSArrayBuffer>(3); memory = args.at<JSArrayBuffer>(3);
} }
if (function->shared()->HasAsmWasmData() && if (function->shared()->HasAsmWasmData() &&
AsmJs::IsStdlibValid(isolate, handle(function->shared()->asm_wasm_data()), AsmJs::IsStdlibValid(isolate, handle(function->shared()->asm_wasm_data()),
......
...@@ -280,9 +280,6 @@ class ModuleDecoder : public Decoder { ...@@ -280,9 +280,6 @@ class ModuleDecoder : public Decoder {
const byte* pos = pc_; const byte* pos = pc_;
import->module_name_offset = import->module_name_offset =
consume_string(&import->module_name_length, true); 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 = import->field_name_offset =
consume_string(&import->field_name_length, true); consume_string(&import->field_name_length, true);
......
...@@ -328,10 +328,10 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const { ...@@ -328,10 +328,10 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
size_t start = EmitSection(kImportSectionCode, buffer); size_t start = EmitSection(kImportSectionCode, buffer);
buffer.write_size(imports_.size()); buffer.write_size(imports_.size());
for (auto import : imports_) { for (auto import : imports_) {
buffer.write_u32v(import.name_length); // module name length buffer.write_u32v(0); // module name length
buffer.write(reinterpret_cast<const byte*>(import.name), // module name buffer.write_u32v(import.name_length); // field name length
buffer.write(reinterpret_cast<const byte*>(import.name), // field name
import.name_length); import.name_length);
buffer.write_u32v(0); // field name length
buffer.write_u8(kExternalFunction); buffer.write_u8(kExternalFunction);
buffer.write_u32v(import.sig_index); buffer.write_u32v(import.sig_index);
} }
......
...@@ -1462,21 +1462,16 @@ class WasmInstanceBuilder { ...@@ -1462,21 +1462,16 @@ class WasmInstanceBuilder {
Handle<Object> module = result.ToHandleChecked(); Handle<Object> module = result.ToHandleChecked();
// TODO(bradnelson): Making this conditional on non-empty names violates the // Look up the value in the module.
// Wasm spec, but seems to be a hack intended for the asm-to-wasm pipeline. if (!module->IsJSReceiver()) {
// We need to get rid of it. return ReportTypeError("module is not an object or function", index,
if (import_name->length() != 0) { 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); result = Object::GetPropertyOrElement(module, import_name);
if (result.is_null()) { if (result.is_null()) {
ReportLinkError("import not found", index, module_name, import_name); ReportLinkError("import not found", index, module_name, import_name);
return MaybeHandle<JSFunction>(); return MaybeHandle<JSFunction>();
}
} }
return result; return result;
......
...@@ -48,7 +48,7 @@ var builder = new WasmModuleBuilder(); ...@@ -48,7 +48,7 @@ var builder = new WasmModuleBuilder();
// wasm_1 calls wasm_2 on offset 2. // wasm_1 calls wasm_2 on offset 2.
// wasm_2 calls call_debugger on offset 1. // 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) builder.addFunction('wasm_1', kSig_v_v)
.addBody([kExprNop, kExprCallFunction, 2]) .addBody([kExprNop, kExprCallFunction, 2])
...@@ -60,7 +60,7 @@ function call_debugger() { ...@@ -60,7 +60,7 @@ function call_debugger() {
debugger; debugger;
} }
var module = builder.instantiate({func: call_debugger}); var module = builder.instantiate({mod: {func: call_debugger}});
(function testFrameInspection() { (function testFrameInspection() {
Debug.setListener(listener); Debug.setListener(listener);
......
...@@ -9,7 +9,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -9,7 +9,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder(); 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) var call_imported_idx = builder.addFunction("call_func", kSig_v_v)
.addBody([kExprCallFunction, imported_idx]) .addBody([kExprCallFunction, imported_idx])
...@@ -40,7 +40,7 @@ function testFunction(bytes) { ...@@ -40,7 +40,7 @@ function testFunction(bytes) {
} }
var module = new WebAssembly.Module(buffer); 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(); instance.exports.main();
} }
......
...@@ -9,7 +9,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -9,7 +9,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder(); 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) var call_imported_idx = builder.addFunction('call_func', kSig_v_v)
.addBody([kExprCallFunction, imported_idx]) .addBody([kExprCallFunction, imported_idx])
...@@ -35,7 +35,7 @@ function testFunction(bytes) { ...@@ -35,7 +35,7 @@ function testFunction(bytes) {
} }
var module = new WebAssembly.Module(buffer); 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(); instance.exports.main();
} }
......
...@@ -20,7 +20,7 @@ var instance4; ...@@ -20,7 +20,7 @@ var instance4;
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
builder.addImport("getValue", kSig_i_v); builder.addImport("", "getValue", kSig_i_v);
builder.addFunction("f", kSig_i_v) builder.addFunction("f", kSig_i_v)
.addBody([ .addBody([
kExprCallFunction, 0 kExprCallFunction, 0
...@@ -29,11 +29,11 @@ var instance4; ...@@ -29,11 +29,11 @@ var instance4;
module = new WebAssembly.Module(builder.toBuffer()); module = new WebAssembly.Module(builder.toBuffer());
%ValidateWasmModuleState(module); %ValidateWasmModuleState(module);
%ValidateWasmInstancesChain(module, 0); %ValidateWasmInstancesChain(module, 0);
instance1 = new WebAssembly.Instance(module, {getValue: () => 1}); instance1 = new WebAssembly.Instance(module, {"": {getValue: () => 1}});
%ValidateWasmInstancesChain(module, 1); %ValidateWasmInstancesChain(module, 1);
instance2 = new WebAssembly.Instance(module, {getValue: () => 2}); instance2 = new WebAssembly.Instance(module, {"": {getValue: () => 2}});
%ValidateWasmInstancesChain(module, 2); %ValidateWasmInstancesChain(module, 2);
instance3 = new WebAssembly.Instance(module, {getValue: () => 3}); instance3 = new WebAssembly.Instance(module, {"": {getValue: () => 3}});
%ValidateWasmInstancesChain(module, 3); %ValidateWasmInstancesChain(module, 3);
})(); })();
...@@ -62,7 +62,7 @@ gc(); ...@@ -62,7 +62,7 @@ gc();
%ValidateWasmModuleState(module); %ValidateWasmModuleState(module);
(function CompiledModuleInstancesInitialize4AndClearModule() { (function CompiledModuleInstancesInitialize4AndClearModule() {
instance4 = new WebAssembly.Instance(module, {getValue: () => 4}); instance4 = new WebAssembly.Instance(module, {"": {getValue: () => 4}});
assertEquals(4, instance4.exports.f()); assertEquals(4, instance4.exports.f());
module = null; module = null;
})(); })();
......
...@@ -12,8 +12,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -12,8 +12,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
var kSig_v_i = makeSig([kAstI32], []); var kSig_v_i = makeSig([kAstI32], []);
var signature = builder.addType(kSig_v_i); var signature = builder.addType(kSig_v_i);
builder.addImport("some_value", kSig_i_v); builder.addImport("", "some_value", kSig_i_v);
builder.addImport("writer", signature); builder.addImport("", "writer", signature);
builder.addFunction("main", kSig_i_i) builder.addFunction("main", kSig_i_i)
.addBody([ .addBody([
...@@ -48,8 +48,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -48,8 +48,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
view_1[0] = 42; view_1[0] = 42;
var outval_1; var outval_1;
var i1 = new WebAssembly.Instance(module, {some_value: () => 1, var i1 = new WebAssembly.Instance(module, {"": {some_value: () => 1,
writer: (x)=>outval_1 = x }, mem_1); writer: (x)=>outval_1 = x }}, mem_1);
assertEquals(43, i1.exports.main(0)); assertEquals(43, i1.exports.main(0));
......
...@@ -39,7 +39,7 @@ function GlobalImportedInitTest(pad) { ...@@ -39,7 +39,7 @@ function GlobalImportedInitTest(pad) {
while (pad-- > 0) builder.addGlobal(kAstI32); // 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 while (pad-- > 0) builder.addGlobal(kAstI32); // pad
...@@ -52,7 +52,7 @@ function GlobalImportedInitTest(pad) { ...@@ -52,7 +52,7 @@ function GlobalImportedInitTest(pad) {
var module = new WebAssembly.Module(buffer); var module = new WebAssembly.Module(buffer);
for (var offset of [0, 12, 192, 1024]) { 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) { for (var i = offset - 20; i < offset + 20; i += 4) {
if (i < 0) continue; if (i < 0) continue;
var expected = i == offset ? 84215045 : 0; var expected = i == offset ? 84215045 : 0;
......
...@@ -71,13 +71,13 @@ function assertConversionError(bytes, imports = {}) { ...@@ -71,13 +71,13 @@ function assertConversionError(bytes, imports = {}) {
let b; let b;
b = builder(); b = builder();
b.addImportWithModule("foo", "bar", kSig_v_v); b.addImport("foo", "bar", kSig_v_v);
assertTypeError(b.toBuffer(), {}); assertTypeError(b.toBuffer(), {});
b = builder(); b = builder();
b.addImportWithModule("foo", "bar", kSig_v_v); b.addImport("foo", "bar", kSig_v_v);
assertLinkError(b.toBuffer(), {foo: {}}); assertLinkError(b.toBuffer(), {foo: {}});
b = builder(); b = builder();
b.addImportWithModule("foo", "bar", kSig_v_v); b.addImport("foo", "bar", kSig_v_v);
assertLinkError(b.toBuffer(), {foo: {bar: 9}}); assertLinkError(b.toBuffer(), {foo: {bar: 9}});
b = builder(); b = builder();
...@@ -132,7 +132,7 @@ function assertConversionError(bytes, imports = {}) { ...@@ -132,7 +132,7 @@ function assertConversionError(bytes, imports = {}) {
(function TestConversionError() { (function TestConversionError() {
let b = builder(); 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([ assertConversionError(b.addFunction("run", kSig_v_v).addBody([
kExprI64Const, 0, kExprCallFunction, 0 kExprI64Const, 0, kExprCallFunction, 0
]).exportFunc().end().toBuffer()); ]).exportFunc().end().toBuffer());
......
...@@ -79,32 +79,32 @@ var test_catch = (function () { ...@@ -79,32 +79,32 @@ var test_catch = (function () {
throw value; throw value;
} }
var sig_index = builder.addType(kSig_v_i); 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. // Helper function that throws a string. Wasm should not catch it.
function throw_string() { function throw_string() {
throw "use wasm;"; throw "use wasm;";
} }
sig_index = builder.addType(kSig_v_v); 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. // Helper function that throws undefined. Wasm should not catch it.
function throw_undefined() { function throw_undefined() {
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. // Helper function that throws an fp. Wasm should not catch it.
function throw_fp() { function throw_fp() {
throw 10.5; 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. // Helper function that throws a large number. Wasm should not catch it.
function throw_large() { function throw_large() {
throw 1e+28; 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. // Helper function for throwing from WebAssembly.
var kWasmThrowFunction = var kWasmThrowFunction =
...@@ -335,13 +335,13 @@ var test_catch = (function () { ...@@ -335,13 +335,13 @@ var test_catch = (function () {
]) ])
.exportFunc(); .exportFunc();
return builder.instantiate({ return builder.instantiate({"": {
throw_i: throw_value, throw_i: throw_value,
throw_string: throw_string, throw_string: throw_string,
throw_fp: throw_fp, throw_fp: throw_fp,
throw_large, throw_large, throw_large, throw_large,
throw_undefined: throw_undefined throw_undefined: throw_undefined
}); }});
})(); })();
// Check the test_catch exists. // Check the test_catch exists.
......
...@@ -141,11 +141,11 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -141,11 +141,11 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
function 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("f", a);
builder.addExport("g", a); builder.addExport("g", a);
let instance = builder.instantiate({a: js}); let instance = builder.instantiate({m: {a: js}});
let e = instance.exports; let e = instance.exports;
assertEquals("function", typeof e.f); assertEquals("function", typeof e.f);
assertEquals("function", typeof e.g); assertEquals("function", typeof e.g);
...@@ -161,12 +161,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -161,12 +161,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
function js() {} function js() {}
var a = builder.addImport("a", kSig_v_v); var a = builder.addImport("q", "a", kSig_v_v);
var b = builder.addImport("b", kSig_v_v); var b = builder.addImport("q", "b", kSig_v_v);
builder.addExport("f", a); builder.addExport("f", a);
builder.addExport("g", b); 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; let e = instance.exports;
assertEquals("function", typeof e.f); assertEquals("function", typeof e.f);
assertEquals("function", typeof e.g); assertEquals("function", typeof e.g);
......
...@@ -11,7 +11,7 @@ function testCallFFI(ffi) { ...@@ -11,7 +11,7 @@ function testCallFFI(ffi) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = kSig_i_dd; var sig_index = kSig_i_dd;
builder.addImport("fun", sig_index); builder.addImport("", "fun", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -25,8 +25,7 @@ function testCallFFI(ffi) { ...@@ -25,8 +25,7 @@ function testCallFFI(ffi) {
// everything is good. // everything is good.
(function() { (function() {
var ffi = new Object(); var ffi = {"": {fun: function(a, b) { print(a, b); }}}
ffi.fun = function(a, b) { print(a, b); }
testCallFFI(ffi); testCallFFI(ffi);
})(); })();
...@@ -101,7 +100,7 @@ assertThrows(function() { ...@@ -101,7 +100,7 @@ assertThrows(function() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_i_i); var sig_index = builder.addType(kSig_i_i);
var sig_i64_index = builder.addType(kSig_i_l); 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) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, kExprGetLocal, 0,
...@@ -110,7 +109,7 @@ assertThrows(function() { ...@@ -110,7 +109,7 @@ assertThrows(function() {
]) // -- ]) // --
.exportFunc(); .exportFunc();
var func = function() {return {};}; var func = function() {return {};};
var main = builder.instantiate({func: func}).exports.main; var main = builder.instantiate({"": {func: func}}).exports.main;
assertThrows(function() { assertThrows(function() {
main(13); main(13);
}, TypeError); }, TypeError);
...@@ -118,11 +117,11 @@ assertThrows(function() { ...@@ -118,11 +117,11 @@ assertThrows(function() {
(function ImportSymbolToNumberThrows() { (function ImportSymbolToNumberThrows() {
var builder = new WasmModuleBuilder(); 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) builder.addFunction("main", kSig_i_v)
.addBody([kExprCallFunction, 0]) .addBody([kExprCallFunction, 0])
.exportFunc(); .exportFunc();
var func = () => Symbol(); var func = () => Symbol();
var main = builder.instantiate({func: func}).exports.main; var main = builder.instantiate({"": {func: func}}).exports.main;
assertThrows(() => main(), TypeError); assertThrows(() => main(), TypeError);
})(); })();
...@@ -11,7 +11,7 @@ function testCallFFI(func, check) { ...@@ -11,7 +11,7 @@ function testCallFFI(func, check) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_i_dd); var sig_index = builder.addType(kSig_i_dd);
builder.addImport("func", sig_index); builder.addImport("", "func", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -20,7 +20,7 @@ function testCallFFI(func, check) { ...@@ -20,7 +20,7 @@ function testCallFFI(func, check) {
]) // -- ]) // --
.exportFunc(); .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) { for (var i = 0; i < 100000; i += 10003) {
var a = 22.5 + i, b = 10.5 + i; var a = 22.5 + i, b = 10.5 + i;
...@@ -37,7 +37,7 @@ var was_called = false; ...@@ -37,7 +37,7 @@ var was_called = false;
var length = -1; var length = -1;
function FOREIGN_SUB(a, b) { function FOREIGN_SUB(a, b) {
print("FOREIGN_SUB(" + a + ", " + b + ")"); // print("FOREIGN_SUB(" + a + ", " + b + ")");
was_called = true; was_called = true;
params[0] = this; params[0] = this;
params[1] = a; params[1] = a;
...@@ -75,7 +75,7 @@ print("Constructor"); ...@@ -75,7 +75,7 @@ print("Constructor");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_i_dd); var sig_index = builder.addType(kSig_i_dd);
builder.addImport("func", sig_index); builder.addImport("", "func", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -84,7 +84,7 @@ print("Constructor"); ...@@ -84,7 +84,7 @@ print("Constructor");
]) // -- ]) // --
.exportFunc(); .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); assertThrows("main_for_constructor_test(12, 43)", TypeError);
}) (); }) ();
...@@ -95,14 +95,14 @@ print("Native function"); ...@@ -95,14 +95,14 @@ print("Native function");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_d_v); var sig_index = builder.addType(kSig_d_v);
builder.addImport("func", sig_index); builder.addImport("", "func", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprCallFunction, 0 // -- kExprCallFunction, 0 // --
]) // -- ]) // --
.exportFunc(); .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 // The result of the call to Object.prototype.toString should be
// [object Undefined]. However, we cannot test for this result because wasm // [object Undefined]. However, we cannot test for this result because wasm
// cannot return objects but converts them to float64 in this test. // cannot return objects but converts them to float64 in this test.
...@@ -113,7 +113,7 @@ print("Callable JSObject"); ...@@ -113,7 +113,7 @@ print("Callable JSObject");
testCallFFI(%GetCallable(), function check(r, a, b) {assertEquals(a - b, r);}); testCallFFI(%GetCallable(), function check(r, a, b) {assertEquals(a - b, r);});
function FOREIGN_ABCD(a, b, c, d) { function FOREIGN_ABCD(a, b, c, d) {
print("FOREIGN_ABCD(" + a + ", " + b + ", " + c + ", " + d + ")"); // print("FOREIGN_ABCD(" + a + ", " + b + ", " + c + ", " + d + ")");
was_called = true; was_called = true;
params[0] = this; params[0] = this;
params[1] = a; params[1] = a;
...@@ -224,7 +224,6 @@ var objWithValueOf = {valueOf: function() { return 198; }} ...@@ -224,7 +224,6 @@ var objWithValueOf = {valueOf: function() { return 198; }}
testCallFFI(returnValue(objWithValueOf), checkReturn(198)); testCallFFI(returnValue(objWithValueOf), checkReturn(198));
function testCallBinopVoid(type, func, check) { function testCallBinopVoid(type, func, check) {
var passed_length = -1; var passed_length = -1;
var passed_a = -1; var passed_a = -1;
...@@ -232,17 +231,17 @@ function testCallBinopVoid(type, func, check) { ...@@ -232,17 +231,17 @@ function testCallBinopVoid(type, func, check) {
var args_a = -1; var args_a = -1;
var args_b = -1; var args_b = -1;
ffi = {func: function(a, b) { ffi = {"": {func: function(a, b) {
passed_length = arguments.length; passed_length = arguments.length;
passed_a = a; passed_a = a;
passed_b = b; passed_b = b;
args_a = arguments[0]; args_a = arguments[0];
args_b = arguments[1]; args_b = arguments[1];
}}; }}};
var builder = new WasmModuleBuilder(); 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)) builder.addFunction("main", makeSig_r_xx(kAstI32, type))
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -293,13 +292,11 @@ testCallBinopVoid(kAstI32); ...@@ -293,13 +292,11 @@ testCallBinopVoid(kAstI32);
testCallBinopVoid(kAstF32); testCallBinopVoid(kAstF32);
testCallBinopVoid(kAstF64); testCallBinopVoid(kAstF64);
(function testCallPrint() { (function testCallPrint() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImport("print", makeSig_v_x(kAstI32)); builder.addImport("", "print", makeSig_v_x(kAstI32));
builder.addImport("print", makeSig_v_x(kAstF64)); builder.addImport("", "print", makeSig_v_x(kAstF64));
builder.addFunction("main", makeSig_v_x(kAstF64)) builder.addFunction("main", makeSig_v_x(kAstF64))
.addBody([ .addBody([
kExprI8Const, 97, // -- kExprI8Const, 97, // --
...@@ -309,27 +306,29 @@ testCallBinopVoid(kAstF64); ...@@ -309,27 +306,29 @@ testCallBinopVoid(kAstF64);
]) // -- ]) // --
.exportFunc() .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); for (var i = -9; i < 900; i += 6.125) main(i);
})(); })();
(function testImportNumbers() { (function testImportNumbers() {
print("TestImportNumbers...");
var builder = new WasmModuleBuilder(); 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() { (function testImportNumbers2() {
print("TestImportNumbers2...");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportWithModule('foo', '0', kSig_v_i); builder.addImport('foo', '0', kSig_v_i);
builder.addImportWithModule('0', 'foo', kSig_v_i); builder.addImport('0', 'foo', kSig_v_i);
builder.addImportWithModule('0', '0', kSig_v_i); builder.addImport('0', '0', kSig_v_i);
builder.addImportWithModule('18', '-3', kSig_v_i); builder.addImport('18', '-3', kSig_v_i);
builder.addImportWithModule('-3', '18', kSig_v_i); builder.addImport('-3', '18', kSig_v_i);
builder.instantiate({ builder.instantiate({
foo: {0: print}, foo: {0: print},
...@@ -340,21 +339,22 @@ testCallBinopVoid(kAstF64); ...@@ -340,21 +339,22 @@ testCallBinopVoid(kAstF64);
})(); })();
(function ImportSymbolAsVoidDoesNotThrow() { (function ImportSymbolAsVoidDoesNotThrow() {
print("ImportSymbolAsVoidDoesNotThrow...");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
// Return type is void, so there should be no ToNumber conversion. // 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) builder.addFunction("main", kSig_v_v)
.addBody([kExprCallFunction, 0]) .addBody([kExprCallFunction, 0])
.exportFunc(); .exportFunc();
var func = () => Symbol(); var func = () => Symbol();
var main = builder.instantiate({func: func}).exports.main; var main = builder.instantiate({"": {func: func}}).exports.main;
main(); main();
})(); })();
(function ToNumberCalledOnImport() { (function ToNumberCalledOnImport() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
// Return type is int, so there should be a ToNumber conversion. // 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) builder.addFunction("main", kSig_i_v)
.addBody([kExprCallFunction, 0]) .addBody([kExprCallFunction, 0])
.exportFunc(); .exportFunc();
...@@ -362,7 +362,7 @@ testCallBinopVoid(kAstF64); ...@@ -362,7 +362,7 @@ testCallBinopVoid(kAstF64);
function Foo() {} function Foo() {}
Foo.prototype.valueOf = () => ++num_valueOf; Foo.prototype.valueOf = () => ++num_valueOf;
var func = () => new Foo(); var func = () => new Foo();
var main = builder.instantiate({func: func}).exports.main; var main = builder.instantiate({"": {func: func}}).exports.main;
main(); main();
assertEquals(1, num_valueOf); assertEquals(1, num_valueOf);
main(); main();
...@@ -372,7 +372,7 @@ testCallBinopVoid(kAstF64); ...@@ -372,7 +372,7 @@ testCallBinopVoid(kAstF64);
(function ToNumberNotCalledOnVoidImport() { (function ToNumberNotCalledOnVoidImport() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
// Return type is void, so there should be no ToNumber conversion. // 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) builder.addFunction("main", kSig_v_v)
.addBody([kExprCallFunction, 0]) .addBody([kExprCallFunction, 0])
.exportFunc(); .exportFunc();
...@@ -380,7 +380,7 @@ testCallBinopVoid(kAstF64); ...@@ -380,7 +380,7 @@ testCallBinopVoid(kAstF64);
function Foo() {} function Foo() {}
Foo.prototype.valueOf = () => ++num_valueOf; Foo.prototype.valueOf = () => ++num_valueOf;
var func = () => new Foo(); var func = () => new Foo();
var main = builder.instantiate({func: func}).exports.main; var main = builder.instantiate({"": {func: func}}).exports.main;
main(); main();
main(); main();
assertEquals(0, num_valueOf); assertEquals(0, num_valueOf);
......
...@@ -12,7 +12,7 @@ function run(f) { ...@@ -12,7 +12,7 @@ function run(f) {
// the module (i.e. the underlying array buffer of WASM wire bytes dies). // the module (i.e. the underlying array buffer of WASM wire bytes dies).
var module = (() => { var module = (() => {
var builder = new WasmModuleBuilder(); 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) builder.addFunction("main", kSig_i_i)
.addBody([ .addBody([
kExprGetLocal, 0, kExprGetLocal, 0,
...@@ -25,7 +25,7 @@ function run(f) { ...@@ -25,7 +25,7 @@ function run(f) {
gc(); gc();
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
print(" instance " + 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; var g = instance.exports.main;
assertEquals("function", typeof g); assertEquals("function", typeof g);
for (var j = 0; j < 10; j++) { for (var j = 0; j < 10; j++) {
......
...@@ -11,7 +11,7 @@ function makeFFI(func, t) { ...@@ -11,7 +11,7 @@ function makeFFI(func, t) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(makeSig([t,t,t,t,t,t,t,t,t,t], [t])); 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 // 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 // on the stack to try to catch GC bugs in the reference maps for
// the different parts of the stack. // the different parts of the stack.
...@@ -43,7 +43,7 @@ function makeFFI(func, t) { ...@@ -43,7 +43,7 @@ function makeFFI(func, t) {
]) // -- ]) // --
.exportFunc(); .exportFunc();
return builder.instantiate({func: func}).exports.main; return builder.instantiate({m: {func: func}}).exports.main;
} }
......
...@@ -9,7 +9,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -9,7 +9,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
function run(f) { function run(f) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImport("f", kSig_i_i); builder.addImport("m", "f", kSig_i_i);
builder.addFunction("main", kSig_i_i) builder.addFunction("main", kSig_i_i)
.addBody([ .addBody([
kExprGetLocal, 0, kExprGetLocal, 0,
...@@ -21,7 +21,7 @@ function run(f) { ...@@ -21,7 +21,7 @@ function run(f) {
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
print(" instance " + 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; var g = instance.exports.main;
for (var j = 0; j < 10; j++) { for (var j = 0; j < 10; j++) {
assertEquals(f(j), g(j)); assertEquals(f(j), g(j));
......
...@@ -11,13 +11,13 @@ function TestImported(type, val, expected) { ...@@ -11,13 +11,13 @@ function TestImported(type, val, expected) {
print("TestImported " + type + "(" + val +")" + " = " + expected); print("TestImported " + type + "(" + val +")" + " = " + expected);
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig = makeSig([], [type]); var sig = makeSig([], [type]);
var g = builder.addImportedGlobal("foo", undefined, type); var g = builder.addImportedGlobal("uuu", "foo", type);
builder.addFunction("main", sig) builder.addFunction("main", sig)
.addBody([kExprGetGlobal, g.index]) .addBody([kExprGetGlobal, g.index])
.exportAs("main"); .exportAs("main");
builder.addGlobal(kAstI32); // pad builder.addGlobal(kAstI32); // pad
var instance = builder.instantiate({foo: val}); var instance = builder.instantiate({uuu: {foo: val}});
assertEquals(expected, instance.exports.main()); assertEquals(expected, instance.exports.main());
} }
...@@ -49,14 +49,14 @@ function TestImportedExported(type, val, expected) { ...@@ -49,14 +49,14 @@ function TestImportedExported(type, val, expected) {
print("TestImportedExported " + type + "(" + val +")" + " = " + expected); print("TestImportedExported " + type + "(" + val +")" + " = " + expected);
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig = makeSig([type], []); var sig = makeSig([type], []);
var i = builder.addImportedGlobal("foo", undefined, type); var i = builder.addImportedGlobal("ttt", "foo", type);
builder.addGlobal(kAstI32); // pad builder.addGlobal(kAstI32); // pad
var o = builder.addGlobal(type, false) var o = builder.addGlobal(type, false)
.exportAs("bar"); .exportAs("bar");
o.init_index = i; o.init_index = i;
builder.addGlobal(kAstI32); // pad builder.addGlobal(kAstI32); // pad
var instance = builder.instantiate({foo: val}); var instance = builder.instantiate({ttt: {foo: val}});
assertEquals(expected, instance.exports.bar); assertEquals(expected, instance.exports.bar);
} }
...@@ -67,7 +67,7 @@ TestImportedExported(kAstF64, 81347.66666, 81347.66666); ...@@ -67,7 +67,7 @@ TestImportedExported(kAstF64, 81347.66666, 81347.66666);
function TestGlobalIndexSpace(type, val) { function TestGlobalIndexSpace(type, val) {
print("TestGlobalIndexSpace(" + val + ") = " + val); print("TestGlobalIndexSpace(" + val + ") = " + val);
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var im = builder.addImportedGlobal("foo", undefined, type); var im = builder.addImportedGlobal("nnn", "foo", type);
assertEquals(0, im); assertEquals(0, im);
var def = builder.addGlobal(type, false); var def = builder.addGlobal(type, false);
assertEquals(1, def.index); assertEquals(1, def.index);
...@@ -78,7 +78,7 @@ function TestGlobalIndexSpace(type, val) { ...@@ -78,7 +78,7 @@ function TestGlobalIndexSpace(type, val) {
.addBody([kExprGetGlobal, def.index]) .addBody([kExprGetGlobal, def.index])
.exportAs("main"); .exportAs("main");
var instance = builder.instantiate({foo: val}); var instance = builder.instantiate({nnn: {foo: val}});
assertEquals(val, instance.exports.main()); assertEquals(val, instance.exports.main());
} }
......
...@@ -13,14 +13,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -13,14 +13,14 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(kPageSize, memory.buffer.byteLength); assertEquals(kPageSize, memory.buffer.byteLength);
let i32 = new Int32Array(memory.buffer); let i32 = new Int32Array(memory.buffer);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImportedMemory("mine"); builder.addImportedMemory("mod", "mine");
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([ .addBody([
kExprI32Const, 0, kExprI32Const, 0,
kExprI32LoadMem, 0, 0]) kExprI32LoadMem, 0, 0])
.exportAs("main"); .exportAs("main");
let main = builder.instantiate({mine: memory}).exports.main; let main = builder.instantiate({mod: {mine: memory}}).exports.main;
assertEquals(0, main()); assertEquals(0, main());
i32[0] = 993377; i32[0] = 993377;
...@@ -33,10 +33,10 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -33,10 +33,10 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
let memory = new WebAssembly.Memory({initial: 1}); let memory = new WebAssembly.Memory({initial: 1});
let i32 = new Int32Array(memory.buffer); let i32 = new Int32Array(memory.buffer);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImportedMemory("garg"); builder.addImportedMemory("dad", "garg");
builder.exportMemoryAs("daggle"); builder.exportMemoryAs("daggle");
let instance = builder.instantiate({garg: memory}); let instance = builder.instantiate({dad: {garg: memory}});
assertSame(memory, instance.exports.daggle); assertSame(memory, instance.exports.daggle);
})(); })();
...@@ -59,13 +59,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -59,13 +59,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
{ {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addMemory(1, 1, false); builder.addMemory(1, 1, false);
builder.addImportedMemory("imported_mem"); builder.addImportedMemory("fil", "imported_mem");
builder.addFunction("bar", kSig_i_i) builder.addFunction("bar", kSig_i_i)
.addBody([ .addBody([
kExprGetLocal, 0, kExprGetLocal, 0,
kExprI32LoadMem, 0, 0]) kExprI32LoadMem, 0, 0])
.exportAs("bar"); .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); let i32 = new Int32Array(i1.exports.exported_mem.buffer);
...@@ -86,8 +86,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -86,8 +86,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(kPageSize, memory.buffer.byteLength); assertEquals(kPageSize, memory.buffer.byteLength);
let i32 = new Int32Array(memory.buffer); let i32 = new Int32Array(memory.buffer);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
// builder.addImportedMemory("mine"); builder.addImportedMemory("gaz", "mine");
builder.addImportedMemory("mine");
builder.addFunction("load", kSig_i_i) builder.addFunction("load", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
.exportFunc(); .exportFunc();
...@@ -96,7 +95,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -96,7 +95,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprGetLocal, 1]) kExprGetLocal, 1])
.exportFunc(); .exportFunc();
var offset; var offset;
let instance = builder.instantiate({mine: memory}); let instance = builder.instantiate({gaz: {mine: memory}});
function load() { return instance.exports.load(offset); } function load() { return instance.exports.load(offset); }
function store(value) { return instance.exports.store(offset, value); } function store(value) { return instance.exports.store(offset, value); }
...@@ -117,7 +116,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -117,7 +116,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(kPageSize, memory.buffer.byteLength); assertEquals(kPageSize, memory.buffer.byteLength);
let i32 = new Int32Array(memory.buffer); let i32 = new Int32Array(memory.buffer);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImportedMemory("mine", "", 0, 20); builder.addImportedMemory("mine", "dog", 0, 20);
builder.addFunction("load", kSig_i_i) builder.addFunction("load", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
.exportFunc(); .exportFunc();
...@@ -126,7 +125,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -126,7 +125,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprGetLocal, 1]) kExprGetLocal, 1])
.exportFunc(); .exportFunc();
var offset; var offset;
let instance = builder.instantiate({mine: memory}); let instance = builder.instantiate({mine: {dog: memory}});
function load() { return instance.exports.load(offset); } function load() { return instance.exports.load(offset); }
function store(value) { return instance.exports.store(offset, value); } function store(value) { return instance.exports.store(offset, value); }
...@@ -155,7 +154,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -155,7 +154,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(0, memory.buffer.byteLength); assertEquals(0, memory.buffer.byteLength);
let i32 = new Int32Array(memory.buffer); let i32 = new Int32Array(memory.buffer);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImportedMemory("mine"); builder.addImportedMemory("mine", "fro");
builder.addFunction("load", kSig_i_i) builder.addFunction("load", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
.exportFunc(); .exportFunc();
...@@ -164,7 +163,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -164,7 +163,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprGetLocal, 1]) kExprGetLocal, 1])
.exportFunc(); .exportFunc();
var offset; var offset;
let instance = builder.instantiate({mine: memory}); let instance = builder.instantiate({mine: {fro: memory}});
function load() { return instance.exports.load(offset); } function load() { return instance.exports.load(offset); }
function store(value) { return instance.exports.store(offset, value); } function store(value) { return instance.exports.store(offset, value); }
...@@ -189,8 +188,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -189,8 +188,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addFunction("grow", kSig_i_i) builder.addFunction("grow", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
.exportFunc(); .exportFunc();
builder.addImportedMemory("mine"); builder.addImportedMemory("cat", "mine");
let instance = builder.instantiate({mine: memory}); let instance = builder.instantiate({cat: {mine: memory}});
function grow(pages) { return instance.exports.grow(pages); } function grow(pages) { return instance.exports.grow(pages); }
assertEquals(2, grow(3)); assertEquals(2, grow(3));
assertEquals(5*kPageSize, memory.buffer.byteLength); assertEquals(5*kPageSize, memory.buffer.byteLength);
...@@ -212,15 +211,15 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -212,15 +211,15 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var instance; var instance;
{ {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedMemory("imported_mem"); builder.addImportedMemory("fur", "imported_mem");
builder.addFunction("mem_size", kSig_i_v) builder.addFunction("mem_size", kSig_i_v)
.addBody([kExprMemorySize, kMemoryZero]) .addBody([kExprMemorySize, kMemoryZero])
.exportFunc(); .exportFunc();
builder.addFunction("grow", kSig_i_i) builder.addFunction("grow", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
.exportFunc(); .exportFunc();
instance = builder.instantiate({ instance = builder.instantiate({fur: {
imported_mem: exp_instance.exports.exported_mem}); imported_mem: exp_instance.exports.exported_mem}});
} }
for (var i = initial_size; i < maximum_size; i++) { for (var i = initial_size; i < maximum_size; i++) {
assertEquals(i, instance.exports.grow(1)); assertEquals(i, instance.exports.grow(1));
...@@ -233,7 +232,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -233,7 +232,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
print("TestMemoryGrowWebAssemblyInstances"); print("TestMemoryGrowWebAssemblyInstances");
let memory = new WebAssembly.Memory({initial: 1, maximum: 15}); let memory = new WebAssembly.Memory({initial: 1, maximum: 15});
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedMemory("imported_mem"); builder.addImportedMemory("lit", "imported_mem");
builder.addFunction("mem_size", kSig_i_v) builder.addFunction("mem_size", kSig_i_v)
.addBody([kExprMemorySize, kMemoryZero]) .addBody([kExprMemorySize, kMemoryZero])
.exportAs("mem_size"); .exportAs("mem_size");
...@@ -243,7 +242,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -243,7 +242,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var module = new WebAssembly.Module(builder.toBuffer()); var module = new WebAssembly.Module(builder.toBuffer());
var instances = []; var instances = [];
for (var i = 0; i < 6; i++) { 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) { function verify_mem_size(expected_pages) {
assertEquals(expected_pages*kPageSize, assertEquals(expected_pages*kPageSize,
...@@ -274,7 +273,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -274,7 +273,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
print("TestImportMemoryMultipleInstances"); print("TestImportMemoryMultipleInstances");
let memory = new WebAssembly.Memory({initial: 5, maximum: 100}); let memory = new WebAssembly.Memory({initial: 5, maximum: 100});
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedMemory("imported_mem"); builder.addImportedMemory("nob", "imported_mem");
builder.addFunction("mem_size", kSig_i_v) builder.addFunction("mem_size", kSig_i_v)
.addBody([kExprMemorySize, kMemoryZero]) .addBody([kExprMemorySize, kMemoryZero])
.exportFunc(); .exportFunc();
...@@ -283,7 +282,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -283,7 +282,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
.exportFunc(); .exportFunc();
var instances = []; var instances = [];
for (var i = 0; i < 5; i++) { 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_0(pages) { return instances[0].exports.grow(pages); }
function grow_instance_1(pages) { return instances[1].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"); ...@@ -342,7 +341,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
instance = builder.instantiate(); instance = builder.instantiate();
} }
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedMemory("imported_mem"); builder.addImportedMemory("doo", "imported_mem");
builder.addFunction("mem_size", kSig_i_v) builder.addFunction("mem_size", kSig_i_v)
.addBody([kExprMemorySize, kMemoryZero]) .addBody([kExprMemorySize, kMemoryZero])
.exportFunc(); .exportFunc();
...@@ -352,7 +351,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -352,7 +351,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var instances = []; var instances = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
instances.push(builder.instantiate({ instances.push(builder.instantiate({
imported_mem: instance.exports.exported_mem})); doo: {imported_mem: instance.exports.exported_mem}}));
} }
function verify_mem_size(expected_pages) { function verify_mem_size(expected_pages) {
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
......
...@@ -11,7 +11,7 @@ function testCallImport(func, check) { ...@@ -11,7 +11,7 @@ function testCallImport(func, check) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_i_dd); var sig_index = builder.addType(kSig_i_dd);
builder.addImport("func", sig_index); builder.addImport("q", "func", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -19,7 +19,7 @@ function testCallImport(func, check) { ...@@ -19,7 +19,7 @@ function testCallImport(func, check) {
kExprCallFunction, 0]) // -- kExprCallFunction, 0]) // --
.exportAs("main"); .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) { for (var i = 0; i < 100000; i += 10003) {
var a = 22.5 + i, b = 10.5 + i; var a = 22.5 + i, b = 10.5 + i;
...@@ -168,25 +168,23 @@ testCallImport(returnValue(objWithValueOf), checkReturn(198)); ...@@ -168,25 +168,23 @@ testCallImport(returnValue(objWithValueOf), checkReturn(198));
function testCallBinopVoid(type, func, check) { function testCallBinopVoid(type, func, check) {
var ffi = new Object();
var passed_length = -1; var passed_length = -1;
var passed_a = -1; var passed_a = -1;
var passed_b = -1; var passed_b = -1;
var args_a = -1; var args_a = -1;
var args_b = -1; var args_b = -1;
ffi.func = function(a, b) { var ffi = {q: {func: function(a, b) {
passed_length = arguments.length; passed_length = arguments.length;
passed_a = a; passed_a = a;
passed_b = b; passed_b = b;
args_a = arguments[0]; args_a = arguments[0];
args_b = arguments[1]; args_b = arguments[1];
} }}};
var builder = new WasmModuleBuilder(); 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)) builder.addFunction("main", makeSig_r_xx(kAstI32, type))
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -241,8 +239,8 @@ testCallBinopVoid(kAstF64); ...@@ -241,8 +239,8 @@ testCallBinopVoid(kAstF64);
function testCallPrint() { function testCallPrint() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImport("print", makeSig_v_x(kAstI32)); builder.addImport("q", "print", makeSig_v_x(kAstI32));
builder.addImport("print", makeSig_r_x(kAstF64, kAstF64)); builder.addImport("q", "print", makeSig_r_x(kAstF64, kAstF64));
builder.addFunction("main", makeSig_r_x(kAstF64, kAstF64)) builder.addFunction("main", makeSig_r_x(kAstF64, kAstF64))
.addBody([ .addBody([
kExprI8Const, 97, // -- kExprI8Const, 97, // --
...@@ -252,7 +250,7 @@ function testCallPrint() { ...@@ -252,7 +250,7 @@ function testCallPrint() {
]) ])
.exportFunc(); .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) { for (var i = -9; i < 900; i += 16.125) {
main(i); main(i);
...@@ -266,8 +264,8 @@ testCallPrint(); ...@@ -266,8 +264,8 @@ testCallPrint();
function testCallImport2(foo, bar, expected) { function testCallImport2(foo, bar, expected) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImport("foo", kSig_i_v); builder.addImport("q", "foo", kSig_i_v);
builder.addImport("bar", kSig_i_v); builder.addImport("t", "bar", kSig_i_v);
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([ .addBody([
kExprCallFunction, 0, // -- kExprCallFunction, 0, // --
...@@ -276,7 +274,7 @@ function testCallImport2(foo, bar, expected) { ...@@ -276,7 +274,7 @@ function testCallImport2(foo, bar, expected) {
]) // -- ]) // --
.exportFunc(); .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()); assertEquals(expected, main());
} }
...@@ -285,7 +283,7 @@ testCallImport2(function() { return 33; }, function () { return 44; }, 77); ...@@ -285,7 +283,7 @@ testCallImport2(function() { return 33; }, function () { return 44; }, 77);
function testImportName(name) { function testImportName(name) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportWithModule("M", name, kSig_i_v); builder.addImport("M", name, kSig_i_v);
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([ .addBody([
kExprCallFunction, 0 kExprCallFunction, 0
......
...@@ -11,7 +11,7 @@ var module = (function () { ...@@ -11,7 +11,7 @@ var module = (function () {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_i_ii); var sig_index = builder.addType(kSig_i_ii);
builder.addImport("add", sig_index); builder.addImport("q", "add", sig_index);
builder.addFunction("add", sig_index) builder.addFunction("add", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0 kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0
...@@ -32,7 +32,7 @@ var module = (function () { ...@@ -32,7 +32,7 @@ var module = (function () {
.exportFunc() .exportFunc()
builder.appendToTable([1, 2, 3]); 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. // Check the module exists.
...@@ -54,7 +54,7 @@ module = (function () { ...@@ -54,7 +54,7 @@ module = (function () {
var sig_i_ii = builder.addType(kSig_i_ii); var sig_i_ii = builder.addType(kSig_i_ii);
var sig_i_i = builder.addType(kSig_i_i); 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) var add = builder.addFunction("add", sig_i_ii)
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -76,7 +76,7 @@ module = (function () { ...@@ -76,7 +76,7 @@ module = (function () {
.exportFunc(); .exportFunc();
builder.appendToTable([mul.index, add.index, popcnt.index, main.index]); 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)); assertEquals(-6, module.exports.main(0, -2, 3));
...@@ -185,14 +185,14 @@ assertTraps(kTrapFuncInvalid, "module.exports.main(12, 3)"); ...@@ -185,14 +185,14 @@ assertTraps(kTrapFuncInvalid, "module.exports.main(12, 3)");
.exportAs("main"); .exportAs("main");
builder.setFunctionTableLength(10); 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]); builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, f.sub.index]);
var module = new WebAssembly.Module(builder.toBuffer()); var module = new WebAssembly.Module(builder.toBuffer());
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
print(" base = " + 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; main = instance.exports.main;
for (var j = 0; j < i; j++) { for (var j = 0; j < i; j++) {
assertTraps(kTrapFuncSigMismatch, "main(12, " + j + ")"); assertTraps(kTrapFuncSigMismatch, "main(12, " + j + ")");
......
...@@ -37,7 +37,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -37,7 +37,7 @@ function js_div(a, b) { return (a / b) | 0; }
let builder = new WasmModuleBuilder(); 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); let f = AddFunctions(builder);
builder.addFunction("main", kSig_i_ii) builder.addFunction("main", kSig_i_ii)
.addBody([ .addBody([
...@@ -50,7 +50,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -50,7 +50,7 @@ function js_div(a, b) { return (a / b) | 0; }
f.add.exportAs("blarg"); f.add.exportAs("blarg");
builder.setFunctionTableLength(10); 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, builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index,
f.sub.index, f.sub.index,
d]); d]);
...@@ -60,7 +60,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -60,7 +60,7 @@ function js_div(a, b) { return (a / b) | 0; }
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
print(" base = " + 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; main = instance.exports.main;
let table = instance.exports.table; let table = instance.exports.table;
assertTrue(table instanceof WebAssembly.Table); assertTrue(table instanceof WebAssembly.Table);
...@@ -107,10 +107,10 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -107,10 +107,10 @@ function js_div(a, b) { return (a / b) | 0; }
print("ImportedTableTest..."); print("ImportedTableTest...");
var builder = new WasmModuleBuilder(); 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); let f = AddFunctions(builder);
builder.setFunctionTableLength(kTableSize); 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, builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index,
f.sub.index, f.sub.index,
d]); d]);
...@@ -120,7 +120,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -120,7 +120,7 @@ function js_div(a, b) { return (a / b) | 0; }
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedTable("table", undefined, kTableSize, kTableSize); builder.addImportedTable("r", "table", kTableSize, kTableSize);
builder.addFunction("main", kSig_i_ii) builder.addFunction("main", kSig_i_ii)
.addBody([ .addBody([
kExprI32Const, 33, // -- kExprI32Const, 33, // --
...@@ -134,10 +134,10 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -134,10 +134,10 @@ function js_div(a, b) { return (a / b) | 0; }
// Run 5 trials at different table bases. // Run 5 trials at different table bases.
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
print(" base = " + 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; let table = i1.exports.table;
assertEquals(10, table.length); 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; let main = i2.exports.main;
for (var j = 0; j < i; j++) { for (var j = 0; j < i; j++) {
...@@ -178,9 +178,9 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -178,9 +178,9 @@ function js_div(a, b) { return (a / b) | 0; }
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
let d = builder.addImport("js_div", kSig_i_ii); let d = builder.addImport("q", "js_div", kSig_i_ii);
builder.addImportedTable("table", undefined, kTableSize, kTableSize); builder.addImportedTable("q", "table", kTableSize, kTableSize);
let g = builder.addImportedGlobal("base", undefined, kAstI32); let g = builder.addImportedGlobal("q", "base", kAstI32);
let f = AddFunctions(builder); let f = AddFunctions(builder);
builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index, builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index,
f.sub.index, f.sub.index,
...@@ -201,8 +201,8 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -201,8 +201,8 @@ function js_div(a, b) { return (a / b) | 0; }
let table = new WebAssembly.Table({element: "anyfunc", let table = new WebAssembly.Table({element: "anyfunc",
initial: kTableSize}); initial: kTableSize});
assertEquals(10, table.length); assertEquals(10, table.length);
let i2 = new WebAssembly.Instance(m2, {base: i, table: table, let i2 = new WebAssembly.Instance(m2, {q: {base: i, table: table,
js_div: js_div}); js_div: js_div}});
let main = i2.exports.main; let main = i2.exports.main;
for (var j = 0; j < i; j++) { for (var j = 0; j < i; j++) {
...@@ -246,8 +246,8 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -246,8 +246,8 @@ function js_div(a, b) { return (a / b) | 0; }
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedTable("table", undefined, kTableSize, kTableSize); builder.addImportedTable("x", "table", kTableSize, kTableSize);
let g = builder.addImportedGlobal("base", undefined, kAstI32); let g = builder.addImportedGlobal("x", "base", kAstI32);
let sig_index = builder.addType(kSig_i_v); let sig_index = builder.addType(kSig_i_v);
builder.addFunction("g", sig_index) builder.addFunction("g", sig_index)
.addBody([ .addBody([
...@@ -264,7 +264,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -264,7 +264,7 @@ function js_div(a, b) { return (a / b) | 0; }
for (var i = 0; i < kTableSize; i++) { for (var i = 0; i < kTableSize; i++) {
print(" base = " + 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++) { for (var j = 0; j < kTableSize; j++) {
let func = table.get(j); let func = table.get(j);
...@@ -319,14 +319,14 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -319,14 +319,14 @@ function js_div(a, b) { return (a / b) | 0; }
builder.setFunctionTableLength(kTableSize); builder.setFunctionTableLength(kTableSize);
builder.addFunctionTableInit(1, false, [f2.index]); 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()); var m2 = new WebAssembly.Module(builder.toBuffer());
assertFalse(sig_index1 == sig_index2); assertFalse(sig_index1 == sig_index2);
var i1 = new WebAssembly.Instance(m1); 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, i1.exports.main(0));
assertEquals(11, i2.exports.main(0)); assertEquals(11, i2.exports.main(0));
...@@ -355,7 +355,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -355,7 +355,7 @@ function js_div(a, b) { return (a / b) | 0; }
let m1 = new WebAssembly.Module(builder.toBuffer()); let m1 = new WebAssembly.Module(builder.toBuffer());
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedTable("impfoo", undefined, impsize, impsize); builder.addImportedTable("y", "impfoo", impsize, impsize);
let m2 = new WebAssembly.Module(builder.toBuffer()); let m2 = new WebAssembly.Module(builder.toBuffer());
...@@ -363,7 +363,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -363,7 +363,7 @@ function js_div(a, b) { return (a / b) | 0; }
// TODO(titzer): v8 currently requires import table size to match // TODO(titzer): v8 currently requires import table size to match
// export table size. // export table size.
var ffi = {impfoo: i1.exports.expfoo}; var ffi = {y: {impfoo: i1.exports.expfoo}};
if (expsize == impsize) { if (expsize == impsize) {
var i2 = new WebAssembly.Instance(m2, ffi); var i2 = new WebAssembly.Instance(m2, ffi);
} else { } else {
......
...@@ -13,7 +13,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -13,7 +13,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
print("InstanceMemoryGcStress"); print("InstanceMemoryGcStress");
let memory = new WebAssembly.Memory({initial: 100, maximum: 1500}); let memory = new WebAssembly.Memory({initial: 100, maximum: 1500});
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedMemory("imported_mem"); builder.addImportedMemory("mod", "imported_mem");
builder.addFunction("mem_size", kSig_i_v) builder.addFunction("mem_size", kSig_i_v)
.addBody([kExprMemorySize, kMemoryZero]) .addBody([kExprMemorySize, kMemoryZero])
.exportFunc(); .exportFunc();
...@@ -23,7 +23,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -23,7 +23,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var instances = []; var instances = [];
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
gc(); 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_0(pages) { return instances[0].exports.grow(pages); }
function grow_instance_1(pages) { return instances[1].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"); ...@@ -60,7 +60,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(800, instances[0].exports.mem_size()); assertEquals(800, instances[0].exports.mem_size());
// Instantiate a new instance and verify that it can be grown correctly. // 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); } function grow_instance_5(pages) { return instances[5].exports.grow(pages); }
gc(); gc();
gc(); gc();
......
...@@ -120,8 +120,8 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); ...@@ -120,8 +120,8 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
var kSig_v_i = makeSig([kAstI32], []); var kSig_v_i = makeSig([kAstI32], []);
var signature = builder.addType(kSig_v_i); var signature = builder.addType(kSig_v_i);
builder.addImport("some_value", kSig_i_v); builder.addImport("m", "some_value", kSig_i_v);
builder.addImport("writer", signature); builder.addImport("m", "writer", signature);
builder.addFunction("main", kSig_i_i) builder.addFunction("main", kSig_i_i)
.addBody([ .addBody([
...@@ -155,10 +155,12 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); ...@@ -155,10 +155,12 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
var outval_1; var outval_1;
var outval_2; var outval_2;
var i1 = new WebAssembly.Instance(module, {some_value: () => 1, var i1 = new WebAssembly.Instance(module, {m: {some_value: () => 1,
writer: (x)=>outval_1 = x }, mem_1); writer: (x)=>outval_1 = x }},
var i2 = new WebAssembly.Instance(module, {some_value: () => 2, mem_1);
writer: (x)=>outval_2 = x }, mem_2); var i2 = new WebAssembly.Instance(module, {m: {some_value: () => 2,
writer: (x)=>outval_2 = x }},
mem_2);
assertEquals(43, i1.exports.main(0)); assertEquals(43, i1.exports.main(0));
assertEquals(1002, i2.exports.main(0)); assertEquals(1002, i2.exports.main(0));
......
...@@ -39,7 +39,7 @@ let exportingModuleBinary = (() => { ...@@ -39,7 +39,7 @@ let exportingModuleBinary = (() => {
let importingModuleBinary = (() => { let importingModuleBinary = (() => {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImport("f", kSig_i_v); builder.addImport("", "f", kSig_i_v);
return new Int8Array(builder.toBuffer()); return new Int8Array(builder.toBuffer());
})(); })();
......
...@@ -13,7 +13,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -13,7 +13,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
print("ValidateSharedInstanceMemory"); print("ValidateSharedInstanceMemory");
let memory = new WebAssembly.Memory({initial: 5, maximum: 100}); let memory = new WebAssembly.Memory({initial: 5, maximum: 100});
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedMemory("imported_mem"); builder.addImportedMemory("mod", "imported_mem");
builder.addFunction("mem_size", kSig_i_v) builder.addFunction("mem_size", kSig_i_v)
.addBody([kExprMemorySize, kMemoryZero]) .addBody([kExprMemorySize, kMemoryZero])
.exportFunc(); .exportFunc();
...@@ -22,7 +22,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -22,7 +22,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
.exportFunc(); .exportFunc();
var instances = []; var instances = [];
for (var i = 0; i < 5; i++) { 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_0(pages) { return instances[0].exports.grow(pages); }
function grow_instance_1(pages) { return instances[1].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"); ...@@ -82,7 +82,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(28, instances[3].exports.mem_size()); assertEquals(28, instances[3].exports.mem_size());
// Instantiate a new instance and verify that it can be grown correctly. // 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); } function grow_instance_5(pages) { return instances[5].exports.grow(pages); }
// i[2] - i[3] - i[5] // i[2] - i[3] - i[5]
......
...@@ -11,7 +11,7 @@ function testCallImport(func, expected, a, b) { ...@@ -11,7 +11,7 @@ function testCallImport(func, expected, a, b) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_i_dd); var sig_index = builder.addType(kSig_i_dd);
builder.addImport("func", sig_index); builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -19,7 +19,7 @@ function testCallImport(func, expected, a, b) { ...@@ -19,7 +19,7 @@ function testCallImport(func, expected, a, b) {
kExprCallFunction, 0]) // -- kExprCallFunction, 0]) // --
.exportAs("main"); .exportAs("main");
var main = builder.instantiate({func: func}).exports.main; var main = builder.instantiate({mod: {func: func}}).exports.main;
assertEquals(expected, main(a, b)); assertEquals(expected, main(a, b));
} }
......
...@@ -42,7 +42,7 @@ function STACK() { ...@@ -42,7 +42,7 @@ function STACK() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImport("func", kSig_v_v); builder.addImport("mod", "func", kSig_v_v);
builder.addFunction("main", kSig_v_v) builder.addFunction("main", kSig_v_v)
.addBody([kExprCallFunction, 0]) .addBody([kExprCallFunction, 0])
...@@ -63,7 +63,7 @@ builder.addFunction("call_mem_out_of_bounds", kSig_i_v) ...@@ -63,7 +63,7 @@ builder.addFunction("call_mem_out_of_bounds", kSig_i_v)
.addBody([kExprCallFunction, mem_oob_func.index]) .addBody([kExprCallFunction, mem_oob_func.index])
.exportAs("call_mem_out_of_bounds"); .exportAs("call_mem_out_of_bounds");
var module = builder.instantiate({func: STACK}); var module = builder.instantiate({mod: {func: STACK}});
(function testSimpleStack() { (function testSimpleStack() {
var expected_string = "Error\n" + var expected_string = "Error\n" +
......
...@@ -11,7 +11,7 @@ function makeFFI(func) { ...@@ -11,7 +11,7 @@ function makeFFI(func) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_i_dd); var sig_index = builder.addType(kSig_i_dd);
builder.addImport("func", sig_index); builder.addImport("mom", "func", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
...@@ -20,7 +20,7 @@ function makeFFI(func) { ...@@ -20,7 +20,7 @@ function makeFFI(func) {
]) ])
.exportFunc() .exportFunc()
return builder.instantiate({func: func}).exports.main; return builder.instantiate({mom: {func: func}}).exports.main;
} }
......
...@@ -99,15 +99,15 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);}); ...@@ -99,15 +99,15 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);});
(function testStartFFI() { (function testStartFFI() {
print("testStartFFI"); print("testStartFFI");
var ranned = false; var ranned = false;
var ffi = { foo : function() { var ffi = {gak: {foo : function() {
print("we ranned at stert!"); print("we ranned at stert!");
ranned = true; ranned = true;
}}; }}};
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_v_v); 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) var func = builder.addFunction("", sig_index)
.addBody([kExprCallFunction, 0]); .addBody([kExprCallFunction, 0]);
......
...@@ -153,7 +153,7 @@ function assertTableIsValid(table) { ...@@ -153,7 +153,7 @@ function assertTableIsValid(table) {
(function TestSet() { (function TestSet() {
let builder = new WasmModuleBuilder; let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v)); 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 {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
...@@ -201,7 +201,7 @@ function assertTableIsValid(table) { ...@@ -201,7 +201,7 @@ function assertTableIsValid(table) {
(function TestIndexing() { (function TestIndexing() {
let builder = new WasmModuleBuilder; let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v)); 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 {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); let table = new WebAssembly.Table({element: "anyfunc", initial: 10});
...@@ -224,7 +224,7 @@ function assertTableIsValid(table) { ...@@ -224,7 +224,7 @@ function assertTableIsValid(table) {
(function TestGrow() { (function TestGrow() {
let builder = new WasmModuleBuilder; let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v)); 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 {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
function init(table) { function init(table) {
......
...@@ -21,7 +21,7 @@ var expect_no_elison = 1; ...@@ -21,7 +21,7 @@ var expect_no_elison = 1;
var second_module = new WasmModuleBuilder(); var second_module = new WasmModuleBuilder();
var sig_index = second_module.addType(kSig_i_i); var sig_index = second_module.addType(kSig_i_i);
second_module second_module
.addImportWithModule("import_module_2", "import_name_2", sig_index); .addImport("import_module_2", "import_name_2", sig_index);
second_module second_module
.addFunction("second_export", sig_index) .addFunction("second_export", sig_index)
.addBody([ .addBody([
...@@ -34,7 +34,7 @@ var expect_no_elison = 1; ...@@ -34,7 +34,7 @@ var expect_no_elison = 1;
var first_module = new WasmModuleBuilder(); var first_module = new WasmModuleBuilder();
var sig_index = first_module.addType(kSig_i_i); var sig_index = first_module.addType(kSig_i_i);
first_module first_module
.addImportWithModule("import_module_1", "import_name_1", sig_index); .addImport("import_module_1", "import_name_1", sig_index);
first_module first_module
.addFunction("first_export", sig_index) .addFunction("first_export", sig_index)
.addBody([ .addBody([
...@@ -81,7 +81,7 @@ var expect_no_elison = 1; ...@@ -81,7 +81,7 @@ var expect_no_elison = 1;
var sig_index1 = second_module.addType(kSig_i_i); var sig_index1 = second_module.addType(kSig_i_i);
var sig_index_ll = second_module.addType(kSig_l_l); var sig_index_ll = second_module.addType(kSig_l_l);
second_module second_module
.addImportWithModule("import_module_2", "import_name_2", sig_index1); .addImport("import_module_2", "import_name_2", sig_index1);
second_module second_module
.addFunction("second_export", sig_index_ll) .addFunction("second_export", sig_index_ll)
.addBody([ .addBody([
...@@ -97,7 +97,7 @@ var expect_no_elison = 1; ...@@ -97,7 +97,7 @@ var expect_no_elison = 1;
var sig_index = first_module.addType(kSig_i_v); var sig_index = first_module.addType(kSig_i_v);
var sig_index_ll = first_module.addType(kSig_l_l); var sig_index_ll = first_module.addType(kSig_l_l);
first_module first_module
.addImportWithModule("import_module_1", "import_name_1", sig_index_ll); .addImport("import_module_1", "import_name_1", sig_index_ll);
first_module first_module
.addFunction("first_export", sig_index) .addFunction("first_export", sig_index)
.addBody([ .addBody([
...@@ -138,7 +138,7 @@ assertThrows(function TestWasmWrapperNoElisionLessParams() { ...@@ -138,7 +138,7 @@ assertThrows(function TestWasmWrapperNoElisionLessParams() {
var second_module = new WasmModuleBuilder(); var second_module = new WasmModuleBuilder();
var sig_index_1 = second_module.addType(kSig_i_i); var sig_index_1 = second_module.addType(kSig_i_i);
second_module second_module
.addImportWithModule("import_module_2", "import_name_2", sig_index_1); .addImport("import_module_2", "import_name_2", sig_index_1);
second_module second_module
.addFunction("second_export", sig_index_1) .addFunction("second_export", sig_index_1)
.addBody([ .addBody([
...@@ -151,7 +151,7 @@ assertThrows(function TestWasmWrapperNoElisionLessParams() { ...@@ -151,7 +151,7 @@ assertThrows(function TestWasmWrapperNoElisionLessParams() {
var first_module = new WasmModuleBuilder(); var first_module = new WasmModuleBuilder();
var sig_index_2 = first_module.addType(kSig_i_ii); var sig_index_2 = first_module.addType(kSig_i_ii);
first_module first_module
.addImportWithModule("import_module_1", "import_name_1", sig_index_2); .addImport("import_module_1", "import_name_1", sig_index_2);
first_module first_module
.addFunction("first_export", sig_index_2) .addFunction("first_export", sig_index_2)
.addBody([ .addBody([
...@@ -195,7 +195,7 @@ assertThrows(function TestWasmWrapperNoElisionMoreParams() { ...@@ -195,7 +195,7 @@ assertThrows(function TestWasmWrapperNoElisionMoreParams() {
var second_module = new WasmModuleBuilder(); var second_module = new WasmModuleBuilder();
var sig_index_3 = second_module.addType(kSig_i_iii); var sig_index_3 = second_module.addType(kSig_i_iii);
second_module second_module
.addImportWithModule("import_module_2", "import_name_2", sig_index_3); .addImport("import_module_2", "import_name_2", sig_index_3);
second_module second_module
.addFunction("second_export", sig_index_3) .addFunction("second_export", sig_index_3)
.addBody([ .addBody([
...@@ -210,7 +210,7 @@ assertThrows(function TestWasmWrapperNoElisionMoreParams() { ...@@ -210,7 +210,7 @@ assertThrows(function TestWasmWrapperNoElisionMoreParams() {
var first_module = new WasmModuleBuilder(); var first_module = new WasmModuleBuilder();
var sig_index_2 = first_module.addType(kSig_i_ii); var sig_index_2 = first_module.addType(kSig_i_ii);
first_module first_module
.addImportWithModule("import_module_1", "import_name_1", sig_index_2); .addImport("import_module_1", "import_name_1", sig_index_2);
first_module first_module
.addFunction("first_export", sig_index_2) .addFunction("first_export", sig_index_2)
.addBody([ .addBody([
...@@ -254,7 +254,7 @@ assertThrows(function TestWasmWrapperNoElisionTypeMismatch() { ...@@ -254,7 +254,7 @@ assertThrows(function TestWasmWrapperNoElisionTypeMismatch() {
var second_module = new WasmModuleBuilder(); var second_module = new WasmModuleBuilder();
var sig_index_2 = second_module.addType(kSig_d_dd); var sig_index_2 = second_module.addType(kSig_d_dd);
second_module second_module
.addImportWithModule("import_module_2", "import_name_2", sig_index_2); .addImport("import_module_2", "import_name_2", sig_index_2);
second_module second_module
.addFunction("second_export", sig_index_2) .addFunction("second_export", sig_index_2)
.addBody([ .addBody([
...@@ -268,7 +268,7 @@ assertThrows(function TestWasmWrapperNoElisionTypeMismatch() { ...@@ -268,7 +268,7 @@ assertThrows(function TestWasmWrapperNoElisionTypeMismatch() {
var first_module = new WasmModuleBuilder(); var first_module = new WasmModuleBuilder();
var sig_index_2 = first_module.addType(kSig_i_ii); var sig_index_2 = first_module.addType(kSig_i_ii);
first_module first_module
.addImportWithModule("import_module_1", "import_name_1", sig_index_2); .addImport("import_module_1", "import_name_1", sig_index_2);
first_module first_module
.addFunction("first_export", sig_index_2) .addFunction("first_export", sig_index_2)
.addBody([ .addBody([
......
...@@ -27,13 +27,13 @@ function instantiate(buffer, ffi) { ...@@ -27,13 +27,13 @@ function instantiate(buffer, ffi) {
(function ImportTest() { (function ImportTest() {
let builder = new WasmModuleBuilder(); 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) builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 13, kExprCallFunction, index]) .addBody([kExprI8Const, 13, kExprCallFunction, index])
.exportAs("main"); .exportAs("main");
var buffer = builder.toBuffer(debug); var buffer = builder.toBuffer(debug);
var instance = instantiate(buffer, {print: print}); var instance = instantiate(buffer, {"": {print: print}});
print("should print 13! "); print("should print 13! ");
instance.exports.main(); instance.exports.main();
})(); })();
...@@ -145,7 +145,7 @@ function instantiate(buffer, ffi) { ...@@ -145,7 +145,7 @@ function instantiate(buffer, ffi) {
(function ImportTestTwoLevel() { (function ImportTestTwoLevel() {
let builder = new WasmModuleBuilder(); 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) builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 19, kExprCallFunction, index]) .addBody([kExprI8Const, 19, kExprCallFunction, index])
.exportAs("main"); .exportAs("main");
......
...@@ -45,7 +45,7 @@ function checkImportsAndExports(imported_module_name, imported_function_name, ...@@ -45,7 +45,7 @@ function checkImportsAndExports(imported_module_name, imported_function_name,
internal_function_name, exported_function_name, shouldThrow) { internal_function_name, exported_function_name, shouldThrow) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportWithModule(imported_module_name, imported_function_name, builder.addImport(imported_module_name, imported_function_name,
kSig_v_v); kSig_v_v);
builder.addFunction(internal_function_name, kSig_v_v) builder.addFunction(internal_function_name, kSig_v_v)
......
...@@ -179,32 +179,28 @@ class WasmModuleBuilder { ...@@ -179,32 +179,28 @@ class WasmModuleBuilder {
return func; return func;
} }
addImportWithModule(module, name, type) { addImport(module = "", name, type) {
let type_index = (typeof type) == "number" ? type : this.addType(type); let type_index = (typeof type) == "number" ? type : this.addType(type);
this.imports.push({module: module, name: name, kind: kExternalFunction, this.imports.push({module: module, name: name, kind: kExternalFunction,
type: type_index}); type: type_index});
return this.num_imported_funcs++; return this.num_imported_funcs++;
} }
addImport(name, type) { addImportedGlobal(module = "", name, type) {
return this.addImportWithModule(name, undefined, type);
}
addImportedGlobal(module, name, type) {
let o = {module: module, name: name, kind: kExternalGlobal, type: type, let o = {module: module, name: name, kind: kExternalGlobal, type: type,
mutable: false} mutable: false}
this.imports.push(o); this.imports.push(o);
return this.num_imported_globals++; 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, let o = {module: module, name: name, kind: kExternalMemory,
initial: initial, maximum: maximum}; initial: initial, maximum: maximum};
this.imports.push(o); this.imports.push(o);
return this; return this;
} }
addImportedTable(module, name, initial, maximum) { addImportedTable(module = "", name, initial, maximum) {
let o = {module: module, name: name, kind: kExternalTable, initial: initial, let o = {module: module, name: name, kind: kExternalTable, initial: initial,
maximum: maximum}; maximum: maximum};
this.imports.push(o); this.imports.push(o);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment