blob: bc13122f1b1a9b83f67c7a00c7dd9cb172cdb9b7 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --expose-wasm
6
7load("test/mjsunit/wasm/wasm-constants.js");
Ben Murdochda12d292016-06-02 14:46:10 +01008load("test/mjsunit/wasm/wasm-module-builder.js");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009
10var kReturnValue = 117;
11
Ben Murdochda12d292016-06-02 14:46:10 +010012var module = (function Build() {
13 var builder = new WasmModuleBuilder();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014
Ben Murdochda12d292016-06-02 14:46:10 +010015 builder.addMemory(1, 1, true);
16 builder.addFunction("main", [kAstI32])
17 .addBody([kExprI8Const, kReturnValue])
18 .exportFunc();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019
Ben Murdochda12d292016-06-02 14:46:10 +010020 return builder.instantiate();
21})();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022
23// Check the module exists.
24assertFalse(module === undefined);
25assertFalse(module === null);
26assertFalse(module === 0);
27assertEquals("object", typeof module);
28
29// Check the memory is an ArrayBuffer.
Ben Murdochda12d292016-06-02 14:46:10 +010030var mem = module.exports.memory;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000031assertFalse(mem === undefined);
32assertFalse(mem === null);
33assertFalse(mem === 0);
34assertEquals("object", typeof mem);
35assertTrue(mem instanceof ArrayBuffer);
36for (var i = 0; i < 4; i++) {
Ben Murdochda12d292016-06-02 14:46:10 +010037 module.exports.memory = 0; // should be ignored
38 assertEquals(mem, module.exports.memory);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039}
40
Ben Murdochda12d292016-06-02 14:46:10 +010041assertEquals(65536, module.exports.memory.byteLength);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042
43// Check the properties of the main function.
Ben Murdochda12d292016-06-02 14:46:10 +010044var main = module.exports.main;
45assertFalse(main === undefined);
46assertFalse(main === null);
47assertFalse(main === 0);
48assertEquals("function", typeof main);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049
Ben Murdochda12d292016-06-02 14:46:10 +010050assertEquals(kReturnValue, main());