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

Side by Side Diff: test/mjsunit/wasm/start-function.js

Issue 1896863003: [wasm] Binary 11: Module changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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/stackwalk.js ('k') | test/mjsunit/wasm/test-wasm-module-builder.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 load("test/mjsunit/wasm/wasm-module-builder.js");
9 9
10 function instantiate(sig, body) { 10 function instantiate(sig, body) {
(...skipping 19 matching lines...) Expand all
30 30
31 function assertVerifies(sig, body) { 31 function assertVerifies(sig, body) {
32 var module = instantiate(sig, body); 32 var module = instantiate(sig, body);
33 assertFalse(module === undefined); 33 assertFalse(module === undefined);
34 assertFalse(module === null); 34 assertFalse(module === null);
35 assertFalse(module === 0); 35 assertFalse(module === 0);
36 assertEquals("object", typeof module); 36 assertEquals("object", typeof module);
37 return module; 37 return module;
38 } 38 }
39 39
40 assertVerifies([kAstStmt], [kExprNop]); 40 assertVerifies(kSig_v_v, [kExprNop]);
41 assertVerifies([kAstI32], [kExprI8Const, 0]); 41 assertVerifies(kSig_i, [kExprI8Const, 0]);
42 42
43 // Arguments aren't allow to start functions. 43 // Arguments aren't allow to start functions.
44 assertFails([kAstI32, kAstI32], [kExprGetLocal, 0]); 44 assertFails(kSig_i_i, [kExprGetLocal, 0]);
45 assertFails([kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]); 45 assertFails(kSig_i_ii, [kExprGetLocal, 0]);
46 assertFails([kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); 46 assertFails(kSig_i_dd, [kExprGetLocal, 0]);
47 47
48 (function testInvalidIndex() { 48 (function testInvalidIndex() {
49 print("testInvalidIndex"); 49 print("testInvalidIndex");
50 var builder = new WasmModuleBuilder(); 50 var builder = new WasmModuleBuilder();
51 51
52 var func = builder.addFunction("", [kAstStmt]) 52 var func = builder.addFunction("", kSig_v_v)
53 .addBody([kExprNop]); 53 .addBody([kExprNop]);
54 54
55 builder.addStart(func.index + 1); 55 builder.addStart(func.index + 1);
56 56
57 assertThrows(builder.instantiate); 57 assertThrows(builder.instantiate);
58 })(); 58 })();
59 59
60 60
61 (function testTwoStartFuncs() { 61 (function testTwoStartFuncs() {
62 print("testTwoStartFuncs"); 62 print("testTwoStartFuncs");
63 var builder = new WasmModuleBuilder(); 63 var builder = new WasmModuleBuilder();
64 64
65 var func = builder.addFunction("", [kAstStmt]) 65 var func = builder.addFunction("", kSig_v_v)
66 .addBody([kExprNop]); 66 .addBody([kExprNop]);
67 67
68 builder.addExplicitSection([kDeclStartFunction, 0]); 68 builder.addExplicitSection([kDeclStartFunction, 0]);
69 builder.addExplicitSection([kDeclStartFunction, 0]); 69 builder.addExplicitSection([kDeclStartFunction, 0]);
70 70
71 assertThrows(builder.instantiate); 71 assertThrows(builder.instantiate);
72 })(); 72 })();
73 73
74 74
75 (function testRun() { 75 (function testRun() {
76 print("testRun"); 76 print("testRun");
77 var builder = new WasmModuleBuilder(); 77 var builder = new WasmModuleBuilder();
78 78
79 builder.addMemory(12, 12, true); 79 builder.addMemory(12, 12, true);
80 80
81 var func = builder.addFunction("", [kAstStmt]) 81 var func = builder.addFunction("", kSig_v_v)
82 .addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]); 82 .addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]);
83 83
84 builder.addStart(func.index); 84 builder.addStart(func.index);
85 85
86 var module = builder.instantiate(); 86 var module = builder.instantiate();
87 var memory = module.exports.memory; 87 var memory = module.exports.memory;
88 var view = new Int8Array(memory); 88 var view = new Int8Array(memory);
89 assertEquals(77, view[0]); 89 assertEquals(77, view[0]);
90 })(); 90 })();
91 91
92 (function testStartFFI() { 92 (function testStartFFI() {
93 print("testStartFFI"); 93 print("testStartFFI");
94 var ranned = false; 94 var ranned = false;
95 var ffi = { foo : function() { 95 var ffi = { foo : function() {
96 print("we ranned at stert!"); 96 print("we ranned at stert!");
97 ranned = true; 97 ranned = true;
98 }}; 98 }};
99 99
100 var builder = new WasmModuleBuilder(); 100 var builder = new WasmModuleBuilder();
101 var sig_index = builder.addSignature([kAstStmt]); 101 var sig_index = builder.addSignature(kSig_v_v);
102 102
103 builder.addImport("foo", sig_index); 103 builder.addImport("foo", sig_index);
104 var func = builder.addFunction("", sig_index) 104 var func = builder.addFunction("", sig_index)
105 .addBody([kExprCallImport, kArity0, 0]); 105 .addBody([kExprCallImport, kArity0, 0]);
106 106
107 builder.addStart(func.index); 107 builder.addStart(func.index);
108 108
109 var module = builder.instantiate(ffi); 109 var module = builder.instantiate(ffi);
110 assertTrue(ranned); 110 assertTrue(ranned);
111 })(); 111 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/stackwalk.js ('k') | test/mjsunit/wasm/test-wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698