js/src/tests/js1_7/block/regress-344139.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-344139.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     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     = "344139";
    1.11 +var summary = "Basic let functionality";
    1.12 +var actual, expect;
    1.13 +
    1.14 +printBugNumber(BUGNUMBER);
    1.15 +printStatus(summary);
    1.16 +
    1.17 +/**************
    1.18 + * BEGIN TEST *
    1.19 + **************/
    1.20 +
    1.21 +var failed = false;
    1.22 +
    1.23 +var x = 7;
    1.24 +
    1.25 +function f1()
    1.26 +{
    1.27 +  let x = 5;
    1.28 +  return x;
    1.29 +}
    1.30 +
    1.31 +function f2()
    1.32 +{
    1.33 +  let x = 5;
    1.34 +  x = 3;
    1.35 +  return x;
    1.36 +}
    1.37 +
    1.38 +function f3()
    1.39 +{
    1.40 +  let x = 5;
    1.41 +  x += x;
    1.42 +  return x;
    1.43 +}
    1.44 +
    1.45 +function f4()
    1.46 +{
    1.47 +  var v = 5;
    1.48 +  let q = 17;
    1.49 +
    1.50 +  // 0+1+2+...+8+9 == 45
    1.51 +  for (let v = 0; v < 10; v++)
    1.52 +    q += v;
    1.53 +
    1.54 +  if (q != 62)
    1.55 +    throw "f4(): wrong value for q\n" +
    1.56 +      "  expected: 62\n" +
    1.57 +      "  actual:   " + q;
    1.58 +
    1.59 +  return v;
    1.60 +}
    1.61 +
    1.62 +try
    1.63 +{
    1.64 +  if (f1() != 5 || x != 7)
    1.65 +    throw "f1() == 5";
    1.66 +  if (f2() != 3 || x != 7)
    1.67 +    throw "f2() == 3";
    1.68 +  if (f3() != 10 || x != 7)
    1.69 +    throw "f3() == 10";
    1.70 +
    1.71 +  if (f4() != 5)
    1.72 +    throw "f4() == 5";
    1.73 +
    1.74 +  var bad = true;
    1.75 +  try
    1.76 +  {
    1.77 +    eval("q++"); // force error at runtime
    1.78 +  }
    1.79 +  catch (e)
    1.80 +  {
    1.81 +    if (e instanceof ReferenceError)
    1.82 +      bad = false;
    1.83 +  }
    1.84 +  if (bad)
    1.85 +    throw "f4(): q escaping scope!";
    1.86 +}
    1.87 +catch (e)
    1.88 +{
    1.89 +  failed = e;
    1.90 +}
    1.91 +
    1.92 +expect = false;
    1.93 +actual = failed;
    1.94 +
    1.95 +reportCompare(expect, actual, summary);

mercurial