[Webkit-unassigned] [Bug 26382] New: [ES5] Implement Function.prototype.bind

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Jun 13 23:17:56 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=26382

           Summary: [ES5] Implement Function.prototype.bind
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: All
        OS/Version: All
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: tav at espians.com


ES5 adds a bind() method to Function.prototype as pioneered by the Prototype
Library.

  Function.prototype.bind (thisArg [, arg1 [, arg2, …]]) 

It is defined in §15.3.4.5 of
http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf

--------------------------------------------------

The bind method takes one or more arguments, thisArg and (optionally) arg1,
arg2, etc, and returns a new function object by performing the following steps: 

1. Let Target be the this value. 

2. If IsCallable(Target) is false, throw a TypeError exception. 

3. Let A be a new (possibly empty) internal list of all of the argument values
provided after thisArg (arg1, arg2 etc), in order. 

4. Let F be a new native ECMAScript object . 

5. Set the [[TargetFunction]] internal property of F to Target. 

6. Set the [[BoundThis]] internal property of F to the value of thisArg. 

7. Set the [[BoundArgs]] internal property of F to A. 

8. Set the [[Class]] internal property of F to "Function". 

9. Set the [[Prototype]] internal property of F to the standard built-in
Function prototype object as  specified in 15.3.3.1. 

10. Set the [[Call]] internal property of F as described in 15.3.4.5.1. 

11. Set the [[Construct]] internal property of F as described in 15.3.4.5.2. 

12. Set the [[HasInstance]] internal property of F as described in 15.3.4.5.3. 

13. The [[Scope]] internal property of F is unused and need not exist. 

14. If the [[Class]] internal property of Target is "Function", then 

a. Let L be the length property of Target minus the length of A. 
b. Set the length own property of F to either 0 or L, whichever is larger.  

15. Else set the length own property of F to 0. 

16. The length own property of F is given attributes as specified in 15.3.5.1. 

17. Set the [[Extensible]] internal property of F to true. 

18. Call the [[DefineOwnProperty]] internal method of F with arguments
"caller", PropertyDescriptor {[[Value: null, [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false}, and false. 

19. Call the [[DefineOwnProperty]] internal method of F with arguments
"arguments", PropertyDescriptor {[[Value: null, [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: false}, and false. 

20. Return F. 

Note: The length property of the bind method is 1. 

Note: Function objects created using Function.prototype.bind do not have a
prototype property. 

[[Call]] 

When the [[Call]] internal method of a function object, F, which was created
using the bind function is called with a this value and a list of arguments
ExtraArgs the following steps are taken: 

1. Let boundArgs be the value of F‘s [[BoundArgs]] internal property. 

2. Let boundThis be the value of F‘s [[BoundThis]] internal property. 

3. Let target be the value of F‘s [[TargetFunction]] internal property. 

4. Let args be a new list containing the same values as the list boundArgs in
the same order followed by the same values as the list ExtraArgs in the same
order. 

5. Return the result of  calling the [[Call]] internal method of target
providing boundThis as the this value and providing args as the arguments. 

[[Construct]] 

When the [[Construct]] internal method of a function object, F that was created
using the bind function is called with a list of arguments ExtraArgs the
following steps are taken: 

1. Let target be the value of F‘s [[TargetFunction]] internal property. 

2. If target has no [[Construct]] internal method, a TypeError exception is
thrown. 

3. Let boundArgs be the value of F‘s [[BoundArgs]] internal property. 

4. Let args be a new list containing the same values as the list boundArgs in
the same order followed by the same values as the list ExtraArgs in the same
order. 

5. Return the result of  calling the [[Construct]] internal method of  target
providing Args as the arguments. 

[[HasInstance]] (V) 

When the [[HasInstance]] internal method of a function object F, that was
created using the bind function is called with argument V the following steps
are taken: 

1. Let target be the value of F‘s [[TargetFunction]] internal property. 

2. If target has no [[HasInstance]] internal method, a TypeError exception is
thrown. 

3. Return the result of  calling the [[HasInstance]] internal method of target
providing V as the argument. 

--------------------------------------------------

In order to facilitate the implementation of .bind(), Object now has a number
of internal properties. These are defined in §8.6.2 of the spec.

Property: [[TargetFunction]]
Value Type Domain: Object

The target function of a function object created using the standard built-in
Function.prototype.bind method. Only ECMAScript objects created using
Function.prototype.bind have a [[TargetFunction]] internal property. 

Property: [[BoundThis]]
Value Type Domain: any

The pre-bound this value of a function Object created using the standard
built-in Function.prototype.bind method. Only ECMAScript objects created using
Function.prototype.bind have a [[BoundThis]] internal property. 

Property: [[BoundArguments]]
Value Type Domain: List of any

The pre-bound argument values of a function Object created using the standard
built-in Function.prototype.bind method. Only ECMAScript objects created using
Function.prototype.bind have a [[BoundArguments]] internal property. 

See http://www.prototypejs.org/api/function/bind for the inspiration which led
to .bind() becoming part of the spec.


-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list