js/src/tests/js1_8/extensions/regress-422269.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_8/extensions/regress-422269.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//-----------------------------------------------------------------------------
    1.10 +var BUGNUMBER = 422269;
    1.11 +var summary = 'Compile-time let block should not capture runtime references';
    1.12 +var actual = 'referenced only by stack and closure';
    1.13 +var expect = 'referenced only by stack and closure';
    1.14 +
    1.15 +
    1.16 +//-----------------------------------------------------------------------------
    1.17 +test();
    1.18 +
    1.19 +//-----------------------------------------------------------------------------
    1.20 +
    1.21 +function test()
    1.22 +{
    1.23 +  enterFunc ('test');
    1.24 +  printBugNumber(BUGNUMBER);
    1.25 +  printStatus (summary);
    1.26 +
    1.27 +  function f()
    1.28 +  {
    1.29 +    let m = {sin: Math.sin};
    1.30 +    (function holder() { m.sin(1); })();
    1.31 +    return m;
    1.32 +  }
    1.33 +
    1.34 +  if (typeof findReferences == 'undefined')
    1.35 +  {
    1.36 +    expect = actual = 'Test skipped';
    1.37 +    print('Test skipped. Requires findReferences function.');
    1.38 +  }
    1.39 +  else
    1.40 +  {
    1.41 +    var x = f();
    1.42 +    var refs = findReferences(x);
    1.43 +
    1.44 +    // At this point, x should only be referenced from the stack --- the
    1.45 +    // variable 'x' itself, and any random things the conservative scanner
    1.46 +    // finds --- and possibly from the 'holder' closure, which could itself
    1.47 +    // be held alive for random reasons. Remove those from the refs list, and 
    1.48 +    // then complain if anything is left.
    1.49 +    for (var edge in refs) {
    1.50 +      // Remove references from roots, like the stack.
    1.51 +      if (refs[edge].every(function (r) r === null))
    1.52 +        delete refs[edge];
    1.53 +      // Remove references from the closure, which could be held alive for
    1.54 +      // random reasons.
    1.55 +      else if (refs[edge].length === 1 &&
    1.56 +               typeof refs[edge][0] === "function" &&
    1.57 +               refs[edge][0].name === "holder")
    1.58 +        delete refs[edge];
    1.59 +    }
    1.60 +
    1.61 +    if (Object.keys(refs).length != 0)
    1.62 +        actual = "unexpected references to the result of f: " + Object.keys(refs).join(", ");
    1.63 +  }
    1.64 +  reportCompare(expect, actual, summary);
    1.65 +
    1.66 +  exitFunc ('test');
    1.67 +}

mercurial