Changeset 116372 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- May 7, 2012, 4:35:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r113270 r116372 63 63 64 64 m_functionCache = source.provider()->cache(); 65 ScopeFlags scopeFlags = NoScopeFlags; 65 ScopeRef scope = pushScope(); 66 if (parserMode == JSParseFunctionCode) 67 scope->setIsFunction(); 66 68 if (strictness == JSParseStrict) 67 scopeFlags |= StrictModeFlag; 68 if (parserMode == JSParseFunctionCode) 69 scopeFlags |= FunctionModeFlag; 70 ScopeRef scope = pushScope(scopeFlags); 69 scope->setStrictMode(); 71 70 if (parameters) { 72 71 for (unsigned i = 0; i < parameters->size(); i++) … … 98 97 IdentifierSet capturedVariables; 99 98 scope->getCapturedVariables(capturedVariables); 100 ScopeFlags scopeFlags = scope->modeFlags() | scope->usesFlags(); 99 CodeFeatures features = context.features(); 100 if (scope->strictMode()) 101 features |= StrictModeFeature; 102 if (scope->shadowsArguments()) 103 features |= ShadowsArgumentsFeature; 101 104 unsigned functionCacheSize = m_functionCache ? m_functionCache->byteSize() : 0; 102 105 if (functionCacheSize != oldFunctionCacheSize) 103 106 m_lexer->sourceProvider()->notifyCacheSizeChanged(functionCacheSize - oldFunctionCacheSize); 104 107 105 didFinishParsing(sourceElements, context.varDeclarations(), context.funcDeclarations(), scopeFlags,108 didFinishParsing(sourceElements, context.varDeclarations(), context.funcDeclarations(), features, 106 109 m_lastLine, context.numConstants(), capturedVariables); 107 110 … … 111 114 template <typename LexerType> 112 115 void Parser<LexerType>::didFinishParsing(SourceElements* sourceElements, ParserArenaData<DeclarationStacks::VarStack>* varStack, 113 ParserArenaData<DeclarationStacks::FunctionStack>* funcStack, ScopeFlags scopeFlags, int lastLine, int numConstants, IdentifierSet& capturedVars)116 ParserArenaData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants, IdentifierSet& capturedVars) 114 117 { 115 118 m_sourceElements = sourceElements; … … 117 120 m_funcDeclarations = funcStack; 118 121 m_capturedVariables.swap(capturedVars); 119 m_ scopeFlags = scopeFlags;122 m_features = features; 120 123 m_lastLine = lastLine; 121 124 m_numConstants = numConstants; … … 145 148 // "use strict" must be the exact literal without escape sequences or line continuation. 146 149 if (!hasSetStrict && directiveLiteralLength == lengthOfUseStrictLiteral && m_globalData->propertyNames->useStrictIdentifier == *directive) { 147 currentScope()->setFlags(StrictModeFlag);150 setStrictMode(); 148 151 hasSetStrict = true; 149 152 failIfFalse(isValidStrictMode()); … … 253 256 bool hasInitializer = match(EQUAL); 254 257 failIfFalseIfStrictWithNameAndMessage(declareVariable(name), "Cannot declare a variable named", name->impl(), "in strict mode."); 255 if (m_globalData->propertyNames->arguments == *name)256 currentScope()->setFlags(UsesArgumentsFlag);257 258 context.addVar(name, (hasInitializer || (!m_allowsIn && match(INTOKEN))) ? DeclarationStacks::HasInitializer : 0); 258 259 if (hasInitializer) { … … 289 290 bool hasInitializer = match(EQUAL); 290 291 declareVariable(name); 291 if (m_globalData->propertyNames->arguments == *name)292 currentScope()->setFlags(UsesArgumentsFlag);293 292 context.addVar(name, DeclarationStacks::IsConstant | (hasInitializer ? DeclarationStacks::HasInitializer : 0)); 294 293 TreeExpression initializer = 0; … … 513 512 ASSERT(match(WITH)); 514 513 failIfTrueWithMessage(strictMode(), "'with' statements are not valid in strict mode"); 515 currentScope()->set Flags(UsesWithFlag);514 currentScope()->setNeedsFullActivation(); 516 515 int startLine = tokenLine(); 517 516 next(); … … 528 527 failIfFalse(statement); 529 528 530 currentScope()->setFlags(UsesWithFlag);531 529 return context.createWithStatement(m_lexer->lastLineNumber(), expr, statement, start, end, startLine, endLine); 532 530 } … … 617 615 618 616 if (match(CATCH)) { 619 currentScope()->set Flags(UsesCatchFlag);617 currentScope()->setNeedsFullActivation(); 620 618 next(); 621 619 consumeOrFail(OPENPAREN); … … 623 621 ident = m_token.m_data.ident; 624 622 next(); 625 AutoPopScopeRef catchScope(this, pushScope( currentScope()->modeFlags()));623 AutoPopScopeRef catchScope(this, pushScope()); 626 624 failIfFalseIfStrictWithNameAndMessage(declareVariable(ident), "Cannot declare a variable named", ident->impl(), "in strict mode"); 627 c urrentScope()->setFlags(BlockScopeFlag | UsesCatchFlag);625 catchScope->preventNewDecls(); 628 626 consumeOrFail(CLOSEPAREN); 629 627 matchOrFail(OPENBRACE); … … 762 760 { 763 761 if (match(CLOSEBRACE)) 764 return context.createFunctionBody(m_lexer->lastLineNumber(), currentScope()->modeFlags());762 return context.createFunctionBody(m_lexer->lastLineNumber(), strictMode()); 765 763 DepthManager statementDepth(&m_statementDepth); 766 764 m_statementDepth = 0; … … 773 771 template <FunctionRequirements requirements, bool nameIsInContainingScope, class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuilder& context, const Identifier*& name, TreeFormalParameterList& parameters, TreeFunctionBody& body, int& openBracePos, int& closeBracePos, int& bodyStartLine) 774 772 { 775 AutoPopScopeRef functionScope(this, pushScope(currentScope()->modeFlags() | FunctionModeFlag)); 773 AutoPopScopeRef functionScope(this, pushScope()); 774 functionScope->setIsFunction(); 776 775 if (match(IDENT)) { 777 776 name = m_token.m_data.ident; … … 795 794 if (const SourceProviderCacheItem* cachedInfo = TreeBuilder::CanUseFunctionCache ? findCachedFunctionInfo(openBracePos) : 0) { 796 795 // If we're in a strict context, the cached function info must say it was strict too. 797 ASSERT(!strictMode() || (cachedInfo->scopeFlags & StrictModeFlag));798 body = context.createFunctionBody(m_lexer->lastLineNumber(), cachedInfo->s copeFlags);796 ASSERT(!strictMode() || cachedInfo->strictMode); 797 body = context.createFunctionBody(m_lexer->lastLineNumber(), cachedInfo->strictMode); 799 798 800 799 functionScope->restoreFunctionInfo(cachedInfo); … … 856 855 failIfFalse(name); 857 856 failIfFalseIfStrict(declareVariable(name)); 858 if (*name == m_globalData->propertyNames->arguments)859 currentScope()->setFlags(UsesArgumentsFlag);860 857 return context.createFuncDeclStatement(m_lexer->lastLineNumber(), name, body, parameters, openBracePos, closeBracePos, bodyStartLine, m_lastLine); 861 858 } … … 1417 1414 case THISTOKEN: { 1418 1415 next(); 1419 currentScope()->setFlags(UsesThisFlag);1420 1416 return context.thisExpr(m_lexer->lastLineNumber()); 1421 1417 } … … 1424 1420 const Identifier* ident = m_token.m_data.ident; 1425 1421 next(); 1426 if (m_globalData->propertyNames->eval == *ident) 1427 currentScope()->setFlags(UsesEvalFlag); 1428 else if (m_globalData->propertyNames->arguments == *ident) 1429 currentScope()->setFlags(UsesArgumentsFlag); 1430 currentScope()->useVariable(ident); 1422 currentScope()->useVariable(ident, m_globalData->propertyNames->eval == *ident); 1431 1423 m_lastIdentifier = ident; 1432 1424 return context.createResolve(m_lexer->lastLineNumber(), ident, start);
Note:
See TracChangeset
for help on using the changeset viewer.