Commit d171ed41 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Add tests for re-importing into different instances

Since the code around that is quite fragile, and I plan to refactor it,
just add some tests to ensure that everything is and keeps working as
intended.

R=mstarzinger@chromium.org

Bug: v8:7758
Change-Id: Ib3814b93b465286d70b5669ed0161eecb9fc925a
Reviewed-on: https://chromium-review.googlesource.com/1059616Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53187}
parent b5708d92
......@@ -294,8 +294,69 @@ function testImportName(name) {
assertEquals(42, main());
}
testImportName("bla");
testImportName("0");
testImportName(" a @#$2 324 ");
// TODO(bradnelson): This should succeed.
// testImportName("");
testImportName('bla');
testImportName('0');
testImportName(' a @#$2 324 ');
testImportName('');
(function testExportedImportsOnDifferentInstances() {
print(arguments.callee.name);
const exp = (function() {
const builder = new WasmModuleBuilder();
builder.addFunction('f11', kSig_i_v)
.addBody([kExprI32Const, 11])
.exportFunc();
builder.addFunction('f17', kSig_i_v)
.addBody([kExprI32Const, 17])
.exportFunc();
return builder.instantiate().exports;
})();
const builder = new WasmModuleBuilder();
const imp_index = builder.addImport('q', 'imp', kSig_i_v);
builder.addExport('exp', imp_index);
const module = builder.toModule();
const instance0 = new WebAssembly.Instance(module, {q: {imp: exp.f11}});
const instance1 = new WebAssembly.Instance(module, {q: {imp: exp.f17}});
const instance2 = new WebAssembly.Instance(module, {q: {imp: _ => 21}});
const instance3 = new WebAssembly.Instance(module, {q: {imp: _ => 27}});
assertEquals(11, instance0.exports.exp());
assertEquals(17, instance1.exports.exp());
assertEquals(21, instance2.exports.exp());
assertEquals(27, instance3.exports.exp());
})();
(function testImportedStartFunctionOnDifferentInstances() {
print(arguments.callee.name);
var global = 0;
const set_global = n => global = n;
const exp = (function() {
const builder = new WasmModuleBuilder();
const imp_index = builder.addImport('q', 'imp', kSig_v_i);
builder.addFunction('f11', kSig_v_v)
.addBody([kExprI32Const, 11, kExprCallFunction, imp_index])
.exportFunc();
builder.addFunction('f17', kSig_v_v)
.addBody([kExprI32Const, 17, kExprCallFunction, imp_index])
.exportFunc();
return builder.instantiate({q: {imp: set_global}}).exports;
})();
const builder = new WasmModuleBuilder();
const imp_index = builder.addImport('q', 'imp', kSig_v_v);
builder.addStart(imp_index);
const module = builder.toModule();
assertEquals(0, global);
new WebAssembly.Instance(module, {q: {imp: exp.f11}});
assertEquals(11, global);
new WebAssembly.Instance(module, {q: {imp: exp.f17}});
assertEquals(17, global);
new WebAssembly.Instance(module, {q: {imp: _ => set_global(21)}});
assertEquals(21, global);
new WebAssembly.Instance(module, {q: {imp: _ => set_global(27)}});
assertEquals(27, global);
})();
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