Entry: JS_ContextIterator (Function)
Summary: Cycles through the JS contexts associated with a particular JSRuntime.
Syntax:
JSContext * JS_ContextIterator(JSRuntime *rt,
JSContext **iterp);
Argument Type Description
rt JSRuntime * Pointer to a previously established JS run-time environment with which script contexts to iterate through are associated.
iterp JSContext ** Pointer to a JS context pointer that holds current context when JS_ContextIterator is called, and that on return holds the next context to call with a subsequent call to the iterator.
Description:
JS_ContextIterator enables you to cycle through all the executable script contexts associated with a specified JS run-time environment, rt. Each call to JS_ContextIterator cycles from the current context to the previous context.
The first time you call JS_ContextIterator, iterp can point to a null-valued context pointer, or it can point to a known context pointer associated with the specified runtime. If you point iterp at a null-valued context pointer, the function automatically determines the first executable script context for the runtime, and makes it the "current" context for the function. If you set iterp to a valid context pointer, that context becomes the "current" context. If the "current" context matches the starting address of the runtime environment's context list, then there are no context established, and JS_ContextIterator returns NULL. Otherwise JS_ContextIterator points iterp to the previous context pointer in the context chain, and returns that pointer.
In effect, by making repeated calls to JS_ContextIterator you can cycle through all executable script contexts for a given runtime, and perform common operations on each them.
Example:
The following code snippet illustrates how to cycle through the contexts for a given context:
JSContext **cxArray, *acx;
JSContext *iterp = NULL;
int i;i = 0;
while ((acx = JSContextIterator(rt, &iterp)) != NULL)
{
printf("%d ". ++1);
}
See also:
|
|
|