Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-11-24 05:46:13 +0300
committerRyan Dahl <ry@tinyclouds.org>2010-11-24 05:46:13 +0300
commitb57c1f51b9447b79d222f0c98b550eb6ed3f80ec (patch)
tree1058c8833f00986d804c5beed347f707b7a081db /src
parenta6f6532dfbfda5723958d79aef2b0e0fc9805da8 (diff)
Saner, yet still ugly, fix to displaying syntax errors
Diffstat (limited to 'src')
-rw-r--r--src/node.cc22
-rw-r--r--src/node.h1
-rw-r--r--src/node_script.cc5
3 files changed, 18 insertions, 10 deletions
diff --git a/src/node.cc b/src/node.cc
index 31f6d3cd2b7..d3012e95829 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -925,26 +925,24 @@ ssize_t DecodeWrite(char *buf,
return buflen;
}
-// Extracts a C str from a V8 Utf8Value.
-const char* ToCString(const v8::String::Utf8Value& value) {
- return *value ? *value : "<str conversion failed>";
-}
-static void ReportException(TryCatch &try_catch, bool show_line) {
+void DisplayExceptionLine (TryCatch &try_catch) {
+ HandleScope scope;
+
Handle<Message> message = try_catch.Message();
node::Stdio::DisableRawMode(STDIN_FILENO);
fprintf(stderr, "\n");
- if (show_line && !message.IsEmpty()) {
+ if (!message.IsEmpty()) {
// Print (filename):(line number): (message).
String::Utf8Value filename(message->GetScriptResourceName());
- const char* filename_string = ToCString(filename);
+ const char* filename_string = *filename;
int linenum = message->GetLineNumber();
fprintf(stderr, "%s:%i\n", filename_string, linenum);
// Print line of source code.
String::Utf8Value sourceline(message->GetSourceLine());
- const char* sourceline_string = ToCString(sourceline);
+ const char* sourceline_string = *sourceline;
// HACK HACK HACK
//
@@ -978,6 +976,14 @@ static void ReportException(TryCatch &try_catch, bool show_line) {
}
fprintf(stderr, "\n");
}
+}
+
+
+static void ReportException(TryCatch &try_catch, bool show_line) {
+ HandleScope scope;
+ Handle<Message> message = try_catch.Message();
+
+ if (show_line) DisplayExceptionLine(try_catch);
String::Utf8Value trace(try_catch.StackTrace());
diff --git a/src/node.h b/src/node.h
index 07b7f5e17e7..dd5a36a6666 100644
--- a/src/node.h
+++ b/src/node.h
@@ -48,6 +48,7 @@ enum encoding {ASCII, UTF8, BASE64, BINARY};
enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v,
enum encoding _default = BINARY);
void FatalException(v8::TryCatch &try_catch);
+void DisplayExceptionLine(v8::TryCatch &try_catch); // hack
v8::Local<v8::Value> Encode(const void *buf, size_t len,
enum encoding encoding = BINARY);
diff --git a/src/node_script.cc b/src/node_script.cc
index 9cae7483f30..5c4223d10e4 100644
--- a/src/node_script.cc
+++ b/src/node_script.cc
@@ -234,8 +234,9 @@ template <node::Script::EvalInputFlags iFlag,
script = oFlag == returnResult ? v8::Script::Compile(code, filename)
: v8::Script::New(code, filename);
if (script.IsEmpty()) {
- // FIXME HACK TO DISPLAY SYNTAX ERRORS.
- FatalException(try_catch);
+ // FIXME UGLY HACK TO DISPLAY SYNTAX ERRORS.
+ DisplayExceptionLine(try_catch);
+
// Hack because I can't get a proper stacktrace on SyntaxError
return try_catch.ReThrow();
}