Debian Codegraph @

rhino/testsrc/tests/js1_7/block/regress-344139.js

raw symbols SCIP
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/. */
5
6 var gTestfile = 'regress-344139.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = "344139";
9 var summary = "Basic let functionality";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * BEGIN TEST *
17 **************/
18
19 var failed = false;
20
21 var x = 7;
22
23 function f1()
24 {
25 let x = 5;
26 return x;
27 }
28
29 function f2()
30 {
31 let x = 5;
32 x = 3;
33 return x;
34 }
35
36 function f3()
37 {
38 let x = 5;
39 x += x;
40 return x;
41 }
42
43 function f4()
44 {
45 var v = 5;
46 let q = 17;
47
48 // 0+1+2+...+8+9 == 45
49 for (let v = 0; v < 10; v++)
50 q += v;
51
52 if (q != 62)
53 throw "f4(): wrong value for q\n" +
54 " expected: 62\n" +
55 " actual: " + q;
56
57 return v;
58 }
59
60 try
61 {
62 if (f1() != 5 || x != 7)
63 throw "f1() == 5";
64 if (f2() != 3 || x != 7)
65 throw "f2() == 3";
66 if (f3() != 10 || x != 7)
67 throw "f3() == 10";
68
69 if (f4() != 5)
70 throw "f4() == 5";
71
72 var bad = true;
73 try
74 {
75 eval("q++"); // force error at runtime
76 }
77 catch (e)
78 {
79 if (e instanceof ReferenceError)
80 bad = false;
81 }
82 if (bad)
83 throw "f4(): q escaping scope!";
84 }
85 catch (e)
86 {
87 failed = e;
88 }
89
90 expect = false;
91 actual = failed;
92
93 reportCompare(expect, actual, summary);