Debian Codegraph @

rhino/testsrc/tests/js1_7/extensions/regress-351070-02.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-351070-02.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 351070;
9 var summary = 'decompilation of let declaration should not change scope';
10 var actual = '';
11 var expect = '';
12
13
14 //-----------------------------------------------------------------------------
15 test();
16 //-----------------------------------------------------------------------------
17
18 function test()
19 {
20 enterFunc ('test');
21 printBugNumber(BUGNUMBER);
22 printStatus (summary);
23
24 try
25 {
26 var pfx = "(function f() { var n = 2, a = 2; ",
27 decl = " let a = 3;",
28 end = " return a; })";
29
30 var table = [
31 ["if (!!true)", ""],
32 ["if (!!true)", " else foopy();"],
33 ["if (!true); else", ""],
34 ["do ", " while (false);"],
35 ["while (--n)", ""],
36 ["for (--n;n;--n)", ""],
37 ["for (a in this)", ""],
38 ["with (this)", ""],
39 ];
40
41 expect = 3;
42
43 for (i = 0; i < table.length; i++) {
44 var src = pfx + table[i][0] + decl + table[i][1] + end;
45 print('src: ' + src);
46 var fun = eval(src);
47 var testval = fun();
48 reportCompare(expect, testval, summary + ': ' + src);
49 if (testval != expect) {
50 break;
51 }
52 print('uneval: ' + uneval(fun));
53 var declsrc = '(' +
54 src.slice(1, -1).replace('function f', 'function f' + i) + ')';
55 print('declsrc: ' + declsrc);
56 this['f' + i] = eval(declsrc);
57 print('f' + i + ': ' + this['f' + i]);
58 }
59 }
60 catch(ex)
61 {
62 // See https://bugzilla.mozilla.org/show_bug.cgi?id=408957
63 summary = 'let declaration must be direct child of block or top-level implicit block';
64 expect = 'SyntaxError';
65 actual = ex.name;
66 reportCompare(expect, actual, summary);
67 }
68
69 exitFunc ('test');
70 }