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): igor@icesoft.no, pschwartau@netscape.com 20* Date: 24 September 2001 21* 22* SUMMARY: Try assigning arr.length = new Number(n) 23* From correspondence with Igor Bukanov <igor@icesoft.no> 24* See http://bugzilla.mozilla.org/show_bug.cgi?id=101488 25* 26* Without the "new" keyword, assigning arr.length = Number(n) worked. 27* But with it, Rhino was giving an error "Inappropriate array length" 28* and SpiderMonkey was exiting without giving any error or return value - 29* 30* Comments on the Rhino code by igor@icesoft.no: 31* 32* jsSet_length requires that the new length value should be an instance 33* of Number. But according to Ecma 15.4.5.1, item 12-13, an error should 34* be thrown only if ToUint32(length_value) != ToNumber(length_value) 35*/ 36//----------------------------------------------------------------------------- 37var UBound = 0; 38var bug = 101488; 39var summary = 'Try assigning arr.length = new Number(n)'; 40var status = ''; 41var statusitems = []; 42var actual = ''; 43var actualvalues = []; 44var expect= ''; 45var expectedvalues = []; 46var arr = []; 47 48 49status = inSection(1); 50arr = Array(); 51tryThis('arr.length = new Number(1);'); 52actual = arr.length; 53expect = 1; 54addThis(); 55 56status = inSection(2); 57arr = Array(5); 58tryThis('arr.length = new Number(1);'); 59actual = arr.length; 60expect = 1; 61addThis(); 62 63status = inSection(3); 64arr = Array(); 65tryThis('arr.length = new Number(17);'); 66actual = arr.length; 67expect = 17; 68addThis(); 69 70status = inSection(4); 71arr = Array(5); 72tryThis('arr.length = new Number(17);'); 73actual = arr.length; 74expect = 17; 75addThis(); 76 77 78/* 79 * Also try the above with the "new" keyword before Array(). 80 * Array() and new Array() should be equivalent, by ECMA 15.4.1.1 81 */ 82status = inSection(5); 83arr = new Array(); 84tryThis('arr.length = new Number(1);'); 85actual = arr.length; 86expect = 1; 87addThis(); 88 89status = inSection(6); 90arr = new Array(5); 91tryThis('arr.length = new Number(1);'); 92actual = arr.length; 93expect = 1; 94addThis(); 95 96arr = new Array(); 97tryThis('arr.length = new Number(17);'); 98actual = arr.length; 99expect = 17; 100addThis(); 101 102status = inSection(7); 103arr = new Array(5); 104tryThis('arr.length = new Number(17);'); 105actual = arr.length; 106expect = 17; 107addThis(); 108 109 110 111//----------------------------------------------------------------------------- 112test(); 113//----------------------------------------------------------------------------- 114 115 116 117function tryThis(s) 118{ 119 try 120 { 121 eval(s); 122 } 123 catch(e) 124 { 125 // keep going 126 } 127} 128 129 130function addThis() 131{ 132 statusitems[UBound] = status; 133 actualvalues[UBound] = actual; 134 expectedvalues[UBound] = expect; 135 UBound++; 136} 137 138 139function test() 140{ 141 enterFunc ('test'); 142 printBugNumber (bug); 143 printStatus (summary); 144 145 for (var i=0; i<UBound; i++) 146 { 147 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 148 } 149 150 exitFunc ('test'); 151} 152