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 "AS 8* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9* 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): brendan@mozilla.org, pschwartau@netscape.com 20* Date: 09 October 2001 21* 22* SUMMARY: Regression test for Bugzilla bug 99663 23* See http://bugzilla.mozilla.org/show_bug.cgi?id=99663 24* 25******************************************************************************* 26******************************************************************************* 27* ESSENTIAL!: this test should contain, or be loaded after, a call to 28* 29* version(120); 30* 31* Only JS version 1.2 or less has the behavior we're expecting here - 32* 33* Brendan: "The JS_SetVersion stickiness is necessary for tests such as 34* this one to work properly. I think the existing js/tests have been lucky 35* in dodging the buggy way that JS_SetVersion's effect can be undone by 36* function return." 37* 38* Note: it is the function statements for f1(), etc. that MUST be compiled 39* in JS version 1.2 or less for the test to pass - 40* 41******************************************************************************* 42******************************************************************************* 43* 44* 45* NOTE: the test uses the |it| object of SpiderMonkey; don't run it in Rhino - 46* 47*/ 48//----------------------------------------------------------------------------- 49var UBound = 0; 50var bug = 99663; 51var summary = 'Regression test for Bugzilla bug 99663'; 52/* 53 * This testcase expects error messages containing 54 * the phrase 'read-only' or something similar - 55 */ 56var READONLY = /read\s*-?\s*only/; 57var READONLY_TRUE = 'a "read-only" error'; 58var READONLY_FALSE = 'Error: '; 59var FAILURE = 'NO ERROR WAS GENERATED!'; 60var status = ''; 61var actual = ''; 62var expect= ''; 63var statusitems = []; 64var expectedvalues = []; 65var actualvalues = []; 66 67 68/* 69 * These MUST be compiled in JS1.2 or less for the test to work - see above 70 */ 71function f1() 72{ 73 with (it) 74 { 75 for (rdonly in this); 76 } 77} 78 79 80function f2() 81{ 82 for (it.rdonly in this); 83} 84 85 86function f3(s) 87{ 88 for (it[s] in this); 89} 90 91 92 93/* 94 * Begin testing by capturing actual vs. expected values. 95 * Initialize to FAILURE; this will get reset if all goes well - 96 */ 97actual = FAILURE; 98try 99{ 100 f1(); 101} 102catch(e) 103{ 104 actual = readOnly(e.message); 105} 106expect= READONLY_TRUE; 107status = 'Section 1 of test - got ' + actual; 108addThis(); 109 110 111actual = FAILURE; 112try 113{ 114 f2(); 115} 116catch(e) 117{ 118 actual = readOnly(e.message); 119} 120expect= READONLY_TRUE; 121status = 'Section 2 of test - got ' + actual; 122addThis(); 123 124 125actual = FAILURE; 126try 127{ 128 f3('rdonly'); 129} 130catch(e) 131{ 132 actual = readOnly(e.message); 133} 134expect= READONLY_TRUE; 135status = 'Section 3 of test - got ' + actual; 136addThis(); 137 138 139 140//----------------------------------------------------------------------------- 141test(); 142//----------------------------------------------------------------------------- 143 144 145 146function readOnly(msg) 147{ 148 if (msg.match(READONLY)) 149 return READONLY_TRUE; 150 return READONLY_FALSE + msg; 151} 152 153 154function addThis() 155{ 156 statusitems[UBound] = status; 157 actualvalues[UBound] = actual; 158 expectedvalues[UBound] = expect; 159 UBound++; 160} 161 162 163function test() 164{ 165 writeLineToLog ('Bug Number ' + bug); 166 writeLineToLog ('STATUS: ' + summary); 167 168 for (var i=0; i<UBound; i++) 169 { 170 writeTestCaseResult(expectedvalues[i], actualvalues[i], statusitems[i]); 171 } 172} 173