Ignore:
Timestamp:
Jul 26, 2011, 10:53:40 AM (14 years ago)
Author:
[email protected]
Message:

JSON errors should be informative
https://bugs.webkit.org/show_bug.cgi?id=63339

Source/JavaScriptCore:

Added error messages to the JSON Parser.

Patch by Juan C. Montemayor <[email protected]> on 2011-07-26
Reviewed by Oliver Hunt.

  • runtime/JSONObject.cpp:

(JSC::JSONProtoFuncParse):

  • runtime/LiteralParser.cpp:

(JSC::LiteralParser::Lexer::lex):
(JSC::LiteralParser::Lexer::lexString):
(JSC::LiteralParser::Lexer::lexNumber):
(JSC::LiteralParser::parse):

  • runtime/LiteralParser.h:

(JSC::LiteralParser::getErrorMessage):
(JSC::LiteralParser::Lexer::sawError):
(JSC::LiteralParser::Lexer::getErrorMessage):

LayoutTests:

Updated expected test results.

Patch by Juan C. Montemayor <[email protected]> on 2011-07-26
Reviewed by Oliver Hunt.

  • fast/js/JSON-parse-expected.txt:
  • platform/chromium/fast/js/JSON-parse-expected.txt: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/LiteralParser.h

    r91715 r91765  
    4242            , m_mode(mode)
    4343        {
     44        }
     45       
     46        UString getErrorMessage()
     47        {
     48            if (!m_lexer.getErrorMessage().isEmpty())
     49                return String::format("JSON Parse error: %s", m_lexer.getErrorMessage().ascii().data()).impl();
     50            if (!m_parseErrorMessage.isEmpty())
     51                return String::format("JSON Parse error: %s", m_parseErrorMessage.ascii().data()).impl();
     52            return "JSON Parse error: Unable to parse JSON string";
    4453        }
    4554       
     
    113122            }
    114123           
     124            UString getErrorMessage() { return m_lexErrorMessage; }
     125           
    115126        private:
     127            UString m_lexErrorMessage;
    116128            template <ParserMode mode> TokenType lex(LiteralParserToken&);
    117129            template <ParserMode mode, UChar terminator> ALWAYS_INLINE TokenType lexString(LiteralParserToken&);
     
    130142        LiteralParser::Lexer m_lexer;
    131143        ParserMode m_mode;
     144        UString m_parseErrorMessage;
    132145        static unsigned const MaximumCachableCharacter = 128;
    133146        FixedArray<Identifier, MaximumCachableCharacter> m_shortIdentifiers;
Note: See TracChangeset for help on using the changeset viewer.