Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(804)

Side by Side Diff: test/mjsunit/wasm/instantiate-module-basic.js

Issue 1770913002: [wasm] Use the JavaScript WasmModuleBuilder utility in JS tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/indirect-calls.js ('k') | test/mjsunit/wasm/instantiate-run-basic.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --expose-wasm 5 // Flags: --expose-wasm
6 6
7 load("test/mjsunit/wasm/wasm-constants.js"); 7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js");
8 9
9 var kReturnValue = 117; 10 var kReturnValue = 117;
10 11
11 var kBodySize = 2; 12 var module = (function Build() {
12 var kNameOffset = kHeaderSize + 19 + kBodySize + 1; 13 var builder = new WasmModuleBuilder();
13 14
14 var data = bytesWithHeader( 15 builder.addMemory(1, 1, true);
15 // -- memory 16 builder.addFunction("main", [kAstI32])
16 kDeclMemory, 17 .addBody([kExprI8Const, kReturnValue])
17 1, 1, 1, 18 .exportFunc();
18 // -- signatures
19 kDeclSignatures, 1,
20 0, kAstI32, // signature: void -> int
21 // -- main function
22 kDeclFunctions, 1,
23 kDeclFunctionName | kDeclFunctionExport,
24 0, 0, // signature index
25 kNameOffset, 0, 0, 0, // name offset
26 kBodySize, 0, // body size
27 // -- body
28 kExprI8Const, // --
29 kReturnValue, // --
30 kDeclEnd,
31 'm', 'a', 'i', 'n', 0 // name
32 );
33 19
34 var module = _WASMEXP_.instantiateModule(data); 20 return builder.instantiate();
21 })();
35 22
36 // Check the module exists. 23 // Check the module exists.
37 assertFalse(module === undefined); 24 assertFalse(module === undefined);
38 assertFalse(module === null); 25 assertFalse(module === null);
39 assertFalse(module === 0); 26 assertFalse(module === 0);
40 assertEquals("object", typeof module); 27 assertEquals("object", typeof module);
41 28
42 // Check the memory is an ArrayBuffer. 29 // Check the memory is an ArrayBuffer.
43 var mem = module.memory; 30 var mem = module.memory;
44 assertFalse(mem === undefined); 31 assertFalse(mem === undefined);
45 assertFalse(mem === null); 32 assertFalse(mem === null);
46 assertFalse(mem === 0); 33 assertFalse(mem === 0);
47 assertEquals("object", typeof mem); 34 assertEquals("object", typeof mem);
48 assertTrue(mem instanceof ArrayBuffer); 35 assertTrue(mem instanceof ArrayBuffer);
49 for (var i = 0; i < 4; i++) { 36 for (var i = 0; i < 4; i++) {
50 module.memory = 0; // should be ignored 37 module.memory = 0; // should be ignored
51 assertEquals(mem, module.memory); 38 assertEquals(mem, module.memory);
52 } 39 }
53 40
54 assertEquals(65536, module.memory.byteLength); 41 assertEquals(65536, module.memory.byteLength);
55 42
56 // Check the properties of the main function. 43 // Check the properties of the main function.
57 assertFalse(module.main === undefined); 44 var main = module.exports.main;
58 assertFalse(module.main === null); 45 assertFalse(main === undefined);
59 assertFalse(module.main === 0); 46 assertFalse(main === null);
60 assertEquals("function", typeof module.main); 47 assertFalse(main === 0);
48 assertEquals("function", typeof main);
61 49
62 assertEquals(kReturnValue, module.main()); 50 assertEquals(kReturnValue, main());
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/indirect-calls.js ('k') | test/mjsunit/wasm/instantiate-run-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698