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
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
load("test/mjsunit/wasm/wasm-constants.js");
|
2016-03-07 19:32:35 +00:00
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
var kReturnValue = 117;
|
|
|
|
|
2016-03-07 19:32:35 +00:00
|
|
|
var module = (function Build() {
|
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
|
|
|
|
builder.addMemory(1, 1, true);
|
2016-04-29 09:39:26 +00:00
|
|
|
builder.addFunction("main", kSig_i)
|
2016-03-07 19:32:35 +00:00
|
|
|
.addBody([kExprI8Const, kReturnValue])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
return builder.instantiate();
|
|
|
|
})();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
// Check the module exists.
|
|
|
|
assertFalse(module === undefined);
|
|
|
|
assertFalse(module === null);
|
|
|
|
assertFalse(module === 0);
|
|
|
|
assertEquals("object", typeof module);
|
|
|
|
|
|
|
|
// Check the memory is an ArrayBuffer.
|
2016-03-09 13:31:23 +00:00
|
|
|
var mem = module.exports.memory;
|
2015-12-11 12:26:16 +00:00
|
|
|
assertFalse(mem === undefined);
|
|
|
|
assertFalse(mem === null);
|
|
|
|
assertFalse(mem === 0);
|
|
|
|
assertEquals("object", typeof mem);
|
|
|
|
assertTrue(mem instanceof ArrayBuffer);
|
|
|
|
for (var i = 0; i < 4; i++) {
|
2016-03-09 13:31:23 +00:00
|
|
|
module.exports.memory = 0; // should be ignored
|
|
|
|
assertEquals(mem, module.exports.memory);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 13:31:23 +00:00
|
|
|
assertEquals(65536, module.exports.memory.byteLength);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
// Check the properties of the main function.
|
2016-03-07 19:32:35 +00:00
|
|
|
var main = module.exports.main;
|
|
|
|
assertFalse(main === undefined);
|
|
|
|
assertFalse(main === null);
|
|
|
|
assertFalse(main === 0);
|
|
|
|
assertEquals("function", typeof main);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-03-07 19:32:35 +00:00
|
|
|
assertEquals(kReturnValue, main());
|