Closed
Bug 281930
Opened 21 years ago
Closed 21 years ago
|this| is set to wrong value inside function expression
Categories
(Core :: JavaScript Engine, defect, P3)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
mozilla1.8beta2
People
(Reporter: jerfa, Assigned: brendan)
Details
(Whiteboard: [have patch])
Attachments
(3 files, 1 obsolete file)
After executing the following line,
var rv = function() { return this; }();
rv should be a reference to the global object. It is a reference to the
anonymous function instead.
| Reporter | ||
Comment 1•21 years ago
|
||
Expected output:
true
[object Window]
Actual output:
false
function () { return this; }
Comment 2•21 years ago
|
||
you are testing a reference to the function against windows and not the return
value of calling the function. INVALID.
| Reporter | ||
Comment 3•21 years ago
|
||
Please look at my testcase again: I'm calling the function but I don't get the
expected return value. This works as I expect in IE6, Opera, Netscape 4.75 and
Rhino.
Comment 4•21 years ago
|
||
Sorry, I missed the trailing () call on the function expression.
var rv = function() { return this; }();
sets rv to the function rather than the result of calling the expression.
var rv = (function() { return this; })();
will work. The bug isn't about |this| being wrong but is about the () call
being ignored.
Attachment #174041 -
Attachment is obsolete: true
| Reporter | ||
Comment 5•21 years ago
|
||
Sorry, but that's not right either. If you modify the line to
var rv = function() { alert("Yo"); return this; }();
you'll see the function gets called properly.
Comment 6•21 years ago
|
||
you are right. If you change the alert("Yo") to alert(this) you see that |this|
is the function expression.
| Assignee | ||
Comment 7•21 years ago
|
||
I'm going to check this in when the trunk opens; shaver, feel free to stamp r=
any time.
/be
Attachment #174076 -
Flags: review?(shaver)
| Assignee | ||
Updated•21 years ago
|
Assignee: general → brendan
Priority: -- → P3
Target Milestone: --- → mozilla1.8beta2
Comment 8•21 years ago
|
||
Comment on attachment 174076 [details] [diff] [review]
fix
r=shaver
Attachment #174076 -
Flags: review?(shaver) → review+
| Assignee | ||
Updated•21 years ago
|
Status: NEW → ASSIGNED
Whiteboard: [have patch]
Comment 9•21 years ago
|
||
Trunk's open...
| Assignee | ||
Comment 10•21 years ago
|
||
So it is, thanks for the nudge.
/be
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Comment 12•21 years ago
|
||
js/tests/js1_5/Regress/regress-281930.js checked in with Erik's permission.
Updated•20 years ago
|
Flags: testcase+
You need to log in
before you can comment on or make changes to this bug.
Description
•