js/src/tests/js1_5/Scope/scope-004.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/scope-004.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,191 @@
     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 + * Date: 2001-07-16
    1.11 + *
    1.12 + * SUMMARY:  Testing visiblity of variables from within a with block.
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=90325
    1.14 + */
    1.15 +//-----------------------------------------------------------------------------
    1.16 +var UBound = 0;
    1.17 +var BUGNUMBER = 90325;
    1.18 +var summary = 'Testing visiblity of variables from within a with block';
    1.19 +var status = '';
    1.20 +var statusitems = [];
    1.21 +var actual = '';
    1.22 +var actualvalues = [];
    1.23 +var expect= '';
    1.24 +var expectedvalues = [];
    1.25 +
    1.26 +// (compare local definitions which follow) -
    1.27 +var A = 'global A';
    1.28 +var B = 'global B';
    1.29 +var C = 'global C';
    1.30 +var D = 'global D';
    1.31 +
    1.32 +// an object with 'C' and 'D' properties -
    1.33 +var objTEST = new Object();
    1.34 +objTEST.C = C;
    1.35 +objTEST.D = D;
    1.36 +
    1.37 +
    1.38 +status = 'Section 1 of test';
    1.39 +with (new Object())
    1.40 +{
    1.41 +  actual = A;
    1.42 +  expect = 'global A';
    1.43 +}
    1.44 +addThis();
    1.45 +
    1.46 +
    1.47 +status = 'Section 2 of test';
    1.48 +with (Function)
    1.49 +{
    1.50 +  actual = B;
    1.51 +  expect = 'global B';
    1.52 +}
    1.53 +addThis();
    1.54 +
    1.55 +
    1.56 +status = 'Section 3 of test';
    1.57 +with (this)
    1.58 +{
    1.59 +  actual = C;
    1.60 +  expect = 'global C';
    1.61 +}
    1.62 +addThis();
    1.63 +
    1.64 +
    1.65 +status = 'Section 4 of test';
    1.66 +localA();
    1.67 +addThis();
    1.68 +
    1.69 +status = 'Section 5 of test';
    1.70 +localB();
    1.71 +addThis();
    1.72 +
    1.73 +status = 'Section 6 of test';
    1.74 +localC();
    1.75 +addThis();
    1.76 +
    1.77 +status = 'Section 7 of test';
    1.78 +localC(new Object());
    1.79 +addThis();
    1.80 +
    1.81 +status = 'Section 8 of test';
    1.82 +localC.apply(new Object());
    1.83 +addThis();
    1.84 +
    1.85 +status = 'Section 9 of test';
    1.86 +localC.apply(new Object(), [objTEST]);
    1.87 +addThis();
    1.88 +
    1.89 +status = 'Section 10 of test';
    1.90 +localC.apply(objTEST, [objTEST]);
    1.91 +addThis();
    1.92 +
    1.93 +status = 'Section 11 of test';
    1.94 +localD(new Object());
    1.95 +addThis();
    1.96 +
    1.97 +status = 'Section 12 of test';
    1.98 +localD.apply(new Object(), [objTEST]);
    1.99 +addThis();
   1.100 +
   1.101 +status = 'Section 13 of test';
   1.102 +localD.apply(objTEST, [objTEST]);
   1.103 +addThis();
   1.104 +
   1.105 +
   1.106 +
   1.107 +//-------------------------------------------------------------------------------------------------
   1.108 +test();
   1.109 +//-------------------------------------------------------------------------------------------------
   1.110 +
   1.111 +
   1.112 +
   1.113 +// contains a with(new Object()) block -
   1.114 +function localA()
   1.115 +{
   1.116 +  var A = 'local A';
   1.117 +
   1.118 +  with(new Object())
   1.119 +  {
   1.120 +    actual = A;
   1.121 +    expect = 'local A';
   1.122 +  }
   1.123 +}
   1.124 +
   1.125 +
   1.126 +// contains a with(Number) block -
   1.127 +function localB()
   1.128 +{
   1.129 +  var B = 'local B';
   1.130 +
   1.131 +  with(Number)
   1.132 +  {
   1.133 +    actual = B;
   1.134 +    expect = 'local B';
   1.135 +  }
   1.136 +}
   1.137 +
   1.138 +
   1.139 +// contains a with(this) block -
   1.140 +function localC(obj)
   1.141 +{
   1.142 +  var C = 'local C';
   1.143 +
   1.144 +  with(this)
   1.145 +  {
   1.146 +    actual = C;
   1.147 +  }
   1.148 +
   1.149 +  if ('C' in this)
   1.150 +    expect = this.C;
   1.151 +  else
   1.152 +    expect = 'local C';
   1.153 +}
   1.154 +
   1.155 +
   1.156 +// contains a with(obj) block -
   1.157 +function localD(obj)
   1.158 +{
   1.159 +  var D = 'local D';
   1.160 +
   1.161 +  with(obj)
   1.162 +  {
   1.163 +    actual = D;
   1.164 +  }
   1.165 +
   1.166 +  if ('D' in obj)
   1.167 +    expect = obj.D;
   1.168 +  else
   1.169 +    expect = 'local D';
   1.170 +}
   1.171 +
   1.172 +
   1.173 +function addThis()
   1.174 +{
   1.175 +  statusitems[UBound] = status;
   1.176 +  actualvalues[UBound] = actual;
   1.177 +  expectedvalues[UBound] = expect;
   1.178 +  UBound++;
   1.179 +}
   1.180 +
   1.181 +
   1.182 +function test()
   1.183 +{
   1.184 +  enterFunc ('test');
   1.185 +  printBugNumber(BUGNUMBER);
   1.186 +  printStatus (summary);
   1.187 +
   1.188 +  for (var i = 0; i < UBound; i++)
   1.189 +  {
   1.190 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.191 +  }
   1.192 +
   1.193 +  exitFunc ('test');
   1.194 +}

mercurial