mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibJS+LibWeb: Convert string view PrimitiveString instances to String
First, this adds an overload of PrimitiveString::create for StringView. This overload will throw an OOM completion if creating a String fails. This is not only a bit more convenient, but it also ensures at compile time that all PrimitiveString::create(string_view) invocations will be handled as String and OOM-aware. Next, this wraps all invocations to PrimitiveString::create(string_view) with MUST_OR_THROW_OOM. A small PrimitiveString::create(DeprecatedFlyString) overload also had to be added to disambiguate between the StringView and DeprecatedString overloads.
This commit is contained in:
parent
69a56a8e39
commit
c3abb1396c
69 changed files with 223 additions and 186 deletions
|
@ -243,15 +243,15 @@ void NumberFormatBase::set_trailing_zero_display(StringView trailing_zero_displa
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Value NumberFormat::use_grouping_to_value(VM& vm) const
|
||||
ThrowCompletionOr<Value> NumberFormat::use_grouping_to_value(VM& vm) const
|
||||
{
|
||||
switch (m_use_grouping) {
|
||||
case UseGrouping::Always:
|
||||
return PrimitiveString::create(vm, "always"sv);
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "always"sv));
|
||||
case UseGrouping::Auto:
|
||||
return PrimitiveString::create(vm, "auto"sv);
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "auto"sv));
|
||||
case UseGrouping::Min2:
|
||||
return PrimitiveString::create(vm, "min2"sv);
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "min2"sv));
|
||||
case UseGrouping::False:
|
||||
return Value(false);
|
||||
default:
|
||||
|
@ -948,7 +948,7 @@ ThrowCompletionOr<Array*> format_numeric_to_parts(VM& vm, NumberFormat& number_f
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
@ -1932,13 +1932,13 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
||||
// d. Perform ! CreateDataPropertyOrThrow(O, "source", part.[[Source]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.source, PrimitiveString::create(vm, part.source)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.source, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.source))));
|
||||
|
||||
// e. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
|
||||
MUST(result->create_data_property_or_throw(n, object));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue