node/deps/v8/test/mjsunit/wasm/start-function.js
Michaël Zasso 2cc2951796
deps: update V8 to 5.1.281.69
Pick up the latest branch-head for V8 5.1. This branch brings in
improved language support and performance improvements. For full
details: http://v8project.blogspot.com/2016/04/v8-release-51.html

* Picks up the latest branch head for 5.1 [1]
* Edit v8 gitignore to allow trace_event copy
* Update V8 DEP trace_event as per deps/v8/DEPS [2]

[1] https://chromium.googlesource.com/v8/v8.git/+/dc81244
[2] https://chromium.googlesource.com/chromium/src/base/trace_event/common/+/c8c8665

PR-URL: https://github.com/nodejs/node/pull/7016
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-06-29 09:04:28 +02:00

112 lines
2.7 KiB
JavaScript

// Copyright 2016 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: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
function instantiate(sig, body) {
var builder = new WasmModuleBuilder();
var func = builder.addFunction("", sig)
.addBody(body);
builder.addStart(func.index);
return builder.instantiate();
}
function assertFails(sig, body) {
try {
var module = instantiate(sig, body);
print("expected failure, but passes");
assertFalse(true);
} catch (expected) {
print("ok: " + expected);
}
}
function assertVerifies(sig, body) {
var module = instantiate(sig, body);
assertFalse(module === undefined);
assertFalse(module === null);
assertFalse(module === 0);
assertEquals("object", typeof module);
return module;
}
assertVerifies([kAstStmt], [kExprNop]);
assertVerifies([kAstI32], [kExprI8Const, 0]);
// Arguments aren't allow to start functions.
assertFails([kAstI32, kAstI32], [kExprGetLocal, 0]);
assertFails([kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]);
assertFails([kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]);
(function testInvalidIndex() {
print("testInvalidIndex");
var builder = new WasmModuleBuilder();
var func = builder.addFunction("", [kAstStmt])
.addBody([kExprNop]);
builder.addStart(func.index + 1);
assertThrows(builder.instantiate);
})();
(function testTwoStartFuncs() {
print("testTwoStartFuncs");
var builder = new WasmModuleBuilder();
var func = builder.addFunction("", [kAstStmt])
.addBody([kExprNop]);
builder.addExplicitSection([kDeclStartFunction, 0]);
builder.addExplicitSection([kDeclStartFunction, 0]);
assertThrows(builder.instantiate);
})();
(function testRun() {
print("testRun");
var builder = new WasmModuleBuilder();
builder.addMemory(12, 12, true);
var func = builder.addFunction("", [kAstStmt])
.addBody([kExprI32StoreMem, 0, 0, kExprI8Const, 0, kExprI8Const, 77]);
builder.addStart(func.index);
var module = builder.instantiate();
var memory = module.exports.memory;
var view = new Int8Array(memory);
assertEquals(77, view[0]);
})();
(function testStartFFI() {
print("testStartFFI");
var ranned = false;
var ffi = { foo : function() {
print("we ranned at stert!");
ranned = true;
}};
var builder = new WasmModuleBuilder();
var sig_index = builder.addSignature([kAstStmt]);
builder.addImport("foo", sig_index);
var func = builder.addFunction("", sig_index)
.addBody([kExprCallImport, 0]);
builder.addStart(func.index);
var module = builder.instantiate(ffi);
assertTrue(ranned);
})();