1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/Regress/regress-103602.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * 1.11 + * Date: 10 Jan 2002 1.12 + * SUMMARY: Reassignment to a const is NOT an error per ECMA 1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=103602 1.14 + * 1.15 + * ------- Additional Comment #4 From Brendan Eich 2002-01-10 15:30 ------- 1.16 + * 1.17 + * That's per ECMA (don't blame me, I fought for what Netscape always did: 1.18 + * throw an error [could be a catchable exception since 1.3]). 1.19 + * Readonly properties, when set by assignment, are not changed, but no error 1.20 + * or exception is thrown. The value of the assignment expression is the value 1.21 + * of the r.h.s. 1.22 + * 1.23 + * If you want a *strict* warning, pls change the summary of this bug 1.24 + * to say so. 1.25 + */ 1.26 +//----------------------------------------------------------------------------- 1.27 +var UBound = 0; 1.28 +var BUGNUMBER = 103602; 1.29 +var summary = 'Reassignment to a const is NOT an error per ECMA'; 1.30 +var status = ''; 1.31 +var statusitems = []; 1.32 +var actual = ''; 1.33 +var actualvalues = []; 1.34 +var expect= ''; 1.35 +var expectedvalues = []; 1.36 +var cnFAIL_1 = 'Redeclaration of a const FAILED to cause an error'; 1.37 +var cnFAIL_2 = 'Reassigning to a const caused an ERROR! It should not!!!'; 1.38 +var sEval = ''; 1.39 + 1.40 +/* 1.41 + * Not every implementation supports const (a non-ECMA extension) 1.42 + * For example, Rhino does not; it would generate a complile-time error. 1.43 + * So we have to hide this so it will be detected at run-time instead. 1.44 + */ 1.45 +try 1.46 +{ 1.47 + sEval = 'const one = 1'; 1.48 + eval(sEval); 1.49 +} 1.50 +catch(e) 1.51 +{ 1.52 + quit(); // if const is not supported, this testcase is over - 1.53 +} 1.54 + 1.55 + 1.56 +status = inSection(1); 1.57 +try 1.58 +{ 1.59 + /* 1.60 + * Redeclaration of const should be a compile-time error. 1.61 + * Hide so it will be detected at run-time. 1.62 + */ 1.63 + sEval = 'const one = 2;'; 1.64 + eval(sEval); 1.65 + 1.66 + expect = ''; // we shouldn't reach this line 1.67 + actual = cnFAIL_1; 1.68 + addThis(); 1.69 +} 1.70 +catch(e) 1.71 +{ 1.72 + // good - we should be here. 1.73 + actual = expect; 1.74 + addThis(); 1.75 +} 1.76 + 1.77 + 1.78 +status = inSection(2); 1.79 +try 1.80 +{ 1.81 + /* 1.82 + * Reassignment to a const should be NOT be an error, per ECMA. 1.83 + */ 1.84 + one = 2; 1.85 + actual = expect; // good: no error was generated 1.86 + addThis(); 1.87 + 1.88 + // although no error, the assignment should have been ignored - 1.89 + status = inSection(3); 1.90 + actual = one; 1.91 + expect = 1; 1.92 + addThis(); 1.93 + 1.94 + // the value of the EXPRESSION, however, is the value of the r.h.s. - 1.95 + status = inSection(4); 1.96 + actual = (one = 2); 1.97 + expect = 2; 1.98 + addThis(); 1.99 +} 1.100 + 1.101 +catch(e) 1.102 +{ 1.103 + // BAD - we shouldn't be here 1.104 + expect = ''; 1.105 + actual = cnFAIL_2; 1.106 + addThis(); 1.107 +} 1.108 + 1.109 + 1.110 + 1.111 +//----------------------------------------------------------------------------- 1.112 +test(); 1.113 +//----------------------------------------------------------------------------- 1.114 + 1.115 + 1.116 +function addThis() 1.117 +{ 1.118 + statusitems[UBound] = status; 1.119 + actualvalues[UBound] = actual; 1.120 + expectedvalues[UBound] = expect; 1.121 + UBound++; 1.122 +} 1.123 + 1.124 + 1.125 +function test() 1.126 +{ 1.127 + enterFunc ('test'); 1.128 + printBugNumber(BUGNUMBER); 1.129 + printStatus (summary); 1.130 + 1.131 + for (var i = 0; i < UBound; i++) 1.132 + { 1.133 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.134 + } 1.135 + 1.136 + exitFunc ('test'); 1.137 +}