js/src/tests/js1_7/block/regress-343765.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_7/block/regress-343765.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     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 = 343765;
    1.11 +var summary = 'Function defined in a let statement/expression does not work correctly outside the let scope';
    1.12 +var actual = '';
    1.13 +var expect = '';
    1.14 +
    1.15 +
    1.16 +//-----------------------------------------------------------------------------
    1.17 +test();
    1.18 +//-----------------------------------------------------------------------------
    1.19 +
    1.20 +function test()
    1.21 +{
    1.22 +  enterFunc ('test');
    1.23 +  printBugNumber(BUGNUMBER);
    1.24 +  printStatus (summary);
    1.25 + 
    1.26 +  print("SECTION 1");
    1.27 +  try {
    1.28 +    let (a = 2, b = 3) { function f() { return String([a,b]); } f(); throw 42; }
    1.29 +  } catch (e) {
    1.30 +    f();
    1.31 +  }
    1.32 +
    1.33 +  reportCompare(expect, actual, summary);
    1.34 +
    1.35 +  print("SECTION 2");
    1.36 +  try {
    1.37 +    with ({a:2,b:3}) { function f() { return String([a,b]); } f(); throw 42; }
    1.38 +  } catch (e) {
    1.39 +    f();
    1.40 +  }
    1.41 +
    1.42 +  print("SECTION 3");
    1.43 +  function g3() {
    1.44 +    print("Here!");
    1.45 +    with ({a:2,b:3}) {
    1.46 +      function f() {
    1.47 +        return String([a,b]);
    1.48 +      }
    1.49 +
    1.50 +      f();
    1.51 +      return f;
    1.52 +    }
    1.53 +  }
    1.54 +
    1.55 +  k = g3();
    1.56 +  k();
    1.57 +
    1.58 +  print("SECTION 4");
    1.59 +  function g4() {
    1.60 +    print("Here!");
    1.61 +    let (a=2,b=3) {
    1.62 +      function f() {
    1.63 +        return String([a,b]);
    1.64 +      }
    1.65 +
    1.66 +      f();
    1.67 +      return f;
    1.68 +    }
    1.69 +  }
    1.70 +
    1.71 +  k = g4();
    1.72 +  k();
    1.73 +
    1.74 +  print("SECTION 5");
    1.75 +  function g5() {
    1.76 +    print("Here!");
    1.77 +    let (a=2,b=3) {
    1.78 +      function f() {
    1.79 +        return String([a,b]);
    1.80 +      }
    1.81 +
    1.82 +      f();
    1.83 +      yield f;
    1.84 +    }
    1.85 +  }
    1.86 +
    1.87 +  k = g5().next();
    1.88 +  k();
    1.89 +
    1.90 +  reportCompare(expect, actual, summary);
    1.91 +
    1.92 +  exitFunc ('test');
    1.93 +}
    1.94 +
    1.95 +function returnResult(a)
    1.96 +{
    1.97 +  return a + '';
    1.98 +}

mercurial