Home | History | Annotate | Download | only in Scope
      1 /*
      2 * The contents of this file are subject to the Netscape Public
      3 * License Version 1.1 (the "License"); you may not use this file
      4 * except in compliance with the License. You may obtain a copy of
      5 * the License at http://www.mozilla.org/NPL/
      6 *
      7 * Software distributed under the License is distributed on an
      8 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed
      9 * or implied. See the License for the specific language governing
     10 * rights and limitations under the License.
     11 *
     12 * The Original Code is mozilla.org code.
     13 *
     14 * The Initial Developer of the Original Code is Netscape
     15 * Communications Corporation.  Portions created by Netscape are
     16 * Copyright (C) 1998 Netscape Communications Corporation.
     17 * All Rights Reserved.
     18 *
     19 * Contributor(s): pschwartau (at) netscape.com
     20 * Date: 2001-07-16
     21 *
     22 * SUMMARY:  Testing visiblity of variables from within a with block.
     23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90325
     24 */
     25 //-------------------------------------------------------------------------------------------------
     26 var UBound = 0;
     27 var bug = 90325;
     28 var summary = 'Testing visiblity of variables from within a with block';
     29 var status = '';
     30 var statusitems = [];
     31 var actual = '';
     32 var actualvalues = [];
     33 var expect= '';
     34 var expectedvalues = [];
     35 
     36 // (compare local definitions which follow) -
     37 var A = 'global A';
     38 var B = 'global B';
     39 var C = 'global C';
     40 var D = 'global D';
     41 
     42 // an object with 'C' and 'D' properties -
     43 var objTEST = new Object();
     44 objTEST.C = C;
     45 objTEST.D = D;
     46 
     47 
     48 status = 'Section 1 of test';
     49 with (new Object())
     50 {
     51   actual = A;
     52   expect = 'global A';
     53 }
     54 addThis();
     55 
     56 
     57 status = 'Section 2 of test';
     58 with (Function)
     59 {
     60   actual = B;
     61   expect = 'global B';
     62 }
     63 addThis();
     64 
     65 
     66 status = 'Section 3 of test';
     67 with (this)
     68 {
     69   actual = C;
     70   expect = 'global C';
     71 }
     72 addThis();
     73 
     74 
     75 status = 'Section 4 of test';
     76 localA();
     77 addThis();
     78 
     79 status = 'Section 5 of test';
     80 localB();
     81 addThis();
     82 
     83 status = 'Section 6 of test';
     84 localC();
     85 addThis();
     86 
     87 status = 'Section 7 of test';
     88 localC(new Object());
     89 addThis();
     90 
     91 status = 'Section 8 of test';
     92 localC.apply(new Object());
     93 addThis();
     94 
     95 status = 'Section 9 of test';
     96 localC.apply(new Object(), [objTEST]);
     97 addThis();
     98 
     99 status = 'Section 10 of test';
    100 localC.apply(objTEST, [objTEST]);
    101 addThis();
    102 
    103 status = 'Section 11 of test';
    104 localD(new Object());
    105 addThis();
    106 
    107 status = 'Section 12 of test';
    108 localD.apply(new Object(), [objTEST]);
    109 addThis();
    110 
    111 status = 'Section 13 of test';
    112 localD.apply(objTEST, [objTEST]);
    113 addThis();
    114 
    115 
    116 
    117 //-------------------------------------------------------------------------------------------------
    118 test();
    119 //-------------------------------------------------------------------------------------------------
    120 
    121 
    122 
    123 // contains a with(new Object()) block -
    124 function localA()
    125 {
    126   var A = 'local A';
    127 
    128   with(new Object())
    129   {
    130     actual = A;
    131     expect = 'local A';
    132   }
    133 }
    134 
    135 
    136 // contains a with(Number) block -
    137 function localB()
    138 {
    139   var B = 'local B';
    140 
    141   with(Number)
    142   {
    143     actual = B;
    144     expect = 'local B';
    145   }
    146 }
    147 
    148 
    149 // contains a with(this) block -
    150 function localC(obj)
    151 {
    152   var C = 'local C';
    153 
    154   with(this)
    155   {
    156     actual = C;
    157   }
    158 
    159   if ('C' in this)
    160     expect = this.C;
    161   else
    162     expect = 'local C';
    163 }
    164 
    165 
    166 // contains a with(obj) block -
    167 function localD(obj)
    168 {
    169   var D = 'local D';
    170 
    171   with(obj)
    172   {
    173     actual = D;
    174   }
    175 
    176   if ('D' in obj)
    177     expect = obj.D;
    178   else
    179     expect = 'local D';
    180 }
    181 
    182 
    183 function addThis()
    184 {
    185   statusitems[UBound] = status;
    186   actualvalues[UBound] = actual;
    187   expectedvalues[UBound] = expect;
    188   UBound++;
    189 }
    190 
    191 
    192 function test()
    193 {
    194   enterFunc ('test');
    195   printBugNumber (bug);
    196   printStatus (summary);
    197 
    198   for (var i = 0; i < UBound; i++)
    199   {
    200     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    201   }
    202 
    203   exitFunc ('test');
    204 }
    205