1
1
#include " node_report.h"
2
- #include " node_version.h"
3
2
#include " v8.h"
4
3
#include " time.h"
5
- #include " zlib.h"
6
- #include " ares.h"
7
4
8
5
#include < fcntl.h>
9
6
#include < string.h>
@@ -52,7 +49,7 @@ using v8::String;
52
49
using v8::V8;
53
50
54
51
// Internal/static function declarations
55
- static void PrintVersionInformation (FILE* fp);
52
+ static void PrintVersionInformation (FILE* fp, Isolate* isolate );
56
53
static void PrintJavaScriptStack (FILE* fp, Isolate* isolate, DumpEvent event, const char * location);
57
54
static void PrintStackFromStackTrace (FILE* fp, Isolate* isolate, DumpEvent event);
58
55
static void PrintStackFrame (FILE* fp, Isolate* isolate, Local<StackFrame> frame, int index, void * pc);
@@ -70,6 +67,7 @@ const char* v8_states[] = {"JS", "GC", "COMPILER", "OTHER", "EXTERNAL", "IDLE"};
70
67
static bool report_active = false ; // recursion protection
71
68
static char report_filename[NR_MAXNAME + 1 ] = " " ;
72
69
static char report_directory[NR_MAXPATH + 1 ] = " " ; // defaults to current working directory
70
+ static std::string versionString = " Unable to determine Node.js version\n " ;
73
71
#ifdef _WIN32
74
72
static SYSTEMTIME loadtime_tm_struct; // module load time
75
73
#else // UNIX, OSX
@@ -189,6 +187,73 @@ unsigned int ProcessNodeReportVerboseSwitch(const char* args) {
189
187
return 0 ; // Default is verbose mode off
190
188
}
191
189
190
+ void SetVersionString (Isolate* isolate) {
191
+ Nan::MaybeLocal<String> processProp = Nan::New<String>(" process" );
192
+ if (processProp.IsEmpty ()) {
193
+ return ;
194
+ }
195
+ Nan::MaybeLocal<Value> process = Nan::Get (
196
+ isolate->GetCurrentContext ()->Global (),
197
+ processProp.ToLocalChecked ());
198
+ if (process.IsEmpty () || process.ToLocalChecked ()->IsUndefined ()) {
199
+ return ;
200
+ }
201
+ Nan::MaybeLocal<String> versionProp = Nan::New<String>(" version" );
202
+ if (versionProp.IsEmpty ()) {
203
+ return ;
204
+ }
205
+ Nan::MaybeLocal<Value> version = Nan::Get (
206
+ process.ToLocalChecked ().As <Object>(),
207
+ versionProp.ToLocalChecked ());
208
+ if (version.IsEmpty () || version.ToLocalChecked ()->IsUndefined ()) {
209
+ return ;
210
+ }
211
+ Nan::Utf8String nodeVersion (version.ToLocalChecked ());
212
+ versionString.assign (" Node.js version: " );
213
+ versionString.append (*nodeVersion);
214
+ versionString.append (" \n " );
215
+
216
+ // Get the component versions
217
+ Nan::MaybeLocal<String> versionsProp = Nan::New<String>(" versions" );
218
+ if (versionsProp.IsEmpty ()) {
219
+ return ;
220
+ }
221
+ Nan::MaybeLocal<Value> versions = Nan::Get (
222
+ process.ToLocalChecked ().As <Object>(),
223
+ versionsProp.ToLocalChecked ());
224
+ if (versions.IsEmpty () || versions.ToLocalChecked ()->IsUndefined ()) {
225
+ return ;
226
+ }
227
+ Local<Object> versionsObj = versions.ToLocalChecked ().As <Object>();
228
+ Nan::MaybeLocal<v8::Array> keys = Nan::GetOwnPropertyNames (versionsObj);
229
+ if (keys.IsEmpty () || keys.ToLocalChecked ()->IsUndefined ()) {
230
+ return ;
231
+ }
232
+ Local<v8::Array> components = keys.ToLocalChecked ();
233
+ for (uint32_t i = 0 , nComps = (*components)->Length (); i < nComps; i++) {
234
+ Nan::MaybeLocal<Value> maybeComp = Nan::Get (components.As <Object>(), i);
235
+ if (maybeComp.IsEmpty ()) {
236
+ continue ;
237
+ }
238
+ Local<Value> compValue = maybeComp.ToLocalChecked ();
239
+ Nan::MaybeLocal<Value> maybeVers = Nan::Get (versionsObj, compValue);
240
+ if (maybeVers.IsEmpty ()) {
241
+ continue ;
242
+ }
243
+ Local<Value> versValue = maybeVers.ToLocalChecked ();
244
+ Nan::Utf8String compName (compValue);
245
+ Nan::Utf8String compVersion (versValue);
246
+ // Don't duplicate the Node.js version
247
+ if (!strcmp (" node" , *compName)) {
248
+ continue ;
249
+ }
250
+ versionString.append (*compName);
251
+ versionString.append (" : " );
252
+ versionString.append (*compVersion);
253
+ versionString.append (" \n " );
254
+ }
255
+ }
256
+
192
257
/* ******************************************************************************
193
258
* Function to save the nodereport module load time value
194
259
*******************************************************************************/
@@ -317,7 +382,7 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c
317
382
fflush (fp);
318
383
319
384
// Print Node.js and OS version information
320
- PrintVersionInformation (fp);
385
+ PrintVersionInformation (fp, isolate );
321
386
fflush (fp);
322
387
323
388
// Print summary JavaScript stack backtrace
@@ -369,12 +434,10 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c
369
434
* Function to print Node.js version, OS version and machine information
370
435
*
371
436
******************************************************************************/
372
- static void PrintVersionInformation (FILE* fp) {
437
+ static void PrintVersionInformation (FILE* fp, Isolate* isolate ) {
373
438
374
439
// Print Node.js and deps component versions
375
- fprintf (fp, " \n Node.js version: %s\n " , NODE_VERSION);
376
- fprintf (fp, " (v8: %s, libuv: %s, zlib: %s, ares: %s)\n " ,
377
- V8::GetVersion (), uv_version_string (), ZLIB_VERSION, ARES_VERSION_STR);
440
+ fprintf (fp, " \n %s" , versionString.c_str ());
378
441
379
442
// Print operating system and machine information (Windows)
380
443
#ifdef _WIN32
0 commit comments