This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
JSObjectOps is not a supported API. Details of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details.
JSClass.convert callbacks to convert objects to primitive values.
typedef JSBool (*JSConvertOp)(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
||Pointer to the JS context in which the conversion is needed.|
||The object to be converted.|
||The target type.|
||Out parameter. On success, the callback must store the converted value here.|
JSObjectOps.defaultValue callback corresponds to the [[DefaultValue]] method defined in ECMA 262-3 §184.108.40.206. Many expressions in the ECMAScript language, such as
a+b, involve implicit conversion of the operands using [[DefaultValue]].
obj.toString(). Provide a custom
JSObjectOps.defaultValue callback to implement customized [[DefaultValue]] behavior.
JSClass.convert callback should convert
obj to the given
JS_TRUE with the resulting value in
*vp on success, and returning
JS_FALSE on error or exception. On success,
*vp must be a primitive value: per ES5 §8.12.8, every object "must ensure that its [[DefaultValue]] internal method can return only primitive values." Debug builds of SpiderMonkey will assert if a convert callback is successful but leaves
*vp holding a primitive value.
JS_ConvertStub implements the default behavior for the
JSClass.convert hook, which is to call
obj.toString() in accordance with the algorithm in ES5 §8.12.8.