Source/JavaScriptCore/ChangeLog

 12019-10-16 Ross Kirsling <ross.kirsling@sony.com>
 2
 3 [JSC] Lexer flags should be an OptionSet
 4 https://bugs.webkit.org/show_bug.cgi?id=203032
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 LexerFlags has an annoyingly misspelled value LexexFlagsDontBuildKeywords;
 9 let's use this as an opportunity to modernize this enum.
 10
 11 * parser/ASTBuilder.h:
 12 * parser/Lexer.cpp:
 13 (JSC::Lexer<LChar>::parseIdentifier):
 14 (JSC::Lexer<UChar>::parseIdentifier):
 15 (JSC::Lexer<CharacterType>::parseIdentifierSlowCase):
 16 (JSC::Lexer<T>::lexWithoutClearingLineTerminator):
 17 * parser/Lexer.h:
 18 (JSC::Lexer<T>::lexExpectIdentifier):
 19 (JSC::Lexer<T>::lex):
 20 * parser/Parser.cpp:
 21 (JSC::Parser<LexerType>::parseProperty):
 22 (JSC::Parser<LexerType>::parseMemberExpression):
 23 * parser/Parser.h:
 24 (JSC::Parser::next):
 25 (JSC::Parser::nextWithoutClearingLineTerminator):
 26 (JSC::Parser::nextExpectIdentifier):
 27 (JSC::Parser::consume):
 28 * parser/SyntaxChecker.h:
 29
1302019-10-16 Paulo Matos <pmatos@linki.tools>
231
332 Fix GCC warning on MIPS about dead variable metadata

Source/JavaScriptCore/parser/ASTBuilder.h

@@public:
125125 static constexpr bool CreatesAST = true;
126126 static constexpr bool NeedsFreeVariableInfo = true;
127127 static constexpr bool CanUseFunctionCache = true;
128  static constexpr int DontBuildKeywords = 0;
129  static constexpr int DontBuildStrings = 0;
 128 static constexpr OptionSet<LexerFlags> DontBuildKeywords { };
 129 static constexpr OptionSet<LexerFlags> DontBuildStrings { };
130130
131131 ExpressionNode* makeBinaryNode(const JSTokenLocation&, int token, std::pair<ExpressionNode*, BinaryOpInfo>, std::pair<ExpressionNode*, BinaryOpInfo>);
132132 ExpressionNode* makeFunctionCallNode(const JSTokenLocation&, ExpressionNode* func, bool previousBaseWasSuper, ArgumentsNode* args, const JSTextPosition& divotStart, const JSTextPosition& divot, const JSTextPosition& divotEnd, size_t callOrApplyChildDepth, bool isOptionalCall);

Source/JavaScriptCore/parser/Lexer.cpp

@@bool isSafeBuiltinIdentifier(VM& vm, const Identifier* ident)
927927#endif
928928
929929template <>
930 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
 930template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode)
931931{
932932 tokenData->escaped = false;
933933 const ptrdiff_t remaining = m_codeEnd - m_code;
934  if ((remaining >= maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) {
 934 if ((remaining >= maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) {
935935 JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(tokenData);
936936 if (keyword != IDENT) {
937937 ASSERT((!shouldCreateIdentifier) || tokenData->ident);

@@template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::p
975975 } else
976976 tokenData->ident = nullptr;
977977
978  if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {
 978 if (UNLIKELY((remaining < maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) && !isPrivateName) {
979979 ASSERT(shouldCreateIdentifier);
980980 if (remaining < maxTokenLength) {
981981 const HashTableValue* entry = JSC::mainTable.entry(*ident);

@@template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::p
992992}
993993
994994template <>
995 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
 995template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::parseIdentifier(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode)
996996{
997997 tokenData->escaped = false;
998998 const ptrdiff_t remaining = m_codeEnd - m_code;
999  if ((remaining >= maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) {
 999 if ((remaining >= maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) {
10001000 JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(tokenData);
10011001 if (keyword != IDENT) {
10021002 ASSERT((!shouldCreateIdentifier) || tokenData->ident);

@@template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::p
10531053 } else
10541054 tokenData->ident = nullptr;
10551055
1056  if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {
 1056 if (UNLIKELY((remaining < maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) && !isPrivateName) {
10571057 ASSERT(shouldCreateIdentifier);
10581058 if (remaining < maxTokenLength) {
10591059 const HashTableValue* entry = JSC::mainTable.entry(*ident);

@@template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::p
10691069 return IDENT;
10701070}
10711071
1072 template<typename CharacterType> template<bool shouldCreateIdentifier> JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
 1072template<typename CharacterType> template<bool shouldCreateIdentifier> JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode)
10731073{
10741074 tokenData->escaped = true;
10751075 auto identifierStart = currentSourcePtr();

@@template<typename CharacterType> template<bool shouldCreateIdentifier> JSTokenTy
11191119
11201120 m_buffer16.shrink(0);
11211121
1122  if (LIKELY(!(lexerFlags & LexerFlagsIgnoreReservedWords))) {
 1122 if (LIKELY(!lexerFlags.contains(LexerFlags::IgnoreReservedWords))) {
11231123 ASSERT(shouldCreateIdentifier);
11241124 const HashTableValue* entry = JSC::mainTable.entry(*ident);
11251125 if (!entry)

@@void Lexer<T>::fillTokenInfo(JSToken* tokenRecord, JSTokenType token, int lineNu
18591859}
18601860
18611861template <typename T>
1862 JSTokenType Lexer<T>::lexWithoutClearingLineTerminator(JSToken* tokenRecord, unsigned lexerFlags, bool strictMode)
 1862JSTokenType Lexer<T>::lexWithoutClearingLineTerminator(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
18631863{
18641864 JSTokenData* tokenData = &tokenRecord->m_data;
18651865 JSTokenLocation* tokenLocation = &tokenRecord->m_location;

@@start:
23792379 break;
23802380 case CharacterQuote: {
23812381 StringParseResult result = StringCannotBeParsed;
2382  if (lexerFlags & LexerFlagsDontBuildStrings)
 2382 if (lexerFlags.contains(LexerFlags::DontBuildStrings))
23832383 result = parseString<false>(tokenData, strictMode);
23842384 else
23852385 result = parseString<true>(tokenData, strictMode);

@@start:
23972397 FALLTHROUGH;
23982398 case CharacterBackSlash:
23992399 parseIdent:
2400  if (lexerFlags & LexexFlagsDontBuildKeywords)
 2400 if (lexerFlags.contains(LexerFlags::DontBuildKeywords))
24012401 token = parseIdentifier<false>(tokenData, lexerFlags, strictMode);
24022402 else
24032403 token = parseIdentifier<true>(tokenData, lexerFlags, strictMode);

Source/JavaScriptCore/parser/Lexer.h

3232
3333namespace JSC {
3434
35 enum LexerFlags {
36  LexerFlagsIgnoreReservedWords = 1,
37  LexerFlagsDontBuildStrings = 2,
38  LexexFlagsDontBuildKeywords = 4
 35enum class LexerFlags : uint8_t {
 36 IgnoreReservedWords = 1 << 0,
 37 DontBuildStrings = 1 << 1,
 38 DontBuildKeywords = 1 << 2
3939};
4040
4141enum class LexerEscapeParseMode { Template, String };

@@public:
6464 void setIsReparsingFunction() { m_isReparsingFunction = true; }
6565 bool isReparsingFunction() const { return m_isReparsingFunction; }
6666
67  JSTokenType lex(JSToken*, unsigned, bool strictMode);
68  JSTokenType lexWithoutClearingLineTerminator(JSToken*, unsigned, bool strictMode);
 67 JSTokenType lex(JSToken*, OptionSet<LexerFlags>, bool strictMode);
 68 JSTokenType lexWithoutClearingLineTerminator(JSToken*, OptionSet<LexerFlags>, bool strictMode);
6969 bool nextTokenIsColon();
7070 int lineNumber() const { return m_lineNumber; }
7171 ALWAYS_INLINE int currentOffset() const { return offsetFromSourcePtr(m_code); }

@@public:
116116 m_hasLineTerminatorBeforeToken = terminator;
117117 }
118118
119  JSTokenType lexExpectIdentifier(JSToken*, unsigned, bool strictMode);
 119 JSTokenType lexExpectIdentifier(JSToken*, OptionSet<LexerFlags>, bool strictMode);
120120
121121 ALWAYS_INLINE StringView getToken(const JSToken& token)
122122 {

@@private:
164164
165165 template <int shiftAmount> void internalShift();
166166 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType parseKeyword(JSTokenData*);
167  template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, unsigned lexerFlags, bool strictMode);
168  template <bool shouldBuildIdentifiers> NEVER_INLINE JSTokenType parseIdentifierSlowCase(JSTokenData*, unsigned lexerFlags, bool strictMode);
 167 template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, OptionSet<LexerFlags>, bool strictMode);
 168 template <bool shouldBuildIdentifiers> NEVER_INLINE JSTokenType parseIdentifierSlowCase(JSTokenData*, OptionSet<LexerFlags>, bool strictMode);
169169 enum StringParseResult {
170170 StringParsedSuccessfully,
171171 StringUnterminated,

@@bool isSafeBuiltinIdentifier(VM&, const Identifier*);
340340#endif
341341
342342template <typename T>
343 ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, unsigned lexerFlags, bool strictMode)
 343ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
344344{
345345 JSTokenData* tokenData = &tokenRecord->m_data;
346346 JSTokenLocation* tokenLocation = &tokenRecord->m_location;
347  ASSERT((lexerFlags & LexerFlagsIgnoreReservedWords));
 347 ASSERT(lexerFlags.contains(LexerFlags::IgnoreReservedWords));
348348 const T* start = m_code;
349349 const T* ptr = start;
350350 const T* end = m_codeEnd;

@@ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, un
374374 ASSERT(currentOffset() >= currentLineStartOffset());
375375
376376 // Create the identifier if needed
377  if (lexerFlags & LexexFlagsDontBuildKeywords
 377 if (lexerFlags.contains(LexerFlags::DontBuildKeywords)
378378#if !ASSERT_DISABLED
379379 && !m_parsingBuiltinFunction
380380#endif

@@slowCase:
405405}
406406
407407template <typename T>
408 ALWAYS_INLINE JSTokenType Lexer<T>::lex(JSToken* tokenRecord, unsigned lexerFlags, bool strictMode)
 408ALWAYS_INLINE JSTokenType Lexer<T>::lex(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
409409{
410410 m_hasLineTerminatorBeforeToken = false;
411411 return lexWithoutClearingLineTerminator(tokenRecord, lexerFlags, strictMode);

Source/JavaScriptCore/parser/Parser.cpp

@@namedProperty:
40034003 JSToken identToken = m_token;
40044004
40054005 if (complete || (wasIdent && !isGeneratorMethodParseMode(parseMode) && (*ident == m_vm.propertyNames->get || *ident == m_vm.propertyNames->set)))
4006  nextExpectIdentifier(LexerFlagsIgnoreReservedWords);
 4006 nextExpectIdentifier(LexerFlags::IgnoreReservedWords);
40074007 else
4008  nextExpectIdentifier(LexerFlagsIgnoreReservedWords | TreeBuilder::DontBuildKeywords);
 4008 nextExpectIdentifier(TreeBuilder::DontBuildKeywords | LexerFlags::IgnoreReservedWords);
40094009
40104010 if (!isGeneratorMethodParseMode(parseMode) && !isAsyncMethodParseMode(parseMode) && match(COLON)) {
40114011 next();

@@template <class TreeBuilder> TreeExpression Parser<LexerType>::parseMemberExpres
48494849 case DOT: {
48504850 m_parserState.nonTrivialExpressionCount++;
48514851 JSTextPosition expressionEnd = lastTokenEndPosition();
4852  nextExpectIdentifier(LexerFlagsIgnoreReservedWords | TreeBuilder::DontBuildKeywords);
 4852 nextExpectIdentifier(TreeBuilder::DontBuildKeywords | LexerFlags::IgnoreReservedWords);
48534853 matchOrFail(IDENT, "Expected a property name after ", optionalChainBase ? "'?.'" : "'.'");
48544854 base = context.createDotAccess(startLocation, base, m_token.m_data.ident, expressionStart, expressionEnd, tokenEndPosition());
48554855 if (UNLIKELY(baseIsSuper && currentScope()->isArrowFunction()))

Source/JavaScriptCore/parser/Parser.h

@@private:
13551355 bool isFunctionMetadataNode(ScopeNode*) { return false; }
13561356 bool isFunctionMetadataNode(FunctionMetadataNode*) { return true; }
13571357
1358  ALWAYS_INLINE void next(unsigned lexerFlags = 0)
 1358 ALWAYS_INLINE void next(OptionSet<LexerFlags> lexerFlags = { })
13591359 {
13601360 int lastLine = m_token.m_location.line;
13611361 int lastTokenEnd = m_token.m_location.endOffset;

@@private:
13651365 m_token.m_type = m_lexer->lex(&m_token, lexerFlags, strictMode());
13661366 }
13671367
1368  ALWAYS_INLINE void nextWithoutClearingLineTerminator(unsigned lexerFlags = 0)
 1368 ALWAYS_INLINE void nextWithoutClearingLineTerminator(OptionSet<LexerFlags> lexerFlags = { })
13691369 {
13701370 int lastLine = m_token.m_location.line;
13711371 int lastTokenEnd = m_token.m_location.endOffset;

@@private:
13751375 m_token.m_type = m_lexer->lexWithoutClearingLineTerminator(&m_token, lexerFlags, strictMode());
13761376 }
13771377
1378  ALWAYS_INLINE void nextExpectIdentifier(unsigned lexerFlags = 0)
 1378 ALWAYS_INLINE void nextExpectIdentifier(OptionSet<LexerFlags> lexerFlags = { })
13791379 {
13801380 int lastLine = m_token.m_location.line;
13811381 int lastTokenEnd = m_token.m_location.endOffset;

@@private:
13961396 return m_lexer->nextTokenIsColon();
13971397 }
13981398
1399  ALWAYS_INLINE bool consume(JSTokenType expected, unsigned flags = 0)
 1399 ALWAYS_INLINE bool consume(JSTokenType expected, OptionSet<LexerFlags> flags = { })
14001400 {
14011401 bool result = m_token.m_type == expected;
14021402 if (result)

Source/JavaScriptCore/parser/SyntaxChecker.h

@@public:
143143 static constexpr bool CreatesAST = false;
144144 static constexpr bool NeedsFreeVariableInfo = false;
145145 static constexpr bool CanUseFunctionCache = true;
146  static constexpr unsigned DontBuildKeywords = LexexFlagsDontBuildKeywords;
147  static constexpr unsigned DontBuildStrings = LexerFlagsDontBuildStrings;
 146 static constexpr OptionSet<LexerFlags> DontBuildKeywords { LexerFlags::DontBuildKeywords };
 147 static constexpr OptionSet<LexerFlags> DontBuildStrings { LexerFlags::DontBuildStrings };
148148
149149 int createSourceElements() { return SourceElementsResult; }
150150 ExpressionType makeFunctionCallNode(const JSTokenLocation&, ExpressionType, bool, int, int, int, int, size_t, bool) { return CallExpr; }