1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +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:
Timothy Flynn 2023-02-09 09:00:14 -05:00 committed by Linus Groh
parent 69a56a8e39
commit c3abb1396c
69 changed files with 223 additions and 186 deletions

View file

@ -112,11 +112,11 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
// b. Return default.
return default_.visit(
[](GetOptionRequired) -> Value { VERIFY_NOT_REACHED(); },
[](Empty) { return js_undefined(); },
[](bool b) { return Value(b); },
[](double d) { return Value(d); },
[&vm](StringView s) { return Value(PrimitiveString::create(vm, s)); });
[](GetOptionRequired) -> ThrowCompletionOr<Value> { VERIFY_NOT_REACHED(); },
[](Empty) -> ThrowCompletionOr<Value> { return js_undefined(); },
[](bool b) -> ThrowCompletionOr<Value> { return Value(b); },
[](double d) -> ThrowCompletionOr<Value> { return Value(d); },
[&vm](StringView s) -> ThrowCompletionOr<Value> { return MUST_OR_THROW_OOM(PrimitiveString::create(vm, s)); });
}
// 5. If type is "boolean", then
@ -602,7 +602,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
auto date_options = Object::create(realm, nullptr);
// g. Perform ! CreateDataPropertyOrThrow(dateOptions, "overflow", "constrain").
MUST(date_options->create_data_property_or_throw(vm.names.overflow, PrimitiveString::create(vm, "constrain"sv)));
MUST(date_options->create_data_property_or_throw(vm.names.overflow, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "constrain"sv))));
// h. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, dateOptions).
result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *date_options));