Debian Codegraph @

rhino/testsrc/tests/ecma_3/Array/regress-101488.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 <[email protected]>
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 [email protected]:
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 gTestfile = 'regress-101488.js';
25 var UBound = 0;
26 var BUGNUMBER = 101488;
27 var summary = 'Try assigning arr.length = new Number(n)';
28 var status = '';
29 var statusitems = [];
30 var actual = '';
31 var actualvalues = [];
32 var expect= '';
33 var expectedvalues = [];
34 var arr = [];
35
36
37 status = inSection(1);
38 arr = Array();
39 tryThis('arr.length = new Number(1);');
40 actual = arr.length;
41 expect = 1;
42 addThis();
43
44 status = inSection(2);
45 arr = Array(5);
46 tryThis('arr.length = new Number(1);');
47 actual = arr.length;
48 expect = 1;
49 addThis();
50
51 status = inSection(3);
52 arr = Array();
53 tryThis('arr.length = new Number(17);');
54 actual = arr.length;
55 expect = 17;
56 addThis();
57
58 status = inSection(4);
59 arr = Array(5);
60 tryThis('arr.length = new Number(17);');
61 actual = arr.length;
62 expect = 17;
63 addThis();
64
65
66 /*
67 * Also try the above with the "new" keyword before Array().
68 * Array() and new Array() should be equivalent, by ECMA 15.4.1.1
69 */
70 status = inSection(5);
71 arr = new Array();
72 tryThis('arr.length = new Number(1);');
73 actual = arr.length;
74 expect = 1;
75 addThis();
76
77 status = inSection(6);
78 arr = new Array(5);
79 tryThis('arr.length = new Number(1);');
80 actual = arr.length;
81 expect = 1;
82 addThis();
83
84 arr = new Array();
85 tryThis('arr.length = new Number(17);');
86 actual = arr.length;
87 expect = 17;
88 addThis();
89
90 status = inSection(7);
91 arr = new Array(5);
92 tryThis('arr.length = new Number(17);');
93 actual = arr.length;
94 expect = 17;
95 addThis();
96
97
98
99 //-----------------------------------------------------------------------------
100 test();
101 //-----------------------------------------------------------------------------
102
103
104
105 function tryThis(s)
106 {
107 try
108 {
109 eval(s);
110 }
111 catch(e)
112 {
113 // keep going
114 }
115 }
116
117
118 function addThis()
119 {
120 statusitems[UBound] = status;
121 actualvalues[UBound] = actual;
122 expectedvalues[UBound] = expect;
123 UBound++;
124 }
125
126
127 function test()
128 {
129 enterFunc ('test');
130 printBugNumber(BUGNUMBER);
131 printStatus (summary);
132
133 for (var i=0; i<UBound; i++)
134 {
135 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
136 }
137
138 exitFunc ('test');
139 }