JS_DefaultValue 编辑
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论