Skip to content

Commit b1d47d0

Browse files
RafaelGSStargos
authored andcommitted
src: apply getCallSite optimization
PR-URL: #55174 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 8a57550 commit b1d47d0

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/node_util.cc

+25-20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using v8::Isolate;
2323
using v8::KeyCollectionMode;
2424
using v8::Local;
2525
using v8::LocalVector;
26+
using v8::Name;
2627
using v8::Object;
2728
using v8::ObjectTemplate;
2829
using v8::ONLY_CONFIGURABLE;
@@ -262,28 +263,32 @@ static void GetCallSite(const FunctionCallbackInfo<Value>& args) {
262263

263264
// Frame 0 is node:util. It should be skipped.
264265
for (int i = 1; i < frame_count; ++i) {
265-
Local<Object> obj = Object::New(isolate);
266266
Local<StackFrame> stack_frame = stack->GetFrame(isolate, i);
267267

268-
Utf8Value function_name(isolate, stack_frame->GetFunctionName());
269-
Utf8Value script_name(isolate, stack_frame->GetScriptName());
270-
271-
obj->Set(env->context(),
272-
env->function_name_string(),
273-
String::NewFromUtf8(isolate, *function_name).ToLocalChecked())
274-
.Check();
275-
obj->Set(env->context(),
276-
env->script_name_string(),
277-
String::NewFromUtf8(isolate, *script_name).ToLocalChecked())
278-
.Check();
279-
obj->Set(env->context(),
280-
env->line_number_string(),
281-
Integer::NewFromUnsigned(isolate, stack_frame->GetLineNumber()))
282-
.Check();
283-
obj->Set(env->context(),
284-
env->column_string(),
285-
Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()))
286-
.Check();
268+
Local<Value> function_name = stack_frame->GetFunctionName();
269+
if (function_name.IsEmpty()) {
270+
function_name = v8::String::Empty(isolate);
271+
}
272+
273+
Local<Value> script_name = stack_frame->GetScriptName();
274+
if (script_name.IsEmpty()) {
275+
script_name = v8::String::Empty(isolate);
276+
}
277+
278+
Local<Name> names[] = {
279+
env->function_name_string(),
280+
env->script_name_string(),
281+
env->line_number_string(),
282+
env->column_string(),
283+
};
284+
Local<Value> values[] = {
285+
function_name,
286+
script_name,
287+
Integer::NewFromUnsigned(isolate, stack_frame->GetLineNumber()),
288+
Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()),
289+
};
290+
Local<Object> obj = Object::New(
291+
isolate, v8::Null(isolate), names, values, arraysize(names));
287292

288293
callsite_objects.push_back(obj);
289294
}

0 commit comments

Comments
 (0)