Reviewers: cbruni,

Description:
Small MessageLocation related refactoring.

[email protected]

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+29, -30 lines):
  M src/isolate.h
  M src/isolate.cc
  M src/messages.h
  M src/messages.cc
  M src/runtime/runtime-internal.cc


Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index ee2fb7bb9741f2d8b32324ead1a0e65b86061943..73c7bf1824f19301fbfec9164f1806782f222913 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -993,11 +993,10 @@ Object* Isolate::Throw(Object* exception, MessageLocation* location) {

   // Generate the message if required.
   if (requires_message && !rethrowing_message) {
-    MessageLocation potential_computed_location;
-    if (location == NULL) {
-      // If no location was specified we use a computed one instead.
-      ComputeLocation(&potential_computed_location);
-      location = &potential_computed_location;
+    MessageLocation computed_location;
+    // If no location was specified we try to use a computed one instead.
+    if (location == NULL && ComputeLocation(&computed_location)) {
+      location = &computed_location;
     }

     if (bootstrapper()->IsActive()) {
@@ -1258,8 +1257,7 @@ void Isolate::PrintCurrentStackTrace(FILE* out) {
 }


-void Isolate::ComputeLocation(MessageLocation* target) {
-  *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1);
+bool Isolate::ComputeLocation(MessageLocation* target) {
   StackTraceFrameIterator it(this);
   if (!it.done()) {
     JavaScriptFrame* frame = it.frame();
@@ -1271,8 +1269,10 @@ void Isolate::ComputeLocation(MessageLocation* target) {
       // Compute the location from the function and the reloc info.
       Handle<Script> casted_script(Script::cast(script));
       *target = MessageLocation(casted_script, pos, pos + 1, handle(fun));
+      return true;
     }
   }
+  return false;
 }


@@ -1305,8 +1305,6 @@ bool Isolate::ComputeLocationFromException(MessageLocation* target,

 bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
                                             Handle<Object> exception) {
-  *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1);
-
   if (!exception->IsJSObject()) return false;
   Handle<Name> key = factory()->stack_trace_symbol();
   Handle<Object> property =
@@ -1356,7 +1354,6 @@ bool Isolate::IsErrorObject(Handle<Object> obj) {
 Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
                                                MessageLocation* location) {
   Handle<JSArray> stack_trace_object;
-  MessageLocation potential_computed_location;
   if (capture_stack_trace_for_uncaught_exceptions_) {
     if (IsErrorObject(exception)) {
       // We fetch the stack trace that corresponds to this error object.
@@ -1373,15 +1370,12 @@ Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
           stack_trace_for_uncaught_exceptions_options_);
     }
   }
-  if (!location) {
-    if (!ComputeLocationFromException(&potential_computed_location,
-                                      exception)) {
-      if (!ComputeLocationFromStackTrace(&potential_computed_location,
-                                         exception)) {
-        ComputeLocation(&potential_computed_location);
-      }
-    }
-    location = &potential_computed_location;
+  MessageLocation computed_location;
+  if (location == NULL &&
+      (ComputeLocationFromException(&computed_location, exception) ||
+       ComputeLocationFromStackTrace(&computed_location, exception) ||
+       ComputeLocation(&computed_location))) {
+    location = &computed_location;
   }

   return MessageHandler::MakeMessageObject(
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index 3cc4bacfdec70f14ef337263c38b7df5b6f44bce..5339bcce5a0b4f656f6a85bd19f56f442c1c406b 100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -772,7 +772,7 @@ class Isolate {

   // Attempts to compute the current source location, storing the
   // result in the target out parameter.
-  void ComputeLocation(MessageLocation* target);
+  bool ComputeLocation(MessageLocation* target);
   bool ComputeLocationFromException(MessageLocation* target,
                                     Handle<Object> exception);
   bool ComputeLocationFromStackTrace(MessageLocation* target,
Index: src/messages.cc
diff --git a/src/messages.cc b/src/messages.cc
index 908ee08e4bc7793cd4d5ed5fd91fcfb08f9f3e39..ef6b01108f9e7ecfcaf6c708f3eb2ee951be9d2b 100644
--- a/src/messages.cc
+++ b/src/messages.cc
@@ -33,17 +33,20 @@ void MessageHandler::DefaultMessageReport(Isolate* isolate,


 Handle<JSMessageObject> MessageHandler::MakeMessageObject(
- Isolate* isolate, MessageTemplate::Template message, MessageLocation* loc,
-    Handle<Object> argument, Handle<JSArray> stack_frames) {
+    Isolate* isolate, MessageTemplate::Template message,
+    MessageLocation* location, Handle<Object> argument,
+    Handle<JSArray> stack_frames) {
   Factory* factory = isolate->factory();

   int start = 0;
   int end = 0;
   Handle<Object> script_handle = factory->undefined_value();
-  if (loc) {
-    start = loc->start_pos();
-    end = loc->end_pos();
-    script_handle = Script::GetWrapper(loc->script());
+  if (location != NULL) {
+    start = location->start_pos();
+    end = location->end_pos();
+    script_handle = Script::GetWrapper(location->script());
+  } else {
+    script_handle = Script::GetWrapper(isolate->factory()->empty_script());
   }

   Handle<Object> stack_frames_handle = stack_frames.is_null()
Index: src/messages.h
diff --git a/src/messages.h b/src/messages.h
index 14f1dcf3ee92879986b462402da579e6291c974c..c8b9497fb939070724a5bf868cd69d8ee7733f9d 100644
--- a/src/messages.h
+++ b/src/messages.h
@@ -432,8 +432,9 @@ class MessageHandler {
  public:
   // Returns a message object for the API to use.
   static Handle<JSMessageObject> MakeMessageObject(
- Isolate* isolate, MessageTemplate::Template type, MessageLocation* loc,
-      Handle<Object> argument, Handle<JSArray> stack_frames);
+      Isolate* isolate, MessageTemplate::Template type,
+      MessageLocation* location, Handle<Object> argument,
+      Handle<JSArray> stack_frames);

   // Report a formatted message (needs JS allocation).
   static void ReportMessage(Isolate* isolate, MessageLocation* loc,
Index: src/runtime/runtime-internal.cc
diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index 0e098fd1f0f9a12d81b227b7c4c1a0380c9bead6..12864066c4e333d3f9c7f7bb84b1164474a77171 100644
--- a/src/runtime/runtime-internal.cc
+++ b/src/runtime/runtime-internal.cc
@@ -256,8 +256,9 @@ RUNTIME_FUNCTION(Runtime_RenderCallSite) {
   HandleScope scope(isolate);
   DCHECK(args.length() == 0);
   MessageLocation location;
-  isolate->ComputeLocation(&location);
-  if (location.start_pos() == -1) return isolate->heap()->empty_string();
+  if (!isolate->ComputeLocation(&location)) {
+    return isolate->heap()->empty_string();
+  }

   Zone zone;
   base::SmartPointer<ParseInfo> info(


--
--
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