Ignore:
Timestamp:
Jul 25, 2011, 11:41: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-25
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-25
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

    r89219 r91686  
    4242            , m_mode(mode)
    4343        {
     44        }
     45       
     46        UString getErrorMessage()
     47        {
     48            if (m_parseErrorMessage.isEmpty())
     49                m_parseErrorMessage = "Unable to parse JSON string";
     50            UString errorMessage = m_lexer.sawError() ?  m_lexer.getErrorMessage() : m_parseErrorMessage;
     51            return String::format("JSON Parse error: %s", errorMessage.ascii().data()).impl();
    4452        }
    4553       
     
    113121            }
    114122           
     123            bool sawError() { return !m_lexErrorMessage.isEmpty(); }
     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.