2) We can define, in the Web IDL, how an object can be converted to a
primitive type.
Specifically, in an ecmascript binding we can do the following (note:
returns means to stop the steps):
- if object is null, return null
- if object has a member function called valueOf, invoke valueOf in the
context of object
- if the returned value is a primitive type, return the value,
- if object has a member function called toString, invoke toString in
the context of object
- if the returned value is a primitive type, return the value,
- return Object.prototype.toString.call(object), so we get "[object
Class]"
ECMAScript defines a ToPrimitive conversion (Section 9.1 of ECMA-262 5th
edition). I think the right thing to do would be for some spec to point
to those steps. Probably it has to be Web Database, because in many
cases where a Web IDL method takes an "any" type, it's not appropriate
to do ToPrimitive conversion.
Indeed !
--
João Eiras
Core Developer, Opera Software ASA, http://www.opera.com/