michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 351070; michael@0: var summary = 'decompilation of let declaration should not change scope'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: try michael@0: { michael@0: var pfx = "(function f() { var n = 2, a = 2; ", michael@0: decl = " let a = 3;", michael@0: end = " return a; })"; michael@0: michael@0: var table = [ michael@0: ["if (!!true)", ""], michael@0: ["if (!!true)", " else foopy();"], michael@0: ["if (!true); else", ""], michael@0: ["do ", " while (false);"], michael@0: ["while (--n)", ""], michael@0: ["for (--n;n;--n)", ""], michael@0: ["for (a in this)", ""], michael@0: ["with (this)", ""], michael@0: ]; michael@0: michael@0: expect = 3; michael@0: michael@0: for (i = 0; i < table.length; i++) { michael@0: var src = pfx + table[i][0] + decl + table[i][1] + end; michael@0: print('src: ' + src); michael@0: var fun = eval(src); michael@0: var testval = fun(); michael@0: reportCompare(expect, testval, summary + ': ' + src); michael@0: if (testval != expect) { michael@0: break; michael@0: } michael@0: print('uneval: ' + uneval(fun)); michael@0: var declsrc = '(' + michael@0: src.slice(1, -1).replace('function f', 'function f' + i) + ')'; michael@0: print('declsrc: ' + declsrc); michael@0: this['f' + i] = eval(declsrc); michael@0: print('f' + i + ': ' + this['f' + i]); michael@0: } michael@0: } michael@0: catch(ex) michael@0: { michael@0: // See https://bugzilla.mozilla.org/show_bug.cgi?id=408957 michael@0: summary = 'let declaration must be direct child of block or top-level implicit block'; michael@0: expect = 'SyntaxError'; michael@0: actual = ex.name; michael@0: reportCompare(expect, actual, summary); michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: }