diff --git a/js/src/frontend/SharedContext-inl.h b/js/src/frontend/SharedContext-inl.h index 57407d04d118..57880cbd2f17 100644 --- a/js/src/frontend/SharedContext-inl.h +++ b/js/src/frontend/SharedContext-inl.h @@ -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(this); -} - -inline ModuleBox * -SharedContext::asModuleBox() -{ - JS_ASSERT(isModuleBox()); - return static_cast(this); -} - -GlobalSharedContext::GlobalSharedContext(JSContext *cx, JSObject *scopeChain, bool strict) - : SharedContext(cx, strict), - scopeChain_(cx, scopeChain) -{ -} - } /* namespace frontend */ - -template -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 -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 -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 */ diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 01ef28ff83b5..72d33ce946f9 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.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(this); +} + class ModuleBox : public ObjectBox, public SharedContext { public: @@ -200,6 +214,13 @@ class ModuleBox : public ObjectBox, public SharedContext Module *module() const { return &object->as(); } }; +inline ModuleBox * +SharedContext::asModuleBox() +{ + JS_ASSERT(isModuleBox()); + return static_cast(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 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 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 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