Closed
Bug 312759
Opened 20 years ago
Closed 20 years ago
Javascript error. For in array bug, returning 'indexOf' as last element of array, even when array is empty
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: alexbh, Assigned: alexbh)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Firefox/1.0.7 (Debian package 1.0.7-1)
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Firefox/1.0.7 (Debian package 1.0.7-1)
When i am using the 'for (item in array)' even when the array is empty, firefox
returns a elment called 'indexOf' as last item of that array.
Reproducible: Always
Steps to Reproduce:
1. Write a javascript code to create an empty array
2. Use the code "for (item in array)" to navigate in the array.
3. User "alert(item)" in every loop to see the non-existent element "indexOf"
Actual Results:
Firefox return one more item that does not exists
Expected Results:
No "indexOf" item on the array
Comment 1•20 years ago
|
||
->js engine
Assignee: nobody → general
Component: JavaScript Console → JavaScript Engine
Product: Firefox → Core
QA Contact: javascript.console → general
Version: unspecified → 1.7 Branch
Comment 2•20 years ago
|
||
Linux_All_DBG.OBJ/js
js> a = []
js> for (i in a)print(i)
js>
Worksforme. Please give a complete testcase.
/be
Comment 3•20 years ago
|
||
Brendan, this is reported against the 1.7 branch (does that make it FIXED?
INVALID? WONTFIX (not a security bug)?).
Comment 4•20 years ago
|
||
Actually, I can't even reproduce this in a 1.7 build. I guess a full testcase is
needed.
Comment 5•20 years ago
|
||
Right, I tried my SpiderMonkey build from AVIARY_1_0_1_20050124_BRANCH and it
works as expected. We need a testcase file attached to this bug.
/be
Assignee: general → alexbh
What happends is that when I add a new function to an array prototype, doing that:
Array.prototype.getLast = function() {
return this[this.length-1];
}
and do the "for (item in array)" on an array, that function are returned as an
array element. Is that right? Is that the way mozilla should respond???
Comment 7•20 years ago
|
||
This bug is confusingly summarized and reported. The problem is not the
built-in indexOf method being enumerable by for-in loops over arrays. The
reported problem is that a user-defined property is enumerable. That's how JS
works, however, so INVALID. If you want to enumerate only the elements (indexed
properties), use a for (i = 0; i < a.length; i++) loop.
/be
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•