Closed Bug 41864 Opened 24 years ago Closed 24 years ago

ECMA function call incompatibility

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: waldemar, Assigned: brendan)

Details

(Keywords: js1.5)

Attachments

(1 file)

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'.
Adding js1.5.  Patch coming up.

/be
Assignee: rogerl → brendan
Keywords: js1.5
Adding more JS1.5 buddies.

/be
Status: NEW → ASSIGNED
Target Milestone: --- → M17
Attached patch proposed fixSplinter Review
Priority: P3 → P1
Fix checked in.  Thanks pschwartau for the thumbs-up regression testing.

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

Attachment

General

Created:
Updated:
Size: