LibJS+LibWeb: Convert empty PrimitiveString instances to String

This commit is contained in:
Timothy Flynn 2023-02-09 07:50:12 -05:00 committed by Linus Groh
parent e99a4ba7c8
commit 49e8dcf0b2
Notes: sideshowbarker 2024-07-17 23:07:41 +09:00
9 changed files with 26 additions and 26 deletions

View file

@ -622,7 +622,7 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
else if (specifier == "%c"sv) {
// NOTE: This has no spec yet. `%c` specifiers treat the argument as CSS styling for the log message.
add_css_style_to_current_message(TRY(current.to_deprecated_string(vm)));
converted = PrimitiveString::create(vm, "");
converted = PrimitiveString::create(vm, String {});
}
// 7. If any of the previous steps set converted, replace specifier in target with converted.

View file

@ -21,7 +21,7 @@ ThrowCompletionOr<void> AggregateErrorPrototype::initialize(Realm& realm)
MUST_OR_THROW_OOM(Base::initialize(realm));
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.name, PrimitiveString::create(vm, "AggregateError"), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, ""), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, String {}), attr);
return {};
}

View file

@ -993,7 +993,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
// FWIW: engine262, a "100% spec compliant" ECMA-262 impl, aborts with "too much recursion".
// Same applies to Array.prototype.toLocaleString().
if (s_array_join_seen_objects.contains(this_object))
return PrimitiveString::create(vm, "");
return PrimitiveString::create(vm, String {});
s_array_join_seen_objects.set(this_object);
ArmedScopeGuard unsee_object_guard = [&] {
s_array_join_seen_objects.remove(this_object);
@ -1704,7 +1704,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
auto* this_object = TRY(vm.this_value().to_object(vm));
if (s_array_join_seen_objects.contains(this_object))
return PrimitiveString::create(vm, "");
return PrimitiveString::create(vm, String {});
s_array_join_seen_objects.set(this_object);
ArmedScopeGuard unsee_object_guard = [&] {
s_array_join_seen_objects.remove(this_object);

View file

@ -25,7 +25,7 @@ ThrowCompletionOr<void> ErrorPrototype::initialize(Realm& realm)
MUST_OR_THROW_OOM(Base::initialize(realm));
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.name, PrimitiveString::create(vm, "Error"), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, ""), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, String {}), attr);
define_native_function(realm, vm.names.toString, to_string, 0, attr);
// Non standard property "stack"
// Every other engine seems to have this in some way or another, and the spec
@ -124,21 +124,21 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_setter)
return TRY(this_object.create_data_property_or_throw(vm.names.stack, vm.argument(0)));
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
PrototypeName::PrototypeName(Realm& realm) \
: PrototypeObject(*realm.intrinsics().error_prototype()) \
{ \
} \
\
ThrowCompletionOr<void> PrototypeName::initialize(Realm& realm) \
{ \
auto& vm = this->vm(); \
MUST_OR_THROW_OOM(Base::initialize(realm)); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
define_direct_property(vm.names.name, PrimitiveString::create(vm, #ClassName), attr); \
define_direct_property(vm.names.message, PrimitiveString::create(vm, ""), attr); \
\
return {}; \
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
PrototypeName::PrototypeName(Realm& realm) \
: PrototypeObject(*realm.intrinsics().error_prototype()) \
{ \
} \
\
ThrowCompletionOr<void> PrototypeName::initialize(Realm& realm) \
{ \
auto& vm = this->vm(); \
MUST_OR_THROW_OOM(Base::initialize(realm)); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
define_direct_property(vm.names.name, PrimitiveString::create(vm, #ClassName), attr); \
define_direct_property(vm.names.message, PrimitiveString::create(vm, String {}), attr); \
\
return {}; \
}
JS_ENUMERATE_NATIVE_ERRORS

View file

@ -36,7 +36,7 @@ ThrowCompletionOr<void> FunctionPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.toString, to_string, 0, attr);
define_native_function(realm, *vm.well_known_symbol_has_instance(), symbol_has_instance, 1, 0);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
define_direct_property(vm.names.name, PrimitiveString::create(vm, ""), Attribute::Configurable);
define_direct_property(vm.names.name, PrimitiveString::create(vm, String {}), Attribute::Configurable);
return {};
}

View file

@ -232,7 +232,7 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
},
0, "", &realm);
m_throw_type_error_function->define_direct_property(vm.names.length, Value(0), 0);
m_throw_type_error_function->define_direct_property(vm.names.name, PrimitiveString::create(vm, ""), 0);
m_throw_type_error_function->define_direct_property(vm.names.name, PrimitiveString::create(vm, String {}), 0);
MUST(m_throw_type_error_function->internal_prevent_extensions());
initialize_constructor(vm, vm.names.Error, *m_error_constructor, m_error_prototype);

View file

@ -59,7 +59,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> StringConstructor::construct(FunctionObj
PrimitiveString* primitive_string;
if (!vm.argument_count())
primitive_string = PrimitiveString::create(vm, "");
primitive_string = PrimitiveString::create(vm, String {});
else
primitive_string = TRY(vm.argument(0).to_primitive_string(vm));
auto* prototype = TRY(get_prototype_from_constructor(vm, new_target, &Intrinsics::string_prototype));
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
auto literal_segments = TRY(length_of_array_like(vm, *raw));
if (literal_segments == 0)
return PrimitiveString::create(vm, "");
return PrimitiveString::create(vm, String {});
auto const number_of_substituions = vm.argument_count() - 1;

View file

@ -21,7 +21,7 @@ ThrowCompletionOr<void> SuppressedErrorPrototype::initialize(Realm& realm)
MUST_OR_THROW_OOM(Base::initialize(realm));
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.name, PrimitiveString::create(vm, "SuppressedError"), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, ""), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, String {}), attr);
return {};
}

View file

@ -129,7 +129,7 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
if (m_response_type == Bindings::XMLHttpRequestResponseType::Empty || m_response_type == Bindings::XMLHttpRequestResponseType::Text) {
// 1. If thiss state is not loading or done, then return the empty string.
if (m_state != State::Loading && m_state != State::Done)
return JS::PrimitiveString::create(vm, "");
return JS::PrimitiveString::create(vm, String {});
// 2. Return the result of getting a text response for this.
return JS::PrimitiveString::create(vm, get_text_response());