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