Changeset 163225 in webkit for trunk/Source/JavaScriptCore/parser/Lexer.cpp
- Timestamp:
- Jan 31, 2014, 5:37:59 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r163195 r163225 26 26 #include "Lexer.h" 27 27 28 #include "CommonIdentifiers.h" 28 #include "JSFunctionInlines.h" 29 30 #include "JSGlobalObjectFunctions.h" 29 31 #include "Identifier.h" 30 #include "JSFunctionInlines.h"31 #include "JSGlobalObjectFunctions.h"32 32 #include "NodeInfo.h" 33 33 #include "Nodes.h" … … 91 91 // Other types (only one so far) 92 92 CharacterWhiteSpace, 93 CharacterPrivateIdentifierStart94 93 }; 95 94 … … 160 159 /* 62 - > */ CharacterGreater, 161 160 /* 63 - ? */ CharacterQuestion, 162 /* 64 - @ */ Character PrivateIdentifierStart,161 /* 64 - @ */ CharacterInvalid, 163 162 /* 65 - A */ CharacterIdentifierStart, 164 163 /* 66 - B */ CharacterIdentifierStart, … … 488 487 489 488 template <typename T> 490 Lexer<T>::Lexer(VM* vm , JSParserStrictness strictness)489 Lexer<T>::Lexer(VM* vm) 491 490 : m_isReparsing(false) 492 491 , m_vm(vm) 493 , m_parsingBuiltinFunction(strictness == JSParseBuiltin)494 492 { 495 493 } … … 756 754 m_buffer16.append(static_cast<UChar>(c)); 757 755 } 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 756 779 757 template <> 780 758 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode) … … 788 766 } 789 767 } 790 791 bool isPrivateName = m_current == '@' && m_parsingBuiltinFunction; 792 if (isPrivateName) 793 shift(); 794 768 795 769 const LChar* identifierStart = currentSourcePtr(); 796 770 unsigned identifierLineStart = currentLineStartOffset(); … … 806 780 const Identifier* ident = 0; 807 781 808 if (shouldCreateIdentifier || m_parsingBuiltinFunction) {782 if (shouldCreateIdentifier) { 809 783 int identifierLength = currentSourcePtr() - identifierStart; 810 784 ident = makeIdentifier(identifierStart, identifierLength); 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 } 785 823 786 tokenData->ident = ident; 824 787 } else 825 788 tokenData->ident = 0; 826 789 827 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {790 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords))) { 828 791 ASSERT(shouldCreateIdentifier); 829 792 if (remaining < maxTokenLength) { … … 852 815 } 853 816 } 854 855 bool isPrivateName = m_current == '@' && m_parsingBuiltinFunction;856 if (isPrivateName)857 shift();858 817 859 818 const UChar* identifierStart = currentSourcePtr(); … … 868 827 869 828 if (UNLIKELY(m_current == '\\')) { 870 ASSERT(!isPrivateName);871 829 setOffsetFromSourcePtr(identifierStart, identifierLineStart); 872 830 return parseIdentifierSlowCase<shouldCreateIdentifier>(tokenData, lexerFlags, strictMode); … … 880 838 const Identifier* ident = 0; 881 839 882 if (shouldCreateIdentifier || m_parsingBuiltinFunction) {840 if (shouldCreateIdentifier) { 883 841 int identifierLength = currentSourcePtr() - identifierStart; 884 842 if (isAll8Bit) … … 886 844 else 887 845 ident = makeIdentifier(identifierStart, identifierLength); 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 } 846 900 847 tokenData->ident = ident; 901 848 } else 902 849 tokenData->ident = 0; 903 850 904 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {851 if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords))) { 905 852 ASSERT(shouldCreateIdentifier); 906 853 if (remaining < maxTokenLength) { … … 1712 1659 FALLTHROUGH; 1713 1660 case CharacterBackSlash: 1714 parseIdent:1715 1661 if (lexerFlags & LexexFlagsDontBuildKeywords) 1716 1662 token = parseIdentifier<false>(tokenData, lexerFlags, strictMode); … … 1725 1671 m_lineStart = m_code; 1726 1672 goto start; 1727 case CharacterPrivateIdentifierStart:1728 if (m_parsingBuiltinFunction)1729 goto parseIdent;1730 1731 FALLTHROUGH;1732 1673 case CharacterInvalid: 1733 1674 m_lexErrorMessage = invalidCharacterMessage();
Note:
See TracChangeset
for help on using the changeset viewer.