Closed Bug 577840 Opened 16 years ago Closed 3 years ago

calling JSClass::convert before toString

Categories

(Core :: JavaScript Engine, enhancement)

Other Branch
enhancement

Tracking

()

RESOLVED INVALID

People

(Reporter: igor, Unassigned)

References

Details

Currently JSClass::convert effectively is not called when converting object to a string. DefaultObject from jsobj.cpp tries to call the convert method only when a toString method does not exist in the object or its prototype chain or when ToString returns an object. In practice it means that to provide a custom toString conversion the embedding must ensure that the object has proper toString implementation. Embedding could be forced to do that even if it wants just to provide a custom toNumber conversion to ensure that an object behaves like a number in cases like String(object). It also makes the string hint handling in DefaultObject special complicating the code. This suggests either 1. To change DefaultObject to always call JSClass::convert before trying toString and valueOf methods. or 2. To remove JSClass::convert and state that to overwrite the conversions the implementation should always provides toString and valueOf methods. In view of ES5 facilities to define read-only permanent properties the case 2 is preferable from code complexity point of view. But that depends on the usage of the convert hook.
I do not think we should remove JSClass::convert, so plan 1 sounds good. /be
Assignee: igor → general
Assignee: general → nobody
Severity: normal → S3
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.