Commit b6e16ce4 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Add error reporting to ParseJSON

This will be used by manifest parser.

We now pass around a Cursor struct instead of CharType*
and return error type from all internal parsing methods.

Bug: 704441
Change-Id: If2773404d66d6a264cc5b573d7132ad57db117cd
Reviewed-on: https://chromium-review.googlesource.com/1072525Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565438}
parent 0d7abffc
...@@ -14,10 +14,35 @@ namespace blink { ...@@ -14,10 +14,35 @@ namespace blink {
class JSONValue; class JSONValue;
PLATFORM_EXPORT std::unique_ptr<JSONValue> ParseJSON(const String& json); enum class JSONParseErrorType {
kNoError,
PLATFORM_EXPORT std::unique_ptr<JSONValue> ParseJSON(const String& json, kUnexpectedToken,
int max_depth); kSyntaxError,
kInvalidEscape,
kTooMuchNesting,
kUnexpectedDataAfterRoot,
kUnsupportedEncoding,
};
struct PLATFORM_EXPORT JSONParseError {
JSONParseErrorType type;
int line;
int column;
String message;
};
// Parses |json| string and returns a value it represents.
// In case of parsing failure, returns nullptr.
// Optional error struct may be passed in, which will contain
// error details or |kNoError| if parsing succeeded.
PLATFORM_EXPORT std::unique_ptr<JSONValue> ParseJSON(
const String& json,
JSONParseError* opt_error = nullptr);
PLATFORM_EXPORT std::unique_ptr<JSONValue> ParseJSON(
const String& json,
int max_depth,
JSONParseError* opt_error = nullptr);
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment