Reviewers: Igor Sheludko,

Description:
Return MaybeHandle from JsonParser.

[email protected]

Please review this at https://codereview.chromium.org/223553003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+13, -22 lines):
  M src/api.cc
  M src/json-parser.h
  M src/runtime.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 2ef58fdb32f3b7f006678084f9583cbe24e1d1da..1c8cc22385cc149a934336b3a79c78f45c85bf27 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -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)));
Index: src/json-parser.h
diff --git a/src/json-parser.h b/src/json-parser.h
index ca21421d44838ccdd4e23771d9da4679f51483d6..ca937a0968f45444ad93213d885f524e4334daf0 100644
--- a/src/json-parser.h
+++ b/src/json-parser.h
@@ -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;
 }
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 12bce2c9a750707ecdcbbcb8e4ffdf49cda89888..7139f2f06cf0b14cd13eb1e79428977b49db23c6 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -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;
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to