Mozilla.com

Table of contents
  1. 1. Syntax
  2. 2. Description
Table of contents
  1. 1. Syntax
  2. 2. Description

The JSClass.enumerate callback implements iteration over object properties. It is either a JSEnumerateOp or a JSNewEnumerateOp. The new way is described here.

JSNewEnumerateOp is also the type of the JSObjectOps.enumerate callback, an internal SpiderMonkey callback.

Syntax

typedef JSBool (*JSNewEnumerateOp)(JSContext *cx, JSObject *obj,
    JSIterateOp enum_op, jsval *statep, jsid *idp);
Name Type Description
cx JSContext * The context in which the enumeration is taking place.
obj JSObject * The object to be enumerated.
enum_op JSIterateOp Specifies which step in iteration is happening. See the Description below.
statep jsval * In/out parameter. The meaning depends on enum_op. See the Description below.
idp jsid * In/out parameter. The meaning depends on enum_op. See the Description below.

Description

This callback enumerates the properties of an object. To use a JSNewEnumerateOp in a JSClass, set the JSCLASS_NEW_ENUMERATE bit in the JSClass.flags field and set the JSClass.enumerate field to your JSNewEnumerateOp, casting it to JSEnumerateOp. (SpiderMonkey, noting the JSCLASS_NEW_ENUMERATE flag, will cast that function pointer back to type JSNewEnumerateOp before calling it.)

The behavior depends on the value of enum_op:

JSENUMERATE_INIT
A new, opaque iterator state should be allocated and stored in *statep. (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored.)

The number of properties that will be enumerated should be returned as an integer jsval in *idp, if idp is non-null, and provided the number of enumerable properties is known. If idp is non-null and the number of enumerable properties can't be computed in advance, *idp should be set to JSVAL_ZERO.

JSENUMERATE_NEXT
A previously allocated opaque iterator state is passed in via statep. Return the next jsid in the iteration using *idp. The opaque iterator state pointed at by statep is destroyed and *statep is set to JSVAL_NULL if there are no properties left to enumerate.
JSENUMERATE_DESTROY
Destroy the opaque iterator state previously allocated in *statep by a call to this function when enum_op was JSENUMERATE_INIT.

The callback returns JS_TRUE to indicate success or JS_FALSE to indicate failure.

Page last modified 08:34, 2 Apr 2008 by Jorend

Files (0)