tor-browser

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

regress-131348.js (2813B)


      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 *
      8 * Date:    10 Apr 2002
      9 * Revised: 14 July 2002
     10 *
     11 * SUMMARY: JS should NOT error on |for(i in undefined)|, |for(i in null)|
     12 *
     13 * ECMA-262 3rd Edition Final spec says such statements SHOULD error. See:
     14 *
     15 *               Section 12.6.4  The for-in Statement
     16 *               Section 9.9     ToObject
     17 *
     18 *
     19 * But SpiderMonkey has decided NOT to follow this; it's a bug in the spec.
     20 * See http://bugzilla.mozilla.org/show_bug.cgi?id=131348
     21 *
     22 * Update: Rhino has also decided not to follow the spec on this
     23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=136893
     24 */
     25 //-----------------------------------------------------------------------------
     26 var UBound = 0;
     27 var BUGNUMBER = 131348;
     28 var summary = 'JS should not error on |for(i in undefined)|, |for(i in null)|';
     29 var TEST_PASSED = 'No error';
     30 var TEST_FAILED = 'An error was generated!!!';
     31 var status = '';
     32 var statusitems = [];
     33 var actual = '';
     34 var actualvalues = [];
     35 var expect= '';
     36 var expectedvalues = [];
     37 
     38 
     39 
     40 status = inSection(1);
     41 expect = TEST_PASSED;
     42 actual = TEST_PASSED;
     43 try
     44 {
     45  for (var i in undefined)
     46  {
     47    print(i);
     48  }
     49 }
     50 catch(e)
     51 {
     52  actual = TEST_FAILED;
     53 }
     54 addThis();
     55 
     56 
     57 
     58 status = inSection(2);
     59 expect = TEST_PASSED;
     60 actual = TEST_PASSED;
     61 try
     62 {
     63  for (var i in null)
     64  {
     65    print(i);
     66  }
     67 }
     68 catch(e)
     69 {
     70  actual = TEST_FAILED;
     71 }
     72 addThis();
     73 
     74 
     75 
     76 status = inSection(3);
     77 expect = TEST_PASSED;
     78 actual = TEST_PASSED;
     79 /*
     80 * Variable names that cannot be looked up generate ReferenceErrors; however,
     81 * property names like obj.ZZZ that cannot be looked up are set to |undefined|
     82 *
     83 * Therefore, this should indirectly test | for (var i in undefined) |
     84 */
     85 try
     86 {
     87  for (var i in this.ZZZ)
     88  {
     89    print(i);
     90  }
     91 }
     92 catch(e)
     93 {
     94  actual = TEST_FAILED;
     95 }
     96 addThis();
     97 
     98 
     99 
    100 status = inSection(4);
    101 expect = TEST_PASSED;
    102 actual = TEST_PASSED;
    103 /*
    104 * The result of an unsuccessful regexp match is the null value
    105 * Therefore, this should indirectly test | for (var i in null) |
    106 */
    107 try
    108 {
    109  for (var i in 'bbb'.match(/aaa/))
    110  {
    111    print(i);
    112  }
    113 }
    114 catch(e)
    115 {
    116  actual = TEST_FAILED;
    117 }
    118 addThis();
    119 
    120 
    121 
    122 
    123 //-----------------------------------------------------------------------------
    124 test();
    125 //-----------------------------------------------------------------------------
    126 
    127 
    128 
    129 function addThis()
    130 {
    131  statusitems[UBound] = status;
    132  actualvalues[UBound] = actual;
    133  expectedvalues[UBound] = expect;
    134  UBound++;
    135 }
    136 
    137 
    138 function test()
    139 {
    140  printBugNumber(BUGNUMBER);
    141  printStatus(summary);
    142 
    143  for (var i=0; i<UBound; i++)
    144  {
    145    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    146  }
    147 }