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