Changeset 148167 in webkit
- Timestamp:
- Apr 10, 2013 8:17:08 PM (11 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r148162 r148167 1 2013-04-10 Benjamin Poulain <benjamin@webkit.org> 2 3 Unify JSC Parser's error and error message 4 https://bugs.webkit.org/show_bug.cgi?id=114363 5 6 Reviewed by Geoffrey Garen. 7 8 The parser kept the error state over two attributes: 9 error and errorMessage. They were changed in sync, 10 but had some discrepancy (for example, the error message 11 was always defined to something). 12 13 This patch unifies the two. There is an error if 14 if the error message is non-null or if the parsing finished 15 before the end. 16 17 This also gets rid of the allocation of the error message 18 when instantiating a parser. 19 20 * parser/Parser.cpp: 21 (JSC::::Parser): 22 (JSC::::parseInner): 23 (JSC::::parseSourceElements): 24 (JSC::::parseVarDeclaration): 25 (JSC::::parseConstDeclaration): 26 (JSC::::parseForStatement): 27 (JSC::::parseSwitchStatement): 28 (JSC::::parsePrimaryExpression): 29 * parser/Parser.h: 30 (JSC::Parser::updateErrorMessage): 31 (JSC::Parser::updateErrorWithNameAndMessage): 32 (JSC::Parser::hasError): 33 (Parser): 34 1 35 2013-04-10 Oliver Hunt <oliver@apple.com> 2 36 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r146318 r148167 36 36 #include <wtf/WTFThreadData.h> 37 37 38 #define fail() do { if (! m_error) updateErrorMessage(); return 0; } while (0)39 #define failWithToken(tok) do { if (! m_error) updateErrorMessage(tok); return 0; } while (0)40 #define failWithMessage(msg) do { if (! m_error) updateErrorMessage(msg); return 0; } while (0)41 #define failWithNameAndMessage(before, name, after) do { if (! m_error) updateErrorWithNameAndMessage(before, name, after); return 0; } while (0)42 #define failWithStackOverflow() do { m_error = true; m_hasStackOverflow = true; return 0; } while (0)38 #define fail() do { if (!hasError()) updateErrorMessage(); return 0; } while (0) 39 #define failWithToken(tok) do { if (!hasError()) updateErrorMessage(tok); return 0; } while (0) 40 #define failWithMessage(msg) do { if (!hasError()) updateErrorMessage(msg); return 0; } while (0) 41 #define failWithNameAndMessage(before, name, after) do { if (!hasError()) updateErrorWithNameAndMessage(before, name, after); return 0; } while (0) 42 #define failWithStackOverflow() do { updateErrorMessage("Stack exhausted"); m_hasStackOverflow = true; return 0; } while (0) 43 43 #define failIfFalse(cond) do { if (!(cond)) fail(); } while (0) 44 44 #define failIfFalseWithMessage(cond, msg) do { if (!(cond)) failWithMessage(msg); } while (0) … … 68 68 , m_stack(wtfThreadData().stack()) 69 69 , m_hasStackOverflow(false) 70 , m_error(false)71 , m_errorMessage("Parse error")72 70 , m_allowsIn(true) 73 71 , m_lastLine(0) … … 115 113 ScopeRef scope = currentScope(); 116 114 SourceElements* sourceElements = parseSourceElements<CheckForStrictMode>(context); 117 if (!sourceElements || !consume(EOFTOK)) 118 parseError = m_errorMessage; 115 if (!sourceElements || !consume(EOFTOK)) { 116 if (hasError()) 117 parseError = m_errorMessage; 118 else 119 parseError = ASCIILiteral("Parser error"); 120 } 119 121 120 122 IdentifierSet capturedVariables; … … 175 177 m_lexer->setLastLineNumber(oldLastLineNumber); 176 178 m_lexer->setLineNumber(oldLineNumber); 177 failIfTrue( m_error);179 failIfTrue(hasError()); 178 180 continue; 179 181 } … … 183 185 context.appendStatement(sourceElements, statement); 184 186 } 185 186 if (m_error) 187 fail(); 187 188 failIfTrue(hasError()); 188 189 return sourceElements; 189 190 } … … 201 202 int scratch3 = 0; 202 203 TreeExpression varDecls = parseVarDeclarationList(context, scratch, scratch1, scratch2, scratch3, scratch3, scratch3); 203 failIfTrue( m_error);204 failIfTrue(hasError()); 204 205 failIfFalse(autoSemiColon()); 205 206 … … 215 216 int end = 0; 216 217 TreeConstDeclList constDecls = parseConstDeclarationList(context); 217 failIfTrue( m_error);218 failIfTrue(hasError()); 218 219 failIfFalse(autoSemiColon()); 219 220 … … 354 355 decls = parseVarDeclarationList(context, declarations, forInTarget, forInInitializer, declsStart, initStart, initEnd); 355 356 m_allowsIn = true; 356 if (m_error) 357 fail(); 358 357 failIfTrue(hasError()); 358 359 359 // Remainder of a standard for loop is handled identically 360 360 if (match(SEMICOLON)) … … 574 574 startSwitch(); 575 575 TreeClauseList firstClauses = parseSwitchClauses(context); 576 failIfTrue( m_error);576 failIfTrue(hasError()); 577 577 578 578 TreeClause defaultClause = parseSwitchDefaultClause(context); 579 failIfTrue( m_error);579 failIfTrue(hasError()); 580 580 581 581 TreeClauseList secondClauses = parseSwitchClauses(context); 582 failIfTrue( m_error);582 failIfTrue(hasError()); 583 583 endSwitch(); 584 584 consumeOrFail(CLOSEBRACE); … … 1538 1538 if (!re) { 1539 1539 const char* yarrErrorMsg = Yarr::checkSyntax(pattern->string()); 1540 ASSERT(!m_errorMessage.isNull());1541 1540 failWithMessage(yarrErrorMsg); 1542 1541 } -
trunk/Source/JavaScriptCore/parser/Parser.h
r146318 r148167 753 753 NEVER_INLINE void updateErrorMessage() 754 754 { 755 m_error = true;756 755 const char* name = getTokenName(m_token.m_type); 757 756 if (!name) … … 759 758 else 760 759 m_errorMessage = String::format("Unexpected token '%s'", name); 760 ASSERT(!m_errorMessage.isNull()); 761 761 } 762 762 763 763 NEVER_INLINE void updateErrorMessage(JSTokenType expectedToken) 764 764 { 765 m_error = true;766 765 const char* name = getTokenName(expectedToken); 767 766 if (name) … … 773 772 updateErrorMessageSpecialCase(expectedToken); 774 773 } 774 ASSERT(!m_errorMessage.isNull()); 775 775 } 776 776 777 777 NEVER_INLINE void updateErrorWithNameAndMessage(const char* beforeMsg, String name, const char* afterMsg) 778 778 { 779 m_error = true;780 779 m_errorMessage = makeString(beforeMsg, " '", name, "' ", afterMsg); 781 780 } 782 781 783 782 NEVER_INLINE void updateErrorMessage(const char* msg) 784 { 785 m_error = true;783 { 784 ASSERT(msg); 786 785 m_errorMessage = String(msg); 786 ASSERT(!m_errorMessage.isNull()); 787 787 } 788 788 … … 890 890 } 891 891 892 bool hasError() const 893 { 894 return !m_errorMessage.isNull(); 895 } 896 892 897 JSGlobalData* m_globalData; 893 898 const SourceCode* m_source; … … 897 902 StackBounds m_stack; 898 903 bool m_hasStackOverflow; 899 bool m_error;900 904 String m_errorMessage; 901 905 JSToken m_token;
Note: See TracChangeset
for help on using the changeset viewer.