WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
153909
Bound functions toString method should return "bound " + the target function's toString()
https://bugs.webkit.org/show_bug.cgi?id=153909
Summary
Bound functions toString method should return "bound " + the target function'...
Nikita Vasilyev
Reported
2016-02-04 21:10:08 PST
Via
Bug 153796
[ES6] bound functions .name property should be "bound " + the target function's name We improved bound functions .name, but .toString() wasn't affected.
> function foo() {return 42} > boundFunc = foo.bind(null) > boundFunc.name
< "bound foo"
> boundFunc.toString()
< "function foo() { [native code] }" What if we return the following instead:
> boundFunc.toString()
< "function bound foo() {return 42}" or this:
> boundFunc.toString()
< "bound function foo() {return 42}" I have no preference. Two things are different from the current behavior: 1. Instead of "[native code]", the original content of the function is shown. This is much more convenient for debugging. Currently, all anonymous functions look alike: function () { [native code] } 2. Added "bound" prefix. This is just an idea; I don't think ES6 spec touches this point. What do you think?
Attachments
Add attachment
proposed patch, testcase, etc.
Saam Barati
Comment 1
2016-02-05 14:11:37 PST
(In reply to
comment #0
)
> Via
Bug 153796
[ES6] bound functions .name property should be "bound " + the > target function's name > > We improved bound functions .name, but .toString() wasn't affected. > > > function foo() {return 42} > > boundFunc = foo.bind(null) > > boundFunc.name > < "bound foo" > > boundFunc.toString() > < "function foo() { > [native code] > }" > > > What if we return the following instead: > > > boundFunc.toString() > < "function bound foo() {return 42}" > > or this: > > > boundFunc.toString() > < "bound function foo() {return 42}" > > I have no preference. > > Two things are different from the current behavior: > > 1. Instead of "[native code]", the original content of the function is shown. > This is much more convenient for debugging. Currently, all anonymous > functions look alike: > > function () { > [native code] > }
Depending on how we do this, it's not spec compliant. toString() needs to return a string that if eval()ed in the original context, would reproduce an identical function. Or, if that's not possible, the toString(), when eval()ed, must throw a syntax error. We could achieve a syntax error with your proposal of: "function bound foo { return 42; }" And I considered doing this. But, there is new a new proposal that would require the use of "[native code]" here:
https://raw.githubusercontent.com/michaelficarra/Function-prototype-toString-revision/fc69a0a31dc6d625736bfbb712ac782eb241ff3d/proposal.html
Saam Barati
Comment 2
2016-02-05 14:13:51 PST
though that proposal is a bit ambiguous. It says that it's implementation dependent if the bound function contains info about its target. But, it also says that it must comply with "the rules below", which would lead me to think we must show "[native code]"
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug