js/src/tests/ecma_3/Statements/regress-131348.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
     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 = [];
    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();
    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();
    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();
   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();
   123 //-----------------------------------------------------------------------------
   124 test();
   125 //-----------------------------------------------------------------------------
   129 function addThis()
   130 {
   131   statusitems[UBound] = status;
   132   actualvalues[UBound] = actual;
   133   expectedvalues[UBound] = expect;
   134   UBound++;
   135 }
   138 function test()
   139 {
   140   enterFunc('test');
   141   printBugNumber(BUGNUMBER);
   142   printStatus(summary);
   144   for (var i=0; i<UBound; i++)
   145   {
   146     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   147   }
   149   exitFunc ('test');
   150 }

mercurial