LibJS: Use FlyString in PropertyKey instead of DeprecatedFlyString

This required dealing with *substantial* fallout.
This commit is contained in:
Andreas Kling 2025-03-18 18:08:02 -05:00 committed by Andreas Kling
commit 46a5710238
Notes: github-actions[bot] 2025-03-24 22:28:26 +00:00
110 changed files with 985 additions and 987 deletions

View file

@ -63,7 +63,7 @@ static void print_indent(int indent)
out("{}", ByteString::repeated(' ', indent * 2));
}
static void update_function_name(Value value, DeprecatedFlyString const& name)
static void update_function_name(Value value, FlyString const& name)
{
if (!value.is_function())
return;
@ -87,15 +87,15 @@ void LabelledStatement::dump(int indent) const
}
// 15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression, https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
Value FunctionExpression::instantiate_ordinary_function_expression(VM& vm, DeprecatedFlyString given_name) const
Value FunctionExpression::instantiate_ordinary_function_expression(VM& vm, FlyString given_name) const
{
auto& realm = *vm.current_realm();
if (given_name.is_empty())
given_name = "";
given_name = ""_fly_string;
auto has_own_name = !name().is_empty();
auto const used_name = has_own_name ? name() : given_name.view();
auto const used_name = has_own_name ? name() : given_name;
auto environment = GC::Ref { *vm.running_execution_context().lexical_environment };
if (has_own_name) {
VERIFY(environment);
@ -117,10 +117,10 @@ Value FunctionExpression::instantiate_ordinary_function_expression(VM& vm, Depre
return closure;
}
Optional<ByteString> CallExpression::expression_string() const
Optional<String> CallExpression::expression_string() const
{
if (is<Identifier>(*m_callee))
return static_cast<Identifier const&>(*m_callee).string();
return static_cast<Identifier const&>(*m_callee).string().to_string();
if (is<MemberExpression>(*m_callee))
return static_cast<MemberExpression const&>(*m_callee).to_string_approximation();
@ -159,21 +159,20 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassMethod::class_element_evaluatio
auto set_function_name = [&](ByteString prefix = "") {
auto name = property_key_or_private_name.visit(
[&](PropertyKey const& property_key) -> ByteString {
[&](PropertyKey const& property_key) -> String {
if (property_key.is_symbol()) {
auto description = property_key.as_symbol()->description();
if (!description.has_value() || description->is_empty())
return "";
return ByteString::formatted("[{}]", *description);
} else {
return property_key.to_string();
return ""_string;
return MUST(String::formatted("[{}]", *description));
}
return property_key.to_string();
},
[&](PrivateName const& private_name) -> ByteString {
return private_name.description;
[&](PrivateName const& private_name) -> String {
return private_name.description.to_string();
});
update_function_name(method_value, ByteString::formatted("{}{}{}", prefix, prefix.is_empty() ? "" : " ", name));
update_function_name(method_value, MUST(String::formatted("{}{}{}", prefix, prefix.is_empty() ? "" : " ", name)));
};
if (property_key_or_private_name.has<PropertyKey>()) {
@ -230,11 +229,11 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
if (m_initializer) {
auto copy_initializer = m_initializer;
auto name = property_key_or_private_name.visit(
[&](PropertyKey const& property_key) -> ByteString {
[&](PropertyKey const& property_key) -> String {
return property_key.is_number() ? property_key.to_string() : property_key.to_string_or_symbol().to_display_string();
},
[&](PrivateName const& private_name) -> ByteString {
return private_name.description;
[&](PrivateName const& private_name) -> String {
return private_name.description.to_string();
});
// FIXME: A potential optimization is not creating the functions here since these are never directly accessible.
@ -242,7 +241,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
FunctionParsingInsights parsing_insights;
parsing_insights.uses_this_from_environment = true;
parsing_insights.uses_this = true;
initializer = ECMAScriptFunctionObject::create(realm, "field", ByteString::empty(), *function_code, {}, 0, {}, vm.lexical_environment(), vm.running_execution_context().private_environment, FunctionKind::Normal, true, parsing_insights, false, property_key_or_private_name);
initializer = ECMAScriptFunctionObject::create(realm, "field"_string, ByteString::empty(), *function_code, {}, 0, {}, vm.lexical_environment(), vm.running_execution_context().private_environment, FunctionKind::Normal, true, parsing_insights, false, property_key_or_private_name);
initializer->make_method(target);
}
@ -254,19 +253,19 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
};
}
static Optional<DeprecatedFlyString> nullopt_or_private_identifier_description(Expression const& expression)
static Optional<FlyString> nullopt_or_private_identifier_description(Expression const& expression)
{
if (is<PrivateIdentifier>(expression))
return static_cast<PrivateIdentifier const&>(expression).string();
return {};
}
Optional<DeprecatedFlyString> ClassField::private_bound_identifier() const
Optional<FlyString> ClassField::private_bound_identifier() const
{
return nullopt_or_private_identifier_description(*m_key);
}
Optional<DeprecatedFlyString> ClassMethod::private_bound_identifier() const
Optional<FlyString> ClassMethod::private_bound_identifier() const
{
return nullopt_or_private_identifier_description(*m_key);
}
@ -289,7 +288,7 @@ ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_eva
FunctionParsingInsights parsing_insights;
parsing_insights.uses_this_from_environment = true;
parsing_insights.uses_this = true;
auto body_function = ECMAScriptFunctionObject::create(realm, ByteString::empty(), ByteString::empty(), *m_function_body, {}, 0, m_function_body->local_variables_names(), lexical_environment, private_environment, FunctionKind::Normal, true, parsing_insights, false);
auto body_function = ECMAScriptFunctionObject::create(realm, ""_string, ByteString::empty(), *m_function_body, {}, 0, m_function_body->local_variables_names(), lexical_environment, private_environment, FunctionKind::Normal, true, parsing_insights, false);
// 6. Perform MakeMethod(bodyFunction, homeObject).
body_function->make_method(home_object);
@ -298,7 +297,7 @@ ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_eva
return ClassValue { normal_completion(body_function) };
}
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_constructor(VM& vm, Environment* class_environment, Environment* environment, Value super_class, ReadonlySpan<Value> element_keys, Optional<DeprecatedFlyString> const& binding_name, DeprecatedFlyString const& class_name) const
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_constructor(VM& vm, Environment* class_environment, Environment* environment, Value super_class, ReadonlySpan<Value> element_keys, Optional<FlyString> const& binding_name, FlyString const& class_name) const
{
auto& realm = *vm.current_realm();
@ -1209,16 +1208,16 @@ void MemberExpression::dump(int indent) const
m_property->dump(indent + 1);
}
ByteString MemberExpression::to_string_approximation() const
String MemberExpression::to_string_approximation() const
{
ByteString object_string = "<object>";
String object_string = "<object>"_string;
if (is<Identifier>(*m_object))
object_string = static_cast<Identifier const&>(*m_object).string();
object_string = static_cast<Identifier const&>(*m_object).string().to_string();
if (is_computed())
return ByteString::formatted("{}[<computed>]", object_string);
return MUST(String::formatted("{}[<computed>]", object_string));
if (is<PrivateIdentifier>(*m_property))
return ByteString::formatted("{}.{}", object_string, as<PrivateIdentifier>(*m_property).string());
return ByteString::formatted("{}.{}", object_string, as<Identifier>(*m_property).string());
return MUST(String::formatted("{}.{}", object_string, as<PrivateIdentifier>(*m_property).string()));
return MUST(String::formatted("{}.{}", object_string, as<Identifier>(*m_property).string()));
}
bool MemberExpression::ends_in_private_name() const
@ -1349,7 +1348,7 @@ void CatchClause::dump(int indent) const
{
print_indent(indent);
m_parameter.visit(
[&](DeprecatedFlyString const& parameter) {
[&](FlyString const& parameter) {
if (parameter.is_empty())
outln("CatchClause");
else
@ -1498,7 +1497,7 @@ void ScopeNode::add_hoisted_function(NonnullRefPtr<FunctionDeclaration const> de
m_functions_hoistable_with_annexB_extension.append(move(declaration));
}
DeprecatedFlyString ExportStatement::local_name_for_default = "*default*";
FlyString ExportStatement::local_name_for_default = "*default*"_fly_string;
static void dump_assert_clauses(ModuleRequest const& request)
{
@ -1516,7 +1515,7 @@ void ExportStatement::dump(int indent) const
print_indent(indent + 1);
outln("(ExportEntries)");
auto string_or_null = [](Optional<DeprecatedFlyString> const& string) -> ByteString {
auto string_or_null = [](Optional<FlyString> const& string) -> ByteString {
if (!string.has_value()) {
return "null";
}
@ -1564,7 +1563,7 @@ void ImportStatement::dump(int indent) const
}
}
bool ExportStatement::has_export(DeprecatedFlyString const& export_name) const
bool ExportStatement::has_export(FlyString const& export_name) const
{
return any_of(m_entries.begin(), m_entries.end(), [&](auto& entry) {
// Make sure that empty exported names does not overlap with anything
@ -1574,7 +1573,7 @@ bool ExportStatement::has_export(DeprecatedFlyString const& export_name) const
});
}
bool ImportStatement::has_bound_name(DeprecatedFlyString const& name) const
bool ImportStatement::has_bound_name(FlyString const& name) const
{
return any_of(m_entries.begin(), m_entries.end(), [&](auto& entry) {
return entry.local_name == name;
@ -1688,7 +1687,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
Vector<FunctionDeclaration const&> functions_to_initialize;
// 7. Let declaredFunctionNames be a new empty List.
HashTable<DeprecatedFlyString> declared_function_names;
HashTable<FlyString> declared_function_names;
// 8. For each element d of varDeclarations, in reverse List order, do
@ -1723,7 +1722,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
}));
// 9. Let declaredVarNames be a new empty List.
HashTable<DeprecatedFlyString> declared_var_names;
HashTable<FlyString> declared_var_names;
// 10. For each element d of varDeclarations, do
TRY(for_each_var_scoped_variable_declaration([&](Declaration const& declaration) {
@ -1853,7 +1852,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
return {};
}
ModuleRequest::ModuleRequest(DeprecatedFlyString module_specifier_, Vector<ImportAttribute> attributes)
ModuleRequest::ModuleRequest(FlyString module_specifier_, Vector<ImportAttribute> attributes)
: module_specifier(move(module_specifier_))
, attributes(move(attributes))
{