Bug 1141905 part 2. Make the 5-arg version of CreateScopeObjectsForScopeChain non-static so it can be called from multiple files, and move it to a possibly-saner location. r=shu

This commit is contained in:
Boris Zbarsky 2015-03-12 21:46:57 -04:00
parent 73238ec577
commit 48ae1e607a
3 changed files with 46 additions and 40 deletions

View File

@ -3197,49 +3197,11 @@ JS::GetSelfHostedFunction(JSContext *cx, const char *selfHostedName, HandleId id
static bool
CreateScopeObjectsForScopeChain(JSContext *cx, AutoObjectVector &scopeChain,
HandleObject dynamicTerminatingScope,
MutableHandleObject dynamicScopeObj,
MutableHandleObject staticScopeObj)
{
#ifdef DEBUG
for (size_t i = 0; i < scopeChain.length(); ++i) {
assertSameCompartment(cx, scopeChain[i]);
MOZ_ASSERT(!scopeChain[i]->is<GlobalObject>());
}
#endif
// Construct With object wrappers for the things on this scope
// chain and use the result as the thing to scope the function to.
Rooted<StaticWithObject*> staticWith(cx);
RootedObject staticEnclosingScope(cx);
Rooted<DynamicWithObject*> dynamicWith(cx);
RootedObject dynamicEnclosingScope(cx, dynamicTerminatingScope);
for (size_t i = scopeChain.length(); i > 0; ) {
staticWith = StaticWithObject::create(cx);
if (!staticWith)
return false;
staticWith->initEnclosingNestedScope(staticEnclosingScope);
staticEnclosingScope = staticWith;
dynamicWith = DynamicWithObject::create(cx, scopeChain[--i], dynamicEnclosingScope,
staticWith, DynamicWithObject::NonSyntacticWith);
if (!dynamicWith)
return false;
dynamicEnclosingScope = dynamicWith;
}
dynamicScopeObj.set(dynamicEnclosingScope);
staticScopeObj.set(staticEnclosingScope);
return true;
}
static bool
CreateScopeObjectsForScopeChain(JSContext *cx, AutoObjectVector &scopeChain,
MutableHandleObject dynamicScopeObj,
MutableHandleObject staticScopeObj)
{
return CreateScopeObjectsForScopeChain(cx, scopeChain, cx->global(),
dynamicScopeObj, staticScopeObj);
return js::CreateScopeObjectsForScopeChain(cx, scopeChain, cx->global(),
dynamicScopeObj, staticScopeObj);
}
static bool

View File

@ -2512,6 +2512,44 @@ js::GetObjectEnvironmentObjectForFunction(JSFunction *fun)
return &env->as<DynamicWithObject>().object();
}
bool
js::CreateScopeObjectsForScopeChain(JSContext *cx, AutoObjectVector &scopeChain,
HandleObject dynamicTerminatingScope,
MutableHandleObject dynamicScopeObj,
MutableHandleObject staticScopeObj)
{
#ifdef DEBUG
for (size_t i = 0; i < scopeChain.length(); ++i) {
assertSameCompartment(cx, scopeChain[i]);
MOZ_ASSERT(!scopeChain[i]->is<GlobalObject>());
}
#endif
// Construct With object wrappers for the things on this scope
// chain and use the result as the thing to scope the function to.
Rooted<StaticWithObject*> staticWith(cx);
RootedObject staticEnclosingScope(cx);
Rooted<DynamicWithObject*> dynamicWith(cx);
RootedObject dynamicEnclosingScope(cx, dynamicTerminatingScope);
for (size_t i = scopeChain.length(); i > 0; ) {
staticWith = StaticWithObject::create(cx);
if (!staticWith)
return false;
staticWith->initEnclosingNestedScope(staticEnclosingScope);
staticEnclosingScope = staticWith;
dynamicWith = DynamicWithObject::create(cx, scopeChain[--i], dynamicEnclosingScope,
staticWith, DynamicWithObject::NonSyntacticWith);
if (!dynamicWith)
return false;
dynamicEnclosingScope = dynamicWith;
}
dynamicScopeObj.set(dynamicEnclosingScope);
staticScopeObj.set(staticEnclosingScope);
return true;
}
#ifdef DEBUG
typedef HashSet<PropertyName *> PropertyNameSet;

View File

@ -1091,6 +1091,12 @@ ScopeIter::enclosingScope() const
return *scope_;
}
extern bool
CreateScopeObjectsForScopeChain(JSContext *cx, AutoObjectVector &scopeChain,
HandleObject dynamicTerminatingScope,
MutableHandleObject dynamicScopeObj,
MutableHandleObject staticScopeObj);
#ifdef DEBUG
bool
AnalyzeEntrainedVariables(JSContext *cx, HandleScript script);