Obsolete since JSAPI 44
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.
This article covers features introduced in SpiderMonkey 1.8.6
Converts a JavaScript object to a primitive value, using the semantics of that object's internal [[DefaultValue]]
hook.
Renamed to JS::ToPrimitive
from JSAPI 44.
Syntax
bool JS_DefaultValue(JSContext *cx, JS::Handle<JSObject*> obj, JSType hint, JS::MutableHandle<JS::Value> vp);
Name | Type | Description |
---|---|---|
cx |
JSContext * |
The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
obj |
JS::Handle<JSObject*> |
The object to convert. |
hint |
JSType |
The hint to pass to the [[DefaultValue]] hook when converting the object. hint must be JSTYPE_STRING or JSTYPE_NUMBER to pass the corresponding type as a hint, or JSTYPE_VOID to pass no hint. Do not pass any other type. |
vp |
JS::MutableHandle<JS::Value> |
Out parameter. On success, *vp receives the converted value. |
Description
JS_DefaultValue
converts a JavaScript object, obj
, to a primitive value using that object's [[DefaultValue]]
hook. ECMAScript specifies that all objects have a [[DefaultValue]]
hook. Objects with classes defined by ECMAScript itself all use the [[DefaultValue]]
algorithm specified in §8.12.8 (but note the algorithm's special case for Date objects). Objects with a custom JSClass specified by the embedder will invoke that class's convert hook, which must convert the object to a primitive value, to determine the primitive result of conversion. Behavior when the convert hook is JS_ConvertStub
is identical to that for objects defined by ECMAScript.
On success, JS_DefaultValue
stores the converted value in *vp
and returns true
. On error or exception, it returns false
, and the value left in *vp
is undefined.
See Also
- MXR ID Search for
JS_DefaultValue
JS::ToPrimitive
- bug 1054756 - renamed to
JS::ToPrimitive