If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

ECMA function call incompatibility

RESOLVED FIXED in M17

Status

()

Core
JavaScript Engine
P1
normal
RESOLVED FIXED
18 years ago
16 years ago

People

(Reporter: Waldemar Horwat, Assigned: brendan)

Tracking

({js1.5})

Trunk
js1.5
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

18 years ago
name='win';
obj1={name:'obj1'};
obj1.f=function(){alert(this.name)}
obj2={name:'obj2'};
(obj2.f=obj1.f)();

(replace 'alert' with 'print' in JSRef).

The code above should print 'win'.  It prints 'obj2'.
Another test case is:

(obj2.f,obj1.f)();

This should also print 'win'.  It prints 'obj1'.

The reason is as follows:

Step 3 of ECMA 11.13.1 calls GetValue, which turns a reference to a regular 
value.  That value is then returned in step 5.  A function call (section 11.2.3) 
looks to see if the function is a reference or a regular value.  If it's a 
reference then it extracts its base and assigns it to the "this" variable.  If 
it's a regular value, then the "this" variable becomes null (step 6 of 11.2.3).  
The [[call]] method then changes "this" to point to the global object (the last 
paragraph of 10.2.3).  That's why this.name should be 'win'.
(Assignee)

Comment 1

18 years ago
Adding js1.5.  Patch coming up.

/be
Assignee: rogerl → brendan
Keywords: js1.5
(Assignee)

Comment 2

18 years ago
Adding more JS1.5 buddies.

/be
Status: NEW → ASSIGNED
Target Milestone: --- → M17
(Assignee)

Comment 3

18 years ago
Created attachment 9807 [details] [diff] [review]
proposed fix
(Assignee)

Updated

18 years ago
Priority: P3 → P1
(Assignee)

Comment 4

18 years ago
Fix checked in.  Thanks pschwartau for the thumbs-up regression testing.

/be
Status: ASSIGNED → RESOLVED
Last Resolved: 18 years ago
Hardware: Macintosh → All
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.