Refactor functionName in ErrorStackTrace.cpp (#22760)

### What does this PR do?

Make `getName` inner lambda always returns function name instead of
assign to `functionName` in parent scope

### How did you verify your code works?

This is just refactoring
This commit is contained in:
SUZUKI Sosuke
2025-09-19 16:31:25 +09:00
committed by GitHub
parent 1790d108e7
commit 716a2fbea0

View File

@@ -667,7 +667,6 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC::
String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, const JSC::StackFrame& frame, bool isInFinalizer, unsigned int* flags)
{
WTF::String functionName;
bool isConstructor = false;
if (isInFinalizer) {
@@ -684,73 +683,65 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, const
}
};
const auto getName = [&]() -> String {
// First try the "name" property.
{
unsigned attributes;
PropertyOffset offset = structure->getConcurrently(vm.propertyNames->name.impl(), attributes);
if (offset != invalidOffset && !(attributes & (PropertyAttribute::Accessor | PropertyAttribute::CustomAccessorOrValue))) {
JSValue name = object->getDirect(offset);
if (name && name.isString()) {
auto str = asString(name)->tryGetValueWithoutGC();
if (!str->isEmpty()) {
setTypeFlagsIfNecessary();
return str.data;
}
// First try the "name" property.
{
unsigned attributes;
PropertyOffset offset = structure->getConcurrently(vm.propertyNames->name.impl(), attributes);
if (offset != invalidOffset && !(attributes & (PropertyAttribute::Accessor | PropertyAttribute::CustomAccessorOrValue))) {
JSValue name = object->getDirect(offset);
if (name && name.isString()) {
auto str = asString(name)->tryGetValueWithoutGC();
if (!str->isEmpty()) {
setTypeFlagsIfNecessary();
return str;
}
}
}
}
// Then try the "displayName" property.
{
unsigned attributes;
PropertyOffset offset = structure->getConcurrently(vm.propertyNames->displayName.impl(), attributes);
if (offset != invalidOffset && !(attributes & (PropertyAttribute::Accessor | PropertyAttribute::CustomAccessorOrValue))) {
JSValue name = object->getDirect(offset);
if (name && name.isString()) {
auto str = asString(name)->tryGetValueWithoutGC();
if (!str->isEmpty()) {
functionName = str.data;
if (!functionName.isEmpty()) {
setTypeFlagsIfNecessary();
return functionName;
}
}
// Then try the "displayName" property.
{
unsigned attributes;
PropertyOffset offset = structure->getConcurrently(vm.propertyNames->displayName.impl(), attributes);
if (offset != invalidOffset && !(attributes & (PropertyAttribute::Accessor | PropertyAttribute::CustomAccessorOrValue))) {
JSValue name = object->getDirect(offset);
if (name && name.isString()) {
auto str = asString(name)->tryGetValueWithoutGC();
if (!str->isEmpty()) {
setTypeFlagsIfNecessary();
return str;
}
}
}
}
// Lastly, try type-specific properties.
if (jstype == JSC::JSFunctionType) {
auto* function = jsCast<JSC::JSFunction*>(object);
if (function) {
functionName = function->nameWithoutGC(vm);
if (functionName.isEmpty() && !function->isHostFunction()) {
functionName = function->jsExecutable()->ecmaName().string();
}
// Lastly, try type-specific properties.
if (jstype == JSC::JSFunctionType) {
auto* function = jsCast<JSC::JSFunction*>(object);
if (function) {
auto str = function->nameWithoutGC(vm);
if (str.isEmpty() && !function->isHostFunction()) {
setTypeFlagsIfNecessary();
return functionName;
}
} else if (jstype == JSC::InternalFunctionType) {
auto* function = jsCast<JSC::InternalFunction*>(object);
if (function) {
functionName = function->name();
setTypeFlagsIfNecessary();
return functionName;
return function->jsExecutable()->ecmaName().string();
}
setTypeFlagsIfNecessary();
return str;
}
return functionName;
};
functionName = getName();
} else if (jstype == JSC::InternalFunctionType) {
auto* function = jsCast<JSC::InternalFunction*>(object);
if (function) {
auto str = function->name();
setTypeFlagsIfNecessary();
return str;
}
}
}
}
return functionName;
return emptyString();
}
WTF::String functionName;
if (frame.hasLineAndColumnInfo()) {
auto* codeblock = frame.codeBlock();
if (codeblock->isConstructor()) {