Ignore:
Timestamp:
Jul 1, 2011, 12:47:05 PM (14 years ago)
Author:
[email protected]
Message:

2011-07-01 Juan C. Montemayor <[email protected]>

Reviewed by Oliver Hunt.

Lexer error messages are currently appalling
https://bugs.webkit.org/show_bug.cgi?id=63340

Updated expected test results.

  • fast/js/basic-strict-mode-expected.txt:
  • fast/js/kde/parse-expected.txt:
  • fast/js/kde/string-1-n-expected.txt:
  • fast/js/kde/string-2-n-expected.txt:
  • fast/js/numeric-escapes-in-string-literals-expected.txt:
  • fast/js/removing-Cf-characters-expected.txt:
  • fast/regex/non-pattern-characters-expected.txt:
  • http/tests/websocket/tests/bad-sub-protocol-control-chars-expected.txt:
  • loader/reload-subresource-when-type-changes-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.3_Line_Terminators/S7.3_A2.1_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.3_Line_Terminators/S7.3_A2.1_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.3_Line_Terminators/S7.3_A2.2_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.3_Line_Terminators/S7.3_A2.2_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.3_Line_Terminators/S7.3_A2.3-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.3_Line_Terminators/S7.3_A2.4-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.4_Comments/S7.4_A2_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.3_Numeric_Literals/S7.8.3_A6.1_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.3_Numeric_Literals/S7.8.3_A6.1_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.3_Numeric_Literals/S7.8.3_A6.2_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.3_Numeric_Literals/S7.8.3_A6.2_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A1.1_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A1.1_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A1.2_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A1.2_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A3.1_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A3.1_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A3.2_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A3.2_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A7.1_T4-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A7.2_T1-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A7.2_T2-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A7.2_T3-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A7.2_T4-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A7.2_T5-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.4_String_Literals/S7.8.4_A7.2_T6-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.2_T1-expected.txt:
  • sputnik/Conformance/08_Types/8.4_The_String_Type/S8.4_A13_T1-expected.txt:
  • sputnik/Conformance/08_Types/8.4_The_String_Type/S8.4_A13_T2-expected.txt:
  • sputnik/Conformance/08_Types/8.4_The_String_Type/S8.4_A14_T1-expected.txt:
  • sputnik/Conformance/08_Types/8.4_The_String_Type/S8.4_A14_T2-expected.txt:

2011-07-01 Juan C. Montemayor <[email protected]>

Reviewed by Oliver Hunt.

Lexer error messages are currently appalling
https://bugs.webkit.org/show_bug.cgi?id=63340

Added error messages for the Lexer. These messages will be displayed
instead of the lexer error messages from the parser that are currently
shown.

  • parser/Lexer.cpp: (JSC::Lexer::getInvalidCharMessage): (JSC::Lexer::setCode): (JSC::Lexer::parseString): (JSC::Lexer::lex): (JSC::Lexer::clear):
  • parser/Lexer.h: (JSC::Lexer::getErrorMessage): (JSC::Lexer::setOffset):
  • parser/Parser.cpp: (JSC::Parser::parse):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r89257 r90265  
    234234    m_keywordTable.deleteTable();
    235235}
     236   
     237UString Lexer::getInvalidCharMessage()
     238{
     239    switch (m_current) {
     240    case 0:
     241        return "Invalid character: '\\0'";
     242    case 10:
     243        return "Invalid character: '\\n'";
     244    case 11:
     245        return "Invalid character: '\\v'";
     246    case 13:
     247        return "Invalid character: '\\r'";
     248    case 35:
     249        return "Invalid character: '#'";
     250    case 64:
     251        return "Invalid character: '@'";
     252    case 96:
     253        return "Invalid character: '`'";
     254    default:
     255        return String::format("Invalid character '\\u%04u'", m_current).impl();
     256    }
     257}
    236258
    237259ALWAYS_INLINE const UChar* Lexer::currentCharacter() const
     
    262284    m_error = false;
    263285    m_atLineStart = true;
     286    m_lexErrorMessage = UString();
    264287
    265288    m_buffer8.reserveInitialCapacity(initialReadBufferCapacity);
     
    528551                    if (shouldBuildStrings)
    529552                        record16('u');
    530                 } else // Only stringQuoteCharacter allowed after \u
     553                } else {
     554                    m_lexErrorMessage = "\\u can only be followed by a Unicode character sequence";
    531555                    return false;
     556                }
    532557            } else if (strictMode && isASCIIDigit(m_current)) {
    533558                // The only valid numeric escape in strict mode is '\0', and this must not be followed by a decimal digit.
    534559                int character1 = m_current;
    535560                shift();
    536                 if (character1 != '0' || isASCIIDigit(m_current))
     561                if (character1 != '0' || isASCIIDigit(m_current)) {
     562                    m_lexErrorMessage = "The only valid numeric escape in strict mode is '\\0'";
    537563                    return false;
     564                }
    538565                if (shouldBuildStrings)
    539566                    record16(0);
     
    562589                    record16(m_current);
    563590                shift();
    564             } else
     591            } else {
     592                m_lexErrorMessage = "Unterminated string constant";
    565593                return false;
     594            }
    566595
    567596            stringStart = currentCharacter();
     
    573602        if (UNLIKELY(((static_cast<unsigned>(m_current) - 0xE) & 0x2000))) {
    574603            // New-line or end of input is not allowed
    575             if (UNLIKELY(isLineTerminator(m_current)) || UNLIKELY(m_current == -1))
     604            if (UNLIKELY(isLineTerminator(m_current)) || UNLIKELY(m_current == -1)) {
     605                m_lexErrorMessage = "Unexpected EOF";
    576606                return false;
     607            }
    577608            // Anything else is just a normal character
    578609        }
     
    924955            if (parseMultilineComment())
    925956                goto start;
     957            m_lexErrorMessage = "Multiline comment was not closed properly";
    926958            goto returnError;
    927959        }
     
    10431075            if (isASCIIOctalDigit(m_current)) {
    10441076                if (parseOctal(tokenData->doubleValue)) {
    1045                     if (strictMode)
     1077                    if (strictMode) {
     1078                        m_lexErrorMessage = "Octal escapes are forbidden in strict mode";
    10461079                        goto returnError;
     1080                    }
    10471081                    token = NUMBER;
    10481082                }
     
    10591093                }
    10601094                if ((m_current | 0x20) == 'e')
    1061                     if (!parseNumberAfterExponentIndicator())
     1095                    if (!parseNumberAfterExponentIndicator()) {
     1096                        m_lexErrorMessage = "Non-number found after exponent indicator";
    10621097                        goto returnError;
     1098                    }
    10631099                // Null-terminate string for strtod.
    10641100                m_buffer8.append('\0');
     
    10691105
    10701106        // No identifiers allowed directly after numeric literal, e.g. "3in" is bad.
    1071         if (UNLIKELY(isIdentStart(m_current)))
     1107        if (UNLIKELY(isIdentStart(m_current))) {
     1108            m_lexErrorMessage = "At least one digit must occur after a decimal point";
    10721109            goto returnError;
     1110        }
    10731111        m_buffer8.resize(0);
    10741112        m_delimited = false;
     
    11021140        goto start;
    11031141    case CharacterInvalid:
     1142        m_lexErrorMessage = getInvalidCharMessage();
    11041143        goto returnError;
    11051144    default:
    11061145        ASSERT_NOT_REACHED();
     1146        m_lexErrorMessage = "Internal Error";
    11071147        goto returnError;
    11081148    }
Note: See TracChangeset for help on using the changeset viewer.