JS_Enumerate 编辑
Get an array of the enumerable properties of a given object.
Syntax
JSIdArray *
JS_Enumerate(JSContext *cx, JS::HandleObject obj);
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to enumerate object properties. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
obj | JS::HandleObject | The object whose properties are to be enumerated. |
Description
JS_Enumerate
gets the ids of all own properties of the specified object, obj
, that have the JSPROP_ENUMERATE
attribute. (The term own property refers to a property that is not inherited from the object's prototype.) This is not quite the same behavior as a JavaScript for
...in
loop, which converts all property ids to strings and also enumerates inherited properties.
This calls obj
's JSClass.enumerate
hook.
On success, JS_Enumerate
returns a pointer to the first element of an array of property IDs. The application must free this array using JS_DestroyIdArray
. On error or exception, JS_Enumerate
returns NULL
.
JSIdArray
are subject to garbage collection. As long as obj
is reachable, its current property ids are reachable. But, for example, if an application calls back into JavaScript while it is looping over the property ids in the JSIdArray
, the script could delete properties from obj
. The property ids would then become unreachable and could be collected. Therefore a program that loops over the property ids must either root them all, ensure that the properties are not deleted (in a multithreaded program this requires even greater care), or ensure that garbage collection does not occur.See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论