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

Unified Diff: test/mjsunit/asm/asm-validation.js

Issue 2435823002: [V8][asm.js] Adds support to global const variables. (Closed)
Patch Set: Addresses comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/asmjs/test-asm-typer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/asm/asm-validation.js
diff --git a/test/mjsunit/asm/asm-validation.js b/test/mjsunit/asm/asm-validation.js
index eae282ca570ace79bcd2ca6fdd7cc0d68afbafeb..158187a7966b53606eb5c923741a386b8f010360 100644
--- a/test/mjsunit/asm/asm-validation.js
+++ b/test/mjsunit/asm/asm-validation.js
@@ -8,6 +8,76 @@ function assertValidAsm(func) {
assertTrue(%IsAsmWasmCode(func));
}
+(function TestConst() {
+ function Module(s) {
+ "use asm";
+ var fround = s.Math.fround;
+ // Global constants. These are treated just like numeric literals.
+ const fConst = fround(-3.0);
+ const dConst = -3.0;
+ const iConst = -3;
+
+ // consts can be used to initialize other consts.
+ const fPrime = fConst;
+
+ // The following methods verify that return statements with global constants
+ // do not need type annotations.
+ function f() {
+ return fPrime;
+ }
+ function d() {
+ return dConst;
+ }
+ function i() {
+ return iConst;
+ }
+
+ // The following methods verify that locals initialized with global
+ // constants do not need type annotations.
+ function fVar() {
+ var v = fPrime;
+ return fround(v);
+ }
+ function iVar() {
+ var v = iConst;
+ return v|0;
+ }
+ function dVar() {
+ var v = dConst;
+ return +v;
+ }
+
+ return {
+ f: f, d: d, i: i,
+ fVar: fVar, dVar: dVar, iVar: iVar,
+ };
+ }
+
+ function DisallowAssignToConstGlobal() {
+ const constant = 0;
+ function invalid(i) {
+ i = i|0;
+ constant = i;
+ return constant;
+ }
+ return invalid;
+ }
+
+ var m = Module(this);
+ assertValidAsm(Module);
+
+ assertEquals(-3, m.i());
+ assertEquals(-3.0, m.d());
+ assertEquals(Math.fround(-3.0), m.f());
+
+ assertEquals(-3, m.iVar());
+ assertEquals(-3.0, m.dVar());
+ assertEquals(Math.fround(-3.0), m.fVar());
+
+ var m = DisallowAssignToConstGlobal();
+ assertTrue(%IsNotAsmWasmCode(DisallowAssignToConstGlobal));
+})();
+
(function TestModuleArgs() {
function Module1(stdlib) {
"use asm";
« no previous file with comments | « 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