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