2019-07-09 12:36:15 +00:00
|
|
|
// Copyright 2019 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.
|
|
|
|
|
2021-06-01 12:46:36 +00:00
|
|
|
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
|
2019-07-09 12:36:15 +00:00
|
|
|
|
2021-01-05 16:22:51 +00:00
|
|
|
let kSig_s_v = makeSig([], [kWasmS128]);
|
2019-07-09 12:36:15 +00:00
|
|
|
// Generate a re-exported function that wraps a JavaScript callable, but with a
|
2021-01-05 16:22:51 +00:00
|
|
|
// function signature that is incompatible (i.e. simd return type) with JS.
|
2019-07-09 12:36:15 +00:00
|
|
|
var fun1 = (function GenerateFun1() {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
function fun() { return 0 }
|
2021-01-05 16:22:51 +00:00
|
|
|
let fun_index = builder.addImport('m', 'fun', kSig_s_v)
|
2019-07-09 12:36:15 +00:00
|
|
|
builder.addExport("fun", fun_index);
|
|
|
|
let instance = builder.instantiate({ m: { fun: fun }});
|
|
|
|
return instance.exports.fun;
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Generate an exported function that calls the above re-export from another
|
|
|
|
// module, still with a function signature that is incompatible with JS.
|
|
|
|
var fun2 = (function GenerateFun2() {
|
|
|
|
let builder = new WasmModuleBuilder();
|
2021-01-05 16:22:51 +00:00
|
|
|
let fun_index = builder.addImport("m", "fun", kSig_s_v)
|
2019-07-09 12:36:15 +00:00
|
|
|
builder.addFunction('main', kSig_v_v)
|
|
|
|
.addBody([
|
|
|
|
kExprCallFunction, fun_index,
|
|
|
|
kExprDrop
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
let instance = builder.instantiate({ m: { fun: fun1 }});
|
|
|
|
return instance.exports.main;
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Both exported functions should throw, no matter how often they get wrapped.
|
2020-10-21 10:07:57 +00:00
|
|
|
assertThrows(fun1, TypeError,
|
|
|
|
/type incompatibility when transforming from\/to JS/);
|
|
|
|
assertThrows(fun2, TypeError,
|
|
|
|
/type incompatibility when transforming from\/to JS/);
|