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 = 422269; michael@0: var summary = 'Compile-time let block should not capture runtime references'; michael@0: var actual = 'referenced only by stack and closure'; michael@0: var expect = 'referenced only by stack and closure'; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: 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: function f() michael@0: { michael@0: let m = {sin: Math.sin}; michael@0: (function holder() { m.sin(1); })(); michael@0: return m; michael@0: } michael@0: michael@0: if (typeof findReferences == 'undefined') michael@0: { michael@0: expect = actual = 'Test skipped'; michael@0: print('Test skipped. Requires findReferences function.'); michael@0: } michael@0: else michael@0: { michael@0: var x = f(); michael@0: var refs = findReferences(x); michael@0: michael@0: // At this point, x should only be referenced from the stack --- the michael@0: // variable 'x' itself, and any random things the conservative scanner michael@0: // finds --- and possibly from the 'holder' closure, which could itself michael@0: // be held alive for random reasons. Remove those from the refs list, and michael@0: // then complain if anything is left. michael@0: for (var edge in refs) { michael@0: // Remove references from roots, like the stack. michael@0: if (refs[edge].every(function (r) r === null)) michael@0: delete refs[edge]; michael@0: // Remove references from the closure, which could be held alive for michael@0: // random reasons. michael@0: else if (refs[edge].length === 1 && michael@0: typeof refs[edge][0] === "function" && michael@0: refs[edge][0].name === "holder") michael@0: delete refs[edge]; michael@0: } michael@0: michael@0: if (Object.keys(refs).length != 0) michael@0: actual = "unexpected references to the result of f: " + Object.keys(refs).join(", "); michael@0: } michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: exitFunc ('test'); michael@0: }