JS_ValueToObject 编辑
Converts any JavaScript value to an object.
Syntax
bool
JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp);
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to convert the value. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
v | JS::HandleValue | The value to convert. |
objp | JS::MutableHandleObject | Out parameter. On success, *objp receives NULL or a pointer to the resulting object. |
Description
JS_ValueToObject
converts a specified JavaScript value, v
, to an object. On success, this function stores either NULL
or a pointer to the resulting object in *objp
and returns true
. Otherwise it returns false
and the value left in *objp
is unspecified.
- If
v
isJSVAL_NULL
orJSVAL_VOID
, the result isNULL
. - If
v
is a boolean value, a number, or a string, the result is a new wrapper object of typeBoolean
,Number
, orString
. - Otherwise
v
is an object, and the result depends on the object. Ifv
is a native JavaScriptObject
, this calls the object'svalueOf
method, if any. In any case, the result is not guaranteed to be the same object asv
. (Implementation note: the object'sJSObjectOps.defaultValue
method is called withhint=JSTYPE_OBJECT
.)
The resulting object is subject to garbage collection unless the variable *objp
is protected by a local root scope, an object property, or the JS_AddRoot
function. Note that a local root scope is not sufficient to protect the resulting object in some cases involving the valueOf
method!
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论