JS Enumerate
From MDC
Get an array of the properties of a given object.
[edit] Syntax
JSIdArray * JS_Enumerate(JSContext *cx, JSObject *obj);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
The context in which to enumerate object properties.
Requires request. (In a |
obj |
JSObject * |
The object whose properties are to be enumerated. |
[edit] Description
JS_Enumerate gets an array of the ids of all own properties of the specified object, obj. (The term own property refers to a property that is not inherited from the object's prototype.)
This calls obj's JSClass.enumerate hook.
On success, JS_Enumerate returns a pointer to an array of property IDs. The application must free this array using JS_DestroyIdArray. On error or exception, JS_Enumerate returns NULL.
Warning: 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.