Mark: considering that explicitly invoking a builtin prototype method,
expecting a throw, to test for the [[Call]] internal slot, was the branding
approach the committee agreed to preserve when it reaffirmed
Symbol.toStringTag, as an alternative to `Object#toString.call`, I think
Claude's point ("The expectation is not that `F.p.toString` will always
return something useful; it is that, for any callable object, it will
return a string and not throw, because it was so since the dawn of JS.") is
the one that convinces me.Shouldn't tests in existing code that rely on `Function#toString` not throwing to indicate that something is callable, or throwing to indicate that it is not, remain true for a function proxy? On Tue, Oct 27, 2015 at 7:52 AM, Mark S. Miller <[email protected]> wrote: > Notice that whatever we decide on the issue, functionProxy.toString() will > work regardless, since you'd be getting the toString method itself through > the membrane. functionProxy.toString will be a function proxy for the > target.toString method. The invocation on the toString proxy with > functionProxy as this will be translated by the membrane back into an > invocation of target.toString with target as this. > > The issue we're debating is only relevant on an edge case -- when > explicitly invoking F.p.toString.call(functionProxy). > > > > On Tue, Oct 27, 2015 at 10:04 AM, Claude Pache <[email protected]> > wrote: > >> >> > Le 27 oct. 2015 à 14:14, Boris Zbarsky <[email protected]> a écrit : >> > >> > On 10/27/15 4:35 AM, Claude Pache wrote: >> >> it is that, for any callable object, it will return a string and not >> throw, because it was so since the dawn of JS. >> > >> > It's totally false for random "host objects" with a [[Call]] in ES5, >> per spec and in at least some implementations. As you can tell in Firefox >> for example: >> > >> > Function.prototype.toString.call(document.createElement("object")) >> > >> > (though it does not throw for document.all in Firefox, for interesting >> implementation reasons). >> > >> >> That function will work (in the sense of: will return an answer; I'm >> not judging the quality of that answer) with anything reasonable fed to it >> (where "reasonable" excludes things like `(class { static toString() { >> throw "pwnd!" }})`). >> > >> > Won't work with an HTMLObjectElement in at least some browsers. How >> "reasonable" that is, who knows. >> > >> > -Boris >> >> You're right. But since `document.createElement("object")` does not >> inherit from `Function.prototype`, the code (`f.toString()`) accidentally >> works after all. >> >> (I've tried not to be too smart in my example by writing `f.toString()` >> instead of `Function.prototype.toString.call(f)`. Maybe I should have been >> even less smart by defining an instance method on `Function.prototype` >> instead of a static method on `Function`...) >> >> —Claude >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> > > > > -- > Cheers, > --MarkM > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

