From 6db7170648669869f1fd026cc0d8d4b2a22d8ced Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 30 Sep 2024 08:46:24 -0300 Subject: [PATCH] src: apply getCallSite optimization PR-URL: https://github.com/nodejs/node/pull/55174 Reviewed-By: Yagiz Nizipli Reviewed-By: Joyee Cheung Reviewed-By: Chengzhong Wu --- src/node_util.cc | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/node_util.cc b/src/node_util.cc index ea16a472c27c67..c99e26752c7d93 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -23,6 +23,7 @@ using v8::Isolate; using v8::KeyCollectionMode; using v8::Local; using v8::LocalVector; +using v8::Name; using v8::Object; using v8::ObjectTemplate; using v8::ONLY_CONFIGURABLE; @@ -262,28 +263,32 @@ static void GetCallSite(const FunctionCallbackInfo& args) { // Frame 0 is node:util. It should be skipped. for (int i = 1; i < frame_count; ++i) { - Local obj = Object::New(isolate); Local stack_frame = stack->GetFrame(isolate, i); - Utf8Value function_name(isolate, stack_frame->GetFunctionName()); - Utf8Value script_name(isolate, stack_frame->GetScriptName()); - - obj->Set(env->context(), - env->function_name_string(), - String::NewFromUtf8(isolate, *function_name).ToLocalChecked()) - .Check(); - obj->Set(env->context(), - env->script_name_string(), - String::NewFromUtf8(isolate, *script_name).ToLocalChecked()) - .Check(); - obj->Set(env->context(), - env->line_number_string(), - Integer::NewFromUnsigned(isolate, stack_frame->GetLineNumber())) - .Check(); - obj->Set(env->context(), - env->column_string(), - Integer::NewFromUnsigned(isolate, stack_frame->GetColumn())) - .Check(); + Local function_name = stack_frame->GetFunctionName(); + if (function_name.IsEmpty()) { + function_name = v8::String::Empty(isolate); + } + + Local script_name = stack_frame->GetScriptName(); + if (script_name.IsEmpty()) { + script_name = v8::String::Empty(isolate); + } + + Local names[] = { + env->function_name_string(), + env->script_name_string(), + env->line_number_string(), + env->column_string(), + }; + Local values[] = { + function_name, + script_name, + Integer::NewFromUnsigned(isolate, stack_frame->GetLineNumber()), + Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()), + }; + Local obj = Object::New( + isolate, v8::Null(isolate), names, values, arraysize(names)); callsite_objects.push_back(obj); }