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 (at) mozilla.org, pschwartau (at) 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 //----------------------------------------------------------------------------- 49 var UBound = 0; 50 var bug = 99663; 51 var summary = 'Regression test for Bugzilla bug 99663'; 52 /* 53 * This testcase expects error messages containing 54 * the phrase 'read-only' or something similar - 55 */ 56 var READONLY = /read\s*-?\s*only/; 57 var READONLY_TRUE = 'a "read-only" error'; 58 var READONLY_FALSE = 'Error: '; 59 var FAILURE = 'NO ERROR WAS GENERATED!'; 60 var status = ''; 61 var actual = ''; 62 var expect= ''; 63 var statusitems = []; 64 var expectedvalues = []; 65 var actualvalues = []; 66 67 68 /* 69 * These MUST be compiled in JS1.2 or less for the test to work - see above 70 */ 71 function f1() 72 { 73 with (it) 74 { 75 for (rdonly in this); 76 } 77 } 78 79 80 function f2() 81 { 82 for (it.rdonly in this); 83 } 84 85 86 function 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 */ 97 actual = FAILURE; 98 try 99 { 100 f1(); 101 } 102 catch(e) 103 { 104 actual = readOnly(e.message); 105 } 106 expect= READONLY_TRUE; 107 status = 'Section 1 of test - got ' + actual; 108 addThis(); 109 110 111 actual = FAILURE; 112 try 113 { 114 f2(); 115 } 116 catch(e) 117 { 118 actual = readOnly(e.message); 119 } 120 expect= READONLY_TRUE; 121 status = 'Section 2 of test - got ' + actual; 122 addThis(); 123 124 125 actual = FAILURE; 126 try 127 { 128 f3('rdonly'); 129 } 130 catch(e) 131 { 132 actual = readOnly(e.message); 133 } 134 expect= READONLY_TRUE; 135 status = 'Section 3 of test - got ' + actual; 136 addThis(); 137 138 139 140 //----------------------------------------------------------------------------- 141 test(); 142 //----------------------------------------------------------------------------- 143 144 145 146 function readOnly(msg) 147 { 148 if (msg.match(READONLY)) 149 return READONLY_TRUE; 150 return READONLY_FALSE + msg; 151 } 152 153 154 function addThis() 155 { 156 statusitems[UBound] = status; 157 actualvalues[UBound] = actual; 158 expectedvalues[UBound] = expect; 159 UBound++; 160 } 161 162 163 function 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