Skip to content

Commit 0ad5c07

Browse files
mattcolegatetobespc
authored andcommitted
Support Node 13 (#619)
* Support Node 13 * More context additions
1 parent 9032850 commit 0ad5c07

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_js:
66
- "8"
77
- "10"
88
- "12"
9+
- "13"
910
os:
1011
- osx
1112
- linux
@@ -18,13 +19,17 @@ matrix:
1819
node_js: "10"
1920
- os: windows
2021
node_js: "12"
22+
- os: windows
23+
node_js: "13"
2124
allow_failures:
2225
- os: windows
2326
node_js: "8"
2427
- os: windows
2528
node_js: "10"
2629
- os: windows
2730
node_js: "12"
31+
- os: windows
32+
node_js: "13"
2833
fast_finish: true
2934

3035

src/appmetrics.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ NAN_METHOD(getOption) {
330330
if (info.Length() > 0) {
331331
Local<String> value = Nan::To<String>(info[0]).ToLocalChecked();
332332
std::string property = loaderApi->getProperty(toStdString(value).c_str());
333-
#if NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
333+
#if NODE_VERSION_AT_LEAST(13, 0, 0) // > v13.0+
334+
v8::Local<v8::String> v8str = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), property.c_str()).ToLocalChecked();
335+
#elif NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
334336
v8::Local<v8::String> v8str = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), property.c_str());
335337
#else
336338
v8::Local<v8::String> v8str = v8::String::New(property.c_str(), strlen(property.c_str()));
@@ -584,8 +586,13 @@ void lrtime(const Nan::FunctionCallbackInfo<v8::Value>& info) {
584586
}
585587
timespec ts = {0, 0};
586588
clock_gettime(clock_id, &ts);
587-
588-
#if NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
589+
#if NODE_VERSION_AT_LEAST(13, 0, 0) // > v13.0+
590+
v8::Isolate* isolate = info.GetIsolate();
591+
v8::Local<v8::Context> context = isolate -> GetCurrentContext();
592+
v8::Local<v8::Array> result = v8::Array::New(isolate, 2);
593+
result->Set(context, 0, v8::Number::New(isolate, ts.tv_sec));
594+
result->Set(context, 1, v8::Integer::NewFromUnsigned(isolate, ts.tv_nsec));
595+
#elif NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
589596
v8::Isolate* isolate = info.GetIsolate();
590597
v8::Local<v8::Array> result = v8::Array::New(isolate, 2);
591598
result->Set(0, v8::Number::New(isolate, ts.tv_sec));

src/headlessutils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ void asyncfunc(uv_async_t* handle, int status) {
4141
#endif
4242
Nan::HandleScope scope;
4343
v8::Isolate* isolate = v8::Isolate::GetCurrent();
44-
#if NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
44+
#if NODE_VERSION_AT_LEAST(13, 0, 0) // > v13.0+
45+
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8(isolate, outputDir.c_str()).ToLocalChecked() };
46+
#elif NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
4547
v8::Local<v8::Value> argv[] = { v8::String::NewFromUtf8(isolate, outputDir.c_str()) };
4648
#else
4749
v8::Local<v8::Value> argv[] = { v8::String::New(outputDir.c_str(), strlen(outputDir.c_str())) };

src/heapdump/heapdump.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ inline C::ReturnType Configure(const C::ArgumentType& args) {
160160
inline void Initialize(Local<Object> binding) {
161161
Isolate* const isolate = Isolate::GetCurrent();
162162
Local<Context> context = Nan::GetCurrentContext();
163+
#if NODE_VERSION_AT_LEAST(13, 0, 0)
164+
binding->Set(context, C::String::NewFromUtf8(isolate, "kForkFlag"),
165+
C::Integer::New(isolate, kForkFlag));
166+
binding->Set(context, C::String::NewFromUtf8(isolate, "kSignalFlag"),
167+
C::Integer::New(isolate, kSignalFlag));
168+
binding->Set(context, C::String::NewFromUtf8(isolate, "configure"),
169+
C::FunctionTemplate::New(isolate, Configure)
170+
->GetFunction(context).ToLocalChecked());
171+
binding->Set(context, C::String::NewFromUtf8(isolate, "writeSnapshot"),
172+
C::FunctionTemplate::New(isolate, WriteSnapshot)
173+
->GetFunction(context).ToLocalChecked());
174+
#else
163175
binding->Set(C::String::NewFromUtf8(isolate, "kForkFlag"),
164176
C::Integer::New(isolate, kForkFlag));
165177
binding->Set(C::String::NewFromUtf8(isolate, "kSignalFlag"),
@@ -170,6 +182,7 @@ inline void Initialize(Local<Object> binding) {
170182
binding->Set(C::String::NewFromUtf8(isolate, "writeSnapshot"),
171183
C::FunctionTemplate::New(isolate, WriteSnapshot)
172184
->GetFunction(context).ToLocalChecked());
185+
#endif
173186
}
174187

175188
NODE_MODULE(addon, Initialize)

src/objecttracker.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

src/plugins/node/prof/compat-inl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ v8::Local<v8::String> String::NewFromUtf8(v8::Isolate* isolate,
350350
const char* data, NewStringType type,
351351
int length) {
352352
return v8::String::NewFromUtf8(
353+
#if NODE_VERSION_AT_LEAST(13, 0, 0)
354+
isolate, data, static_cast<v8::NewStringType>(type), length).ToLocalChecked();
355+
#else
353356
isolate, data, static_cast<v8::String::NewStringType>(type), length);
357+
#endif
354358
}
355359

356360
HandleScope::HandleScope(v8::Isolate* isolate) : handle_scope_(isolate) {}

0 commit comments

Comments
 (0)