From f8649b9ccb8b5953455d2c19d6cbd6ae37738e0e Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Thu, 16 Jan 2025 15:14:22 +0100 Subject: [PATCH] Use stricter checks on object setters; don't use Nan --- bindings/profilers/wall.cc | 49 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/bindings/profilers/wall.cc b/bindings/profilers/wall.cc index 8e3e57bf..1c760c95 100644 --- a/bindings/profilers/wall.cc +++ b/bindings/profilers/wall.cc @@ -380,16 +380,17 @@ ContextsByNode WallProfiler::GetContextsByNode(CpuProfile* profile, } auto isolate = Isolate::GetCurrent(); + auto v8Context = isolate->GetCurrentContext(); auto contextIt = contexts.begin(); // deltaIdx is the offset of the sample to process compared to current // iteration index int deltaIdx = 0; - auto contextKey = Nan::New("context").ToLocalChecked(); - auto timestampKey = Nan::New("timestamp").ToLocalChecked(); - auto cpuTimeKey = Nan::New("cpuTime").ToLocalChecked(); - auto asyncIdKey = Nan::New("asyncId").ToLocalChecked(); + auto contextKey = String::NewFromUtf8Literal(isolate, "context"); + auto timestampKey = String::NewFromUtf8Literal(isolate, "timestamp"); + auto cpuTimeKey = String::NewFromUtf8Literal(isolate, "cpuTime"); + auto asyncIdKey = String::NewFromUtf8Literal(isolate, "asyncId"); auto V8toEpochOffset = GetV8ToEpochOffset(); auto lastCpuTime = startCpuTime; @@ -434,7 +435,7 @@ ContextsByNode WallProfiler::GetContextsByNode(CpuProfile* profile, auto it = contextsByNode.find(sample); Local array; if (it == contextsByNode.end()) { - array = Nan::New(); + array = Array::New(isolate); contextsByNode[sample] = {array, 1}; } else { array = it->second.contexts; @@ -442,27 +443,35 @@ ContextsByNode WallProfiler::GetContextsByNode(CpuProfile* profile, } if (sampleContext.context) { // Conforms to TimeProfileNodeContext defined in v8-types.ts - v8::Local timedContext = Nan::New(); - Nan::Set(timedContext, - contextKey, - sampleContext.context.get()->Get(isolate)); - Nan::Set(timedContext, - timestampKey, - BigInt::New(isolate, sampleTimestamp + V8toEpochOffset)); + Local timedContext = Object::New(isolate); + timedContext + ->Set(v8Context, + contextKey, + sampleContext.context.get()->Get(isolate)) + .Check(); + timedContext + ->Set(v8Context, + timestampKey, + BigInt::New(isolate, sampleTimestamp + V8toEpochOffset)) + .Check(); // if current sample is idle/program, reports its cpu time to the next // sample if (collectCpuTime_ && !isIdleOrProgram(sample)) { - Nan::Set( - timedContext, - cpuTimeKey, - Nan::New(sampleContext.cpu_time - lastCpuTime)); + timedContext + ->Set( + v8Context, + cpuTimeKey, + Number::New(isolate, sampleContext.cpu_time - lastCpuTime)) + .Check(); lastCpuTime = sampleContext.cpu_time; } - Nan::Set(timedContext, - asyncIdKey, - Nan::New(sampleContext.async_id)); - Nan::Set(array, array->Length(), timedContext); + timedContext + ->Set(v8Context, + asyncIdKey, + Number::New(isolate, sampleContext.async_id)) + .Check(); + array->Set(v8Context, array->Length(), timedContext).Check(); } // Sample context was consumed, fetch the next one