This article covers features introduced in SpiderMonkey 45
Converts a JavaScript object to a primitive value, using the semantics of ToPrimitive
.
Syntax
bool JS::ToPrimitive(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue 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::HandleObject |
The object to convert. |
hint |
JSType |
The hint to pass to the ToPrimitive and @@toPrimitive method 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::MutableHandleObject |
Out parameter. On success, *vp receives the converted value. |
Description
JS::ToPrimitive
converts a JavaScript object, obj
, to a primitive value using ECMAScript 6 ToPrimitive
.
On success, JS::ToPrimitive
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::ToPrimitive
JS::GetFirstArgumentAsTypeHint
JS_DefaultValue
-- old name of this function- bug 1054756 - added