Changeset 237054 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Oct 11, 2018, 4:43:58 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r233855 r237054 196 196 197 197 template <typename LexerType> 198 String Parser<LexerType>::parseInner(const Identifier& calleeName, SourceParseMode parseMode )198 String Parser<LexerType>::parseInner(const Identifier& calleeName, SourceParseMode parseMode, ParsingContext parsingContext, std::optional<int> functionConstructorParametersEndPosition) 199 199 { 200 200 String parseError = String(); … … 240 240 else if (isAsyncGeneratorWrapperParseMode(parseMode)) 241 241 sourceElements = parseAsyncGeneratorFunctionSourceElements(context, parseMode, isArrowFunctionBodyExpression, CheckForStrictMode); 242 else if (parsingContext == ParsingContext::FunctionConstructor) 243 sourceElements = parseSingleFunction(context, functionConstructorParametersEndPosition); 242 244 else 243 245 sourceElements = parseSourceElements(context, CheckForStrictMode); … … 612 614 return sourceElements; 613 615 } 616 617 template <typename LexerType> 618 template <class TreeBuilder> TreeSourceElements Parser<LexerType>::parseSingleFunction(TreeBuilder& context, std::optional<int> functionConstructorParametersEndPosition) 619 { 620 TreeSourceElements sourceElements = context.createSourceElements(); 621 TreeStatement statement = 0; 622 switch (m_token.m_type) { 623 case FUNCTION: 624 statement = parseFunctionDeclaration(context, ExportType::NotExported, DeclarationDefaultContext::Standard, functionConstructorParametersEndPosition); 625 break; 626 case IDENT: 627 if (*m_token.m_data.ident == m_vm->propertyNames->async && !m_token.m_data.escaped) { 628 next(); 629 failIfFalse(match(FUNCTION) && !m_lexer->prevTerminator(), "Cannot parse the async function"); 630 statement = parseAsyncFunctionDeclaration(context, ExportType::NotExported, DeclarationDefaultContext::Standard, functionConstructorParametersEndPosition); 631 break; 632 } 633 FALLTHROUGH; 634 default: 635 failDueToUnexpectedToken(); 636 break; 637 } 638 639 if (statement) { 640 context.setEndOffset(statement, m_lastTokenEndPosition.offset); 641 context.appendStatement(sourceElements, statement); 642 } 643 644 propagateError(); 645 return sourceElements; 646 } 647 614 648 615 649 template <typename LexerType> … … 2265 2299 2266 2300 template <typename LexerType> 2267 template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuilder& context, FunctionNameRequirements requirements, SourceParseMode mode, bool nameIsInContainingScope, ConstructorKind constructorKind, SuperBinding expectedSuperBinding, int functionKeywordStart, ParserFunctionInfo<TreeBuilder>& functionInfo, FunctionDefinitionType functionDefinitionType )2301 template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuilder& context, FunctionNameRequirements requirements, SourceParseMode mode, bool nameIsInContainingScope, ConstructorKind constructorKind, SuperBinding expectedSuperBinding, int functionKeywordStart, ParserFunctionInfo<TreeBuilder>& functionInfo, FunctionDefinitionType functionDefinitionType, std::optional<int> functionConstructorParametersEndPosition) 2268 2302 { 2269 2303 RELEASE_ASSERT(isFunctionParseMode(mode)); … … 2461 2495 2462 2496 matchOrFail(OPENBRACE, "Expected an opening '{' at the start of a ", stringForFunctionMode(mode), " body"); 2497 2498 // If the code is invoked from function constructor, we need to ensure that parameters are only composed by the string offered as parameters. 2499 if (functionConstructorParametersEndPosition) 2500 semanticFailIfFalse(lastTokenEndPosition().offset == *functionConstructorParametersEndPosition, "Parameters should match arguments offered as parameters in Function constructor"); 2463 2501 2464 2502 // BytecodeGenerator emits code to throw TypeError when a class constructor is "call"ed. … … 2595 2633 2596 2634 template <typename LexerType> 2597 template <class TreeBuilder> TreeStatement Parser<LexerType>::parseFunctionDeclaration(TreeBuilder& context, ExportType exportType, DeclarationDefaultContext declarationDefaultContext )2635 template <class TreeBuilder> TreeStatement Parser<LexerType>::parseFunctionDeclaration(TreeBuilder& context, ExportType exportType, DeclarationDefaultContext declarationDefaultContext, std::optional<int> functionConstructorParametersEndPosition) 2598 2636 { 2599 2637 ASSERT(match(FUNCTION)); … … 2632 2670 } 2633 2671 2634 failIfFalse((parseFunctionInfo(context, requirements, parseMode, true, ConstructorKind::None, SuperBinding::NotNeeded, functionKeywordStart, functionInfo, FunctionDefinitionType::Declaration )), "Cannot parse this function");2672 failIfFalse((parseFunctionInfo(context, requirements, parseMode, true, ConstructorKind::None, SuperBinding::NotNeeded, functionKeywordStart, functionInfo, FunctionDefinitionType::Declaration, functionConstructorParametersEndPosition)), "Cannot parse this function"); 2635 2673 ASSERT(functionInfo.name); 2636 2674 … … 2653 2691 2654 2692 template <typename LexerType> 2655 template <class TreeBuilder> TreeStatement Parser<LexerType>::parseAsyncFunctionDeclaration(TreeBuilder& context, ExportType exportType, DeclarationDefaultContext declarationDefaultContext )2693 template <class TreeBuilder> TreeStatement Parser<LexerType>::parseAsyncFunctionDeclaration(TreeBuilder& context, ExportType exportType, DeclarationDefaultContext declarationDefaultContext, std::optional<int> functionConstructorParametersEndPosition) 2656 2694 { 2657 2695 ASSERT(match(FUNCTION)); … … 2690 2728 } 2691 2729 2692 failIfFalse((parseFunctionInfo(context, requirements, parseMode, true, ConstructorKind::None, SuperBinding::NotNeeded, functionKeywordStart, functionInfo, FunctionDefinitionType::Declaration )), "Cannot parse this async function");2730 failIfFalse((parseFunctionInfo(context, requirements, parseMode, true, ConstructorKind::None, SuperBinding::NotNeeded, functionKeywordStart, functionInfo, FunctionDefinitionType::Declaration, functionConstructorParametersEndPosition)), "Cannot parse this async function"); 2693 2731 failIfFalse(functionInfo.name, "Async function statements must have a name"); 2694 2732
Note:
See TracChangeset
for help on using the changeset viewer.