Changeset 163960 in webkit for trunk/Source/JavaScriptCore/parser/Lexer.cpp
- Timestamp:
- Feb 12, 2014, 9:14:23 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r163844 r163960 92 92 // Other types (only one so far) 93 93 CharacterWhiteSpace, 94 CharacterPrivateIdentifierStart 94 95 }; 95 96 … … 160 161 /* 62 - > */ CharacterGreater, 161 162 /* 63 - ? */ CharacterQuestion, 162 /* 64 - @ */ Character Invalid,163 /* 64 - @ */ CharacterPrivateIdentifierStart, 163 164 /* 65 - A */ CharacterIdentifierStart, 164 165 /* 66 - B */ CharacterIdentifierStart, … … 488 489 489 490 template <typename T> 490 Lexer<T>::Lexer(VM* vm )491 Lexer<T>::Lexer(VM* vm, JSParserStrictness strictness) 491 492 : m_isReparsing(false) 492 493 , m_vm(vm) 494 , m_parsingBuiltinFunction(strictness == JSParseBuiltin) 493 495 { 494 496 } … … 755 757 m_buffer16.append(static_cast<UChar>(c)); 756 758 } 757 759 760 #if !ASSERT_DISABLED 761 bool isSafeBuiltinIdentifier(VM& vm, const Identifier* ident) 762 { 763 if (!ident) 764 return true; 765 /* Just block any use of suspicious identifiers. This is intended to 766 * be used as a safety net while implementing builtins. 767 */ 768 if (*ident == vm.propertyNames->call) 769 return false; 770 if (*ident == vm.propertyNames->apply) 771 return false; 772 if (*ident == vm.propertyNames->eval) 773 return false; 774 if (*ident == vm.propertyNames->Function) 775 return false; 776 return true; 777 } 778 #endif 779 758 780 template <> 759 781 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode) … … 767 789 } 768 790 } 769 791 792 bool isPrivateName = m_current == '@' && m_parsingBuiltinFunction; 793 if (isPrivateName) 794 shift(); 795 770 796 const LChar* identifierStart = currentSourcePtr(); 771 797 unsigned identifierLineStart = currentLineStartOffset(); … … 781 807 const Identifier* ident = 0; 782 808 783 if (shouldCreateIdentifier ) {809 if (shouldCreateIdentifier || m_parsingBuiltinFunction) { 784 810 int identifierLength = currentSourcePtr() - identifierStart; 785 811 ident = makeIdentifier(identifierStart, identifierLength); 786 812 if (m_parsingBuiltinFunction) { 813 if (!isSafeBuiltinIdentifier(*m_vm, ident) && !isPrivateName) { 814 m_lexErrorMessage = makeString("The use of '", ident->string(), "' is disallowed in builtin functions."); 815 return ERRORTOK; 816 } 817 if (isPrivateName) 818 ident = m_vm->propertyNames->getPrivateName(*ident); 819 else if (*ident == m_vm->propertyNames->undefinedKeyword) 820 tokenData->ident = &m_vm->propertyNames->undefinedPrivateName; 821 if (!ident) 822 return INVALID_PRIVATE_NAME_ERRORTOK; 823 } 787 824 tokenData->ident = ident; 788 825 } else 789 826 tokenData->ident = 0; 790 827 791 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) ) {828 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) { 792 829 ASSERT(shouldCreateIdentifier); 793 830 if (remaining < maxTokenLength) { … … 816 853 } 817 854 } 855 856 bool isPrivateName = m_current == '@' && m_parsingBuiltinFunction; 857 if (isPrivateName) 858 shift(); 818 859 819 860 const UChar* identifierStart = currentSourcePtr(); … … 828 869 829 870 if (UNLIKELY(m_current == '\\')) { 871 ASSERT(!isPrivateName); 830 872 setOffsetFromSourcePtr(identifierStart, identifierLineStart); 831 873 return parseIdentifierSlowCase<shouldCreateIdentifier>(tokenData, lexerFlags, strictMode); … … 839 881 const Identifier* ident = 0; 840 882 841 if (shouldCreateIdentifier ) {883 if (shouldCreateIdentifier || m_parsingBuiltinFunction) { 842 884 int identifierLength = currentSourcePtr() - identifierStart; 843 885 if (isAll8Bit) … … 845 887 else 846 888 ident = makeIdentifier(identifierStart, identifierLength); 847 889 if (m_parsingBuiltinFunction) { 890 if (!isSafeBuiltinIdentifier(*m_vm, ident) && !isPrivateName) { 891 m_lexErrorMessage = makeString("The use of '", ident->string(), "' is disallowed in builtin functions."); 892 return ERRORTOK; 893 } 894 if (isPrivateName) 895 ident = m_vm->propertyNames->getPrivateName(*ident); 896 else if (*ident == m_vm->propertyNames->undefinedKeyword) 897 tokenData->ident = &m_vm->propertyNames->undefinedPrivateName; 898 if (!ident) 899 return INVALID_PRIVATE_NAME_ERRORTOK; 900 } 848 901 tokenData->ident = ident; 849 902 } else 850 903 tokenData->ident = 0; 851 904 852 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) ) {905 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) { 853 906 ASSERT(shouldCreateIdentifier); 854 907 if (remaining < maxTokenLength) { … … 1660 1713 FALLTHROUGH; 1661 1714 case CharacterBackSlash: 1715 parseIdent: 1662 1716 if (lexerFlags & LexexFlagsDontBuildKeywords) 1663 1717 token = parseIdentifier<false>(tokenData, lexerFlags, strictMode); … … 1672 1726 m_lineStart = m_code; 1673 1727 goto start; 1728 case CharacterPrivateIdentifierStart: 1729 if (m_parsingBuiltinFunction) 1730 goto parseIdent; 1731 1732 FALLTHROUGH; 1674 1733 case CharacterInvalid: 1675 1734 m_lexErrorMessage = invalidCharacterMessage();
Note:
See TracChangeset
for help on using the changeset viewer.