mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:57: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
|
@ -39,7 +39,7 @@ ThrowCompletionOr<void> Intl::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 8.1.1 Intl[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl-toStringTag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_intrinsic_accessor(vm.names.Collator, attr, [](auto& realm) -> Value { return realm.intrinsics().intl_collator_constructor(); });
|
||||
|
@ -157,7 +157,9 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
|
|||
}
|
||||
|
||||
// 9. Return CreateArrayFromList( list ).
|
||||
return Array::create_from<StringView>(realm, list, [&](auto value) { return PrimitiveString::create(vm, value); });
|
||||
return MUST_OR_THROW_OOM(Array::try_create_from<StringView>(vm, realm, list, [&](auto value) {
|
||||
return PrimitiveString::create(vm, value);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue