@@ -58,16 +58,16 @@ static void WriteNodeReport(Isolate* isolate,
58
58
const char * trigger,
59
59
const std::string& filename,
60
60
std::ostream& out,
61
- Local<Object > error,
61
+ Local<Value > error,
62
62
bool compact);
63
63
static void PrintVersionInformation (JSONWriter* writer);
64
64
static void PrintJavaScriptErrorStack (JSONWriter* writer,
65
65
Isolate* isolate,
66
- Local<Object > error,
66
+ Local<Value > error,
67
67
const char * trigger);
68
68
static void PrintJavaScriptErrorProperties (JSONWriter* writer,
69
69
Isolate* isolate,
70
- Local<Object > error);
70
+ Local<Value > error);
71
71
static void PrintNativeStack (JSONWriter* writer);
72
72
static void PrintResourceUsage (JSONWriter* writer);
73
73
static void PrintGCStatistics (JSONWriter* writer, Isolate* isolate);
@@ -84,7 +84,7 @@ std::string TriggerNodeReport(Isolate* isolate,
84
84
const char * message,
85
85
const char * trigger,
86
86
const std::string& name,
87
- Local<Object > error) {
87
+ Local<Value > error) {
88
88
std::string filename;
89
89
90
90
// Determine the required report filename. In order of priority:
@@ -169,7 +169,7 @@ void GetNodeReport(Isolate* isolate,
169
169
Environment* env,
170
170
const char * message,
171
171
const char * trigger,
172
- Local<Object > error,
172
+ Local<Value > error,
173
173
std::ostream& out) {
174
174
WriteNodeReport (isolate, env, message, trigger, " " , out, error, false );
175
175
}
@@ -182,7 +182,7 @@ static void WriteNodeReport(Isolate* isolate,
182
182
const char * trigger,
183
183
const std::string& filename,
184
184
std::ostream& out,
185
- Local<Object > error,
185
+ Local<Value > error,
186
186
bool compact) {
187
187
// Obtain the current time and the pid.
188
188
TIME_TYPE tm_struct;
@@ -474,13 +474,14 @@ static void PrintNetworkInterfaceInfo(JSONWriter* writer) {
474
474
475
475
static void PrintJavaScriptErrorProperties (JSONWriter* writer,
476
476
Isolate* isolate,
477
- Local<Object > error) {
477
+ Local<Value > error) {
478
478
writer->json_objectstart (" errorProperties" );
479
- if (!error.IsEmpty ()) {
479
+ if (!error.IsEmpty () && error-> IsObject () ) {
480
480
TryCatch try_catch (isolate);
481
- Local<Context> context = error->GetIsolate ()->GetCurrentContext ();
481
+ Local<Object> error_obj = error.As <Object>();
482
+ Local<Context> context = error_obj->GetIsolate ()->GetCurrentContext ();
482
483
Local<Array> keys;
483
- if (!error ->GetOwnPropertyNames (context).ToLocal (&keys)) {
484
+ if (!error_obj ->GetOwnPropertyNames (context).ToLocal (&keys)) {
484
485
return writer->json_objectend (); // the end of 'errorProperties'
485
486
}
486
487
uint32_t keys_length = keys->Length ();
@@ -491,7 +492,7 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer,
491
492
}
492
493
Local<Value> value;
493
494
Local<String> value_string;
494
- if (!error ->Get (context, key).ToLocal (&value) ||
495
+ if (!error_obj ->Get (context, key).ToLocal (&value) ||
495
496
!value->ToString (context).ToLocal (&value_string)) {
496
497
continue ;
497
498
}
@@ -505,26 +506,45 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer,
505
506
writer->json_objectend (); // the end of 'errorProperties'
506
507
}
507
508
509
+ static void ErrorToString (Isolate* isolate,
510
+ Local<Context> context,
511
+ Local<Value> error,
512
+ std::string* ss) {
513
+ if (error.IsEmpty ()) {
514
+ return ;
515
+ }
516
+
517
+ Local<Value> js_str;
518
+ // `ToString` is not available to Symbols.
519
+ if (error->IsSymbol () &&
520
+ error.As <v8::Symbol>()->ToDetailString (context).ToLocal (&js_str)) {
521
+ String::Utf8Value sv (isolate, js_str);
522
+ *ss = std::string (*sv, sv.length ());
523
+ } else if (!error->IsObject () && error->ToString (context).ToLocal (&js_str)) {
524
+ String::Utf8Value sv (isolate, js_str);
525
+ *ss = std::string (*sv, sv.length ());
526
+ } else if (error->IsObject () &&
527
+ error.As <Object>()
528
+ ->Get (context, node::FIXED_ONE_BYTE_STRING (isolate, " stack" ))
529
+ .ToLocal (&js_str)) {
530
+ String::Utf8Value sv (isolate, js_str);
531
+ *ss = std::string (*sv, sv.length ());
532
+ }
533
+ }
534
+
508
535
// Report the JavaScript stack.
509
536
static void PrintJavaScriptErrorStack (JSONWriter* writer,
510
- Isolate* isolate,
511
- Local<Object> error,
512
- const char * trigger) {
513
- Local<Value> stackstr;
514
- std::string ss = " " ;
537
+ Isolate* isolate,
538
+ Local<Value> error,
539
+ const char * trigger) {
515
540
TryCatch try_catch (isolate);
541
+ Local<Context> context = isolate->GetCurrentContext ();
542
+ std::string ss = " " ;
516
543
if ((!strcmp (trigger, " FatalError" )) ||
517
544
(!strcmp (trigger, " Signal" ))) {
518
545
ss = " No stack.\n Unavailable.\n " ;
519
- } else if (!error.IsEmpty () &&
520
- error
521
- ->Get (isolate->GetCurrentContext (),
522
- node::FIXED_ONE_BYTE_STRING (isolate,
523
- " stack" ))
524
- .ToLocal (&stackstr)) {
525
- String::Utf8Value sv (isolate, stackstr);
526
- ss = std::string (*sv, sv.length ());
527
546
}
547
+ ErrorToString (isolate, context, error, &ss);
528
548
int line = ss.find (' \n ' );
529
549
if (line == -1 ) {
530
550
writer->json_keyvalue (" message" , ss);
0 commit comments