tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

scope-004.js (3151B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 * Date: 2001-07-16
      8 *
      9 * SUMMARY:  Testing visiblity of variables from within a with block.
     10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90325
     11 */
     12 //-----------------------------------------------------------------------------
     13 var UBound = 0;
     14 var BUGNUMBER = 90325;
     15 var summary = 'Testing visiblity of variables from within a with block';
     16 var status = '';
     17 var statusitems = [];
     18 var actual = '';
     19 var actualvalues = [];
     20 var expect= '';
     21 var expectedvalues = [];
     22 
     23 // (compare local definitions which follow) -
     24 var A = 'global A';
     25 var B = 'global B';
     26 var C = 'global C';
     27 var D = 'global D';
     28 
     29 // an object with 'C' and 'D' properties -
     30 var objTEST = new Object();
     31 objTEST.C = C;
     32 objTEST.D = D;
     33 
     34 
     35 status = 'Section 1 of test';
     36 with (new Object())
     37 {
     38  actual = A;
     39  expect = 'global A';
     40 }
     41 addThis();
     42 
     43 
     44 status = 'Section 2 of test';
     45 with (Function)
     46 {
     47  actual = B;
     48  expect = 'global B';
     49 }
     50 addThis();
     51 
     52 
     53 status = 'Section 3 of test';
     54 with (this)
     55 {
     56  actual = C;
     57  expect = 'global C';
     58 }
     59 addThis();
     60 
     61 
     62 status = 'Section 4 of test';
     63 localA();
     64 addThis();
     65 
     66 status = 'Section 5 of test';
     67 localB();
     68 addThis();
     69 
     70 status = 'Section 6 of test';
     71 localC();
     72 addThis();
     73 
     74 status = 'Section 7 of test';
     75 localC(new Object());
     76 addThis();
     77 
     78 status = 'Section 8 of test';
     79 localC.apply(new Object());
     80 addThis();
     81 
     82 status = 'Section 9 of test';
     83 localC.apply(new Object(), [objTEST]);
     84 addThis();
     85 
     86 status = 'Section 10 of test';
     87 localC.apply(objTEST, [objTEST]);
     88 addThis();
     89 
     90 status = 'Section 11 of test';
     91 localD(new Object());
     92 addThis();
     93 
     94 status = 'Section 12 of test';
     95 localD.apply(new Object(), [objTEST]);
     96 addThis();
     97 
     98 status = 'Section 13 of test';
     99 localD.apply(objTEST, [objTEST]);
    100 addThis();
    101 
    102 
    103 
    104 //-------------------------------------------------------------------------------------------------
    105 test();
    106 //-------------------------------------------------------------------------------------------------
    107 
    108 
    109 
    110 // contains a with(new Object()) block -
    111 function localA()
    112 {
    113  var A = 'local A';
    114 
    115  with(new Object())
    116  {
    117    actual = A;
    118    expect = 'local A';
    119  }
    120 }
    121 
    122 
    123 // contains a with(Number) block -
    124 function localB()
    125 {
    126  var B = 'local B';
    127 
    128  with(Number)
    129  {
    130    actual = B;
    131    expect = 'local B';
    132  }
    133 }
    134 
    135 
    136 // contains a with(this) block -
    137 function localC(obj)
    138 {
    139  var C = 'local C';
    140 
    141  with(this)
    142  {
    143    actual = C;
    144  }
    145 
    146  if ('C' in this)
    147    expect = this.C;
    148  else
    149    expect = 'local C';
    150 }
    151 
    152 
    153 // contains a with(obj) block -
    154 function localD(obj)
    155 {
    156  var D = 'local D';
    157 
    158  with(obj)
    159  {
    160    actual = D;
    161  }
    162 
    163  if ('D' in obj)
    164    expect = obj.D;
    165  else
    166    expect = 'local D';
    167 }
    168 
    169 
    170 function addThis()
    171 {
    172  statusitems[UBound] = status;
    173  actualvalues[UBound] = actual;
    174  expectedvalues[UBound] = expect;
    175  UBound++;
    176 }
    177 
    178 
    179 function test()
    180 {
    181  printBugNumber(BUGNUMBER);
    182  printStatus (summary);
    183 
    184  for (var i = 0; i < UBound; i++)
    185  {
    186    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    187  }
    188 }