JS_ValueToObject 编辑

Converts any JavaScript value to an object.

Syntax

bool
JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp);
NameTypeDescription
cxJSContext *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.
vJS::HandleValueThe value to convert.
objpJS::MutableHandleObjectOut 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 is JSVAL_NULL or JSVAL_VOID, the result is NULL.
  • If v is a boolean value, a number, or a string, the result is a new wrapper object of type Boolean, Number, or String.
  • Otherwise v is an object, and the result depends on the object. If v is a native JavaScript Object, this calls the object's valueOf method, if any. In any case, the result is not guaranteed to be the same object as v. (Implementation note: the object's JSObjectOps.defaultValue method is called with hint=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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:56 次

字数:4092

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文