Bug 69156

Summary: Implicitly add toString and valueOf to prototype when convertToType callback is provided
Product: WebKit Reporter: Mark Hahnenberg <mhahnenberg>
Component: JavaScriptCoreAssignee: 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 Flags
Patch
none
Test modification none

Mark Hahnenberg
Reported 2011-09-30 10:50:37 PDT
Due to the fact that JSCallbackObject overrides JSCell::toString, I don't believe we can do a simple refactoring to de-virtualize toString like we did with the other conversion methods. We'll just add it to the method table, at least for now. The first step in doing this is to create a static version of toString in the classes that override toString and have the virtual versions call it.
Attachments
Patch (6.24 KB, patch)
2011-10-03 17:32 PDT, Mark Hahnenberg
no flags
Test modification (6.25 KB, patch)
2011-10-03 18:22 PDT, Mark Hahnenberg
no flags
Gavin Barraclough
Comment 1 2011-09-30 15:07:42 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.
Geoffrey Garen
Comment 2 2011-10-02 15:08:15 PDT
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
Mark Hahnenberg
Comment 3 2011-10-03 17:32:57 PDT
Mark Hahnenberg
Comment 4 2011-10-03 18:22:45 PDT
Created attachment 109566 [details] Test modification
Geoffrey Garen
Comment 5 2011-10-03 18:24:50 PDT
Comment on attachment 109566 [details] Test modification r=me
WebKit Review Bot
Comment 6 2011-10-04 12:01:13 PDT
Comment on attachment 109566 [details] Test modification Clearing flags on attachment: 109566 Committed r96627: <http://trac.webkit.org/changeset/96627>
WebKit Review Bot
Comment 7 2011-10-04 12:01:18 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.