JS_AlreadyHasOwnProperty 编辑
This article covers features introduced in SpiderMonkey 1.8
Determine whether a property is already physically present on a JSObject
.
Syntax
boo
JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name,
bool *foundp);
boo
JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name,
size_t namelen, bool *foundp);
boo
JS_AlreadyHasOwnPropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
bool *foundp); // Added in SpiderMonkey 1.8.1
boo
JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index,
bool *foundp);
Name | Type | Description |
---|---|---|
cx | JSContext * | Pointer to a JS context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
obj | JSObject * | The object to be searched. |
name or id | const char * or const char16_t *or | (in JS_AlreadyHasOwnProperty , AlreadyHasOwnUCProperty , and JS_AlreadyHasOwnPropertyById ) The name of the property to search for. |
namelen | size_t | (in JS_AlreadyHasOwnUCProperty only) The length of name , in characters; or the special value (size_t) -1 to indicate that name is null-terminated. |
index | uint32_t | (in JS_AlreadyHasOwnElement only) The index of the element to search for. |
foundp | bool * | Out parameter. *foundp receives true if the property is found or false if it is not found. If an error occurs, the value left in *foundp is undefined. |
Description
These functions attempt to determine whether a property already exists on a specific JSObject
without modifying the object. By design, this search may not find a property that other property lookup functions, such as JS_LookupProperty
, would find.
For native objects—objects whose properties are stored in the default data structure provided by SpiderMonkey—these functions simply check that data structure to see if the specified field is present. They do not search anywhere else for the property. This means that:
- The prototype chain of
obj
is not searched. - The object's
JSClass.resolve
hook is not called, so lazily defined properties are not found. (This is the only API that can directly detect that a lazily resolved property has not yet been resolved.) - Shared, permanent, delegated properties are not found. (Such properties are an implementation detail of SpiderMonkey. They are meant to be a transparent optimization; this is the only API that breaks the abstraction.)
For non-native objects, this falls back on a complete search. This calls the JSObjectOps.lookupProperty
hook. *foundp
is set to true only if lookupProperty
reports that the property was found on obj
itself and not on some other object (even the corresponding outer object, if any).
If the property is found on obj
, this sets *foundp
to true
and returns true
.
If the property is not found on obj
, this sets *foundp
to false
and returns true
(to indicate that no error occurred).
If the search fails with an error or exception, this returns false
.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论