From 9cc90739c248896d53d514ebe8ed2a6b4f8b5f33 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Thu, 3 Apr 2014 14:25:59 +0000 Subject: [PATCH] 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 --- src/api.cc | 10 ++++------ src/json-parser.h | 11 +++++------ src/runtime.cc | 14 ++++---------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/api.cc b/src/api.cc index 2ef58fdb..060914a 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2315,13 +2315,11 @@ Local JSON::Parse(Local json_string) { i::Handle source = i::Handle( FlattenGetString(Utils::OpenHandle(*json_string))); EXCEPTION_PREAMBLE(isolate); + i::MaybeHandle maybe_result = + source->IsSeqOneByteString() ? i::JsonParser::Parse(source) + : i::JsonParser::Parse(source); i::Handle result; - if (source->IsSeqOneByteString()) { - result = i::JsonParser::Parse(source); - } else { - result = i::JsonParser::Parse(source); - } - has_pending_exception = result.is_null(); + has_pending_exception = !maybe_result.ToHandle(&result); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Utils::ToLocal( i::Handle::cast(scope.CloseAndEscape(result))); diff --git a/src/json-parser.h b/src/json-parser.h index ca21421..ca937a0 100644 --- a/src/json-parser.h +++ b/src/json-parser.h @@ -43,7 +43,7 @@ namespace internal { template class JsonParser BASE_EMBEDDED { public: - static Handle Parse(Handle source) { + static MaybeHandle Parse(Handle source) { return JsonParser(source).ParseJson(); } @@ -69,7 +69,7 @@ class JsonParser BASE_EMBEDDED { } // Parse a string containing a single JSON value. - Handle ParseJson(); + MaybeHandle ParseJson(); inline void Advance() { position_++; @@ -219,7 +219,7 @@ class JsonParser BASE_EMBEDDED { }; template -Handle JsonParser::ParseJson() { +MaybeHandle JsonParser::ParseJson() { // Advance to the first character (possibly EOS) AdvanceSkipWhitespace(); Handle result = ParseJsonValue(); @@ -268,9 +268,8 @@ Handle JsonParser::ParseJson() { MessageLocation location(factory->NewScript(source_), position_, position_ + 1); - Handle result = factory->NewSyntaxError(message, array); - isolate()->Throw(*result, &location); - return Handle::null(); + Handle error = factory->NewSyntaxError(message, array); + return isolate()->template Throw(error, &location); } return result; } diff --git a/src/runtime.cc b/src/runtime.cc index 12bce2c..7139f2f 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -9769,16 +9769,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) { source = Handle(FlattenGetString(source)); // Optimized fast case where we only have ASCII characters. Handle result; - if (source->IsSeqOneByteString()) { - result = JsonParser::Parse(source); - } else { - result = JsonParser::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::Parse(source) + : JsonParser::Parse(source)); return *result; } -- 2.7.4