Commit 9cc90739 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Return MaybeHandle from JsonParser.

R=ishell@chromium.org

Review URL: https://codereview.chromium.org/223553003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20485 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5a57e644
......@@ -2315,13 +2315,11 @@ Local<Value> JSON::Parse(Local<String> json_string) {
i::Handle<i::String> source = i::Handle<i::String>(
FlattenGetString(Utils::OpenHandle(*json_string)));
EXCEPTION_PREAMBLE(isolate);
i::MaybeHandle<i::Object> maybe_result =
source->IsSeqOneByteString() ? i::JsonParser<true>::Parse(source)
: i::JsonParser<false>::Parse(source);
i::Handle<i::Object> result;
if (source->IsSeqOneByteString()) {
result = i::JsonParser<true>::Parse(source);
} else {
result = i::JsonParser<false>::Parse(source);
}
has_pending_exception = result.is_null();
has_pending_exception = !maybe_result.ToHandle(&result);
EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
return Utils::ToLocal(
i::Handle<i::Object>::cast(scope.CloseAndEscape(result)));
......
......@@ -43,7 +43,7 @@ namespace internal {
template <bool seq_ascii>
class JsonParser BASE_EMBEDDED {
public:
static Handle<Object> Parse(Handle<String> source) {
static MaybeHandle<Object> Parse(Handle<String> source) {
return JsonParser(source).ParseJson();
}
......@@ -69,7 +69,7 @@ class JsonParser BASE_EMBEDDED {
}
// Parse a string containing a single JSON value.
Handle<Object> ParseJson();
MaybeHandle<Object> ParseJson();
inline void Advance() {
position_++;
......@@ -219,7 +219,7 @@ class JsonParser BASE_EMBEDDED {
};
template <bool seq_ascii>
Handle<Object> JsonParser<seq_ascii>::ParseJson() {
MaybeHandle<Object> JsonParser<seq_ascii>::ParseJson() {
// Advance to the first character (possibly EOS)
AdvanceSkipWhitespace();
Handle<Object> result = ParseJsonValue();
......@@ -268,9 +268,8 @@ Handle<Object> JsonParser<seq_ascii>::ParseJson() {
MessageLocation location(factory->NewScript(source_),
position_,
position_ + 1);
Handle<Object> result = factory->NewSyntaxError(message, array);
isolate()->Throw(*result, &location);
return Handle<Object>::null();
Handle<Object> error = factory->NewSyntaxError(message, array);
return isolate()->template Throw<Object>(error, &location);
}
return result;
}
......
......@@ -9769,16 +9769,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) {
source = Handle<String>(FlattenGetString(source));
// Optimized fast case where we only have ASCII characters.
Handle<Object> result;
if (source->IsSeqOneByteString()) {
result = JsonParser<true>::Parse(source);
} else {
result = JsonParser<false>::Parse(source);
}
if (result.is_null()) {
// Syntax error or stack overflow in scanner.
ASSERT(isolate->has_pending_exception());
return Failure::Exception();
}
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
source->IsSeqOneByteString() ? JsonParser<true>::Parse(source)
: JsonParser<false>::Parse(source));
return *result;
}
......
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