2015-12-11 12:26:16 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2015-12-17 10:54:08 +00:00
|
|
|
// Flags: --expose-wasm --expose-gc --allow-natives-syntax
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2021-06-01 12:46:36 +00:00
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
function makeFFI(func) {
|
2016-03-07 19:32:35 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
|
2016-06-21 19:47:51 +00:00
|
|
|
var sig_index = builder.addType(kSig_i_dd);
|
2016-12-20 15:32:56 +00:00
|
|
|
builder.addImport("mom", "func", sig_index);
|
2016-03-07 19:32:35 +00:00
|
|
|
builder.addFunction("main", sig_index)
|
|
|
|
.addBody([
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalGet, 0, // --
|
|
|
|
kExprLocalGet, 1, // --
|
2016-09-27 20:46:10 +00:00
|
|
|
kExprCallFunction, 0, // --
|
2016-04-29 09:15:26 +00:00
|
|
|
])
|
2016-03-07 19:32:35 +00:00
|
|
|
.exportFunc()
|
|
|
|
|
2016-12-20 15:32:56 +00:00
|
|
|
return builder.instantiate({mom: {func: func}}).exports.main;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function makeReentrantFFI(func) {
|
|
|
|
var main = makeFFI(reenter);
|
|
|
|
|
|
|
|
function reenter(a, b) {
|
|
|
|
print(" reenter " + a);
|
|
|
|
if (a > 0) main(a - 1, b);
|
|
|
|
else func();
|
|
|
|
}
|
|
|
|
return main;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function runTest(builder) {
|
|
|
|
// ---- THROWING TEST -----------------------------------------------
|
|
|
|
|
|
|
|
function throwadd(a, b) {
|
|
|
|
print("-- trying throw --");
|
|
|
|
throw a + b;
|
|
|
|
}
|
|
|
|
|
|
|
|
function throwa(a) {
|
|
|
|
print("-- trying throw --");
|
|
|
|
throw a;
|
|
|
|
}
|
|
|
|
|
|
|
|
function throwstr() {
|
|
|
|
print("-- trying throw --");
|
|
|
|
throw "string";
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(builder(throwadd));
|
|
|
|
assertThrows(builder(throwa));
|
|
|
|
assertThrows(builder(throwstr));
|
|
|
|
|
|
|
|
try {
|
|
|
|
builder(throwadd)(7.8, 9.9);
|
|
|
|
} catch(e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
builder(throwa)(11.8, 9.3);
|
|
|
|
} catch(e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
builder(throwstr)(3, 5);
|
|
|
|
} catch(e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---- DEOPT TEST -----------------------------------------------
|
|
|
|
|
|
|
|
function deopt() {
|
|
|
|
print("-- trying deopt --");
|
|
|
|
%DeoptimizeFunction(deopter);
|
|
|
|
}
|
|
|
|
|
|
|
|
var deopter = builder(deopt);
|
|
|
|
|
|
|
|
deopter(5, 5);
|
|
|
|
for (var i = 0; i < 9; i++) {
|
|
|
|
deopter(6, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---- GC TEST -----------------------------------------------
|
|
|
|
function dogc(a, b) {
|
|
|
|
print("-- trying gc --");
|
|
|
|
gc();
|
|
|
|
gc();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var gcer = builder(dogc);
|
|
|
|
gcer(7, 7);
|
|
|
|
|
|
|
|
for (var i = 0; i < 9; i++) {
|
|
|
|
gcer(8, 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runTest(makeReentrantFFI);
|
|
|
|
runTest(makeFFI);
|