Skip to content

Commit

Permalink
src: apply getCallSite optimization
Browse files Browse the repository at this point in the history
PR-URL: #55174
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
RafaelGSS authored and targos committed Oct 4, 2024
1 parent 17665d4 commit 6db7170
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -262,28 +263,32 @@ static void GetCallSite(const FunctionCallbackInfo<Value>& args) {

// Frame 0 is node:util. It should be skipped.
for (int i = 1; i < frame_count; ++i) {
Local<Object> obj = Object::New(isolate);
Local<StackFrame> 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<Value> function_name = stack_frame->GetFunctionName();
if (function_name.IsEmpty()) {
function_name = v8::String::Empty(isolate);
}

Local<Value> script_name = stack_frame->GetScriptName();
if (script_name.IsEmpty()) {
script_name = v8::String::Empty(isolate);
}

Local<Name> names[] = {
env->function_name_string(),
env->script_name_string(),
env->line_number_string(),
env->column_string(),
};
Local<Value> values[] = {
function_name,
script_name,
Integer::NewFromUnsigned(isolate, stack_frame->GetLineNumber()),
Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()),
};
Local<Object> obj = Object::New(
isolate, v8::Null(isolate), names, values, arraysize(names));

callsite_objects.push_back(obj);
}
Expand Down

0 comments on commit 6db7170

Please sign in to comment.