Closed Bug 299644 Opened 19 years ago Closed 19 years ago

Javascript's concat doesn't verify, if the properties exist.

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: mozilla, Assigned: mrbkap)

Details

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.0 (like Gecko)
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) 

According to ECMAscript spec (section 15.4.4.4 step 9) the concat 
function should test (for each element < array.length), if the array has 
an entry. An concat on an empty array (of non-0 length) should therefore 
produce an empty array. 

Reproducible: Always
the array "b", should be empty, as "a" doesn't contain any property.
a "for ... in" should therefore not print anything.
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.7 Branch
I think we may actually be following the spec here. Notice that step 9 says to
go to step 13 if the property doesn't exist, but step 13 is incrementing n, so
in the new array, this location would be a "hole" in the new array also. Also
notice that step 22 sets the new array's length to be n, which in this case
would be 10 (per step 13), giving us the correct answer. Am I missing anything?

Note: I have a patch that reflects the spec. a bit better than the current code
(and avoids calling OBJ_SET_PROPERTY() for the holes) that I'll attach in a
second, but it preserves the same behavior (as far as I can tell) on the given
testcase.
Version: 1.7 Branch → Trunk
I'm not sure if we want this patch. I *think* it's more "correct" than the
current code, but I guess Brendan or Shaver get the final call on this.
mrbkap's right, the bug is INVALID as stated in comment 0 -- see ECMA-262 Ed. 3,
15.4.4.4 steps 9, 13, and 22.

mrbkap: do you want to morph this bug, or is there a better bug in which to
patch SpiderMonkey to preserve holes?

/be
I'll mark this as INVALID and open a new bug to audit for Spidermonkey plugging
holes in arrays.
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → INVALID
as far as I understood, in the test-case b should be identical to a. But when 
I do "for(var v in a) alert(v);" I will get no alert, but "for(var v in b) 
alert(v)" will alert ten times. Maybe my version is just too old (but I even 
tried on a 1.7.8). 
Maybe the given patch fixes this, but in this case it shouldn't be "invalid". 
(In reply to comment #6)
> as far as I understood, in the test-case b should be identical to a. But when 
> I do "for(var v in a) alert(v);" I will get no alert, but "for(var v in b) 
> alert(v)" will alert ten times. Maybe my version is just too old (but I even 
> tried on a 1.7.8). 

No, your version is not too old, but the summary in comment 0 is still invalid.
 (new Array(10).concat()).length must be 10 by ECMA-262 Ed. 3.

> Maybe the given patch fixes this, but in this case it shouldn't be "invalid". 

The bug where we fill holes enumerably is valid, you're right.  The claim that
the concat result should be empty as in zero length is still invalid.

mrbkap, let's make progress here with a spot fix, ok?

/be
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Comment on attachment 188222 [details] [diff] [review]
the promised patch

r+a=me, thanks.

/be
Attachment #188222 - Flags: review+
Attachment #188222 - Flags: approval1.8b3+
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Assignee: general → mrbkap
Status: ASSIGNED → NEW
Status: NEW → ASSIGNED
Fix checked in. I filed bug 299738 on the more general problem of jsarray.c
functions plugging holes in arrays.
Status: ASSIGNED → RESOLVED
Closed: 19 years ago19 years ago
Resolution: --- → FIXED
Flags: testcase?
Checking in regress-299644.js;
/cvsroot/mozilla/js/tests/js1_5/Array/regress-299644.js,v  <--  regress-299644.js
initial revision: 1.1
Flags: testcase? → testcase+
verified fixed 1.9 20060818
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: