Ignore:
Timestamp:
Sep 24, 2010, 1:54:48 PM (15 years ago)
Author:
[email protected]
Message:

2010-09-24 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Variable declarations inside a catch scope don't get propogated to the parent scope
https://bugs.webkit.org/show_bug.cgi?id=46501

Add logic to make variable declaration look for a scope for the
new variable. This allows us to create a scope (eg. for catch)
and then seal it, so that additional variable declarations
contained are propogated to the correct target. Strangely this
comes out as a performance win, but I think it's mostly cache
effects.

  • parser/JSParser.cpp: (JSC::JSParser::Scope::Scope): (JSC::JSParser::Scope::preventNewDecls): (JSC::JSParser::Scope::allowsNewDecls): (JSC::JSParser::declareVariable): (JSC::JSParser::parseVarDeclarationList): (JSC::JSParser::parseConstDeclarationList): (JSC::JSParser::parseTryStatement): (JSC::JSParser::parseFormalParameters): (JSC::JSParser::parseFunctionDeclaration):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/JSParser.cpp

    r67769 r68288  
    205205            : m_usesEval(false)
    206206            , m_needsFullActivation(false)
     207            , m_allowsNewDecls(true)
    207208        {
    208209        }
     
    213214        }
    214215       
     216        void preventNewDecls() { m_allowsNewDecls = false; }
     217        bool allowsNewDecls() const { return m_allowsNewDecls; }
     218
    215219        void useVariable(const Identifier* ident, bool isEval)
    216220        {
     
    250254        bool m_usesEval;
    251255        bool m_needsFullActivation;
     256        bool m_allowsNewDecls;
    252257        IdentifierSet m_declaredVariables;
    253258        IdentifierSet m_usedVariables;
     
    287292        m_scopeStack[m_scopeStack.size() - 2].collectFreeVariables(&m_scopeStack.last(), shouldTrackClosedVariables);
    288293        m_scopeStack.removeLast();
     294    }
     295   
     296    void declareVariable(const Identifier* ident)
     297    {
     298        unsigned i = m_scopeStack.size() - 1;
     299        ASSERT(i < m_scopeStack.size());
     300        while (!m_scopeStack[i].allowsNewDecls()) {
     301            i--;
     302            ASSERT(i < m_scopeStack.size());
     303        }
     304        m_scopeStack[i].declareVariable(ident);
    289305    }
    290306
     
    426442        next();
    427443        bool hasInitializer = match(EQUAL);
    428         currentScope()->declareVariable(name);
     444        declareVariable(name);
    429445        context.addVar(name, (hasInitializer || (!m_allowsIn && match(INTOKEN))) ? DeclarationStacks::HasInitializer : 0);
    430446        if (hasInitializer) {
     
    458474        next();
    459475        bool hasInitializer = match(EQUAL);
    460         currentScope()->declareVariable(name);
     476        declareVariable(name);
    461477        context.addVar(name, DeclarationStacks::IsConstant | (hasInitializer ? DeclarationStacks::HasInitializer : 0));
    462478        TreeExpression initializer = 0;
     
    760776        ScopeRef catchScope = pushScope();
    761777        catchScope->declareVariable(ident);
     778        catchScope->preventNewDecls();
    762779        consumeOrFail(CLOSEPAREN);
    763780        matchOrFail(OPENBRACE);
     
    863880    matchOrFail(IDENT);
    864881    usesArguments = m_globalData->propertyNames->arguments == *m_token.m_data.ident;
    865     currentScope()->declareVariable(m_token.m_data.ident);
     882    declareVariable(m_token.m_data.ident);
    866883    TreeFormalParameterList list = context.createFormalParameterList(*m_token.m_data.ident);
    867884    TreeFormalParameterList tail = list;
     
    871888        matchOrFail(IDENT);
    872889        const Identifier* ident = m_token.m_data.ident;
    873         currentScope()->declareVariable(ident);
     890        declareVariable(ident);
    874891        next();
    875892        usesArguments = usesArguments || m_globalData->propertyNames->arguments == *ident;
     
    934951    failIfFalse((parseFunctionInfo<FunctionNeedsName, true>(context, name, parameters, body, openBracePos, closeBracePos, bodyStartLine)));
    935952    failIfFalse(name);
    936     currentScope()->declareVariable(name);
     953    declareVariable(name);
    937954    return context.createFuncDeclStatement(name, body, parameters, openBracePos, closeBracePos, bodyStartLine, m_lastLine);
    938955}
Note: See TracChangeset for help on using the changeset viewer.