2020-07-28 08:24:01 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Flags: --wasm-generic-wrapper
|
|
|
|
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
2020-08-10 08:49:41 +00:00
|
|
|
(function testGenericWrapper0Param() {
|
2020-07-28 08:24:01 +00:00
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
let sig_index = builder.addType(kSig_v_v);
|
|
|
|
let func_index = builder.addImport("mod", "func", sig_index);
|
|
|
|
builder.addFunction("main", sig_index)
|
|
|
|
.addBody([
|
|
|
|
kExprCallFunction, func_index
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
let x = 12;
|
|
|
|
function import_func() {
|
|
|
|
x = 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.instantiate({ mod: { func: import_func } }).exports.main();
|
|
|
|
assertEquals(x, 20);
|
|
|
|
})();
|
|
|
|
|
2020-08-10 08:49:41 +00:00
|
|
|
(function testGenericWrapper0ParamTraps() {
|
2020-07-28 08:24:01 +00:00
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
let sig_index = builder.addType(kSig_v_v);
|
|
|
|
builder.addFunction("main", sig_index)
|
|
|
|
.addBody([
|
|
|
|
kExprUnreachable
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
let instance = builder.instantiate();
|
|
|
|
assertTraps(kTrapUnreachable, instance.exports.main);
|
|
|
|
})();
|
2020-08-10 08:49:41 +00:00
|
|
|
|
|
|
|
(function testGenericWrapper1ParamTrap() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
let sig_index = builder.addType(kSig_v_i);
|
|
|
|
builder.addFunction("main", sig_index)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0, kExprUnreachable
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
let instance = builder.instantiate();
|
|
|
|
assertTraps(kTrapUnreachable, () => instance.exports.main(1));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function testGenericWrapper1ParamGeneral() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
let sig_index = builder.addType(kSig_v_i);
|
|
|
|
let func_index = builder.addImport("mod", "func", sig_index);
|
|
|
|
builder.addFunction("main", sig_index)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0, kExprCallFunction, func_index
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
let x = 12;
|
|
|
|
function import_func(param) {
|
|
|
|
x += param;
|
|
|
|
}
|
|
|
|
|
|
|
|
let instance = builder.instantiate({ mod: { func: import_func } });
|
|
|
|
instance.exports.main(5);
|
|
|
|
assertEquals(17, x);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function testGenericWrapper1ParamNotSmi() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
let sig_index = builder.addType(kSig_v_i);
|
|
|
|
let func_index = builder.addImport("mod", "func", sig_index);
|
|
|
|
builder.addFunction("main", sig_index)
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0, kExprCallFunction, func_index
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
let x = 12;
|
|
|
|
function import_func(param) {
|
|
|
|
x += param;
|
|
|
|
}
|
|
|
|
|
|
|
|
let y = {valueOf:() => {return 24;}};
|
|
|
|
let instance = builder.instantiate({ mod: { func: import_func } });
|
|
|
|
instance.exports.main(y);
|
|
|
|
assertEquals(36, x);
|
|
|
|
})();
|