Summary: | Implicitly add toString and valueOf to prototype when convertToType callback is provided | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Mark Hahnenberg <mhahnenberg> | ||||||
Component: | JavaScriptCore | Assignee: | Mark Hahnenberg <mhahnenberg> | ||||||
Status: | RESOLVED FIXED | ||||||||
Severity: | Normal | CC: | barraclough, ggaren, webkit.review.bot | ||||||
Priority: | P2 | ||||||||
Version: | 528+ (Nightly build) | ||||||||
Hardware: | Unspecified | ||||||||
OS: | Unspecified | ||||||||
Bug Depends on: | |||||||||
Bug Blocks: | 67690, 69677, 69679 | ||||||||
Attachments: |
|
Description
Mark Hahnenberg
2011-09-30 10:50:37 PDT
I wonder if we really need to do this? ToString applied to Object (JSObject::toString) will try looking up a default value using the object's toString property, if one exists. For API objects that define a custom toString we could implicitly add a toString property to the object that is a host function that would call the API class's toString callback. This would allow us to retire the ability to override toString, and make API object behave more like normal objects. ggaren: mhahnenberg: i'd suggest a two-step process: [9:51pm] ggaren: mhahnenberg: (1) change API classes to supply a custom toString and valueOf on the class's prototype, which forwards to classDefinition.convertToType, if classDefinition.convertToType is supplied, and add tests to testapi verifying this behavior. [9:52pm] ggaren: mhahnenberg: (2) make toString non-virtual [9:53pm] ggaren: mhahnenberg: internally, you can reuse JSCallbackFunction to implement (1) [9:54pm] ggaren: mhahnenberg: you can have a shared JSObjectCallAsFunctionCallback for toString, and another for valueOf [9:54pm] ggaren: mhahnenberg: and they just take the 'this' object supplied, check that it inherits from JSCallbackObject, cast to JSCallbackObject, grab the convertToType function out of the JSCallbackObject's class, and call it, passing the right JSType parameter Created attachment 109561 [details]
Patch
Created attachment 109566 [details]
Test modification
Comment on attachment 109566 [details]
Test modification
r=me
Comment on attachment 109566 [details] Test modification Clearing flags on attachment: 109566 Committed r96627: <http://trac.webkit.org/changeset/96627> All reviewed patches have been landed. Closing bug. |