mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
LibJS: Port create_temporal_calendar() to String
This commit is contained in:
parent
0f5f9acc9c
commit
a101b15ad0
3 changed files with 11 additions and 11 deletions
|
@ -27,7 +27,7 @@
|
|||
namespace JS::Temporal {
|
||||
|
||||
// 12 Temporal.Calendar Objects, https://tc39.es/proposal-temporal/#sec-temporal-calendar-objects
|
||||
Calendar::Calendar(DeprecatedString identifier, Object& prototype)
|
||||
Calendar::Calendar(String identifier, Object& prototype)
|
||||
: Object(ConstructWithPrototypeTag::Tag, prototype)
|
||||
, m_identifier(move(identifier))
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ Span<StringView const> available_calendars()
|
|||
}
|
||||
|
||||
// 12.2.1 CreateTemporalCalendar ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalcalendar
|
||||
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, DeprecatedString const& identifier, FunctionObject const* new_target)
|
||||
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, String const& identifier, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
|
@ -78,7 +78,7 @@ ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, DeprecatedString c
|
|||
|
||||
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
|
||||
// 4. Set object.[[Identifier]] to the ASCII-lowercase of identifier.
|
||||
auto object = TRY(ordinary_create_from_constructor<Calendar>(vm, *new_target, &Intrinsics::temporal_calendar_prototype, identifier.to_lowercase()));
|
||||
auto object = TRY(ordinary_create_from_constructor<Calendar>(vm, *new_target, &Intrinsics::temporal_calendar_prototype, TRY_OR_THROW_OOM(vm, identifier.to_lowercase())));
|
||||
|
||||
// 5. Return object.
|
||||
return object.ptr();
|
||||
|
@ -92,7 +92,7 @@ ThrowCompletionOr<Calendar*> get_builtin_calendar(VM& vm, DeprecatedString const
|
|||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarIdentifier, identifier);
|
||||
|
||||
// 2. Return ! CreateTemporalCalendar(id).
|
||||
return MUST(create_temporal_calendar(vm, identifier));
|
||||
return MUST_OR_THROW_OOM(create_temporal_calendar(vm, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(identifier))));
|
||||
}
|
||||
|
||||
// 12.2.3 GetISO8601Calendar ( ), https://tc39.es/proposal-temporal/#sec-temporal-getiso8601calendar
|
||||
|
@ -473,7 +473,7 @@ ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_
|
|||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarIdentifier, identifier);
|
||||
|
||||
// 5. Return ! CreateTemporalCalendar(identifier).
|
||||
return MUST(create_temporal_calendar(vm, identifier.to_deprecated_string()));
|
||||
return MUST_OR_THROW_OOM(create_temporal_calendar(vm, identifier));
|
||||
}
|
||||
|
||||
// 12.2.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
|
||||
|
|
|
@ -22,13 +22,13 @@ class Calendar final : public Object {
|
|||
public:
|
||||
virtual ~Calendar() override = default;
|
||||
|
||||
[[nodiscard]] DeprecatedString const& identifier() const { return m_identifier; }
|
||||
[[nodiscard]] String const& identifier() const { return m_identifier; }
|
||||
|
||||
private:
|
||||
Calendar(DeprecatedString identifier, Object& prototype);
|
||||
Calendar(String identifier, Object& prototype);
|
||||
|
||||
// 12.5 Properties of Temporal.Calendar Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-calendar-instances
|
||||
DeprecatedString m_identifier; // [[Identifier]]
|
||||
String m_identifier; // [[Identifier]]
|
||||
};
|
||||
|
||||
// 14.2 The Year-Week Record Specification Type, https://tc39.es/proposal-temporal/#sec-year-week-record-specification-type
|
||||
|
@ -39,7 +39,7 @@ struct YearWeekRecord {
|
|||
|
||||
bool is_builtin_calendar(StringView identifier);
|
||||
Span<StringView const> available_calendars();
|
||||
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM&, DeprecatedString const& identifier, FunctionObject const* new_target = nullptr);
|
||||
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM&, String const& identifier, FunctionObject const* new_target = nullptr);
|
||||
ThrowCompletionOr<Calendar*> get_builtin_calendar(VM&, DeprecatedString const& identifier);
|
||||
Calendar* get_iso8601_calendar(VM&);
|
||||
ThrowCompletionOr<Vector<String>> calendar_fields(VM&, Object& calendar, Vector<StringView> const& field_names);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -47,7 +47,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> CalendarConstructor::construct(FunctionO
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 2. Set id to ? ToString(id).
|
||||
auto identifier = TRY(vm.argument(0).to_deprecated_string(vm));
|
||||
auto identifier = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 3. If IsBuiltinCalendar(id) is false, then
|
||||
if (!is_builtin_calendar(identifier)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue