Author: [EMAIL PROTECTED]
Date: Tue Sep  9 12:08:40 2008
New Revision: 237

Removed:
    changes/[EMAIL PROTECTED]/better-shell-error-messages/
Modified:
    branches/bleeding_edge/SConstruct
    branches/bleeding_edge/samples/shell.cc

Log:
Changed the shell to print source position with error messages.
Added debug flags to gcc when compiling samples in debug mode.



Modified: branches/bleeding_edge/SConstruct
==============================================================================
--- branches/bleeding_edge/SConstruct   (original)
+++ branches/bleeding_edge/SConstruct   Tue Sep  9 12:08:40 2008
@@ -190,6 +190,9 @@
        'CCFLAGS':      ['-m32'],
        'LINKFLAGS':    ['-m32']
      },
+    'mode:debug': {
+      'CCFLAGS':      ['-g', '-O0']
+    }
    },
    'msvc': {
      'all': {

Modified: branches/bleeding_edge/samples/shell.cc
==============================================================================
--- branches/bleeding_edge/samples/shell.cc     (original)
+++ branches/bleeding_edge/samples/shell.cc     Tue Sep  9 12:08:40 2008
@@ -40,6 +40,7 @@
  v8::Handle<v8::Value> Quit(const v8::Arguments& args);
  v8::Handle<v8::Value> Version(const v8::Arguments& args);
  v8::Handle<v8::String> ReadFile(const char* name);
+void ReportException(v8::TryCatch* handler);


  int main(int argc, char* argv[]) {
@@ -174,7 +175,7 @@
      char* str = fgets(buffer, kBufferSize, stdin);
      if (str == NULL) break;
      v8::HandleScope handle_scope;
-    ExecuteString(v8::String::New(str), v8::Undefined(), true);
+    ExecuteString(v8::String::New(str), v8::String::New("(shell)"), true);
    }
    printf("\n");
  }
@@ -189,15 +190,13 @@
    v8::Handle<v8::Script> script = v8::Script::Compile(source, name);
    if (script.IsEmpty()) {
      // Print errors that happened during compilation.
-    v8::String::AsciiValue error(try_catch.Exception());
-    printf("%s\n", *error);
+    ReportException(&try_catch);
      return false;
    } else {
      v8::Handle<v8::Value> result = script->Run();
      if (result.IsEmpty()) {
        // Print errors that happened during execution.
-      v8::String::AsciiValue error(try_catch.Exception());
-      printf("%s\n", *error);
+      ReportException(&try_catch);
        return false;
      } else {
        if (print_result && !result->IsUndefined()) {
@@ -208,5 +207,35 @@
        }
        return true;
      }
+  }
+}
+
+
+void ReportException(v8::TryCatch* try_catch) {
+  v8::HandleScope handle_scope;
+  v8::String::AsciiValue exception(try_catch->Exception());
+  v8::Handle<v8::Message> message = try_catch->Message();
+  if (message.IsEmpty()) {
+    // V8 didn't provide any extra information about this error; just
+    // print the exception.
+    printf("%s\n", *exception);
+  } else {
+    // Print (filename):(line number): (message).
+    v8::String::AsciiValue filename(message->GetScriptResourceName());
+    int linenum = message->GetLineNumber();
+    printf("%s:%i: %s\n", *filename, linenum, *exception);
+    // Print line of source code.
+    v8::String::AsciiValue sourceline(message->GetSourceLine());
+    printf("%s\n", *sourceline);
+    // Print wavy underline (GetUnderline is deprecated).
+    int start = message->GetStartColumn();
+    for (int i = 0; i < start; i++) {
+      printf(" ");
+    }
+    int end = message->GetEndColumn();
+    for (int i = start; i < end; i++) {
+      printf("^");
+    }
+    printf("\n");
    }
  }

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to