Skip to content

Commit e28fc06

Browse files
authored
Don't use Nan in WallProfiler::GetContextsByNode (#190)
1 parent faee6c2 commit e28fc06

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

bindings/profilers/wall.cc

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,17 @@ ContextsByNode WallProfiler::GetContextsByNode(CpuProfile* profile,
380380
}
381381

382382
auto isolate = Isolate::GetCurrent();
383+
auto v8Context = isolate->GetCurrentContext();
383384
auto contextIt = contexts.begin();
384385

385386
// deltaIdx is the offset of the sample to process compared to current
386387
// iteration index
387388
int deltaIdx = 0;
388389

389-
auto contextKey = Nan::New<v8::String>("context").ToLocalChecked();
390-
auto timestampKey = Nan::New<v8::String>("timestamp").ToLocalChecked();
391-
auto cpuTimeKey = Nan::New<v8::String>("cpuTime").ToLocalChecked();
392-
auto asyncIdKey = Nan::New<v8::String>("asyncId").ToLocalChecked();
390+
auto contextKey = String::NewFromUtf8Literal(isolate, "context");
391+
auto timestampKey = String::NewFromUtf8Literal(isolate, "timestamp");
392+
auto cpuTimeKey = String::NewFromUtf8Literal(isolate, "cpuTime");
393+
auto asyncIdKey = String::NewFromUtf8Literal(isolate, "asyncId");
393394
auto V8toEpochOffset = GetV8ToEpochOffset();
394395
auto lastCpuTime = startCpuTime;
395396

@@ -434,35 +435,43 @@ ContextsByNode WallProfiler::GetContextsByNode(CpuProfile* profile,
434435
auto it = contextsByNode.find(sample);
435436
Local<Array> array;
436437
if (it == contextsByNode.end()) {
437-
array = Nan::New<Array>();
438+
array = Array::New(isolate);
438439
contextsByNode[sample] = {array, 1};
439440
} else {
440441
array = it->second.contexts;
441442
++it->second.hitcount;
442443
}
443444
if (sampleContext.context) {
444445
// Conforms to TimeProfileNodeContext defined in v8-types.ts
445-
v8::Local<v8::Object> timedContext = Nan::New<v8::Object>();
446-
Nan::Set(timedContext,
447-
contextKey,
448-
sampleContext.context.get()->Get(isolate));
449-
Nan::Set(timedContext,
450-
timestampKey,
451-
BigInt::New(isolate, sampleTimestamp + V8toEpochOffset));
446+
Local<Object> timedContext = Object::New(isolate);
447+
timedContext
448+
->Set(v8Context,
449+
contextKey,
450+
sampleContext.context.get()->Get(isolate))
451+
.Check();
452+
timedContext
453+
->Set(v8Context,
454+
timestampKey,
455+
BigInt::New(isolate, sampleTimestamp + V8toEpochOffset))
456+
.Check();
452457

453458
// if current sample is idle/program, reports its cpu time to the next
454459
// sample
455460
if (collectCpuTime_ && !isIdleOrProgram(sample)) {
456-
Nan::Set(
457-
timedContext,
458-
cpuTimeKey,
459-
Nan::New<v8::Number>(sampleContext.cpu_time - lastCpuTime));
461+
timedContext
462+
->Set(
463+
v8Context,
464+
cpuTimeKey,
465+
Number::New(isolate, sampleContext.cpu_time - lastCpuTime))
466+
.Check();
460467
lastCpuTime = sampleContext.cpu_time;
461468
}
462-
Nan::Set(timedContext,
463-
asyncIdKey,
464-
Nan::New<v8::Number>(sampleContext.async_id));
465-
Nan::Set(array, array->Length(), timedContext);
469+
timedContext
470+
->Set(v8Context,
471+
asyncIdKey,
472+
Number::New(isolate, sampleContext.async_id))
473+
.Check();
474+
array->Set(v8Context, array->Length(), timedContext).Check();
466475
}
467476

468477
// Sample context was consumed, fetch the next one

0 commit comments

Comments
 (0)