This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
JSObject * JS_GetScopeChain(JSContext *cx);
||The context to query.|
JS_GetScopeChain returns the first
The ECMAScript standard, ECMA 262-3 §10, describes execution contexts and scope chains. A scope chain is a sequence of objects whose properties are searched whenever a script or function refers to a variable. These objects represent the lexical scope of the currently executing statement or expression, not the call stack, so they include:
- the variable objects of any enclosing functions or
letstatements or expressions, and any objects selected by enclosing
withstatements, in order from the most-nested scope outward;
- lastly the global object against which the function was created.
cx's current global object, as set by
JS_SetGlobalObject, is not guaranteed to be on the scope chain. If the currently executing function was created in the scope of a different global object, then that object will be the last object in the current scope chain. If the context is currently executing a script, and not in any function, it's running in a scope that was passed to
JS_ExecuteScript or a similar function by the application. This scope chain may or may not contain
cx's current global object.
If any code is currently executing in
JS_GetScopeChain returns a pointer to the first
JSObject on the current scope chain. Otherwise, if
cx has a global object,
JS_GetScopeChain returns that. Otherwise, an error is reported and
To walk the scope chain, use