Closed
Bug 134828
Opened 24 years ago
Closed 24 years ago
Declaring arrays 'new Array(x)' will return a single element array containing x.
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
VERIFIED
WORKSFORME
People
(Reporter: knifehandz, Assigned: rogerl)
References
(
URL
)
Details
(Whiteboard: [js1.2])
Attachments
(2 files)
In IE4 & above and also NS4, Obj1=new Array(6) will return an array with
length equal to 6; but in Mozilla then length will equal to 1 instead of 6 -
with Obj1[0]==6.
Comment 1•24 years ago
|
||
Eric, which build version of Mozilla are you using? Look for the Build ID in
the title bar of your browser. This works as expected for me in a freshly
updated linux CVS build, and on linux 2002032717.
If this indeed is a regression on Windows (as reported), it would be pretty
serious, so I'm pre-emptively upgrading the severity to major.
Severity: normal → major
Comment 2•24 years ago
|
||
Adding simple testcase to the URL field of this bug.
URL: javascript:var foo = new Array(6); if...
// --- Begin of Script
function obtuseRect(offX,offY,rx,ry,height,zIndex,colorA,colorB,direction) {
this.offX=offX || 0;
this.offY=offY || 0;
this.height=(!height || height>90)? 90: Math.round(height);
this.zIndex=zIndex || 10;
this.direction=direction || 'up';
this.coordsX=new Array();
this.coordsY=new Array();
this.coordsX.length=this.coordsY.length=this.height;
colorA=(colorA && colorA!='')? colorA: colorB? colorB: '#FF0000';
colorB=(colorA==colorB || colorB=='')? null: colorB;
switch(this.direction) {
case 'down':
DynAPI.functions.arcCoords(rx,ry,this.coordsX,this.coordsY,3);
break;
case 'left':
DynAPI.functions.arcCoords(rx,ry,this.coordsX,this.coordsY,2);
break;
case 'right':
if(colorB) { // Switch the colors so it draws from left to right
var temp=colorB;
colorB=colorA;
colorA=temp;
}
DynAPI.functions.arcCoords(rx,ry,this.coordsX,this.coordsY,4);
break;
default:
if(colorB) { // Switch the colors so it draws from top to bottom.
var temp=colorB;
colorB=colorA;
colorA=temp;
}
DynAPI.functions.arcCoords(rx,ry,this.coordsX,this.coordsY,1);
break;
}
if(colorB) { // Problem Occurs here
this.colors=new Array(); // Originally 'this.colors=new Array
(this.height);
this.colors.length=this.height; // Inserted to use in Mozilla ...
DynAPI.functions.fadeColors(colorA,colorB,this.colors);
}
else { this.color=colorA; }
return this;
}
// ---- End of Script
I'm using build 2002020406 ... for the simple tests in objects like
function testobj(arrayTest) { if(arrayTest.length==6) { alert('ok!'); } }
function testfunc() { this.arrayTest=new Array(6); this.obj=new testobj
(this.arrayTest); }
var x=new testfunc();
would work; but the script that I wrote didn't practically work in Mozilla.
I'm not sure if this is the bug of declaring arrays ... but during creation
time I gave the parameters:
var Obj1=new obtuseRect(100,100,50,60,20,15,'#FFFFFF','#FF0000','up');
So the array length should be like the height, it works for simple tests but
just not this script. If it's simply my mistake, please disregard this bug
report, but I found it working without the "this.colors.length=this.height" on
IE>=4 and NS4, but not Mozilla.
URL: javascript:var foo = new Array(6); if...
QA Contact: pschwartau
Summary: Declaring arrays 'new Array(x)' will return a single element array containing x. → I have a script that doesn't pass the test ...
URL: javascript:var foo = new Array(6); if...
QA Contact: pschwartau
Summary: I have a script that doesn't pass the test ... → Declaring arrays 'new Array(x)' will return a single element array containing x.
Comment 4•24 years ago
|
||
This testcase has the code from comment #3 and just takes out the DynAPI calls.
It worksforme on Linux.... Eric, are you seeing a problem with it on Windows?
Comment 5•24 years ago
|
||
Comment 6•24 years ago
|
||
If you try Boris' testcase with <SCRIPT language="JavaScript1.2">,
you see the problem. The reason is, the behavior of the Array() constructor
is different in JavaScript 1.2 than in any other Netscape implementation.
Here is an example from the standalone JS shell:
------------------------------- JS1.5 --------------------------------
js> var arr = new Array(6);
js> arr.toSource();
[, , , , , , ]
------------------------------- JS1.2 --------------------------------
js> version(120);
0
js> version(120);
120
js> var arr = new Array(6);
js> arr.toSource();
[6]
------------------------------- JS1.1 --------------------------------
js> version(110);
120
js> version(110);
110
js> var arr = new Array(6);
js> arr.toSource();
[, , , , , , ]
OS: Windows XP → All
Comment 7•24 years ago
|
||
Have to mark this one as WORKSFORME. The behavior Eric describes
does occur if one specifies language="JavaScript1.2" in the <SCRIPT>
tag. We cannot change the behavior of an historical version, however,
because some websites depend on it.
The moral is: don't specify version 1.2 unless you intend to use the
specific traits it has. Intsead, use <SCRIPT language="JavaScript">.
Historical note: Netscape released JS1.2 before the ECMA-262 spec
was finished. Because of that, Netscape JS1.2 has some quirks that
make it different from all other implementations of ECMAScript.
Status: UNCONFIRMED → RESOLVED
Closed: 24 years ago
Resolution: --- → WORKSFORME
Comment 8•24 years ago
|
||
Marking Verified. Thanks to Boris and Christopher for their help on this!
Status: RESOLVED → VERIFIED
Updated•22 years ago
|
Whiteboard: [js1.2]
You need to log in
before you can comment on or make changes to this bug.
Description
•