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)
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
Comment 1•16 years ago
|
||
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.
Updated•16 years ago
|
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 → ---
Updated•16 years ago
|
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Comment 3•16 years ago
|
||
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.
Comment 4•16 years ago
|
||
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
Comment 6•16 years ago
|
||
Ignore the data:uri in comment #4 as bugzilla have broken it. I have updated the URL of the bug instead to reflect this.
Updated•16 years ago
|
Version: unspecified → 1.9.0 Branch
Updated•16 years ago
|
Assignee: general → brendan
Status: NEW → ASSIGNED
Priority: -- → P1
Target Milestone: --- → mozilla1.9.1
Assignee | ||
Comment 7•16 years ago
|
||
I can't reproduce this bug with TM tip.
Assignee | ||
Comment 8•16 years ago
|
||
I can't reproduce this in a 1.9.1 debug shell.
Assignee: brendan → gal
Assignee | ||
Comment 9•16 years ago
|
||
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.
Updated•16 years ago
|
Flags: blocking1.9.1+
Assignee | ||
Comment 10•16 years ago
|
||
We need a reverse regression window (going back in time until this breaks).
Whiteboard: regression-window-wanted
Comment 11•16 years ago
|
||
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.
Comment 12•16 years ago
|
||
(In reply to comment #11)
Err it was 7 Apr 2009 (verified).
Updated•15 years ago
|
Keywords: regressionwindow-wanted
Whiteboard: regression-window-wanted
Comment 13•15 years ago
|
||
Why is "regressionwindow-wanted" needed? What is missing?
![]() |
||
Comment 14•15 years ago
|
||
(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.
Keywords: regressionwindow-wanted
![]() |
||
Updated•13 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 16 years ago → 13 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•