js/src/tests/js1_5/Regress/regress-103602.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 Jan 2002
     9  * SUMMARY: Reassignment to a const is NOT an error per ECMA
    10  * See http://bugzilla.mozilla.org/show_bug.cgi?id=103602
    11  *
    12  * ------- Additional Comment #4 From Brendan Eich 2002-01-10 15:30 -------
    13  *
    14  * That's per ECMA (don't blame me, I fought for what Netscape always did:
    15  * throw an error [could be a catchable exception since 1.3]).
    16  * Readonly properties, when set by assignment, are not changed, but no error
    17  * or exception is thrown. The value of the assignment expression is the value
    18  * of the r.h.s.
    19  *
    20  * If you want a *strict* warning, pls change the summary of this bug
    21  * to say so.
    22  */
    23 //-----------------------------------------------------------------------------
    24 var UBound = 0;
    25 var BUGNUMBER = 103602;
    26 var summary = 'Reassignment to a const is NOT an error per ECMA';
    27 var status = '';
    28 var statusitems = [];
    29 var actual = '';
    30 var actualvalues = [];
    31 var expect= '';
    32 var expectedvalues = [];
    33 var cnFAIL_1 = 'Redeclaration of a const FAILED to cause an error';
    34 var cnFAIL_2 = 'Reassigning to a const caused an ERROR! It should not!!!';
    35 var sEval = '';
    37 /*
    38  * Not every implementation supports const (a non-ECMA extension)
    39  * For example, Rhino does not; it would generate a complile-time error.
    40  * So we have to hide this so it will be detected at run-time instead.
    41  */
    42 try
    43 {
    44   sEval = 'const one = 1';
    45   eval(sEval);
    46 }
    47 catch(e)
    48 {
    49   quit(); // if const is not supported, this testcase is over -
    50 }
    53 status = inSection(1);
    54 try
    55 {
    56   /*
    57    * Redeclaration of const should be a compile-time error.
    58    * Hide so it will be detected at run-time.
    59    */
    60   sEval = 'const one = 2;';
    61   eval(sEval);
    63   expect = ''; // we shouldn't reach this line
    64   actual = cnFAIL_1;
    65   addThis();
    66 }
    67 catch(e)
    68 {
    69   // good - we should be here.
    70   actual = expect;
    71   addThis();
    72 }
    75 status = inSection(2);
    76 try
    77 {
    78   /*
    79    * Reassignment to a const should be NOT be an error, per ECMA.
    80    */
    81   one = 2;
    82   actual = expect; // good: no error was generated
    83   addThis();
    85   // although no error, the assignment should have been ignored -
    86   status = inSection(3);
    87   actual = one;
    88   expect = 1;
    89   addThis();
    91   // the value of the EXPRESSION, however, is the value of the r.h.s. -
    92   status = inSection(4);
    93   actual = (one = 2);
    94   expect = 2;
    95   addThis();
    96 }
    98 catch(e)
    99 {
   100   // BAD - we shouldn't be here
   101   expect = '';
   102   actual = cnFAIL_2;
   103   addThis();
   104 }
   108 //-----------------------------------------------------------------------------
   109 test();
   110 //-----------------------------------------------------------------------------
   113 function addThis()
   114 {
   115   statusitems[UBound] = status;
   116   actualvalues[UBound] = actual;
   117   expectedvalues[UBound] = expect;
   118   UBound++;
   119 }
   122 function test()
   123 {
   124   enterFunc ('test');
   125   printBugNumber(BUGNUMBER);
   126   printStatus (summary);
   128   for (var i = 0; i < UBound; i++)
   129   {
   130     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   131   }
   133   exitFunc ('test');
   134 }

mercurial