js/src/tests/js1_5/Scope/regress-184107.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Scope/regress-184107.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     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 + *
    1.11 + * Date:    09 December 2002
    1.12 + * SUMMARY: with(...) { function f ...} should set f in the global scope
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=184107
    1.14 + *
    1.15 + * In fact, any variable defined in a with-block should be created
    1.16 + * in global scope, i.e. should be a property of the global object.
    1.17 + *
    1.18 + * The with-block syntax allows existing local variables to be SET,
    1.19 + * but does not allow new local variables to be CREATED.
    1.20 + *
    1.21 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=159849#c11
    1.22 + */
    1.23 +//-----------------------------------------------------------------------------
    1.24 +var UBound = 0;
    1.25 +var BUGNUMBER = 184107;
    1.26 +var summary = 'with(...) { function f ...} should set f in the global scope';
    1.27 +var status = '';
    1.28 +var statusitems = [];
    1.29 +var actual = '';
    1.30 +var actualvalues = [];
    1.31 +var expect= '';
    1.32 +var expectedvalues = [];
    1.33 +
    1.34 +var obj = {y:10};
    1.35 +with (obj)
    1.36 +{
    1.37 +  // function statement
    1.38 +  function f()
    1.39 +  {
    1.40 +    return y;
    1.41 +  }
    1.42 +
    1.43 +  // function expression
    1.44 +  g = function() {return y;}
    1.45 +}
    1.46 +
    1.47 +status = inSection(1);
    1.48 +actual = obj.f;
    1.49 +expect = undefined;
    1.50 +addThis();
    1.51 +
    1.52 +status = inSection(2);
    1.53 +actual = f();
    1.54 +expect = obj.y;
    1.55 +addThis();
    1.56 +
    1.57 +status = inSection(3);
    1.58 +actual = obj.g;
    1.59 +expect = undefined;
    1.60 +addThis();
    1.61 +
    1.62 +status = inSection(4);
    1.63 +actual = g();
    1.64 +expect = obj.y;
    1.65 +addThis();
    1.66 +
    1.67 +
    1.68 +
    1.69 +//-----------------------------------------------------------------------------
    1.70 +test();
    1.71 +//-----------------------------------------------------------------------------
    1.72 +
    1.73 +
    1.74 +
    1.75 +function addThis()
    1.76 +{
    1.77 +  statusitems[UBound] = status;
    1.78 +  actualvalues[UBound] = actual;
    1.79 +  expectedvalues[UBound] = expect;
    1.80 +  UBound++;
    1.81 +}
    1.82 +
    1.83 +
    1.84 +function test()
    1.85 +{
    1.86 +  enterFunc('test');
    1.87 +  printBugNumber(BUGNUMBER);
    1.88 +  printStatus(summary);
    1.89 +
    1.90 +  for (var i=0; i<UBound; i++)
    1.91 +  {
    1.92 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    1.93 +  }
    1.94 +
    1.95 +  exitFunc ('test');
    1.96 +}

mercurial