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