Closed Bug 284064 Opened 20 years ago Closed 20 years ago

Javascript array initializer creates wrong length array object

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

VERIFIED DUPLICATE of bug 67279

People

(Reporter: cstaylor, Assigned: bugzilla)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050223 Firefox/1.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050223 Firefox/1.0.1

I'm no Javascript expert, but when working with JSON, an object defined like this:
var obj = {children:[,,,,,,,,,]};
window.alert ( obj.children.length ); // 9??

gives a different length result than:
var obj = {children:[,,,,,,,,,"Foo!"]};
window.alert ( obj.children.length ); // 10

This is important when returning arrays of empty objects via JSON.

In IE, both arrays are length 10, which is the proper behavior.

Reproducible: Always

Steps to Reproduce:
Make a simple HTML page:

<SCRIPT LANGUAGE="Javascript" >
var blob = {children:[,,,,,,,,,]};
window.alert(blob.children.length);
</script>

Load the page.

Watch the 9 appear.

Do the same in IE.

Watch the 10 appear
Actual Results:  
9 appears

Expected Results:  
10 should have appeared
Javascript gurus appear to think that IE is wrong here...

*** This bug has been marked as a duplicate of 67279 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Component: General → JavaScript Engine
Product: Firefox → Core
Resolution: --- → DUPLICATE
Version: unspecified → Trunk
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.