JS_Enumerate 编辑

Get an array of the enumerable properties of a given object.

Syntax

JSIdArray *
JS_Enumerate(JSContext *cx, JS::HandleObject obj);
NameTypeDescription
cxJSContext *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.
objJS::HandleObjectThe 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.

The property ids in the returned 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 技术交流群。

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

发布评论

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

词条统计

浏览:71 次

字数:3725

最后编辑:7年前

编辑次数:0 次

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