@@ -32,23 +32,29 @@ ToCString(const v8::String::Utf8Value& value)
32
32
return *value ? *value : " <string conversion failed>" ;
33
33
}
34
34
35
- void
36
- ReportException (TryCatch* try_catch)
35
+ static void
36
+ ReportException (TryCatch & try_catch)
37
37
{
38
- HandleScope handle_scope;
39
- String::Utf8Value exception (try_catch->Exception ());
40
- const char * exception_string = ToCString (exception );
41
- Handle <Message> message = try_catch->Message ();
38
+ Handle <Message> message = try_catch.Message ();
42
39
if (message.IsEmpty ()) {
43
- // V8 didn't provide any extra information about this error; just
44
- // print the exception.
45
- fprintf (stderr, " %s\n " , exception_string);
46
- } else {
40
+ fprintf (stderr, " Error: (no message)\n " );
41
+ return ;
42
+ }
43
+ Handle <Value> error = try_catch.Exception ();
44
+ Handle <String> stack;
45
+ if (error->IsObject ()) {
46
+ Handle <Object> obj = Handle <Object>::Cast (error);
47
+ Handle <Value> raw_stack = obj->Get (String::New (" stack" ));
48
+ if (raw_stack->IsString ()) stack = Handle <String>::Cast (raw_stack);
49
+ }
50
+ if (stack.IsEmpty ()) {
51
+ String::Utf8Value exception (error);
52
+
47
53
// Print (filename):(line number): (message).
48
54
String::Utf8Value filename (message->GetScriptResourceName ());
49
55
const char * filename_string = ToCString (filename);
50
56
int linenum = message->GetLineNumber ();
51
- fprintf (stderr, " %s:%i: %s\n " , filename_string, linenum, exception_string );
57
+ fprintf (stderr, " %s:%i: %s\n " , filename_string, linenum, * exception );
52
58
// Print line of source code.
53
59
String::Utf8Value sourceline (message->GetSourceLine ());
54
60
const char * sourceline_string = ToCString (sourceline);
@@ -65,6 +71,11 @@ ReportException(TryCatch* try_catch)
65
71
fprintf (stderr, " \n " );
66
72
67
73
message->PrintCurrentStackTrace (stderr);
74
+
75
+
76
+ } else {
77
+ String::Utf8Value trace (stack);
78
+ fprintf (stderr, " %s\n " , *trace);
68
79
}
69
80
}
70
81
@@ -78,13 +89,13 @@ ExecuteString(v8::Handle<v8::String> source,
78
89
79
90
Handle <Script> script = Script::Compile (source, filename);
80
91
if (script.IsEmpty ()) {
81
- ReportException (& try_catch);
92
+ ReportException (try_catch);
82
93
exit (1 );
83
94
}
84
95
85
96
Handle <Value> result = script->Run ();
86
97
if (result.IsEmpty ()) {
87
- ReportException (& try_catch);
98
+ ReportException (try_catch);
88
99
exit (1 );
89
100
}
90
101
@@ -162,7 +173,7 @@ OnFatalError (const char* location, const char* message)
162
173
void
163
174
node::FatalException (TryCatch &try_catch)
164
175
{
165
- ReportException (& try_catch);
176
+ ReportException (try_catch);
166
177
exit (1 );
167
178
}
168
179
@@ -210,7 +221,7 @@ ExecuteNativeJS (const char *filename, const char *data)
210
221
if (try_catch.HasCaught ()) {
211
222
puts (" There is an error in Node's built-in javascript" );
212
223
puts (" This should be reported as a bug!" );
213
- ReportException (& try_catch);
224
+ ReportException (try_catch);
214
225
exit (1 );
215
226
}
216
227
}
@@ -242,6 +253,9 @@ Load (int argc, char *argv[])
242
253
EventEmitter::constructor_template->GetFunction ());
243
254
Promise::Initialize (node_obj);
244
255
256
+ ExecuteNativeJS (" util.js" , native_util);
257
+ ExecuteNativeJS (" events.js" , native_events);
258
+
245
259
Stdio::Initialize (node_obj);
246
260
Timer::Initialize (node_obj);
247
261
ChildProcess::Initialize (node_obj);
@@ -266,8 +280,6 @@ Load (int argc, char *argv[])
266
280
HTTPServer::Initialize (http);
267
281
HTTPConnection::Initialize (http);
268
282
269
- ExecuteNativeJS (" util.js" , native_util);
270
- ExecuteNativeJS (" events.js" , native_events);
271
283
ExecuteNativeJS (" http.js" , native_http);
272
284
ExecuteNativeJS (" file.js" , native_file);
273
285
ExecuteNativeJS (" node.js" , native_node);
0 commit comments