Bug 10782 - Classes should not override JSObject::toString(ExecState *)
Summary: Classes should not override JSObject::toString(ExecState *)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-08 04:59 PDT by mitz
Modified: 2007-05-31 20:27 PDT (History)
3 users (show)

See Also:


Attachments
Test matrix for an HTML element (4.39 KB, text/html)
2006-09-08 05:08 PDT, mitz
no flags Details
Unfinished patch (10.28 KB, patch)
2007-03-04 11:32 PST, mitz
no flags Details | Formatted Diff | Diff
updated patch (32.01 KB, patch)
2007-05-31 16:46 PDT, Sam Weinig
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.