@@ -36,6 +36,7 @@ NAN_METHOD(getObjectHistogram) {
3636 }
3737
3838 HeapProfiler *heapProfiler = isolate->GetHeapProfiler ();
39+ Local<Context> currentContext = isolate->GetCurrentContext ();
3940
4041#if NODE_VERSION_AT_LEAST(4, 0, 0) // > v4.00+
4142 // Title field removed in Node 4.x
@@ -51,7 +52,7 @@ NAN_METHOD(getObjectHistogram) {
5152#else
5253 const HeapSnapshot* snapshot = heapProfiler->TakeSnapshot (snapshotName);
5354#endif
54- #if NODE_VERSION_AT_LEAST(4, 0, 0) // > v0.11 +
55+ #if NODE_VERSION_AT_LEAST(4, 0, 0) // > v4.0 +
5556 // Title field removed in Node 4.x
5657#else
5758 snapshotName
@@ -60,19 +61,26 @@ NAN_METHOD(getObjectHistogram) {
6061
6162 /* Build a simple histogram from the heap snapshot. */
6263 Local<Object> histogram = Object::New (isolate);
64+ #if NODE_VERSION_AT_LEAST(13, 0, 0) // > v13.0+
6365
6466 /* Declare our tuple keys outside the loop. */
65- Local<String> countName = String::NewFromUtf8 (isolate, " count" );
66- Local<String> sizeName = String::NewFromUtf8 (isolate, " size" );
67+ Local<String> countName = String::NewFromUtf8 (isolate, " count" ). ToLocalChecked () ;
68+ Local<String> sizeName = String::NewFromUtf8 (isolate, " size" ). ToLocalChecked () ;
6769
6870 /* v8-profiler.h says that kObject is "A JS object (except for arrays and strings)."
6971 * so we should include strings and arrays as objects in the histogram as they are
7072 * objects as the user understands them.
7173 * When you take a heap dump in Chrome dev tools and then view it the
7274 * names "(string)" and "(array)" are used for these, so that's what we'll show the user.
7375 */
76+ Local<String> stringName = String::NewFromUtf8 (isolate, " (string)" ).ToLocalChecked ();
77+ Local<String> arrayName = String::NewFromUtf8 (isolate, " (array)" ).ToLocalChecked ();
78+ #else
79+ Local<String> countName = String::NewFromUtf8 (isolate, " count" );
80+ Local<String> sizeName = String::NewFromUtf8 (isolate, " size" );
7481 Local<String> stringName = String::NewFromUtf8 (isolate, " (string)" );
7582 Local<String> arrayName = String::NewFromUtf8 (isolate, " (array)" );
83+ #endif
7684
7785 /* Walk every node by index (not id) */
7886 for (int i = 0 ; i < snapshot->GetNodesCount (); i++ ) {
@@ -119,15 +127,25 @@ NAN_METHOD(getObjectHistogram) {
119127 * values for count and size.
120128 */
121129 tuple = Object::New (isolate);
122- histogram->Set (name, tuple);
130+ #if NODE_VERSION_AT_LEAST(13, 0, 0) // > v13.0+
131+ histogram->Set (currentContext, name, tuple);
123132 }
124133
125134 /* Update the values in the existing (or new) tuple */
126135 Local<Value> newcount = Number::New (isolate, ++ncount);
127- tuple->Set (countName, newcount);
136+ tuple->Set (currentContext, countName, newcount);
128137 Local<Value> newsize = Number::New (isolate, nsize+node->GetShallowSize ());
129- tuple->Set (sizeName, newsize);
138+ tuple->Set (currentContext,sizeName, newsize);
139+ #else
140+ histogram->Set (currentContext, name, tuple);
141+ }
130142
143+ /* Update the values in the existing (or new) tuple */
144+ Local<Value> newcount = Number::New (isolate, ++ncount);
145+ tuple->Set (currentContext, countName, newcount);
146+ Local<Value> newsize = Number::New (isolate, nsize+node->GetShallowSize ());
147+ tuple->Set (currentContext,sizeName, newsize);
148+ #endif
131149 }
132150
133151 // Delete the snapshot as soon as we are done with it.
0 commit comments