Bug 1089026 part 3. Add a friend API for getting the scope object for a function, if it has one. r=shu

This commit is contained in:
Boris Zbarsky 2014-10-30 19:40:28 -04:00
parent 526be6f105
commit 021f135323
2 changed files with 23 additions and 0 deletions

View File

@ -2675,6 +2675,15 @@ extern JS_FRIEND_API(void)
SetJitExceptionHandler(JitExceptionHandler handler); SetJitExceptionHandler(JitExceptionHandler handler);
#endif #endif
/*
* Get the object underlying the object environment (in the ES
* NewObjectEnvironment) sense for a given function. If the function is not
* scripted or does not have an object environment, just returns the function's
* parent.
*/
extern JS_FRIEND_API(JSObject *)
GetObjectEnvironmentObjectForFunction(JSFunction *fun);
} /* namespace js */ } /* namespace js */
extern JS_FRIEND_API(bool) extern JS_FRIEND_API(bool)

View File

@ -2517,6 +2517,20 @@ js::GetDebugScopeForFrame(JSContext *cx, AbstractFramePtr frame, jsbytecode *pc)
return GetDebugScope(cx, si); return GetDebugScope(cx, si);
} }
// See declaration and documentation in jsfriendapi.h
JS_FRIEND_API(JSObject *)
js::GetObjectEnvironmentObjectForFunction(JSFunction *fun)
{
if (!fun->isInterpreted())
return fun->getParent();
JSObject *env = fun->environment();
if (!env || !env->is<DynamicWithObject>())
return fun->getParent();
return &env->as<DynamicWithObject>().object();
}
#ifdef DEBUG #ifdef DEBUG
typedef HashSet<PropertyName *> PropertyNameSet; typedef HashSet<PropertyName *> PropertyNameSet;