Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 //-----------------------------------------------------------------------------
7 var BUGNUMBER = "(none)";
8 var summary = "Test let and order of operation issues";
9 var actual, expect;
11 printBugNumber(BUGNUMBER);
12 printStatus(summary);
14 /**************
15 * BEGIN TEST *
16 **************/
18 var failed = false;
20 function f1(x)
21 {
22 let (foo) {
23 // scope of lhs x includes rhs, so x is NaN here -- bug 344952
24 let x = ++x;
25 return x;
26 }
27 }
29 function f2(x)
30 {
31 let (foo)
32 {
33 // scope of lhs x includes rhs, so x is NaN here -- bug 344952
34 let x = x++;
35 return x;
36 }
37 }
39 function f3(x)
40 {
41 let (foo)
42 {
43 var q = x;
44 let (x = x++)
45 {
46 if (x != q)
47 throw "f3():\n" +
48 " expected: x == q\n" +
49 " actual: x != q " +
50 "(where x == " + x + ", q == " + q + ")\n";
51 }
52 return x;
53 }
54 }
56 function f4(x)
57 {
58 var y = 7;
59 let (y = x, x = 3)
60 {
61 var q = 7 + x;
62 }
63 return x + y + q;
64 }
66 function f5(x)
67 {
68 var q = x++;
69 let (y = x, r = 17, m = 32) {
70 return function(code)
71 {
72 return eval(code);
73 };
74 }
75 }
77 function f6() {
78 let (foo)
79 {
80 var i=3;
81 for (let i=i;;) { if (i != 3) throw "f6(): fail 1"; i = 7; break; }
82 if (i != 3) throw "f6(): fail 2";
83 }
84 }
86 try
87 {
88 var rv = f1(5);
89 if (!isNaN(rv))
90 throw "f1(5):\n" +
91 " expected: NaN\n" +
92 " actual: " + rv;
94 rv = f2(5);
95 if (!isNaN(rv))
96 throw "f2(5):\n" +
97 " expected: NaN\n" +
98 " actual: " + rv;
99 /*
100 rv = f3(8);
101 if (rv != 9)
102 throw "f3(8):\n" +
103 " expected: 9\n" +
104 " actual: " + rv;
105 */
107 rv = f4(13);
108 if (rv != 30)
109 throw "f4(13):\n" +
110 " expected: 30\n" +
111 " actual: " + rv;
113 var fun = f5(2);
115 rv = fun("q");
116 if (rv != 2)
117 throw "fun('q'):\n" +
118 " expected: 2\n" +
119 " actual: " + rv;
121 rv = fun("x");
122 if (rv != 3)
123 throw "fun('x'):\n" +
124 " expected: 3\n" +
125 " actual: " + rv;
127 rv = fun("y");
128 if (rv != 3)
129 throw "fun('y'):\n" +
130 " expected: 3\n" +
131 " actual: " + rv;
133 rv = fun("let (y = y) { y += 32; }; y");
134 if (rv != 3)
135 throw "fun('let (y = y) { y += 32; }; y'):\n" +
136 " expected: 3\n" +
137 " actual: " + rv;
139 /*
140 f6();
141 */
142 }
143 catch (e)
144 {
145 print(e.toSource());
146 failed = e;
147 }
149 expect = false;
150 actual = failed;
152 reportCompare(expect, actual, summary);