Bug 891215 (part 6) - Slim down SharedContext-inl.h. r=terrence.

--HG--
extra : rebase_source : 285dee0a66dd433666dbf6a8d836ffc9bc25f5dc
This commit is contained in:
Nicholas Nethercote 2013-07-08 20:50:40 -07:00
Родитель 4b7191bfe3
Коммит 16f9d6d79a
2 изменённых файлов: 57 добавлений и 78 удалений

Просмотреть файл

@ -13,86 +13,13 @@
namespace js {
namespace frontend {
inline
SharedContext::SharedContext(JSContext *cx, bool strict)
: context(cx),
anyCxFlags(),
strict(strict)
{
}
inline bool
SharedContext::needStrictChecks()
{
return context->hasExtraWarningsOption() || strict;
}
inline GlobalSharedContext *
SharedContext::asGlobalSharedContext()
{
JS_ASSERT(isGlobalSharedContext());
return static_cast<GlobalSharedContext*>(this);
}
inline ModuleBox *
SharedContext::asModuleBox()
{
JS_ASSERT(isModuleBox());
return static_cast<ModuleBox*>(this);
}
GlobalSharedContext::GlobalSharedContext(JSContext *cx, JSObject *scopeChain, bool strict)
: SharedContext(cx, strict),
scopeChain_(cx, scopeChain)
{
}
} /* namespace frontend */
template <class ContextT>
void
frontend::PushStatement(ContextT *ct, typename ContextT::StmtInfo *stmt, StmtType type)
{
stmt->type = type;
stmt->isBlockScope = false;
stmt->isForLetBlock = false;
stmt->label = NULL;
stmt->blockObj = NULL;
stmt->down = ct->topStmt;
ct->topStmt = stmt;
if (stmt->linksScope()) {
stmt->downScope = ct->topScopeStmt;
ct->topScopeStmt = stmt;
} else {
stmt->downScope = NULL;
}
}
template <class ContextT>
void
frontend::FinishPushBlockScope(ContextT *ct, typename ContextT::StmtInfo *stmt,
StaticBlockObject &blockObj)
{
stmt->isBlockScope = true;
stmt->downScope = ct->topScopeStmt;
ct->topScopeStmt = stmt;
ct->blockChain = &blockObj;
stmt->blockObj = &blockObj;
}
template <class ContextT>
void
frontend::FinishPopStatement(ContextT *ct)
{
typename ContextT::StmtInfo *stmt = ct->topStmt;
ct->topStmt = stmt->down;
if (stmt->linksScope()) {
ct->topScopeStmt = stmt->downScope;
if (stmt->isBlockScope)
ct->blockChain = stmt->blockObj->enclosingBlock();
}
}
} // namespace js
#endif /* frontend_SharedContext_inl_h */

Просмотреть файл

@ -155,7 +155,11 @@ class SharedContext
// If it's function code, funbox must be non-NULL and scopeChain must be NULL.
// If it's global code, funbox must be NULL.
inline SharedContext(JSContext *cx, bool strict);
SharedContext(JSContext *cx, bool strict)
: context(cx),
anyCxFlags(),
strict(strict)
{}
virtual ObjectBox *toObjectBox() = 0;
inline bool isGlobalSharedContext() { return toObjectBox() == NULL; }
@ -183,12 +187,22 @@ class GlobalSharedContext : public SharedContext
const RootedObject scopeChain_; /* scope chain object for the script */
public:
inline GlobalSharedContext(JSContext *cx, JSObject *scopeChain, bool strict);
GlobalSharedContext(JSContext *cx, JSObject *scopeChain, bool strict)
: SharedContext(cx, strict),
scopeChain_(cx, scopeChain)
{}
ObjectBox *toObjectBox() { return NULL; }
JSObject *scopeChain() const { return scopeChain_; }
};
inline GlobalSharedContext *
SharedContext::asGlobalSharedContext()
{
JS_ASSERT(isGlobalSharedContext());
return static_cast<GlobalSharedContext*>(this);
}
class ModuleBox : public ObjectBox, public SharedContext
{
public:
@ -200,6 +214,13 @@ class ModuleBox : public ObjectBox, public SharedContext
Module *module() const { return &object->as<Module>(); }
};
inline ModuleBox *
SharedContext::asModuleBox()
{
JS_ASSERT(isModuleBox());
return static_cast<ModuleBox*>(this);
}
class FunctionBox : public ObjectBox, public SharedContext
{
public:
@ -364,18 +385,49 @@ struct StmtInfoBase {
// Push the C-stack-allocated struct at stmt onto the StmtInfoPC stack.
template <class ContextT>
void
PushStatement(ContextT *ct, typename ContextT::StmtInfo *stmt, StmtType type);
PushStatement(ContextT *ct, typename ContextT::StmtInfo *stmt, StmtType type)
{
stmt->type = type;
stmt->isBlockScope = false;
stmt->isForLetBlock = false;
stmt->label = NULL;
stmt->blockObj = NULL;
stmt->down = ct->topStmt;
ct->topStmt = stmt;
if (stmt->linksScope()) {
stmt->downScope = ct->topScopeStmt;
ct->topScopeStmt = stmt;
} else {
stmt->downScope = NULL;
}
}
template <class ContextT>
void
FinishPushBlockScope(ContextT *ct, typename ContextT::StmtInfo *stmt, StaticBlockObject &blockObj);
FinishPushBlockScope(ContextT *ct, typename ContextT::StmtInfo *stmt, StaticBlockObject &blockObj)
{
stmt->isBlockScope = true;
stmt->downScope = ct->topScopeStmt;
ct->topScopeStmt = stmt;
ct->blockChain = &blockObj;
stmt->blockObj = &blockObj;
}
// Pop pc->topStmt. If the top StmtInfoPC struct is not stack-allocated, it
// is up to the caller to free it. The dummy argument is just to make the
// template matching work.
template <class ContextT>
void
FinishPopStatement(ContextT *ct);
FinishPopStatement(ContextT *ct)
{
typename ContextT::StmtInfo *stmt = ct->topStmt;
ct->topStmt = stmt->down;
if (stmt->linksScope()) {
ct->topScopeStmt = stmt->downScope;
if (stmt->isBlockScope)
ct->blockChain = stmt->blockObj->enclosingBlock();
}
}
/*
* Find a lexically scoped variable (one declared by let, catch, or an array