Closed Bug 494896 Opened 16 years ago Closed 13 years ago

functions assigned in a loop in window scope are not unique

Categories

(Core :: JavaScript Engine, defect, P1)

1.9.0 Branch
x86
Windows XP
defect

Tracking

()

RESOLVED WORKSFORME
mozilla1.9.1

People

(Reporter: firefox, Assigned: gal)

References

()

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 //example 1 var a = [{},{}]; for(var i = 0; i < a.length; ++i) a[i].f = function(){}; alert(a[0].f === a[1].f); //expect "false" //result "true" //example 2 var a = [{},{}]; (function(){ for(var i = 0; i < a.length; ++i) a[i].f = function(){}; })(); alert(a[0].f === a[1].f); //expect "false" //result "false" Reproducible: Always
Even simplify it more: a = function(){}; b = function(){}; a === b Returns false. b === b returns true. You want true in both cases. I'd believe such a compare would treat to compare the two as prototypes. In which case it would be true... But a == b is false because a is not b in which case it will always be false. The use-case for === is: Returns true if the operands are equal and of the same type.
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → INVALID
I expect a[0].f and a[1].f to be distinct references in both cases (they are not in example 1, are in example 2 with the only difference being the assignment of the f property inside an anonymous function).
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
After investigating a little more and some discussion with mzz in #firefox, then its found that var a = [{},{}]; for(var i = 0; i < a.length; ++i) a[i].f = function(){}; alert(a[0].f === a[1].f); In fact returns true on a webpage, but returns false in .xul documents (including browser.xul which I tested against). Should be found out why we have this difference.
It seems to be some strange cases where it actually returns true on a webpage, but to always get it to return true: Copy to url bar: data:text/html;charset=utf-8,<script>%0D%0Avar a %3D [{}%2C{}]%3B%0D%0Afor(var i %3D 0%3B i < a.length%3B %2B%2Bi) a[i].f %3D function(){}%3B%0D%0Aalert(a[0].f %3D%3D%3D a[1].f)%3B%0D%0A<%2Fscript> This renders true in Firefox 3.0 and false in Firefox 3.5
Status: UNCONFIRMED → NEW
Ever confirmed: true
Aye, blocking. :-/
Flags: blocking1.9.1+
Ignore the data:uri in comment #4 as bugzilla have broken it. I have updated the URL of the bug instead to reflect this.
Version: unspecified → 1.9.0 Branch
Assignee: general → brendan
Status: NEW → ASSIGNED
Priority: -- → P1
Target Milestone: --- → mozilla1.9.1
I can't reproduce this bug with TM tip.
I can't reproduce this in a 1.9.1 debug shell.
Assignee: brendan → gal
This returns true in 3.0, which I think is wrong. It correctly returns false in 3.5/TM/trunk and branch (1.9.1). In other words this is correct in 3.5, but wrong in 3.0. Should this be documented? var a = [{},{}]; for(var i = 0; i < a.length; ++i) a[i].f = function(){}; alert(a[0].f === a[1].f); Suggested action: unblock for 3.5 (its fixed), but bisect and find fix.
Flags: blocking1.9.1+
We need a reverse regression window (going back in time until this breaks).
Whiteboard: regression-window-wanted
Not sure if I understand it correctly, but this was fixed on trunk on 20 Apr 2009: http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=d056669074c7&tochange=57213af4a45d Talking about the first example in comment 0.
(In reply to comment #11) Err it was 7 Apr 2009 (verified).
Whiteboard: regression-window-wanted
Why is "regressionwindow-wanted" needed? What is missing?
(In reply to comment #11) Removing the KW. Must have been fixed by Bug 479198, Bug 481514 or Bug 452498 (Typo in the Pushlog)) and all of them landed on TM Branch on the same Day and on 1.9.1 Branch too.
Status: ASSIGNED → RESOLVED
Closed: 16 years ago13 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.