Closed
Bug 324500
Opened 20 years ago
Closed 20 years ago
Array bug, when used array[".."] both with toSource()
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: mozilla, Unassigned)
References
()
Details
(Keywords: testcase)
Attachments
(2 files)
User-Agent: Mozilla/5.0 (X11; U; Linux i686; cs; rv:1.8) Gecko/20051111 Firefox/1.5
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; cs; rv:1.8) Gecko/20051111 Firefox/1.5
if you look at that link, you will see 3 methods of arrays
1. and 3. works fine, but i guess 2. method, when you call toSource() works bad.
if you use:
for (a in array) {..} it browse inside whole array, and shows all items, but if you call toSource() it isn't, and if you want print array2 object, it writes nothing.
Reproducible: Always
Comment 1•20 years ago
|
||
Array1 .. Array3 are reporter's testcase, I've added array4, a modified array2
// Array2
var array2 = new Array();
array2["1"] = 'hi';
array2["b"] = 'hello';
array2["c"] = 'fo';
document.write('Array2:<br />');
for (a in array2) {
document.write(a + ':' + array2[a] + '<br />');
}
document.write('Clear: ' + array2 + '<br />'); // BUG
document.write('toSource(): ' + array2.toSource() + '<br /><hr />'); // BUG
Comment 2•20 years ago
|
||
var array4 = new Array();
array4["a"] = 'hi';
array4["2"] = 'hello';
array4["0"] = 'fo';
document.write('Array4:<br />');
for (a in array4) {
document.write(a + ':' + array4[a] + '<br />');
}
document.write('Clear: ' + array4 + '<br />');
document.write('toSource(): ' + array4.toSource() + '<br /><hr />');
Comment 3•20 years ago
|
||
Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.9a1) Gecko/20060122 SeaMonkey/1.5a
view-source:https://bugzilla.mozilla.org/attachment.cgi?id=209442
Minimal testcase Attachment 209442 [details]:
The for loop loops a as "a","2","0" and shows the entries array4[a] in the sequence they've been made.
Accessing array4 as a whole the index loops from 0 through 2, matches entries "2" and "0" and shows them sorted.
Comment 4•20 years ago
|
||
I don't quite understand the focus of this bug report. If it is only about an array's toSource method not showing all properties then it's a duplicate of bug 253138.
| Reporter | ||
Comment 5•20 years ago
|
||
i guess it's not only problem with toSource() method, but in associative array walking.
Comment 6•20 years ago
|
||
Ondrej, I don't see the difference between this bug and bug 253138. Could you please explain what you mean when you mention your problem with associative array walking?
| Reporter | ||
Comment 7•20 years ago
|
||
for example:
document.write('Clear: ' + array2 + '<br />');
if i put
array2["a"]='ble';
array2["b"]='bla';
that document.write writes nothing
in that other bug is reported only toSource()
Comment 8•20 years ago
|
||
Ah, I see. You're talking about Array.prototype.toString as well as Array.prototype.toSource. toString is specified by ECMA-262, section 15.4.4.2 as not including non-integral properties. Brendan, will this bug be covered by bug 253138?
Comment 9•20 years ago
|
||
We can't change toString without changing ECMA, and then we'd need to keep it working as before for default versions (anything that didn't select the new ECMA edition explicitly). So this bug is misfiled -- it really should be a bug filed against the ECMA spec -- and therefore INVALID.
The desire for a better toString() alternative is valid, and it's served by either fixing toSource() and using that, or asking for yet another method, perhaps one that ECMA TG1 can agree on and add to the standard. This could be like the repr method aping Python, found in MochiKit, or similar such in other DHTML libraries.
IMHO we shouldn't just let the old ECMA standard remain a Procrustean bed that causes everyone to reinvent this wheel in higher-level JS libraries that have to be downloaded. We should fix the core language, since it will be around for another decade or more.
But now I am preaching to the choir -- I'll save this for ECMA TG1.
/be
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
Comment 10•20 years ago
|
||
ok but the output of toString is wrong, it's putting too much ","
// Array4
var array4 = new Array();
array4["c"] = 'hi';
array4["2"] = 'hello';
array4["1"] = 'fo';
document.write('Array4:<br />');
for (a in array4) {
document.write(a + ':' + array4[a] + '<br />');
}
document.write('Clear: ' + array4 + '<br />'); // BUG
The last line output "Clear: ,fo,hello" and not "Clear: fo,hello"
Comment 11•20 years ago
|
||
(In reply to comment #10)
> ok but the output of toString is wrong, it's putting too much ","
> var array4 = new Array();
> array4["c"] = 'hi';
> array4["2"] = 'hello';
> array4["1"] = 'fo';
> The last line output "Clear: ,fo,hello" and not "Clear: fo,hello"
No, if you compare with the minimal testcase Attachment 209442 [details]:
var array4 = new Array();
array4["a"] = 'hi';
array4["2"] = 'hello';
array4["0"] = 'fo';
The last line output "Clear: fo,,hello"
The array is accessed with index 0,1,2.
In your testcase 0 doesn't match so you see "Clear: ,fo,hello"
In this testcase 1 doesn't match so you see "Clear: fo,,hello"
You need to log in
before you can comment on or make changes to this bug.
Description
•