Bug 10782

Summary: Classes should not override JSObject::toString(ExecState *)
Product: WebKit Reporter: mitz
Component: WebCore JavaScriptAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, ggaren, sam
Priority: P2    
Version: 420+   
Hardware: Mac   
OS: OS X 10.4   
Attachments:
Description Flags
Test matrix for an HTML element
none
Unfinished patch
none
updated patch sam: review+

Description mitz 2006-09-08 04:59:42 PDT
JSObject::toString(ExecState *) implements the (internal) ToString type conversion operator defined in ECMA-262 9.8. That definition applies to all objects, so classes deriving from JSObject should not -- and have no reason to -- override toString.

The correct way to customize the string representation of host objects is to implement in their prototype either a toString() method or the [[DefaultValue]]() internal method. (The native [[DefaultValue]] uses toString, but Firefox compatibility will probably require overriding [[DefaultValue]] as well).
Comment 1 mitz 2006-09-08 05:08:26 PDT
Created attachment 10454 [details]
Test matrix for an HTML element

This table shows the value of several expressions that (should) invoke ToString, ToPrimitive, [[DefaultValue]], and possibly toString and valueOf.

The table shows that, assuming it follows the spec, Firefox overrides [[DefaultValue]] so that when it's called without a hint, it does not invoke valueOf.

Classes that currently override JSObject::toString() are DOMObject, DOMNode, JSHTMLElement, Window, FrameArray, Location, Selection and History.
Comment 2 mitz 2007-03-04 11:32:11 PST
Created attachment 13473 [details]
Unfinished patch
Comment 3 Sam Weinig 2007-05-31 16:46:16 PDT
Created attachment 14815 [details]
updated patch
Comment 4 Sam Weinig 2007-05-31 20:26:40 PDT
Comment on attachment 14815 [details]
updated patch

Geoff gave me the thumbs up on this baby!
Comment 5 Sam Weinig 2007-05-31 20:27:04 PDT
Landed in r21927.