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

Side by Side Diff: test/mjsunit/wasm/adapter-frame.js

Issue 1828223002: [wasm] Fix formal parameter count and parameter indexes in JS->wasm wrappers. (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 | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --expose-wasm
6
7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js");
9
10 const JS = false; // for testing the tests.
11 const WRONG1 = 0x0DEDFACE;
12 const WRONG2 = 0x0DEDBABE;
13 const WRONG3 = 0x0DEDD011
14
15 function makeSelect(type, args, which) {
16 if (JS) {
17 // For testing the tests.
18 return function() {
19 var val = +arguments[which];
20 print(" " + val);
21 if (type == kAstI32) return val | 0;
22 if (type == kAstF32) return Math.fround(val);
23 if (type == kAstF64) return val;
24 return undefined;
25 }
26 }
27
28 var builder = new WasmModuleBuilder();
29 var sig = new Array();
30 sig.push(type);
31 for (var i = 0; i < args; i++) sig.push(type);
32 builder.addFunction("select", sig)
33 .addBody([kExprGetLocal, which])
34 .exportFunc();
35
36 return builder.instantiate().exports.select;
37 }
38
39 const inputs = [
40 -1, 0, 2.2, 3.3, 3000.11, Infinity, -Infinity, NaN
41 ];
42
43 (function TestInt1() {
44 print("i32 1(0)...");
45 var C = function(v) { return v | 0; }
46 var select1 = makeSelect(kAstI32, 1, 0);
47
48 for (val of inputs) {
49 assertEquals(C(val), select1(val));
50
51 // under args
52 assertEquals(C(undefined), select1());
53 // over args
54 assertEquals(C(val), select1(val, WRONG1));
55 assertEquals(C(val), select1(val, WRONG1, WRONG2));
56 }
57 })();
58
59 (function TestInt2() {
60 print("i32 2(0)...");
61 var C = function(v) { return v | 0; }
62 var select = makeSelect(kAstI32, 2, 0);
63
64 for (val of inputs) {
65 assertEquals(C(val), select(val, WRONG1));
66
67 // under args
68 assertEquals(C(undefined), select());
69 assertEquals(C(val), select(val));
70 // over args
71 assertEquals(C(val), select(val, WRONG1, WRONG2));
72 assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
73 }
74
75 print("i32 2(1)...");
76 var select = makeSelect(kAstI32, 2, 1);
77
78 for (val of inputs) {
79 assertEquals(C(val), select(WRONG1, val));
80
81 // under args
82 assertEquals(C(undefined), select());
83 assertEquals(C(undefined), select(val));
84 // over args
85 assertEquals(C(val), select(WRONG1, val));
86 assertEquals(C(val), select(WRONG1, val, WRONG2));
87 assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
88 }
89 })();
90
91 (function TestInt3() {
92 print("i32 3(0)...");
93 var C = function(v) { return v | 0; }
94 var select = makeSelect(kAstI32, 3, 0);
95
96 for (val of inputs) {
97 assertEquals(C(val), select(val, WRONG1, WRONG2));
98
99 // under args
100 assertEquals(C(undefined), select());
101 assertEquals(C(val), select(val));
102 assertEquals(C(val), select(val, WRONG1));
103 // over args
104 assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
105 }
106
107 print("i32 3(1)...");
108 var select = makeSelect(kAstI32, 3, 1);
109
110 for (val of inputs) {
111 assertEquals(val | 0, select(WRONG1, val, WRONG2));
112
113 // under args
114 assertEquals(C(undefined), select());
115 assertEquals(C(undefined), select(0xDEDFACE));
116 assertEquals(C(val), select(WRONG1, val));
117 // over args
118 assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
119 }
120
121 print("i32 3(2)...");
122 var select = makeSelect(kAstI32, 3, 2);
123
124 for (val of inputs) {
125 assertEquals(C(val), select(WRONG1, WRONG2, val));
126
127 // under args
128 assertEquals(C(undefined), select());
129 assertEquals(C(undefined), select(0xDEDFACE));
130 assertEquals(C(undefined), select(WRONG1, WRONG2));
131 // over args
132 assertEquals(C(val), select(WRONG1, WRONG2, val, WRONG3));
133 }
134 })();
135
136 (function TestFloat32_1() {
137 print("f32 1(0)...");
138 var C = function(v) { return Math.fround(v); }
139 var select1 = makeSelect(kAstF32, 1, 0);
140
141 for (val of inputs) {
142 assertEquals(C(val), select1(val));
143
144 // under args
145 assertEquals(C(undefined), select1());
146 // over args
147 assertEquals(C(val), select1(val, WRONG1));
148 assertEquals(C(val), select1(val, WRONG1, WRONG2));
149 }
150 })();
151
152 (function TestFloat32_2() {
153 print("f32 2(0)...");
154 var C = function(v) { return Math.fround(v); }
155 var select = makeSelect(kAstF32, 2, 0);
156
157 for (val of inputs) {
158 assertEquals(C(val), select(val, WRONG1));
159
160 // under args
161 assertEquals(C(undefined), select());
162 assertEquals(C(val), select(val));
163 // over args
164 assertEquals(C(val), select(val, WRONG1, WRONG2));
165 assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
166 }
167
168 print("f32 2(1)...");
169 var select = makeSelect(kAstF32, 2, 1);
170
171 for (val of inputs) {
172 assertEquals(C(val), select(WRONG1, val));
173
174 // under args
175 assertEquals(C(undefined), select());
176 assertEquals(C(undefined), select(val));
177 // over args
178 assertEquals(C(val), select(WRONG1, val));
179 assertEquals(C(val), select(WRONG1, val, WRONG2));
180 assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
181 }
182 })();
183
184 (function TestFloat32_2() {
185 print("f32 3(0)...");
186 var C = function(v) { return Math.fround(v); }
187 var select = makeSelect(kAstF32, 3, 0);
188
189 for (val of inputs) {
190 assertEquals(C(val), select(val, WRONG1, WRONG2));
191
192 // under args
193 assertEquals(C(undefined), select());
194 assertEquals(C(val), select(val));
195 assertEquals(C(val), select(val, WRONG1));
196 // over args
197 assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
198 }
199
200 print("f32 3(1)...");
201 var select = makeSelect(kAstF32, 3, 1);
202
203 for (val of inputs) {
204 assertEquals(C(val), select(WRONG1, val, WRONG2));
205
206 // under args
207 assertEquals(C(undefined), select());
208 assertEquals(C(undefined), select(0xDEDFACE));
209 assertEquals(C(val), select(WRONG1, val));
210 // over args
211 assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
212 }
213
214 print("f32 3(2)...");
215 var select = makeSelect(kAstF32, 3, 2);
216
217 for (val of inputs) {
218 assertEquals(C(val), select(WRONG1, WRONG2, val));
219
220 // under args
221 assertEquals(C(undefined), select());
222 assertEquals(C(undefined), select(0xDEDFACE));
223 assertEquals(C(undefined), select(WRONG1, WRONG2));
224 // over args
225 assertEquals(C(val), select(WRONG1, WRONG2, val, WRONG3));
226 }
227 })();
228
229
230 (function TestFloat64_1() {
231 print("f64 1(0)...");
232 var C = function(v) { return +v; }
233 var select1 = makeSelect(kAstF64, 1, 0);
234
235 for (val of inputs) {
236 assertEquals(C(val), select1(val));
237
238 // under args
239 assertEquals(C(undefined), select1());
240 // over args
241 assertEquals(C(val), select1(val, WRONG1));
242 assertEquals(C(val), select1(val, WRONG1, WRONG2));
243 }
244 })();
245
246 (function TestFloat64_2() {
247 print("f64 2(0)...");
248 var C = function(v) { return +v; }
249 var select = makeSelect(kAstF64, 2, 0);
250
251 for (val of inputs) {
252 assertEquals(C(val), select(val, WRONG1));
253
254 // under args
255 assertEquals(C(undefined), select());
256 assertEquals(C(val), select(val));
257 // over args
258 assertEquals(C(val), select(val, WRONG1, WRONG2));
259 assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
260 }
261
262 print("f64 2(1)...");
263 var select = makeSelect(kAstF64, 2, 1);
264
265 for (val of inputs) {
266 assertEquals(C(val), select(WRONG1, val));
267
268 // under args
269 assertEquals(C(undefined), select());
270 assertEquals(C(undefined), select(val));
271 // over args
272 assertEquals(C(val), select(WRONG1, val));
273 assertEquals(C(val), select(WRONG1, val, WRONG2));
274 assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
275 }
276 })();
277
278 (function TestFloat64_2() {
279 print("f64 3(0)...");
280 var C = function(v) { return +v; }
281 var select = makeSelect(kAstF64, 3, 0);
282
283 for (val of inputs) {
284 assertEquals(C(val), select(val, WRONG1, WRONG2));
285
286 // under args
287 assertEquals(C(undefined), select());
288 assertEquals(C(val), select(val));
289 assertEquals(C(val), select(val, WRONG1));
290 // over args
291 assertEquals(C(val), select(val, WRONG1, WRONG2, WRONG3));
292 }
293
294 print("f64 3(1)...");
295 var select = makeSelect(kAstF64, 3, 1);
296
297 for (val of inputs) {
298 assertEquals(C(val), select(WRONG1, val, WRONG2));
299
300 // under args
301 assertEquals(C(undefined), select());
302 assertEquals(C(undefined), select(0xDEDFACE));
303 assertEquals(C(val), select(WRONG1, val));
304 // over args
305 assertEquals(C(val), select(WRONG1, val, WRONG2, WRONG3));
306 }
307
308 print("f64 3(2)...");
309 var select = makeSelect(kAstF64, 3, 2);
310
311 for (val of inputs) {
312 assertEquals(C(val), select(WRONG1, WRONG2, val));
313
314 // under args
315 assertEquals(C(undefined), select());
316 assertEquals(C(undefined), select(0xDEDFACE));
317 assertEquals(C(undefined), select(WRONG1, WRONG2));
318 // over args
319 assertEquals(C(val), select(WRONG1, WRONG2, val, WRONG3));
320 }
321 })();
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698