Ignore:
Timestamp:
May 7, 2012, 4:35:52 PM (13 years ago)
Author:
[email protected]
Message:

2012-05-07 Oliver Hunt <[email protected]>

Rolling out r110287

RS=Filip Pizlo

r110287 was meant to be refactoring only, but changed behavior
enough to break some websites, including qq.com.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r115217 r116372  
    131131
    132132struct Scope {
    133     Scope(const JSGlobalData* globalData, ScopeFlags scopeFlags)
     133    Scope(const JSGlobalData* globalData, bool isFunction, bool strictMode)
    134134        : m_globalData(globalData)
    135         , m_scopeFlags(scopeFlags)
     135        , m_shadowsArguments(false)
     136        , m_usesEval(false)
     137        , m_needsFullActivation(false)
     138        , m_allowsNewDecls(true)
     139        , m_strictMode(strictMode)
     140        , m_isFunction(isFunction)
     141        , m_isFunctionBoundary(false)
    136142        , m_isValidStrictMode(true)
    137143        , m_loopDepth(0)
    138144        , m_switchDepth(0)
    139145    {
    140         ASSERT(!(scopeFlags & ~AllScopeModeFlags));
    141146    }
    142147
    143148    Scope(const Scope& rhs)
    144149        : m_globalData(rhs.m_globalData)
    145         , m_scopeFlags(rhs.m_scopeFlags)
     150        , m_shadowsArguments(rhs.m_shadowsArguments)
     151        , m_usesEval(rhs.m_usesEval)
     152        , m_needsFullActivation(rhs.m_needsFullActivation)
     153        , m_allowsNewDecls(rhs.m_allowsNewDecls)
     154        , m_strictMode(rhs.m_strictMode)
     155        , m_isFunction(rhs.m_isFunction)
     156        , m_isFunctionBoundary(rhs.m_isFunctionBoundary)
    146157        , m_isValidStrictMode(rhs.m_isValidStrictMode)
    147158        , m_loopDepth(rhs.m_loopDepth)
     
    157168        }
    158169    }
    159 
    160     ALWAYS_INLINE ScopeFlags scopeFlags() const { return m_scopeFlags; }
    161     ALWAYS_INLINE ScopeFlags modeFlags() const { return m_scopeFlags & AllScopeModeFlags; }
    162     ALWAYS_INLINE ScopeFlags usesFlags() const { return m_scopeFlags & AllScopeUsesFlags; }
    163     ALWAYS_INLINE void setFlags(ScopeFlags scopeFlags) { m_scopeFlags |= scopeFlags; }
    164 
    165     ALWAYS_INLINE bool usesEval() const { return m_scopeFlags & UsesEvalFlag; }
    166     ALWAYS_INLINE bool strictMode() const { return m_scopeFlags & StrictModeFlag; }
    167     ALWAYS_INLINE bool shadowsArguments() const { return m_scopeFlags & ShadowsArgumentsFlag; }
    168     ALWAYS_INLINE bool isFunction() const { return m_scopeFlags & FunctionModeFlag; }
    169     ALWAYS_INLINE bool isBlockScope() const { return m_scopeFlags & BlockScopeFlag; }
    170     ALWAYS_INLINE bool isFunctionBoundary() const { return isFunction() && !isBlockScope(); }
    171 
    172     ALWAYS_INLINE bool allowsNewDecls() const { return !isBlockScope(); }
    173 
    174     ALWAYS_INLINE bool isValidStrictMode() const { return m_isValidStrictMode; }
    175170
    176171    void startSwitch() { m_switchDepth++; }
     
    207202    }
    208203
     204    void setIsFunction()
     205    {
     206        m_isFunction = true;
     207        m_isFunctionBoundary = true;
     208    }
     209    bool isFunction() { return m_isFunction; }
     210    bool isFunctionBoundary() { return m_isFunctionBoundary; }
     211
    209212    bool declareVariable(const Identifier* ident)
    210213    {
     
    217220    void declareWrite(const Identifier* ident)
    218221    {
    219         ASSERT(strictMode());
     222        ASSERT(m_strictMode);
    220223        m_writtenVariables.add(ident->impl());
    221224    }
     225
     226    void preventNewDecls() { m_allowsNewDecls = false; }
     227    bool allowsNewDecls() const { return m_allowsNewDecls; }
    222228
    223229    bool declareParameter(const Identifier* ident)
     
    227233        m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode;
    228234        if (isArguments)
    229             setFlags(ShadowsArgumentsFlag);
     235            m_shadowsArguments = true;
    230236        return isValidStrictMode;
    231237    }
    232238
    233     void useVariable(const Identifier* ident)
    234     {
     239    void useVariable(const Identifier* ident, bool isEval)
     240    {
     241        m_usesEval |= isEval;
    235242        m_usedVariables.add(ident->ustring().impl());
    236243    }
    237244
     245    void setNeedsFullActivation() { m_needsFullActivation = true; }
     246
    238247    bool collectFreeVariables(Scope* nestedScope, bool shouldTrackClosedVariables)
    239248    {
    240         setFlags(nestedScope->usesFlags());
     249        if (nestedScope->m_usesEval)
     250            m_usesEval = true;
    241251        IdentifierSet::iterator end = nestedScope->m_usedVariables.end();
    242252        for (IdentifierSet::iterator ptr = nestedScope->m_usedVariables.begin(); ptr != end; ++ptr) {
     
    270280    void getCapturedVariables(IdentifierSet& capturedVariables)
    271281    {
    272         if (usesEval()) {
     282        if (m_needsFullActivation || m_usesEval) {
    273283            capturedVariables.swap(m_declaredVariables);
    274284            return;
     
    280290        }
    281291    }
     292    void setStrictMode() { m_strictMode = true; }
     293    bool strictMode() const { return m_strictMode; }
     294    bool isValidStrictMode() const { return m_isValidStrictMode; }
     295    bool shadowsArguments() const { return m_shadowsArguments; }
     296
    282297    void copyCapturedVariablesToVector(const IdentifierSet& capturedVariables, Vector<RefPtr<StringImpl> >& vector)
    283298    {
     
    293308    void saveFunctionInfo(SourceProviderCacheItem* info)
    294309    {
    295         ASSERT(isFunction());
    296         info->scopeFlags = m_scopeFlags;
     310        ASSERT(m_isFunction);
     311        info->usesEval = m_usesEval;
     312        info->strictMode = m_strictMode;
     313        info->needsFullActivation = m_needsFullActivation;
    297314        copyCapturedVariablesToVector(m_writtenVariables, info->writtenVariables);
    298315        copyCapturedVariablesToVector(m_usedVariables, info->usedVariables);
     
    301318    void restoreFunctionInfo(const SourceProviderCacheItem* info)
    302319    {
    303         ASSERT(isFunction());
    304         m_scopeFlags |= info->scopeFlags;
     320        ASSERT(m_isFunction);
     321        m_usesEval = info->usesEval;
     322        m_strictMode = info->strictMode;
     323        m_needsFullActivation = info->needsFullActivation;
    305324        unsigned size = info->usedVariables.size();
    306325        for (unsigned i = 0; i < size; ++i)
     
    313332private:
    314333    const JSGlobalData* m_globalData;
    315     ScopeFlags m_scopeFlags;
     334    bool m_shadowsArguments : 1;
     335    bool m_usesEval : 1;
     336    bool m_needsFullActivation : 1;
     337    bool m_allowsNewDecls : 1;
     338    bool m_strictMode : 1;
     339    bool m_isFunction : 1;
     340    bool m_isFunctionBoundary : 1;
    316341    bool m_isValidStrictMode : 1;
    317342    int m_loopDepth;
     
    403428    };
    404429
    405     ALWAYS_INLINE ScopeRef currentScope()
     430    ScopeRef currentScope()
    406431    {
    407432        return ScopeRef(&m_scopeStack, m_scopeStack.size() - 1);
    408433    }
    409434   
    410     ScopeRef pushScope(ScopeFlags scopeFlags)
    411     {
    412         m_scopeStack.append(Scope(m_globalData, scopeFlags));
     435    ScopeRef pushScope()
     436    {
     437        bool isFunction = false;
     438        bool isStrict = false;
     439        if (!m_scopeStack.isEmpty()) {
     440            isStrict = m_scopeStack.last().strictMode();
     441            isFunction = m_scopeStack.last().isFunction();
     442        }
     443        m_scopeStack.append(Scope(m_globalData, isFunction, isStrict));
    413444        return currentScope();
    414445    }
     
    462493
    463494    void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*,
    464                           ParserArenaData<DeclarationStacks::FunctionStack>*, ScopeFlags,
     495                          ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures,
    465496                          int, int, IdentifierSet&);
    466497
     
    793824    }
    794825   
    795     ALWAYS_INLINE void startLoop() { currentScope()->startLoop(); }
    796     ALWAYS_INLINE void endLoop() { currentScope()->endLoop(); }
    797     ALWAYS_INLINE void startSwitch() { currentScope()->startSwitch(); }
    798     ALWAYS_INLINE void endSwitch() { currentScope()->endSwitch(); }
    799     ALWAYS_INLINE bool strictMode() { return currentScope()->strictMode(); }
    800     ALWAYS_INLINE bool isValidStrictMode() { return currentScope()->isValidStrictMode(); }
    801     ALWAYS_INLINE bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); }
     826    void startLoop() { currentScope()->startLoop(); }
     827    void endLoop() { currentScope()->endLoop(); }
     828    void startSwitch() { currentScope()->startSwitch(); }
     829    void endSwitch() { currentScope()->endSwitch(); }
     830    void setStrictMode() { currentScope()->setStrictMode(); }
     831    bool strictMode() { return currentScope()->strictMode(); }
     832    bool isValidStrictMode() { return currentScope()->isValidStrictMode(); }
     833    bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); }
    802834    bool breakIsValid()
    803835    {
     
    918950    ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
    919951    IdentifierSet m_capturedVariables;
    920     ScopeFlags m_scopeFlags;
     952    CodeFeatures m_features;
    921953    int m_numConstants;
    922954   
     
    9791011                                    m_capturedVariables,
    9801012                                    *m_source,
    981                                     m_scopeFlags,
     1013                                    m_features,
    9821014                                    m_numConstants);
    9831015        result->setLoc(m_source->firstLine(), m_lastLine);
Note: See TracChangeset for help on using the changeset viewer.