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

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

Issue 1763433002: [wasm] Rework encoding of local declarations. (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
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 8
9 function instantiate(sig, body) { 9 function instantiate(sig, body) {
10 var module = new Array(); 10 var module = new Array();
11 module = module.concat([ 11 module = module.concat([
12 // -- header 12 // -- header
13 kWasmH0, kWasmH1, kWasmH2, kWasmH3, 13 kWasmH0, kWasmH1, kWasmH2, kWasmH3,
14 kWasmV0, kWasmV1, kWasmV2, kWasmV3 14 kWasmV0, kWasmV1, kWasmV2, kWasmV3
15 ]); 15 ]);
16 module = module.concat([ 16 module = module.concat([
17 // -- signatures 17 // -- signatures
18 kDeclSignatures, 1, 18 kDeclSignatures, 1,
19 ]); 19 ]);
20 module = module.concat(sig); 20 module = module.concat(sig);
21 module = module.concat([ 21 module = module.concat([
22 // -- functions 22 // -- functions
23 kDeclFunctions, 1, 23 kDeclFunctions, 1,
24 0, // decl flags 24 0, // decl flags
25 0, 0, // signature 25 0, 0, // signature
26 body.length, 0, // body size 26 body.length + 1, 0, // body size
27 ]); 27 ]);
28 module = module.concat([kDeclNoLocals]);
28 module = module.concat(body); 29 module = module.concat(body);
29 module = module.concat([ 30 module = module.concat([
30 // -- declare start function 31 // -- declare start function
31 kDeclStartFunction, 32 kDeclStartFunction,
32 0 33 0
33 ]); 34 ]);
34 35
35 var data = bytes.apply(this, module); 36 var data = bytes.apply(this, module);
36 print(module); 37 print(module);
37 print(data instanceof ArrayBuffer); 38 print(data instanceof ArrayBuffer);
(...skipping 22 matching lines...) Expand all
60 61
61 assertVerifies([0, kAstStmt], [kExprNop]); 62 assertVerifies([0, kAstStmt], [kExprNop]);
62 assertVerifies([0, kAstI32], [kExprI8Const, 0]); 63 assertVerifies([0, kAstI32], [kExprI8Const, 0]);
63 64
64 // Arguments aren't allow to start functions. 65 // Arguments aren't allow to start functions.
65 assertFails([1, kAstI32, kAstI32], [kExprGetLocal, 0]); 66 assertFails([1, kAstI32, kAstI32], [kExprGetLocal, 0]);
66 assertFails([2, kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]); 67 assertFails([2, kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]);
67 assertFails([3, kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); 68 assertFails([3, kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]);
68 69
69 (function testInvalidIndex() { 70 (function testInvalidIndex() {
70 var kBodySize = 1; 71 var kBodySize = 2;
71 var data = bytesWithHeader( 72 var data = bytesWithHeader(
72 // -- signatures 73 // -- signatures
73 kDeclSignatures, 1, 74 kDeclSignatures, 1,
74 0, kAstStmt, 75 0, kAstStmt,
75 // -- functions 76 // -- functions
76 kDeclFunctions, 1, 77 kDeclFunctions, 1,
77 0, // decl flags 78 0, // decl flags
78 0, 0, // signature 79 0, 0, // signature
80 kDeclNoLocals,
79 kBodySize, 0, // body size 81 kBodySize, 0, // body size
80 kExprNop, // body 82 kExprNop, // body
81 // -- declare start function 83 // -- declare start function
82 kDeclStartFunction, 84 kDeclStartFunction,
83 1 85 1
84 ); 86 );
85 87
86 assertThrows(function() { _WASMEXP_.instantiateModule(data); }); 88 assertThrows(function() { _WASMEXP_.instantiateModule(data); });
87 })(); 89 })();
88 90
89 91
90 (function testTwoStartFuncs() { 92 (function testTwoStartFuncs() {
91 var kBodySize = 1; 93 var kBodySize = 2;
92 var data = bytesWithHeader( 94 var data = bytesWithHeader(
93 // -- signatures 95 // -- signatures
94 kDeclSignatures, 1, 96 kDeclSignatures, 1,
95 0, kAstStmt, 97 0, kAstStmt,
96 // -- functions 98 // -- functions
97 kDeclFunctions, 1, 99 kDeclFunctions, 1,
98 0, // decl flags 100 0, // decl flags
99 0, 0, // signature 101 0, 0, // signature
100 kBodySize, 0, // body size 102 kBodySize, 0, // body size
103 kDeclNoLocals,
101 kExprNop, // body 104 kExprNop, // body
102 // -- declare start function 105 // -- declare start function
103 kDeclStartFunction, 106 kDeclStartFunction,
104 0, 107 0,
105 // -- declare start function 108 // -- declare start function
106 kDeclStartFunction, 109 kDeclStartFunction,
107 0 110 0
108 ); 111 );
109 112
110 assertThrows(function() { _WASMEXP_.instantiateModule(data); }); 113 assertThrows(function() { _WASMEXP_.instantiateModule(data); });
111 })(); 114 })();
112 115
113 116
114 (function testRun() { 117 (function testRun() {
115 var kBodySize = 6; 118 var kBodySize = 7;
116 119
117 var data = bytesWithHeader( 120 var data = bytesWithHeader(
118 kDeclMemory, 121 kDeclMemory,
119 12, 12, 1, // memory 122 12, 12, 1, // memory
120 // -- signatures 123 // -- signatures
121 kDeclSignatures, 1, 124 kDeclSignatures, 1,
122 0, kAstStmt, 125 0, kAstStmt,
123 // -- start function 126 // -- start function
124 kDeclFunctions, 1, 127 kDeclFunctions, 1,
125 0, // decl flags 128 0, // decl flags
126 0, 0, // signature 129 0, 0, // signature
127 kBodySize, 0, // code size 130 kBodySize, 0, // code size
131 kDeclNoLocals,
128 // -- start body 132 // -- start body
129 kExprI32StoreMem, 0, kExprI8Const, 0, kExprI8Const, 77, 133 kExprI32StoreMem, 0, kExprI8Const, 0, kExprI8Const, 77,
130 // -- declare start function 134 // -- declare start function
131 kDeclStartFunction, 135 kDeclStartFunction,
132 0 136 0
133 ); 137 );
134 138
135 var module = _WASMEXP_.instantiateModule(data); 139 var module = _WASMEXP_.instantiateModule(data);
136 var memory = module.memory; 140 var memory = module.memory;
137 var view = new Int8Array(memory); 141 var view = new Int8Array(memory);
138 assertEquals(77, view[0]); 142 assertEquals(77, view[0]);
139 })(); 143 })();
140 144
141 (function testStartFFI() { 145 (function testStartFFI() {
142 var kBodySize = 2; 146 var kBodySize = 3;
143 var kNameOffset = kHeaderSize + 4 + 9 + 7 + 3; 147 var kNameOffset = kHeaderSize + 4 + 9 + 5 + kBodySize + 3;
144 148
145 var data = bytesWithHeader( 149 var data = bytesWithHeader(
146 // -- signatures 150 // -- signatures
147 kDeclSignatures, 1, 151 kDeclSignatures, 1,
148 0, kAstStmt, 152 0, kAstStmt,
149 // -- imported function 153 // -- imported function
150 kDeclFunctions, 2, 154 kDeclFunctions, 2,
151 kDeclFunctionImport | kDeclFunctionName, // decl flags 155 kDeclFunctionImport | kDeclFunctionName, // decl flags
152 0, 0, // signature 156 0, 0, // signature
153 kNameOffset, 0, 0, 0, 157 kNameOffset, 0, 0, 0,
154 // -- start function 158 // -- start function
155 0, // decl flags 159 0, // decl flags
156 0, 0, // signature 160 0, 0, // signature
157 kBodySize, 0, // code size 161 kBodySize, 0, // code size
162 kDeclNoLocals,
158 // -- start body 163 // -- start body
159 kExprCallFunction, 0, 164 kExprCallFunction, 0,
160 // -- declare start function 165 // -- declare start function
161 kDeclStartFunction, 166 kDeclStartFunction,
162 1, 167 1,
163 kDeclEnd, 168 kDeclEnd,
164 'f', 'o', 'o', 0 169 'f', 'o', 'o', 0
165 ); 170 );
166 171
167 var ranned = false; 172 var ranned = false;
168 var ffi = new Object(); 173 var ffi = new Object();
169 ffi.foo = function() { 174 ffi.foo = function() {
170 print("we ranned at stert!"); 175 print("we ranned at stert!");
171 ranned = true; 176 ranned = true;
172 } 177 }
173 var module = _WASMEXP_.instantiateModule(data, ffi); 178 var module = _WASMEXP_.instantiateModule(data, ffi);
174 var memory = module.memory; 179 var memory = module.memory;
175 var view = new Int8Array(memory); 180 var view = new Int8Array(memory);
176 assertTrue(ranned); 181 assertTrue(ranned);
177 })(); 182 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698