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

Side by Side Diff: test/mjsunit/wasm/asm-wasm.js

Issue 1770383002: [wasm] Rename _WASMEXP_ object to Wasm. (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/regress/regress-575364.js ('k') | test/mjsunit/wasm/embenchen/box2d.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 function EmptyTest() { 7 function EmptyTest() {
8 "use asm"; 8 "use asm";
9 function caller() { 9 function caller() {
10 empty(); 10 empty();
11 return 11; 11 return 11;
12 } 12 }
13 function empty() { 13 function empty() {
14 } 14 }
15 return {caller: caller}; 15 return {caller: caller};
16 } 16 }
17 17
18 assertEquals(11, _WASMEXP_.instantiateModuleFromAsm( 18 assertEquals(11, Wasm.instantiateModuleFromAsm(
19 EmptyTest.toString()).caller()); 19 EmptyTest.toString()).caller());
20 20
21 21
22 function IntTest() { 22 function IntTest() {
23 "use asm"; 23 "use asm";
24 function sum(a, b) { 24 function sum(a, b) {
25 a = a|0; 25 a = a|0;
26 b = b|0; 26 b = b|0;
27 var c = (b + 1)|0 27 var c = (b + 1)|0
28 var d = 3.0; 28 var d = 3.0;
29 var e = ~~d; // double conversion 29 var e = ~~d; // double conversion
30 return (a + c + 1)|0; 30 return (a + c + 1)|0;
31 } 31 }
32 32
33 function caller() { 33 function caller() {
34 return sum(77,22) | 0; 34 return sum(77,22) | 0;
35 } 35 }
36 36
37 return {caller: caller}; 37 return {caller: caller};
38 } 38 }
39 39
40 assertEquals(101, _WASMEXP_.instantiateModuleFromAsm( 40 assertEquals(101, Wasm.instantiateModuleFromAsm(
41 IntTest.toString()).caller()); 41 IntTest.toString()).caller());
42 42
43 43
44 function Float64Test() { 44 function Float64Test() {
45 "use asm"; 45 "use asm";
46 function sum(a, b) { 46 function sum(a, b) {
47 a = +a; 47 a = +a;
48 b = +b; 48 b = +b;
49 return +(a + b); 49 return +(a + b);
50 } 50 }
51 51
52 function caller() { 52 function caller() {
53 var a = +sum(70.1,10.2); 53 var a = +sum(70.1,10.2);
54 var ret = 0|0; 54 var ret = 0|0;
55 if (a == 80.3) { 55 if (a == 80.3) {
56 ret = 1|0; 56 ret = 1|0;
57 } else { 57 } else {
58 ret = 0|0; 58 ret = 0|0;
59 } 59 }
60 return ret|0; 60 return ret|0;
61 } 61 }
62 62
63 return {caller: caller}; 63 return {caller: caller};
64 } 64 }
65 65
66 assertEquals(1, _WASMEXP_.instantiateModuleFromAsm( 66 assertEquals(1, Wasm.instantiateModuleFromAsm(
67 Float64Test.toString()).caller()); 67 Float64Test.toString()).caller());
68 68
69 69
70 function BadModule() { 70 function BadModule() {
71 "use asm"; 71 "use asm";
72 function caller(a, b) { 72 function caller(a, b) {
73 a = a|0; 73 a = a|0;
74 b = b+0; 74 b = b+0;
75 var c = (b + 1)|0 75 var c = (b + 1)|0
76 return (a + c + 1)|0; 76 return (a + c + 1)|0;
77 } 77 }
78 78
79 function caller() { 79 function caller() {
80 return call(1, 2)|0; 80 return call(1, 2)|0;
81 } 81 }
82 82
83 return {caller: caller}; 83 return {caller: caller};
84 } 84 }
85 85
86 assertThrows(function() { 86 assertThrows(function() {
87 _WASMEXP_.instantiateModuleFromAsm(BadModule.toString()).caller(); 87 Wasm.instantiateModuleFromAsm(BadModule.toString()).caller();
88 }); 88 });
89 89
90 90
91 function TestReturnInBlock() { 91 function TestReturnInBlock() {
92 "use asm"; 92 "use asm";
93 93
94 function caller() { 94 function caller() {
95 if(1) { 95 if(1) {
96 { 96 {
97 { 97 {
98 return 1; 98 return 1;
99 } 99 }
100 } 100 }
101 } 101 }
102 return 0; 102 return 0;
103 } 103 }
104 104
105 return {caller: caller}; 105 return {caller: caller};
106 } 106 }
107 107
108 assertEquals(1, _WASMEXP_.instantiateModuleFromAsm( 108 assertEquals(1, Wasm.instantiateModuleFromAsm(
109 TestReturnInBlock.toString()).caller()); 109 TestReturnInBlock.toString()).caller());
110 110
111 111
112 function TestWhileSimple() { 112 function TestWhileSimple() {
113 "use asm"; 113 "use asm";
114 114
115 function caller() { 115 function caller() {
116 var x = 0; 116 var x = 0;
117 while(x < 5) { 117 while(x < 5) {
118 x = (x + 1)|0; 118 x = (x + 1)|0;
119 } 119 }
120 return x|0; 120 return x|0;
121 } 121 }
122 122
123 return {caller: caller}; 123 return {caller: caller};
124 } 124 }
125 125
126 assertEquals(5, _WASMEXP_.instantiateModuleFromAsm( 126 assertEquals(5, Wasm.instantiateModuleFromAsm(
127 TestWhileSimple.toString()).caller()); 127 TestWhileSimple.toString()).caller());
128 128
129 129
130 function TestWhileWithoutBraces() { 130 function TestWhileWithoutBraces() {
131 "use asm"; 131 "use asm";
132 132
133 function caller() { 133 function caller() {
134 var x = 0; 134 var x = 0;
135 while(x <= 3) 135 while(x <= 3)
136 x = (x + 1)|0; 136 x = (x + 1)|0;
137 return x|0; 137 return x|0;
138 } 138 }
139 139
140 return {caller: caller}; 140 return {caller: caller};
141 } 141 }
142 142
143 assertEquals(4, _WASMEXP_.instantiateModuleFromAsm( 143 assertEquals(4, Wasm.instantiateModuleFromAsm(
144 TestWhileWithoutBraces.toString()).caller()); 144 TestWhileWithoutBraces.toString()).caller());
145 145
146 146
147 function TestReturnInWhile() { 147 function TestReturnInWhile() {
148 "use asm"; 148 "use asm";
149 149
150 function caller() { 150 function caller() {
151 var x = 0; 151 var x = 0;
152 while(x < 10) { 152 while(x < 10) {
153 x = (x + 6)|0; 153 x = (x + 6)|0;
154 return x|0; 154 return x|0;
155 } 155 }
156 return x|0; 156 return x|0;
157 } 157 }
158 158
159 return {caller: caller}; 159 return {caller: caller};
160 } 160 }
161 161
162 assertEquals(6, _WASMEXP_.instantiateModuleFromAsm( 162 assertEquals(6, Wasm.instantiateModuleFromAsm(
163 TestReturnInWhile.toString()).caller()); 163 TestReturnInWhile.toString()).caller());
164 164
165 165
166 function TestReturnInWhileWithoutBraces() { 166 function TestReturnInWhileWithoutBraces() {
167 "use asm"; 167 "use asm";
168 168
169 function caller() { 169 function caller() {
170 var x = 0; 170 var x = 0;
171 while(x < 5) 171 while(x < 5)
172 return 7; 172 return 7;
173 return x|0; 173 return x|0;
174 } 174 }
175 175
176 return {caller: caller}; 176 return {caller: caller};
177 } 177 }
178 178
179 assertEquals( 179 assertEquals(
180 7, _WASMEXP_.instantiateModuleFromAsm( 180 7, Wasm.instantiateModuleFromAsm(
181 TestReturnInWhileWithoutBraces.toString()).caller()); 181 TestReturnInWhileWithoutBraces.toString()).caller());
182 182
183 183
184 function TestBreakInWhile() { 184 function TestBreakInWhile() {
185 "use asm"; 185 "use asm";
186 186
187 function caller() { 187 function caller() {
188 while(1) { 188 while(1) {
189 break; 189 break;
190 } 190 }
191 return 8; 191 return 8;
192 } 192 }
193 193
194 return {caller: caller}; 194 return {caller: caller};
195 } 195 }
196 196
197 assertEquals(8, _WASMEXP_.instantiateModuleFromAsm( 197 assertEquals(8, Wasm.instantiateModuleFromAsm(
198 TestBreakInWhile.toString()).caller()); 198 TestBreakInWhile.toString()).caller());
199 199
200 200
201 function TestBreakInNestedWhile() { 201 function TestBreakInNestedWhile() {
202 "use asm"; 202 "use asm";
203 203
204 function caller() { 204 function caller() {
205 var x = 1.0; 205 var x = 1.0;
206 while(x < 1.5) { 206 while(x < 1.5) {
207 while(1) 207 while(1)
208 break; 208 break;
209 x = +(x + 0.25); 209 x = +(x + 0.25);
210 } 210 }
211 var ret = 0; 211 var ret = 0;
212 if (x == 1.5) { 212 if (x == 1.5) {
213 ret = 9; 213 ret = 9;
214 } 214 }
215 return ret|0; 215 return ret|0;
216 } 216 }
217 217
218 return {caller: caller}; 218 return {caller: caller};
219 } 219 }
220 220
221 assertEquals(9, _WASMEXP_.instantiateModuleFromAsm( 221 assertEquals(9, Wasm.instantiateModuleFromAsm(
222 TestBreakInNestedWhile.toString()).caller()); 222 TestBreakInNestedWhile.toString()).caller());
223 223
224 224
225 function TestBreakInBlock() { 225 function TestBreakInBlock() {
226 "use asm"; 226 "use asm";
227 227
228 function caller() { 228 function caller() {
229 var x = 0; 229 var x = 0;
230 abc: { 230 abc: {
231 x = 10; 231 x = 10;
232 if (x == 10) { 232 if (x == 10) {
233 break abc; 233 break abc;
234 } 234 }
235 x = 20; 235 x = 20;
236 } 236 }
237 return x|0; 237 return x|0;
238 } 238 }
239 239
240 return {caller: caller}; 240 return {caller: caller};
241 } 241 }
242 242
243 assertEquals(10, _WASMEXP_.instantiateModuleFromAsm( 243 assertEquals(10, Wasm.instantiateModuleFromAsm(
244 TestBreakInBlock.toString()).caller()); 244 TestBreakInBlock.toString()).caller());
245 245
246 246
247 function TestBreakInNamedWhile() { 247 function TestBreakInNamedWhile() {
248 "use asm"; 248 "use asm";
249 249
250 function caller() { 250 function caller() {
251 var x = 0; 251 var x = 0;
252 outer: while (1) { 252 outer: while (1) {
253 x = (x + 1)|0; 253 x = (x + 1)|0;
254 while (x == 11) { 254 while (x == 11) {
255 break outer; 255 break outer;
256 } 256 }
257 } 257 }
258 return x|0; 258 return x|0;
259 } 259 }
260 260
261 return {caller: caller}; 261 return {caller: caller};
262 } 262 }
263 263
264 assertEquals(11, _WASMEXP_.instantiateModuleFromAsm( 264 assertEquals(11, Wasm.instantiateModuleFromAsm(
265 TestBreakInNamedWhile.toString()).caller()); 265 TestBreakInNamedWhile.toString()).caller());
266 266
267 267
268 function TestContinue() { 268 function TestContinue() {
269 "use asm"; 269 "use asm";
270 270
271 function caller() { 271 function caller() {
272 var x = 5; 272 var x = 5;
273 var ret = 0; 273 var ret = 0;
274 while (x >= 0) { 274 while (x >= 0) {
275 x = (x - 1)|0; 275 x = (x - 1)|0;
276 if (x == 2) { 276 if (x == 2) {
277 continue; 277 continue;
278 } 278 }
279 ret = (ret - 1)|0; 279 ret = (ret - 1)|0;
280 } 280 }
281 return ret|0; 281 return ret|0;
282 } 282 }
283 283
284 return {caller: caller}; 284 return {caller: caller};
285 } 285 }
286 286
287 assertEquals(-5, _WASMEXP_.instantiateModuleFromAsm( 287 assertEquals(-5, Wasm.instantiateModuleFromAsm(
288 TestContinue.toString()).caller()); 288 TestContinue.toString()).caller());
289 289
290 290
291 function TestContinueInNamedWhile() { 291 function TestContinueInNamedWhile() {
292 "use asm"; 292 "use asm";
293 293
294 function caller() { 294 function caller() {
295 var x = 5; 295 var x = 5;
296 var y = 0; 296 var y = 0;
297 var ret = 0; 297 var ret = 0;
298 outer: while (x > 0) { 298 outer: while (x > 0) {
299 x = (x - 1)|0; 299 x = (x - 1)|0;
300 y = 0; 300 y = 0;
301 while (y < 5) { 301 while (y < 5) {
302 if (x == 3) { 302 if (x == 3) {
303 continue outer; 303 continue outer;
304 } 304 }
305 ret = (ret + 1)|0; 305 ret = (ret + 1)|0;
306 y = (y + 1)|0; 306 y = (y + 1)|0;
307 } 307 }
308 } 308 }
309 return ret|0; 309 return ret|0;
310 } 310 }
311 311
312 return {caller: caller}; 312 return {caller: caller};
313 } 313 }
314 314
315 assertEquals(20, _WASMEXP_.instantiateModuleFromAsm( 315 assertEquals(20, Wasm.instantiateModuleFromAsm(
316 TestContinueInNamedWhile.toString()).caller()); 316 TestContinueInNamedWhile.toString()).caller());
317 317
318 318
319 function TestNot() { 319 function TestNot() {
320 "use asm"; 320 "use asm";
321 321
322 function caller() { 322 function caller() {
323 var a = !(2 > 3); 323 var a = !(2 > 3);
324 return a | 0; 324 return a | 0;
325 } 325 }
326 326
327 return {caller:caller}; 327 return {caller:caller};
328 } 328 }
329 329
330 assertEquals(1, _WASMEXP_.instantiateModuleFromAsm( 330 assertEquals(1, Wasm.instantiateModuleFromAsm(
331 TestNot.toString()).caller()); 331 TestNot.toString()).caller());
332 332
333 333
334 function TestNotEquals() { 334 function TestNotEquals() {
335 "use asm"; 335 "use asm";
336 336
337 function caller() { 337 function caller() {
338 var a = 3; 338 var a = 3;
339 if (a != 2) { 339 if (a != 2) {
340 return 21; 340 return 21;
341 } 341 }
342 return 0; 342 return 0;
343 } 343 }
344 344
345 return {caller:caller}; 345 return {caller:caller};
346 } 346 }
347 347
348 assertEquals(21, _WASMEXP_.instantiateModuleFromAsm( 348 assertEquals(21, Wasm.instantiateModuleFromAsm(
349 TestNotEquals.toString()).caller()); 349 TestNotEquals.toString()).caller());
350 350
351 351
352 function TestUnsignedComparison() { 352 function TestUnsignedComparison() {
353 "use asm"; 353 "use asm";
354 354
355 function caller() { 355 function caller() {
356 var a = 0xffffffff; 356 var a = 0xffffffff;
357 if ((a>>>0) > (0>>>0)) { 357 if ((a>>>0) > (0>>>0)) {
358 return 22; 358 return 22;
359 } 359 }
360 return 0; 360 return 0;
361 } 361 }
362 362
363 return {caller:caller}; 363 return {caller:caller};
364 } 364 }
365 365
366 assertEquals(22, _WASMEXP_.instantiateModuleFromAsm( 366 assertEquals(22, Wasm.instantiateModuleFromAsm(
367 TestUnsignedComparison.toString()).caller()); 367 TestUnsignedComparison.toString()).caller());
368 368
369 369
370 function TestMixedAdd() { 370 function TestMixedAdd() {
371 "use asm"; 371 "use asm";
372 372
373 function caller() { 373 function caller() {
374 var a = 0x80000000; 374 var a = 0x80000000;
375 var b = 0x7fffffff; 375 var b = 0x7fffffff;
376 var c = 0; 376 var c = 0;
377 c = ((a>>>0) + b)|0; 377 c = ((a>>>0) + b)|0;
378 if ((c >>> 0) > (0>>>0)) { 378 if ((c >>> 0) > (0>>>0)) {
379 if (c < 0) { 379 if (c < 0) {
380 return 23; 380 return 23;
381 } 381 }
382 } 382 }
383 return 0; 383 return 0;
384 } 384 }
385 385
386 return {caller:caller}; 386 return {caller:caller};
387 } 387 }
388 388
389 assertEquals(23, _WASMEXP_.instantiateModuleFromAsm( 389 assertEquals(23, Wasm.instantiateModuleFromAsm(
390 TestMixedAdd.toString()).caller()); 390 TestMixedAdd.toString()).caller());
391 391
392 392
393 function TestInt32HeapAccess(stdlib, foreign, buffer) { 393 function TestInt32HeapAccess(stdlib, foreign, buffer) {
394 "use asm"; 394 "use asm";
395 395
396 var m = new stdlib.Int32Array(buffer); 396 var m = new stdlib.Int32Array(buffer);
397 function caller() { 397 function caller() {
398 var i = 4; 398 var i = 4;
399 399
400 m[0] = (i + 1) | 0; 400 m[0] = (i + 1) | 0;
401 m[i >> 2] = ((m[0]|0) + 1) | 0; 401 m[i >> 2] = ((m[0]|0) + 1) | 0;
402 m[2] = ((m[i >> 2]|0) + 1) | 0; 402 m[2] = ((m[i >> 2]|0) + 1) | 0;
403 return m[2] | 0; 403 return m[2] | 0;
404 } 404 }
405 405
406 return {caller: caller}; 406 return {caller: caller};
407 } 407 }
408 408
409 assertEquals(7, _WASMEXP_.instantiateModuleFromAsm( 409 assertEquals(7, Wasm.instantiateModuleFromAsm(
410 TestInt32HeapAccess.toString()).caller()); 410 TestInt32HeapAccess.toString()).caller());
411 411
412 412
413 function TestInt32HeapAccessExternal() { 413 function TestInt32HeapAccessExternal() {
414 var memory = new ArrayBuffer(1024); 414 var memory = new ArrayBuffer(1024);
415 var memory_int32 = new Int32Array(memory); 415 var memory_int32 = new Int32Array(memory);
416 var module = _WASMEXP_.instantiateModuleFromAsm( 416 var module = Wasm.instantiateModuleFromAsm(
417 TestInt32HeapAccess.toString(), null, memory); 417 TestInt32HeapAccess.toString(), null, memory);
418 assertEquals(7, module.caller()); 418 assertEquals(7, module.caller());
419 assertEquals(7, memory_int32[2]); 419 assertEquals(7, memory_int32[2]);
420 } 420 }
421 421
422 TestInt32HeapAccessExternal(); 422 TestInt32HeapAccessExternal();
423 423
424 424
425 function TestHeapAccessIntTypes() { 425 function TestHeapAccessIntTypes() {
426 var types = [ 426 var types = [
427 [Int8Array, 'Int8Array', '>> 0'], 427 [Int8Array, 'Int8Array', '>> 0'],
428 [Uint8Array, 'Uint8Array', '>> 0'], 428 [Uint8Array, 'Uint8Array', '>> 0'],
429 [Int16Array, 'Int16Array', '>> 1'], 429 [Int16Array, 'Int16Array', '>> 1'],
430 [Uint16Array, 'Uint16Array', '>> 1'], 430 [Uint16Array, 'Uint16Array', '>> 1'],
431 [Int32Array, 'Int32Array', '>> 2'], 431 [Int32Array, 'Int32Array', '>> 2'],
432 [Uint32Array, 'Uint32Array', '>> 2'], 432 [Uint32Array, 'Uint32Array', '>> 2'],
433 ]; 433 ];
434 for (var i = 0; i < types.length; i++) { 434 for (var i = 0; i < types.length; i++) {
435 var code = TestInt32HeapAccess.toString(); 435 var code = TestInt32HeapAccess.toString();
436 code = code.replace('Int32Array', types[i][1]); 436 code = code.replace('Int32Array', types[i][1]);
437 code = code.replace(/>> 2/g, types[i][2]); 437 code = code.replace(/>> 2/g, types[i][2]);
438 var memory = new ArrayBuffer(1024); 438 var memory = new ArrayBuffer(1024);
439 var memory_view = new types[i][0](memory); 439 var memory_view = new types[i][0](memory);
440 var module = _WASMEXP_.instantiateModuleFromAsm(code, null, memory); 440 var module = Wasm.instantiateModuleFromAsm(code, null, memory);
441 assertEquals(7, module.caller()); 441 assertEquals(7, module.caller());
442 assertEquals(7, memory_view[2]); 442 assertEquals(7, memory_view[2]);
443 assertEquals(7, _WASMEXP_.instantiateModuleFromAsm(code).caller()); 443 assertEquals(7, Wasm.instantiateModuleFromAsm(code).caller());
444 } 444 }
445 } 445 }
446 446
447 TestHeapAccessIntTypes(); 447 TestHeapAccessIntTypes();
448 448
449 449
450 function TestFloatHeapAccess(stdlib, foreign, buffer) { 450 function TestFloatHeapAccess(stdlib, foreign, buffer) {
451 "use asm"; 451 "use asm";
452 452
453 var f32 = new stdlib.Float32Array(buffer); 453 var f32 = new stdlib.Float32Array(buffer);
454 var f64 = new stdlib.Float64Array(buffer); 454 var f64 = new stdlib.Float64Array(buffer);
455 var fround = stdlib.Math.fround; 455 var fround = stdlib.Math.fround;
456 function caller() { 456 function caller() {
457 var i = 8; 457 var i = 8;
458 var j = 8; 458 var j = 8;
459 var v = 6.0; 459 var v = 6.0;
460 460
461 // TODO(bradnelson): Add float32 when asm-wasm supports it. 461 // TODO(bradnelson): Add float32 when asm-wasm supports it.
462 f64[2] = v + 1.0; 462 f64[2] = v + 1.0;
463 f64[i >> 3] = +f64[2] + 1.0; 463 f64[i >> 3] = +f64[2] + 1.0;
464 f64[j >> 3] = +f64[j >> 3] + 1.0; 464 f64[j >> 3] = +f64[j >> 3] + 1.0;
465 i = +f64[i >> 3] == 9.0; 465 i = +f64[i >> 3] == 9.0;
466 return i|0; 466 return i|0;
467 } 467 }
468 468
469 return {caller: caller}; 469 return {caller: caller};
470 } 470 }
471 471
472 assertEquals(1, _WASMEXP_.instantiateModuleFromAsm( 472 assertEquals(1, Wasm.instantiateModuleFromAsm(
473 TestFloatHeapAccess.toString()).caller()); 473 TestFloatHeapAccess.toString()).caller());
474 474
475 475
476 function TestFloatHeapAccessExternal() { 476 function TestFloatHeapAccessExternal() {
477 var memory = new ArrayBuffer(1024); 477 var memory = new ArrayBuffer(1024);
478 var memory_float64 = new Float64Array(memory); 478 var memory_float64 = new Float64Array(memory);
479 var module = _WASMEXP_.instantiateModuleFromAsm( 479 var module = Wasm.instantiateModuleFromAsm(
480 TestFloatHeapAccess.toString(), null, memory); 480 TestFloatHeapAccess.toString(), null, memory);
481 assertEquals(1, module.caller()); 481 assertEquals(1, module.caller());
482 assertEquals(9.0, memory_float64[1]); 482 assertEquals(9.0, memory_float64[1]);
483 } 483 }
484 484
485 TestFloatHeapAccessExternal(); 485 TestFloatHeapAccessExternal();
486 486
487 487
488 function TestConvertI32() { 488 function TestConvertI32() {
489 "use asm"; 489 "use asm";
490 490
491 function caller() { 491 function caller() {
492 var a = 1.5; 492 var a = 1.5;
493 if ((~~(a + a)) == 3) { 493 if ((~~(a + a)) == 3) {
494 return 24; 494 return 24;
495 } 495 }
496 return 0; 496 return 0;
497 } 497 }
498 498
499 return {caller:caller}; 499 return {caller:caller};
500 } 500 }
501 501
502 assertEquals(24, _WASMEXP_.instantiateModuleFromAsm( 502 assertEquals(24, Wasm.instantiateModuleFromAsm(
503 TestConvertI32.toString()).caller()); 503 TestConvertI32.toString()).caller());
504 504
505 505
506 function TestConvertF64FromInt() { 506 function TestConvertF64FromInt() {
507 "use asm"; 507 "use asm";
508 508
509 function caller() { 509 function caller() {
510 var a = 1; 510 var a = 1;
511 if ((+(a + a)) > 1.5) { 511 if ((+(a + a)) > 1.5) {
512 return 25; 512 return 25;
513 } 513 }
514 return 0; 514 return 0;
515 } 515 }
516 516
517 return {caller:caller}; 517 return {caller:caller};
518 } 518 }
519 519
520 assertEquals(25, _WASMEXP_.instantiateModuleFromAsm( 520 assertEquals(25, Wasm.instantiateModuleFromAsm(
521 TestConvertF64FromInt.toString()).caller()); 521 TestConvertF64FromInt.toString()).caller());
522 522
523 523
524 function TestConvertF64FromUnsigned() { 524 function TestConvertF64FromUnsigned() {
525 "use asm"; 525 "use asm";
526 526
527 function caller() { 527 function caller() {
528 var a = 0xffffffff; 528 var a = 0xffffffff;
529 if ((+(a>>>0)) > 0.0) { 529 if ((+(a>>>0)) > 0.0) {
530 if((+a) < 0.0) { 530 if((+a) < 0.0) {
531 return 26; 531 return 26;
532 } 532 }
533 } 533 }
534 return 0; 534 return 0;
535 } 535 }
536 536
537 return {caller:caller}; 537 return {caller:caller};
538 } 538 }
539 539
540 assertEquals(26, _WASMEXP_.instantiateModuleFromAsm( 540 assertEquals(26, Wasm.instantiateModuleFromAsm(
541 TestConvertF64FromUnsigned.toString()).caller()); 541 TestConvertF64FromUnsigned.toString()).caller());
542 542
543 543
544 function TestModInt() { 544 function TestModInt() {
545 "use asm"; 545 "use asm";
546 546
547 function caller() { 547 function caller() {
548 var a = -83; 548 var a = -83;
549 var b = 28; 549 var b = 28;
550 return ((a|0)%(b|0))|0; 550 return ((a|0)%(b|0))|0;
551 } 551 }
552 552
553 return {caller:caller}; 553 return {caller:caller};
554 } 554 }
555 555
556 assertEquals(-27, _WASMEXP_.instantiateModuleFromAsm( 556 assertEquals(-27, Wasm.instantiateModuleFromAsm(
557 TestModInt.toString()).caller()); 557 TestModInt.toString()).caller());
558 558
559 559
560 function TestModUnsignedInt() { 560 function TestModUnsignedInt() {
561 "use asm"; 561 "use asm";
562 562
563 function caller() { 563 function caller() {
564 var a = 0x80000000; //2147483648 564 var a = 0x80000000; //2147483648
565 var b = 10; 565 var b = 10;
566 return ((a>>>0)%(b>>>0))|0; 566 return ((a>>>0)%(b>>>0))|0;
567 } 567 }
568 568
569 return {caller:caller}; 569 return {caller:caller};
570 } 570 }
571 571
572 assertEquals(8, _WASMEXP_.instantiateModuleFromAsm( 572 assertEquals(8, Wasm.instantiateModuleFromAsm(
573 TestModUnsignedInt.toString()).caller()); 573 TestModUnsignedInt.toString()).caller());
574 574
575 575
576 function TestModDouble() { 576 function TestModDouble() {
577 "use asm"; 577 "use asm";
578 578
579 function caller() { 579 function caller() {
580 var a = 5.25; 580 var a = 5.25;
581 var b = 2.5; 581 var b = 2.5;
582 if (a%b == 0.25) { 582 if (a%b == 0.25) {
583 return 28; 583 return 28;
584 } 584 }
585 return 0; 585 return 0;
586 } 586 }
587 587
588 return {caller:caller}; 588 return {caller:caller};
589 } 589 }
590 590
591 assertEquals(28, _WASMEXP_.instantiateModuleFromAsm( 591 assertEquals(28, Wasm.instantiateModuleFromAsm(
592 TestModDouble.toString()).caller()); 592 TestModDouble.toString()).caller());
593 593
594 594
595 /* 595 /*
596 TODO: Fix parsing of negative doubles 596 TODO: Fix parsing of negative doubles
597 Fix code to use trunc instead of casts 597 Fix code to use trunc instead of casts
598 function TestModDoubleNegative() { 598 function TestModDoubleNegative() {
599 "use asm"; 599 "use asm";
600 600
601 function caller() { 601 function caller() {
602 var a = -34359738368.25; 602 var a = -34359738368.25;
603 var b = 2.5; 603 var b = 2.5;
604 if (a%b == -0.75) { 604 if (a%b == -0.75) {
605 return 28; 605 return 28;
606 } 606 }
607 return 0; 607 return 0;
608 } 608 }
609 609
610 return {caller:caller}; 610 return {caller:caller};
611 } 611 }
612 612
613 assertEquals(28, _WASMEXP_.instantiateModuleFromAsm( 613 assertEquals(28, Wasm.instantiateModuleFromAsm(
614 TestModDoubleNegative.toString()).caller()); 614 TestModDoubleNegative.toString()).caller());
615 */ 615 */
616 616
617 617
618 function TestNamedFunctions() { 618 function TestNamedFunctions() {
619 "use asm"; 619 "use asm";
620 620
621 var a = 0.0; 621 var a = 0.0;
622 var b = 0.0; 622 var b = 0.0;
623 623
624 function add() { 624 function add() {
625 return +(a + b); 625 return +(a + b);
626 } 626 }
627 627
628 function init() { 628 function init() {
629 a = 43.25; 629 a = 43.25;
630 b = 34.25; 630 b = 34.25;
631 } 631 }
632 632
633 return {init:init, 633 return {init:init,
634 add:add}; 634 add:add};
635 } 635 }
636 636
637 var module = _WASMEXP_.instantiateModuleFromAsm(TestNamedFunctions.toString()); 637 var module = Wasm.instantiateModuleFromAsm(TestNamedFunctions.toString());
638 module.init(); 638 module.init();
639 assertEquals(77.5, module.add()); 639 assertEquals(77.5, module.add());
640 640
641 641
642 function TestGlobalsWithInit() { 642 function TestGlobalsWithInit() {
643 "use asm"; 643 "use asm";
644 644
645 var a = 43.25; 645 var a = 43.25;
646 var b = 34.25; 646 var b = 34.25;
647 647
648 function add() { 648 function add() {
649 return +(a + b); 649 return +(a + b);
650 } 650 }
651 651
652 return {add:add}; 652 return {add:add};
653 } 653 }
654 654
655 var module = _WASMEXP_.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); 655 var module = Wasm.instantiateModuleFromAsm(TestGlobalsWithInit.toString());
656 assertEquals(77.5, module.add()); 656 assertEquals(77.5, module.add());
657 657
658 658
659 function TestForLoop() { 659 function TestForLoop() {
660 "use asm" 660 "use asm"
661 661
662 function caller() { 662 function caller() {
663 var ret = 0; 663 var ret = 0;
664 var i = 0; 664 var i = 0;
665 for (i = 2; i <= 10; i = (i+1)|0) { 665 for (i = 2; i <= 10; i = (i+1)|0) {
666 ret = (ret + i) | 0; 666 ret = (ret + i) | 0;
667 } 667 }
668 return ret|0; 668 return ret|0;
669 } 669 }
670 670
671 return {caller:caller}; 671 return {caller:caller};
672 } 672 }
673 673
674 assertEquals(54, _WASMEXP_.instantiateModuleFromAsm( 674 assertEquals(54, Wasm.instantiateModuleFromAsm(
675 TestForLoop.toString()).caller()); 675 TestForLoop.toString()).caller());
676 676
677 677
678 function TestForLoopWithoutInit() { 678 function TestForLoopWithoutInit() {
679 "use asm" 679 "use asm"
680 680
681 function caller() { 681 function caller() {
682 var ret = 0; 682 var ret = 0;
683 var i = 0; 683 var i = 0;
684 for (; i < 10; i = (i+1)|0) { 684 for (; i < 10; i = (i+1)|0) {
685 ret = (ret + 10) | 0; 685 ret = (ret + 10) | 0;
686 } 686 }
687 return ret|0; 687 return ret|0;
688 } 688 }
689 689
690 return {caller:caller}; 690 return {caller:caller};
691 } 691 }
692 692
693 assertEquals(100, _WASMEXP_.instantiateModuleFromAsm( 693 assertEquals(100, Wasm.instantiateModuleFromAsm(
694 TestForLoopWithoutInit.toString()).caller()); 694 TestForLoopWithoutInit.toString()).caller());
695 695
696 696
697 function TestForLoopWithoutCondition() { 697 function TestForLoopWithoutCondition() {
698 "use asm" 698 "use asm"
699 699
700 function caller() { 700 function caller() {
701 var ret = 0; 701 var ret = 0;
702 var i = 0; 702 var i = 0;
703 for (i=1;; i = (i+1)|0) { 703 for (i=1;; i = (i+1)|0) {
704 ret = (ret + i) | 0; 704 ret = (ret + i) | 0;
705 if (i == 11) { 705 if (i == 11) {
706 break; 706 break;
707 } 707 }
708 } 708 }
709 return ret|0; 709 return ret|0;
710 } 710 }
711 711
712 return {caller:caller}; 712 return {caller:caller};
713 } 713 }
714 714
715 assertEquals(66, _WASMEXP_.instantiateModuleFromAsm( 715 assertEquals(66, Wasm.instantiateModuleFromAsm(
716 TestForLoopWithoutCondition.toString()).caller()); 716 TestForLoopWithoutCondition.toString()).caller());
717 717
718 718
719 function TestForLoopWithoutNext() { 719 function TestForLoopWithoutNext() {
720 "use asm" 720 "use asm"
721 721
722 function caller() { 722 function caller() {
723 var i = 0; 723 var i = 0;
724 for (i=1; i < 41;) { 724 for (i=1; i < 41;) {
725 i = (i + 1) | 0; 725 i = (i + 1) | 0;
726 } 726 }
727 return i|0; 727 return i|0;
728 } 728 }
729 729
730 return {caller:caller}; 730 return {caller:caller};
731 } 731 }
732 732
733 assertEquals(41, _WASMEXP_.instantiateModuleFromAsm( 733 assertEquals(41, Wasm.instantiateModuleFromAsm(
734 TestForLoopWithoutNext.toString()).caller()); 734 TestForLoopWithoutNext.toString()).caller());
735 735
736 736
737 function TestForLoopWithoutBody() { 737 function TestForLoopWithoutBody() {
738 "use asm" 738 "use asm"
739 739
740 function caller() { 740 function caller() {
741 var i = 0; 741 var i = 0;
742 for (i=1; i < 45 ; i = (i+1)|0) { 742 for (i=1; i < 45 ; i = (i+1)|0) {
743 } 743 }
744 return i|0; 744 return i|0;
745 } 745 }
746 746
747 return {caller:caller}; 747 return {caller:caller};
748 } 748 }
749 749
750 assertEquals(45, _WASMEXP_.instantiateModuleFromAsm( 750 assertEquals(45, Wasm.instantiateModuleFromAsm(
751 TestForLoopWithoutBody.toString()).caller()); 751 TestForLoopWithoutBody.toString()).caller());
752 752
753 753
754 function TestDoWhile() { 754 function TestDoWhile() {
755 "use asm" 755 "use asm"
756 756
757 function caller() { 757 function caller() {
758 var i = 0; 758 var i = 0;
759 var ret = 21; 759 var ret = 21;
760 do { 760 do {
761 ret = (ret + ret)|0; 761 ret = (ret + ret)|0;
762 i = (i + 1)|0; 762 i = (i + 1)|0;
763 } while (i < 2); 763 } while (i < 2);
764 return ret|0; 764 return ret|0;
765 } 765 }
766 766
767 return {caller:caller}; 767 return {caller:caller};
768 } 768 }
769 769
770 assertEquals(84, _WASMEXP_.instantiateModuleFromAsm( 770 assertEquals(84, Wasm.instantiateModuleFromAsm(
771 TestDoWhile.toString()).caller()); 771 TestDoWhile.toString()).caller());
772 772
773 773
774 function TestConditional() { 774 function TestConditional() {
775 "use asm" 775 "use asm"
776 776
777 function caller() { 777 function caller() {
778 var x = 1; 778 var x = 1;
779 return ((x > 0) ? 41 : 71)|0; 779 return ((x > 0) ? 41 : 71)|0;
780 } 780 }
781 781
782 return {caller:caller}; 782 return {caller:caller};
783 } 783 }
784 784
785 assertEquals(41, _WASMEXP_.instantiateModuleFromAsm( 785 assertEquals(41, Wasm.instantiateModuleFromAsm(
786 TestConditional.toString()).caller()); 786 TestConditional.toString()).caller());
787 787
788 788
789 function TestSwitch() { 789 function TestSwitch() {
790 "use asm" 790 "use asm"
791 791
792 function caller() { 792 function caller() {
793 var ret = 0; 793 var ret = 0;
794 var x = 7; 794 var x = 7;
795 switch (x) { 795 switch (x) {
796 case 1: return 0; 796 case 1: return 0;
797 case 7: { 797 case 7: {
798 ret = 12; 798 ret = 12;
799 break; 799 break;
800 } 800 }
801 default: return 0; 801 default: return 0;
802 } 802 }
803 switch (x) { 803 switch (x) {
804 case 1: return 0; 804 case 1: return 0;
805 case 8: return 0; 805 case 8: return 0;
806 default: ret = (ret + 11)|0; 806 default: ret = (ret + 11)|0;
807 } 807 }
808 return ret|0; 808 return ret|0;
809 } 809 }
810 810
811 return {caller:caller}; 811 return {caller:caller};
812 } 812 }
813 813
814 assertEquals(23, _WASMEXP_.instantiateModuleFromAsm( 814 assertEquals(23, Wasm.instantiateModuleFromAsm(
815 TestSwitch.toString()).caller()); 815 TestSwitch.toString()).caller());
816 816
817 817
818 function TestSwitchFallthrough() { 818 function TestSwitchFallthrough() {
819 "use asm" 819 "use asm"
820 820
821 function caller() { 821 function caller() {
822 var x = 17; 822 var x = 17;
823 var ret = 0; 823 var ret = 0;
824 switch (x) { 824 switch (x) {
825 case 17: 825 case 17:
826 case 14: ret = 39; 826 case 14: ret = 39;
827 case 1: ret = (ret + 3)|0; 827 case 1: ret = (ret + 3)|0;
828 case 4: break; 828 case 4: break;
829 default: ret = (ret + 1)|0; 829 default: ret = (ret + 1)|0;
830 } 830 }
831 return ret|0; 831 return ret|0;
832 } 832 }
833 833
834 return {caller:caller}; 834 return {caller:caller};
835 } 835 }
836 836
837 assertEquals(42, _WASMEXP_.instantiateModuleFromAsm( 837 assertEquals(42, Wasm.instantiateModuleFromAsm(
838 TestSwitchFallthrough.toString()).caller()); 838 TestSwitchFallthrough.toString()).caller());
839 839
840 840
841 function TestNestedSwitch() { 841 function TestNestedSwitch() {
842 "use asm" 842 "use asm"
843 843
844 function caller() { 844 function caller() {
845 var x = 3; 845 var x = 3;
846 var y = -13; 846 var y = -13;
847 switch (x) { 847 switch (x) {
848 case 1: return 0; 848 case 1: return 0;
849 case 3: { 849 case 3: {
850 switch (y) { 850 switch (y) {
851 case 2: return 0; 851 case 2: return 0;
852 case -13: return 43; 852 case -13: return 43;
853 default: return 0; 853 default: return 0;
854 } 854 }
855 } 855 }
856 default: return 0; 856 default: return 0;
857 } 857 }
858 return 0; 858 return 0;
859 } 859 }
860 860
861 return {caller:caller}; 861 return {caller:caller};
862 } 862 }
863 863
864 assertEquals(43, _WASMEXP_.instantiateModuleFromAsm( 864 assertEquals(43, Wasm.instantiateModuleFromAsm(
865 TestNestedSwitch.toString()).caller()); 865 TestNestedSwitch.toString()).caller());
866 866
867 867
868 function TestInitFunctionWithNoGlobals() { 868 function TestInitFunctionWithNoGlobals() {
869 "use asm"; 869 "use asm";
870 function caller() { 870 function caller() {
871 return 51; 871 return 51;
872 } 872 }
873 return {caller}; 873 return {caller};
874 } 874 }
875 875
876 var module = _WASMEXP_.instantiateModuleFromAsm( 876 var module = Wasm.instantiateModuleFromAsm(
877 TestInitFunctionWithNoGlobals.toString()); 877 TestInitFunctionWithNoGlobals.toString());
878 assertEquals(51, module.caller()); 878 assertEquals(51, module.caller());
879 879
880 880
881 function TestExportNameDifferentFromFunctionName() { 881 function TestExportNameDifferentFromFunctionName() {
882 "use asm"; 882 "use asm";
883 function caller() { 883 function caller() {
884 return 55; 884 return 55;
885 } 885 }
886 return {alt_caller:caller}; 886 return {alt_caller:caller};
887 } 887 }
888 888
889 var module = _WASMEXP_.instantiateModuleFromAsm( 889 var module = Wasm.instantiateModuleFromAsm(
890 TestExportNameDifferentFromFunctionName.toString()); 890 TestExportNameDifferentFromFunctionName.toString());
891 assertEquals(55, module.alt_caller()); 891 assertEquals(55, module.alt_caller());
892 892
893 893
894 function TestFunctionTableSingleFunction() { 894 function TestFunctionTableSingleFunction() {
895 "use asm"; 895 "use asm";
896 896
897 function dummy() { 897 function dummy() {
898 return 71; 898 return 71;
899 } 899 }
900 900
901 function caller() { 901 function caller() {
902 return function_table[0&0]() | 0; 902 return function_table[0&0]() | 0;
903 } 903 }
904 904
905 var function_table = [dummy] 905 var function_table = [dummy]
906 906
907 return {caller:caller}; 907 return {caller:caller};
908 } 908 }
909 909
910 assertEquals(71, _WASMEXP_.instantiateModuleFromAsm( 910 assertEquals(71, Wasm.instantiateModuleFromAsm(
911 TestFunctionTableSingleFunction.toString()).caller()); 911 TestFunctionTableSingleFunction.toString()).caller());
912 912
913 913
914 function TestFunctionTableMultipleFunctions() { 914 function TestFunctionTableMultipleFunctions() {
915 "use asm"; 915 "use asm";
916 916
917 function inc1(x) { 917 function inc1(x) {
918 x = x|0; 918 x = x|0;
919 return (x+1)|0; 919 return (x+1)|0;
920 } 920 }
(...skipping 10 matching lines...) Expand all
931 } 931 }
932 } 932 }
933 return 0; 933 return 0;
934 } 934 }
935 935
936 var function_table = [inc1, inc2] 936 var function_table = [inc1, inc2]
937 937
938 return {caller:caller}; 938 return {caller:caller};
939 } 939 }
940 940
941 assertEquals(73, _WASMEXP_.instantiateModuleFromAsm( 941 assertEquals(73, Wasm.instantiateModuleFromAsm(
942 TestFunctionTableMultipleFunctions.toString()).caller()); 942 TestFunctionTableMultipleFunctions.toString()).caller());
943 943
944 944
945 function TestFunctionTable() { 945 function TestFunctionTable() {
946 "use asm"; 946 "use asm";
947 947
948 function add(a, b) { 948 function add(a, b) {
949 a = a|0; 949 a = a|0;
950 b = b|0; 950 b = b|0;
951 return (a+b)|0; 951 return (a+b)|0;
(...skipping 22 matching lines...) Expand all
974 } 974 }
975 return 0; 975 return 0;
976 } 976 }
977 977
978 var funBin = [add, sub, sub, add]; 978 var funBin = [add, sub, sub, add];
979 var fun = [inc]; 979 var fun = [inc];
980 980
981 return {caller:caller}; 981 return {caller:caller};
982 } 982 }
983 983
984 var module = _WASMEXP_.instantiateModuleFromAsm(TestFunctionTable.toString()); 984 var module = Wasm.instantiateModuleFromAsm(TestFunctionTable.toString());
985 assertEquals(55, module.caller(0, 0, 33, 22)); 985 assertEquals(55, module.caller(0, 0, 33, 22));
986 assertEquals(11, module.caller(0, 1, 33, 22)); 986 assertEquals(11, module.caller(0, 1, 33, 22));
987 assertEquals(9, module.caller(0, 2, 54, 45)); 987 assertEquals(9, module.caller(0, 2, 54, 45));
988 assertEquals(99, module.caller(0, 3, 54, 45)); 988 assertEquals(99, module.caller(0, 3, 54, 45));
989 assertEquals(23, module.caller(0, 4, 12, 11)); 989 assertEquals(23, module.caller(0, 4, 12, 11));
990 assertEquals(31, module.caller(1, 0, 30, 11)); 990 assertEquals(31, module.caller(1, 0, 30, 11));
991 991
992 992
993 function TestForeignFunctions() { 993 function TestForeignFunctions() {
994 function AsmModule(stdlib, foreign, buffer) { 994 function AsmModule(stdlib, foreign, buffer) {
(...skipping 24 matching lines...) Expand all
1019 1019
1020 function setVal(new_val) { 1020 function setVal(new_val) {
1021 val = new_val; 1021 val = new_val;
1022 } 1022 }
1023 1023
1024 return {getVal:getVal, setVal:setVal}; 1024 return {getVal:getVal, setVal:setVal};
1025 } 1025 }
1026 1026
1027 var foreign = new ffi(23); 1027 var foreign = new ffi(23);
1028 1028
1029 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), 1029 var module = Wasm.instantiateModuleFromAsm(AsmModule.toString(),
1030 foreign, null); 1030 foreign, null);
1031 1031
1032 assertEquals(103, module.caller(23, 103)); 1032 assertEquals(103, module.caller(23, 103));
1033 } 1033 }
1034 1034
1035 TestForeignFunctions(); 1035 TestForeignFunctions();
1036 1036
1037 1037
1038 function TestForeignFunctionMultipleUse() { 1038 function TestForeignFunctionMultipleUse() {
1039 function AsmModule(stdlib, foreign, buffer) { 1039 function AsmModule(stdlib, foreign, buffer) {
(...skipping 18 matching lines...) Expand all
1058 function ffi() { 1058 function ffi() {
1059 function getVal() { 1059 function getVal() {
1060 return 83.25; 1060 return 83.25;
1061 } 1061 }
1062 1062
1063 return {getVal:getVal}; 1063 return {getVal:getVal};
1064 } 1064 }
1065 1065
1066 var foreign = new ffi(); 1066 var foreign = new ffi();
1067 1067
1068 var module = _WASMEXP_.instantiateModuleFromAsm(AsmModule.toString(), 1068 var module = Wasm.instantiateModuleFromAsm(AsmModule.toString(),
1069 foreign, null); 1069 foreign, null);
1070 1070
1071 assertEquals(89, module.caller(83, 83.25)); 1071 assertEquals(89, module.caller(83, 83.25));
1072 } 1072 }
1073 1073
1074 TestForeignFunctionMultipleUse(); 1074 TestForeignFunctionMultipleUse();
1075 1075
1076 1076
1077 function TestForeignVariables() { 1077 function TestForeignVariables() {
1078 function AsmModule(stdlib, foreign, buffer) { 1078 function AsmModule(stdlib, foreign, buffer) {
(...skipping 17 matching lines...) Expand all
1096 } 1096 }
1097 1097
1098 function getf2() { 1098 function getf2() {
1099 return +f2; 1099 return +f2;
1100 } 1100 }
1101 1101
1102 return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2}; 1102 return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2};
1103 } 1103 }
1104 1104
1105 function TestCase(env, i1, f1, i2, f2) { 1105 function TestCase(env, i1, f1, i2, f2) {
1106 var module = _WASMEXP_.instantiateModuleFromAsm( 1106 var module = Wasm.instantiateModuleFromAsm(
1107 AsmModule.toString(), env); 1107 AsmModule.toString(), env);
1108 assertEquals(i1, module.geti1()); 1108 assertEquals(i1, module.geti1());
1109 assertEquals(f1, module.getf1()); 1109 assertEquals(f1, module.getf1());
1110 assertEquals(i2, module.geti2()); 1110 assertEquals(i2, module.geti2());
1111 assertEquals(f2, module.getf2()); 1111 assertEquals(f2, module.getf2());
1112 } 1112 }
1113 1113
1114 // Check normal operation. 1114 // Check normal operation.
1115 TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7); 1115 TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7);
1116 // Check partial operation. 1116 // Check partial operation.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 } 1188 }
1189 1189
1190 function iload(i) { 1190 function iload(i) {
1191 i = i | 0; 1191 i = i | 0;
1192 return HEAP8[HEAP32[i >> 2] | 0] | 0; 1192 return HEAP8[HEAP32[i >> 2] | 0] | 0;
1193 } 1193 }
1194 1194
1195 return {load: load, iload: iload, store: store, storeb: storeb}; 1195 return {load: load, iload: iload, store: store, storeb: storeb};
1196 } 1196 }
1197 1197
1198 var m = _WASMEXP_.instantiateModuleFromAsm( 1198 var m = Wasm.instantiateModuleFromAsm(
1199 TestByteHeapAccessCompat.toString()); 1199 TestByteHeapAccessCompat.toString());
1200 m.store(0, 20); 1200 m.store(0, 20);
1201 m.store(4, 21); 1201 m.store(4, 21);
1202 m.store(8, 22); 1202 m.store(8, 22);
1203 m.storeb(20, 123); 1203 m.storeb(20, 123);
1204 m.storeb(21, 42); 1204 m.storeb(21, 42);
1205 m.storeb(22, 77); 1205 m.storeb(22, 77);
1206 assertEquals(123, m.load(20)); 1206 assertEquals(123, m.load(20));
1207 assertEquals(42, m.load(21)); 1207 assertEquals(42, m.load(21));
1208 assertEquals(77, m.load(22)); 1208 assertEquals(77, m.load(22));
1209 assertEquals(123, m.iload(0)); 1209 assertEquals(123, m.iload(0));
1210 assertEquals(42, m.iload(4)); 1210 assertEquals(42, m.iload(4));
1211 assertEquals(77, m.iload(8)); 1211 assertEquals(77, m.iload(8));
1212 })(); 1212 })();
1213 1213
1214 1214
1215 (function TestGlobalBlock() { 1215 (function TestGlobalBlock() {
1216 function Module(stdlib, foreign, buffer) { 1216 function Module(stdlib, foreign, buffer) {
1217 "use asm"; 1217 "use asm";
1218 1218
1219 var x = foreign.x | 0, y = foreign.y | 0; 1219 var x = foreign.x | 0, y = foreign.y | 0;
1220 1220
1221 function test() { 1221 function test() {
1222 return (x + y) | 0; 1222 return (x + y) | 0;
1223 } 1223 }
1224 1224
1225 return {test: test}; 1225 return {test: test};
1226 } 1226 }
1227 1227
1228 var m = _WASMEXP_.instantiateModuleFromAsm( 1228 var m = Wasm.instantiateModuleFromAsm(
1229 Module.toString(), { x: 4, y: 11 }); 1229 Module.toString(), { x: 4, y: 11 });
1230 assertEquals(15, m.test()); 1230 assertEquals(15, m.test());
1231 })(); 1231 })();
1232 1232
1233 1233
1234 (function TestComma() { 1234 (function TestComma() {
1235 function CommaModule() { 1235 function CommaModule() {
1236 "use asm"; 1236 "use asm";
1237 1237
1238 function ifunc(a, b) { 1238 function ifunc(a, b) {
1239 a = +a; 1239 a = +a;
1240 b = b | 0; 1240 b = b | 0;
1241 return (a, b) | 0; 1241 return (a, b) | 0;
1242 } 1242 }
1243 1243
1244 function dfunc(a, b) { 1244 function dfunc(a, b) {
1245 a = a | 0; 1245 a = a | 0;
1246 b = +b; 1246 b = +b;
1247 return +(a, b); 1247 return +(a, b);
1248 } 1248 }
1249 1249
1250 return {ifunc: ifunc, dfunc: dfunc}; 1250 return {ifunc: ifunc, dfunc: dfunc};
1251 } 1251 }
1252 1252
1253 var m = _WASMEXP_.instantiateModuleFromAsm(CommaModule.toString()); 1253 var m = Wasm.instantiateModuleFromAsm(CommaModule.toString());
1254 assertEquals(123, m.ifunc(456.7, 123)); 1254 assertEquals(123, m.ifunc(456.7, 123));
1255 assertEquals(123.4, m.dfunc(456, 123.4)); 1255 assertEquals(123.4, m.dfunc(456, 123.4));
1256 })(); 1256 })();
1257 1257
1258 1258
1259 (function TestStdlibConstants() { 1259 (function TestStdlibConstants() {
1260 function Module(stdlib) { 1260 function Module(stdlib) {
1261 "use asm"; 1261 "use asm";
1262 1262
1263 var StdlibInfinity = stdlib.Infinity; 1263 var StdlibInfinity = stdlib.Infinity;
(...skipping 20 matching lines...) Expand all
1284 return 1; 1284 return 1;
1285 } 1285 }
1286 1286
1287 function nanCheck() { 1287 function nanCheck() {
1288 return +StdlibNaN; 1288 return +StdlibNaN;
1289 } 1289 }
1290 1290
1291 return {caller:caller, nanCheck:nanCheck}; 1291 return {caller:caller, nanCheck:nanCheck};
1292 } 1292 }
1293 1293
1294 var m =_WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1294 var m =Wasm.instantiateModuleFromAsm(Module.toString());
1295 assertEquals(1, m.caller()); 1295 assertEquals(1, m.caller());
1296 assertTrue(isNaN(m.nanCheck())); 1296 assertTrue(isNaN(m.nanCheck()));
1297 })(); 1297 })();
1298 1298
1299 1299
1300 (function TestStdlibFunctions() { 1300 (function TestStdlibFunctions() {
1301 function Module(stdlib) { 1301 function Module(stdlib) {
1302 "use asm"; 1302 "use asm";
1303 1303
1304 var StdlibMathCeil = stdlib.Math.ceil; 1304 var StdlibMathCeil = stdlib.Math.ceil;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 if (StdlibMathImul(6, 7) != 42) return 0; 1362 if (StdlibMathImul(6, 7) != 42) return 0;
1363 if (!deltaEqual(StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)) return 0; 1363 if (!deltaEqual(StdlibMathAtan2(6.0, 7.0), 0.7086262721276703)) return 0;
1364 if (StdlibMathPow(6.0, 7.0) != 279936.0) return 0; 1364 if (StdlibMathPow(6.0, 7.0) != 279936.0) return 0;
1365 1365
1366 return 1; 1366 return 1;
1367 } 1367 }
1368 1368
1369 return {caller:caller}; 1369 return {caller:caller};
1370 } 1370 }
1371 1371
1372 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1372 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1373 assertEquals(1, m.caller()); 1373 assertEquals(1, m.caller());
1374 })(); 1374 })();
1375 1375
1376 1376
1377 (function TestOr() { 1377 (function TestOr() {
1378 function Module() { 1378 function Module() {
1379 "use asm"; 1379 "use asm";
1380 function func() { 1380 function func() {
1381 var x = 1; 1381 var x = 1;
1382 var y = 2; 1382 var y = 2;
1383 return (x | y) | 0; 1383 return (x | y) | 0;
1384 } 1384 }
1385 return {func: func}; 1385 return {func: func};
1386 } 1386 }
1387 1387
1388 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1388 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1389 assertEquals(3, m.func()); 1389 assertEquals(3, m.func());
1390 })(); 1390 })();
1391 1391
1392 1392
1393 (function TestAnd() { 1393 (function TestAnd() {
1394 function Module() { 1394 function Module() {
1395 "use asm"; 1395 "use asm";
1396 function func() { 1396 function func() {
1397 var x = 3; 1397 var x = 3;
1398 var y = 2; 1398 var y = 2;
1399 return (x & y) | 0; 1399 return (x & y) | 0;
1400 } 1400 }
1401 return {func: func}; 1401 return {func: func};
1402 } 1402 }
1403 1403
1404 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1404 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1405 assertEquals(2, m.func()); 1405 assertEquals(2, m.func());
1406 })(); 1406 })();
1407 1407
1408 1408
1409 (function TestXor() { 1409 (function TestXor() {
1410 function Module() { 1410 function Module() {
1411 "use asm"; 1411 "use asm";
1412 function func() { 1412 function func() {
1413 var x = 3; 1413 var x = 3;
1414 var y = 2; 1414 var y = 2;
1415 return (x ^ y) | 0; 1415 return (x ^ y) | 0;
1416 } 1416 }
1417 return {func: func}; 1417 return {func: func};
1418 } 1418 }
1419 1419
1420 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1420 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1421 assertEquals(1, m.func()); 1421 assertEquals(1, m.func());
1422 })(); 1422 })();
1423 1423
1424 1424
1425 (function TestIntishAssignment() { 1425 (function TestIntishAssignment() {
1426 function Module(stdlib, foreign, heap) { 1426 function Module(stdlib, foreign, heap) {
1427 "use asm"; 1427 "use asm";
1428 var HEAP32 = new stdlib.Int32Array(heap); 1428 var HEAP32 = new stdlib.Int32Array(heap);
1429 function func() { 1429 function func() {
1430 var a = 1; 1430 var a = 1;
1431 var b = 2; 1431 var b = 2;
1432 HEAP32[0] = a + b; 1432 HEAP32[0] = a + b;
1433 return HEAP32[0] | 0; 1433 return HEAP32[0] | 0;
1434 } 1434 }
1435 return {func: func}; 1435 return {func: func};
1436 } 1436 }
1437 1437
1438 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1438 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1439 assertEquals(3, m.func()); 1439 assertEquals(3, m.func());
1440 })(); 1440 })();
1441 1441
1442 1442
1443 (function TestFloatishAssignment() { 1443 (function TestFloatishAssignment() {
1444 function Module(stdlib, foreign, heap) { 1444 function Module(stdlib, foreign, heap) {
1445 "use asm"; 1445 "use asm";
1446 var HEAPF32 = new stdlib.Float32Array(heap); 1446 var HEAPF32 = new stdlib.Float32Array(heap);
1447 var fround = stdlib.Math.fround; 1447 var fround = stdlib.Math.fround;
1448 function func() { 1448 function func() {
1449 var a = fround(1.0); 1449 var a = fround(1.0);
1450 var b = fround(2.0); 1450 var b = fround(2.0);
1451 HEAPF32[0] = a + b; 1451 HEAPF32[0] = a + b;
1452 return +HEAPF32[0]; 1452 return +HEAPF32[0];
1453 } 1453 }
1454 return {func: func}; 1454 return {func: func};
1455 } 1455 }
1456 1456
1457 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1457 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1458 assertEquals(3, m.func()); 1458 assertEquals(3, m.func());
1459 }); // TODO(bradnelson): Enable when Math.fround implementation lands. 1459 }); // TODO(bradnelson): Enable when Math.fround implementation lands.
1460 1460
1461 1461
1462 (function TestDoubleToFloatAssignment() { 1462 (function TestDoubleToFloatAssignment() {
1463 function Module(stdlib, foreign, heap) { 1463 function Module(stdlib, foreign, heap) {
1464 "use asm"; 1464 "use asm";
1465 var HEAPF32 = new stdlib.Float32Array(heap); 1465 var HEAPF32 = new stdlib.Float32Array(heap);
1466 var fround = stdlib.Math.fround; 1466 var fround = stdlib.Math.fround;
1467 function func() { 1467 function func() {
1468 var a = 1.23; 1468 var a = 1.23;
1469 HEAPF32[0] = a; 1469 HEAPF32[0] = a;
1470 return +HEAPF32[0]; 1470 return +HEAPF32[0];
1471 } 1471 }
1472 return {func: func}; 1472 return {func: func};
1473 } 1473 }
1474 1474
1475 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1475 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1476 assertEquals(1.23, m.func()); 1476 assertEquals(1.23, m.func());
1477 }); 1477 });
1478 1478
1479 1479
1480 (function TestIntegerMultiplyBothWays() { 1480 (function TestIntegerMultiplyBothWays() {
1481 function Module(stdlib, foreign, heap) { 1481 function Module(stdlib, foreign, heap) {
1482 "use asm"; 1482 "use asm";
1483 function func() { 1483 function func() {
1484 var a = 1; 1484 var a = 1;
1485 return ((a * 3) + (4 * a)) | 0; 1485 return ((a * 3) + (4 * a)) | 0;
1486 } 1486 }
1487 return {func: func}; 1487 return {func: func};
1488 } 1488 }
1489 1489
1490 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1490 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1491 assertEquals(7, m.func()); 1491 assertEquals(7, m.func());
1492 })(); 1492 })();
1493 1493
1494 1494
1495 (function TestBadMultiplyIntish() { 1495 (function TestBadMultiplyIntish() {
1496 function Module(stdlib, foreign, heap) { 1496 function Module(stdlib, foreign, heap) {
1497 "use asm"; 1497 "use asm";
1498 function func() { 1498 function func() {
1499 var a = 1; 1499 var a = 1;
1500 return ((a + a) * 4) | 0; 1500 return ((a + a) * 4) | 0;
1501 } 1501 }
1502 return {func: func}; 1502 return {func: func};
1503 } 1503 }
1504 assertThrows(function() { 1504 assertThrows(function() {
1505 _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1505 Wasm.instantiateModuleFromAsm(Module.toString());
1506 }); 1506 });
1507 })(); 1507 })();
1508 1508
1509 1509
1510 (function TestAndNegative() { 1510 (function TestAndNegative() {
1511 function Module() { 1511 function Module() {
1512 "use asm"; 1512 "use asm";
1513 function func() { 1513 function func() {
1514 var x = 1; 1514 var x = 1;
1515 var y = 2; 1515 var y = 2;
1516 var z = 0; 1516 var z = 0;
1517 z = x + y & -1; 1517 z = x + y & -1;
1518 return z | 0; 1518 return z | 0;
1519 } 1519 }
1520 return {func: func}; 1520 return {func: func};
1521 } 1521 }
1522 1522
1523 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1523 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1524 assertEquals(3, m.func()); 1524 assertEquals(3, m.func());
1525 })(); 1525 })();
1526 1526
1527 1527
1528 (function TestNegativeDouble() { 1528 (function TestNegativeDouble() {
1529 function Module() { 1529 function Module() {
1530 "use asm"; 1530 "use asm";
1531 function func() { 1531 function func() {
1532 var x = -(34359738368.25); 1532 var x = -(34359738368.25);
1533 var y = -2.5; 1533 var y = -2.5;
1534 return +(x + y); 1534 return +(x + y);
1535 } 1535 }
1536 return {func: func}; 1536 return {func: func};
1537 } 1537 }
1538 1538
1539 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1539 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1540 assertEquals(-34359738370.75, m.func()); 1540 assertEquals(-34359738370.75, m.func());
1541 })(); 1541 })();
1542 1542
1543 1543
1544 (function TestBadAndDouble() { 1544 (function TestBadAndDouble() {
1545 function Module() { 1545 function Module() {
1546 "use asm"; 1546 "use asm";
1547 function func() { 1547 function func() {
1548 var x = 1.0; 1548 var x = 1.0;
1549 var y = 2.0; 1549 var y = 2.0;
1550 return (x & y) | 0; 1550 return (x & y) | 0;
1551 } 1551 }
1552 return {func: func}; 1552 return {func: func};
1553 } 1553 }
1554 1554
1555 assertThrows(function() { 1555 assertThrows(function() {
1556 _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1556 Wasm.instantiateModuleFromAsm(Module.toString());
1557 }); 1557 });
1558 })(); 1558 })();
1559 1559
1560 1560
1561 (function TestAndIntAndHeapValue() { 1561 (function TestAndIntAndHeapValue() {
1562 function Module(stdlib, foreign, buffer) { 1562 function Module(stdlib, foreign, buffer) {
1563 "use asm"; 1563 "use asm";
1564 var HEAP32 = new stdlib.Int32Array(buffer); 1564 var HEAP32 = new stdlib.Int32Array(buffer);
1565 function func() { 1565 function func() {
1566 var x = 0; 1566 var x = 0;
1567 x = HEAP32[0] & -1; 1567 x = HEAP32[0] & -1;
1568 return x | 0; 1568 return x | 0;
1569 } 1569 }
1570 return {func: func}; 1570 return {func: func};
1571 } 1571 }
1572 1572
1573 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); 1573 var m = Wasm.instantiateModuleFromAsm(Module.toString());
1574 assertEquals(0, m.func()); 1574 assertEquals(0, m.func());
1575 })(); 1575 })();
1576 1576
1577 (function TestOutOfBoundsConversion() { 1577 (function TestOutOfBoundsConversion() {
1578 function asmModule($a,$b,$c){'use asm'; 1578 function asmModule($a,$b,$c){'use asm';
1579 function aaa() { 1579 function aaa() {
1580 var f = 0.0; 1580 var f = 0.0;
1581 var a = 0; 1581 var a = 0;
1582 f = 5616315000.000001; 1582 f = 5616315000.000001;
1583 a = ~~f >>>0; 1583 a = ~~f >>>0;
1584 return a | 0; 1584 return a | 0;
1585 } 1585 }
1586 return { main : aaa }; 1586 return { main : aaa };
1587 } 1587 }
1588 var wasm = _WASMEXP_.instantiateModuleFromAsm(asmModule.toString()); 1588 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString());
1589 assertEquals(1321347704, wasm.main()); 1589 assertEquals(1321347704, wasm.main());
1590 })(); 1590 })();
OLDNEW
« no previous file with comments | « test/mjsunit/regress/regress-575364.js ('k') | test/mjsunit/wasm/embenchen/box2d.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698