js/src/tests/js1_5/Scope/regress-208496-002.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-208496-002.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     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:    05 June 2003
    1.12 + * SUMMARY: Testing |with (f)| inside the definition of |function f()|
    1.13 + *
    1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=208496
    1.15 + *
    1.16 + * In this test, we check that static function properties of
    1.17 + * of |f| are read correctly from within the |with(f)| block.
    1.18 + *
    1.19 + */
    1.20 +//-----------------------------------------------------------------------------
    1.21 +var UBound = 0;
    1.22 +var BUGNUMBER = 208496;
    1.23 +var summary = 'Testing |with (f)| inside the definition of |function f()|';
    1.24 +var STATIC_VALUE = 'read the static property';
    1.25 +var status = '';
    1.26 +var statusitems = [];
    1.27 +var actual = '(TEST FAILURE)';
    1.28 +var actualvalues = [];
    1.29 +var expect= '';
    1.30 +var expectedvalues = [];
    1.31 +
    1.32 +
    1.33 +function f(par)
    1.34 +{
    1.35 +  with(f)
    1.36 +  {
    1.37 +    actual = par;
    1.38 +  }
    1.39 +
    1.40 +  return par;
    1.41 +}
    1.42 +f.par = STATIC_VALUE;
    1.43 +
    1.44 +
    1.45 +status = inSection(1);
    1.46 +f('abc'); // this sets |actual| inside |f|
    1.47 +expect = STATIC_VALUE;
    1.48 +addThis();
    1.49 +
    1.50 +// test the return: should be the dynamic value
    1.51 +status = inSection(2);
    1.52 +actual = f('abc');
    1.53 +expect = 'abc';
    1.54 +addThis();
    1.55 +
    1.56 +status = inSection(3);
    1.57 +f(111 + 222); // sets |actual| inside |f|
    1.58 +expect = STATIC_VALUE;
    1.59 +addThis();
    1.60 +
    1.61 +// test the return: should be the dynamic value
    1.62 +status = inSection(4);
    1.63 +actual = f(111 + 222);
    1.64 +expect = 333;
    1.65 +addThis();
    1.66 +
    1.67 +
    1.68 +/*
    1.69 + * Add a level of indirection via |x|
    1.70 + */
    1.71 +function g(par)
    1.72 +{
    1.73 +  with(g)
    1.74 +  {
    1.75 +    var x = par;
    1.76 +    actual = x;
    1.77 +  }
    1.78 +
    1.79 +  return par;
    1.80 +}
    1.81 +g.par = STATIC_VALUE;
    1.82 +
    1.83 +
    1.84 +status = inSection(5);
    1.85 +g('abc'); // this sets |actual| inside |g|
    1.86 +expect = STATIC_VALUE;
    1.87 +addThis();
    1.88 +
    1.89 +// test the return: should be the dynamic value
    1.90 +status = inSection(6);
    1.91 +actual = g('abc');
    1.92 +expect = 'abc';
    1.93 +addThis();
    1.94 +
    1.95 +status = inSection(7);
    1.96 +g(111 + 222); // sets |actual| inside |g|
    1.97 +expect = STATIC_VALUE;
    1.98 +addThis();
    1.99 +
   1.100 +// test the return: should be the dynamic value
   1.101 +status = inSection(8);
   1.102 +actual = g(111 + 222);
   1.103 +expect = 333;
   1.104 +addThis();
   1.105 +
   1.106 +
   1.107 +
   1.108 +//-----------------------------------------------------------------------------
   1.109 +test();
   1.110 +//-----------------------------------------------------------------------------
   1.111 +
   1.112 +
   1.113 +
   1.114 +function addThis()
   1.115 +{
   1.116 +  statusitems[UBound] = status;
   1.117 +  actualvalues[UBound] = actual;
   1.118 +  expectedvalues[UBound] = expect;
   1.119 +  UBound++;
   1.120 +}
   1.121 +
   1.122 +
   1.123 +function test()
   1.124 +{
   1.125 +  enterFunc('test');
   1.126 +  printBugNumber(BUGNUMBER);
   1.127 +  printStatus(summary);
   1.128 +
   1.129 +  for (var i=0; i<UBound; i++)
   1.130 +  {
   1.131 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.132 +  }
   1.133 +
   1.134 +  exitFunc ('test');
   1.135 +}

mercurial