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.
|
|
|
|
|
2017-04-18 01:31:16 +00:00
|
|
|
// Flags: --allow-natives-syntax
|
2015-12-17 10:54:08 +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
|
|
|
|
2017-04-18 01:31:16 +00:00
|
|
|
const kReturnValue = 15;
|
|
|
|
|
|
|
|
function getBuilder() {
|
2016-03-07 19:32:35 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
builder.addFunction("main", kSig_i_i)
|
2017-01-09 13:57:26 +00:00
|
|
|
.addBody([kExprI32Const, kReturnValue])
|
2016-03-07 19:32:35 +00:00
|
|
|
.exportFunc();
|
2017-04-18 01:31:16 +00:00
|
|
|
return builder;
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2017-04-18 01:31:16 +00:00
|
|
|
(function BasicTest() {
|
|
|
|
var builder = getBuilder();
|
2016-03-07 19:32:35 +00:00
|
|
|
var main = builder.instantiate().exports.main;
|
|
|
|
assertEquals(kReturnValue, main());
|
|
|
|
})();
|
2017-04-18 01:31:16 +00:00
|
|
|
|
|
|
|
(function AsyncTest() {
|
|
|
|
var builder = getBuilder();
|
|
|
|
var buffer = builder.toBuffer();
|
2017-10-25 14:12:49 +00:00
|
|
|
assertPromiseResult(
|
|
|
|
WebAssembly.instantiate(buffer)
|
|
|
|
.then(pair => pair.instance.exports.main(), assertUnreachable)
|
|
|
|
.then(result => assertEquals(kReturnValue, result), assertUnreachable));
|
2017-04-18 01:31:16 +00:00
|
|
|
})();
|