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

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

Issue 2435823002: [V8][asm.js] Adds support to global const variables. (Closed)
Patch Set: Changes expected error messages in asm-typer cctest. Created 4 years, 2 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: --validate-asm --allow-natives-syntax 5 // Flags: --validate-asm --allow-natives-syntax
6 6
7 function assertValidAsm(func) { 7 function assertValidAsm(func) {
8 assertTrue(%IsAsmWasmCode(func)); 8 assertTrue(%IsAsmWasmCode(func));
9 } 9 }
10 10
11 (function TestConst() {
12 function Module(s) {
13 "use asm";
14 var fround = s.Math.fround;
15 // Global constants. These are treated just like numeric literals.
16 const fConst = fround(-3.0);
17 const dConst = -3.0;
18 const iConst = -3;
19
20 // consts can be used to initialize other consts.
21 const fPrime = fConst;
22
23 // The following methods verify that return statements with global constants
24 // do not need type annotations.
25 function f() {
26 return fPrime;
27 }
28 function d() {
29 return dConst;
30 }
31 function i() {
32 return iConst;
33 }
34
35 // The following methods verify that locals initialized with global
36 // constants dono need type annotations.
bradnelson 2016/10/19 21:52:07 dono -> do not ?
John 2016/10/20 15:13:22 Done.
37 function fVar() {
38 var v = fPrime;
39 return fround(v);
40 }
41 function iVar() {
42 var v = iConst;
43 return v|0;
44 }
45 function dVar() {
46 var v = dConst;
47 return +v;
48 }
49
50 return {
51 f: f, d: d, i: i,
52 fVar: fVar, dVar: dVar, iVar: iVar,
53 };
54 }
55 var m = Module(this);
56 assertValidAsm(Module);
57
58 assertEquals(-3, m.i());
59 assertEquals(-3.0, m.d());
60 assertEquals(Math.fround(-3.0), m.f());
61
62 assertEquals(-3, m.iVar());
63 assertEquals(-3.0, m.dVar());
64 assertEquals(Math.fround(-3.0), m.fVar());
65 })();
66
11 (function TestModuleArgs() { 67 (function TestModuleArgs() {
12 function Module1(stdlib) { 68 function Module1(stdlib) {
13 "use asm"; 69 "use asm";
14 function foo() { } 70 function foo() { }
15 return { foo: foo }; 71 return { foo: foo };
16 } 72 }
17 function Module2(stdlib, ffi) { 73 function Module2(stdlib, ffi) {
18 "use asm"; 74 "use asm";
19 function foo() { } 75 function foo() { }
20 return { foo: foo }; 76 return { foo: foo };
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 "use asm"; 262 "use asm";
207 function foo() { return 123; } 263 function foo() { return 123; }
208 return { foo: foo }; 264 return { foo: foo };
209 } 265 }
210 var heap = new ArrayBuffer(1024 * 1024); 266 var heap = new ArrayBuffer(1024 * 1024);
211 var ModuleBound = Module.bind(this, {}, {}, heap); 267 var ModuleBound = Module.bind(this, {}, {}, heap);
212 var m = ModuleBound(); 268 var m = ModuleBound();
213 assertValidAsm(Module); 269 assertValidAsm(Module);
214 assertEquals(123, m.foo()); 270 assertEquals(123, m.foo());
215 })(); 271 })();
OLDNEW
« test/cctest/asmjs/test-asm-typer.cc ('K') | « test/cctest/asmjs/test-asm-typer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698