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