Skip to content

Commit df67f49

Browse files
committed
LibJS: Convert Temporal.Now functions to ThrowCompletionOr
1 parent 149231d commit df67f49

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,116 +35,116 @@ void Now::initialize(GlobalObject& global_object)
3535
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal.Now"), Attribute::Configurable);
3636

3737
u8 attr = Attribute::Writable | Attribute::Configurable;
38-
define_old_native_function(vm.names.timeZone, time_zone, 0, attr);
39-
define_old_native_function(vm.names.instant, instant, 0, attr);
40-
define_old_native_function(vm.names.plainDateTime, plain_date_time, 1, attr);
41-
define_old_native_function(vm.names.plainDateTimeISO, plain_date_time_iso, 0, attr);
42-
define_old_native_function(vm.names.zonedDateTime, zoned_date_time, 1, attr);
43-
define_old_native_function(vm.names.zonedDateTimeISO, zoned_date_time_iso, 0, attr);
44-
define_old_native_function(vm.names.plainDate, plain_date, 1, attr);
45-
define_old_native_function(vm.names.plainDateISO, plain_date_iso, 0, attr);
46-
define_old_native_function(vm.names.plainTimeISO, plain_time_iso, 0, attr);
38+
define_native_function(vm.names.timeZone, time_zone, 0, attr);
39+
define_native_function(vm.names.instant, instant, 0, attr);
40+
define_native_function(vm.names.plainDateTime, plain_date_time, 1, attr);
41+
define_native_function(vm.names.plainDateTimeISO, plain_date_time_iso, 0, attr);
42+
define_native_function(vm.names.zonedDateTime, zoned_date_time, 1, attr);
43+
define_native_function(vm.names.zonedDateTimeISO, zoned_date_time_iso, 0, attr);
44+
define_native_function(vm.names.plainDate, plain_date, 1, attr);
45+
define_native_function(vm.names.plainDateISO, plain_date_iso, 0, attr);
46+
define_native_function(vm.names.plainTimeISO, plain_time_iso, 0, attr);
4747
}
4848

4949
// 2.2.1 Temporal.Now.timeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.timezone
50-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::time_zone)
50+
JS_DEFINE_NATIVE_FUNCTION(Now::time_zone)
5151
{
5252
// 1. Return ! SystemTimeZone().
5353
return system_time_zone(global_object);
5454
}
5555

5656
// 2.2.2 Temporal.Now.instant ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.instant
57-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::instant)
57+
JS_DEFINE_NATIVE_FUNCTION(Now::instant)
5858
{
5959
// 1. Return ! SystemInstant().
6060
return system_instant(global_object);
6161
}
6262

6363
// 2.2.3 Temporal.Now.plainDateTime ( calendar [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindatetime
64-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::plain_date_time)
64+
JS_DEFINE_NATIVE_FUNCTION(Now::plain_date_time)
6565
{
6666
auto calendar = vm.argument(0);
6767
auto temporal_time_zone_like = vm.argument(1);
6868

6969
// 1. Return ? SystemDateTime(temporalTimeZoneLike, calendar).
70-
return TRY_OR_DISCARD(system_date_time(global_object, temporal_time_zone_like, calendar));
70+
return TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
7171
}
7272

7373
// 2.2.4 Temporal.Now.plainDateTimeISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindatetimeiso
74-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::plain_date_time_iso)
74+
JS_DEFINE_NATIVE_FUNCTION(Now::plain_date_time_iso)
7575
{
7676
auto temporal_time_zone_like = vm.argument(0);
7777

7878
// 1, Let calendar be ! GetISO8601Calendar().
7979
auto* calendar = get_iso8601_calendar(global_object);
8080

8181
// 2. Return ? SystemDateTime(temporalTimeZoneLike, calendar).
82-
return TRY_OR_DISCARD(system_date_time(global_object, temporal_time_zone_like, calendar));
82+
return TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
8383
}
8484

8585
// 2.2.5 Temporal.Now.zonedDateTime ( calendar [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.zoneddatetime
86-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::zoned_date_time)
86+
JS_DEFINE_NATIVE_FUNCTION(Now::zoned_date_time)
8787
{
8888
auto calendar = vm.argument(0);
8989
auto temporal_time_zone_like = vm.argument(1);
9090

9191
// 1. Return ? SystemZonedDateTime(temporalTimeZoneLike, calendar).
92-
return TRY_OR_DISCARD(system_zoned_date_time(global_object, temporal_time_zone_like, calendar));
92+
return TRY(system_zoned_date_time(global_object, temporal_time_zone_like, calendar));
9393
}
9494

9595
// 2.2.6 Temporal.Now.zonedDateTimeISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.zoneddatetimeiso
96-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::zoned_date_time_iso)
96+
JS_DEFINE_NATIVE_FUNCTION(Now::zoned_date_time_iso)
9797
{
9898
auto temporal_time_zone_like = vm.argument(0);
9999

100100
// 1, Let calendar be ! GetISO8601Calendar().
101101
auto* calendar = get_iso8601_calendar(global_object);
102102

103103
// 2. Return ? SystemZonedDateTime(temporalTimeZoneLike, calendar).
104-
return TRY_OR_DISCARD(system_zoned_date_time(global_object, temporal_time_zone_like, calendar));
104+
return TRY(system_zoned_date_time(global_object, temporal_time_zone_like, calendar));
105105
}
106106

107107
// 2.2.7 Temporal.Now.plainDate ( calendar [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindate
108-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::plain_date)
108+
JS_DEFINE_NATIVE_FUNCTION(Now::plain_date)
109109
{
110110
auto calendar = vm.argument(0);
111111
auto temporal_time_zone_like = vm.argument(1);
112112

113113
// 1. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
114-
auto* date_time = TRY_OR_DISCARD(system_date_time(global_object, temporal_time_zone_like, calendar));
114+
auto* date_time = TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
115115

116116
// 2. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[Calendar]]).
117-
return TRY_OR_DISCARD(create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
117+
return TRY(create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
118118
}
119119

120120
// 2.2.8 Temporal.Now.plainDateISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindateiso
121-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::plain_date_iso)
121+
JS_DEFINE_NATIVE_FUNCTION(Now::plain_date_iso)
122122
{
123123
auto temporal_time_zone_like = vm.argument(0);
124124

125125
// 1. Let calendar be ! GetISO8601Calendar().
126126
auto* calendar = get_iso8601_calendar(global_object);
127127

128128
// 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
129-
auto* date_time = TRY_OR_DISCARD(system_date_time(global_object, temporal_time_zone_like, calendar));
129+
auto* date_time = TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
130130

131131
// 3. Return ! CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[Calendar]]).
132-
return TRY_OR_DISCARD(create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
132+
return TRY(create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()));
133133
}
134134

135135
// 2.2.9 Temporal.Now.plainTimeISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaintimeiso
136-
JS_DEFINE_OLD_NATIVE_FUNCTION(Now::plain_time_iso)
136+
JS_DEFINE_NATIVE_FUNCTION(Now::plain_time_iso)
137137
{
138138
auto temporal_time_zone_like = vm.argument(0);
139139

140140
// 1. Let calendar be ! GetISO8601Calendar().
141141
auto* calendar = get_iso8601_calendar(global_object);
142142

143143
// 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
144-
auto* date_time = TRY_OR_DISCARD(system_date_time(global_object, temporal_time_zone_like, calendar));
144+
auto* date_time = TRY(system_date_time(global_object, temporal_time_zone_like, calendar));
145145

146146
// 3. Return ! CreateTemporalTime(dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
147-
return TRY_OR_DISCARD(create_temporal_time(global_object, date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond()));
147+
return MUST(create_temporal_time(global_object, date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond()));
148148
}
149149

150150
// 2.3.1 SystemTimeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemtimezone
@@ -154,7 +154,7 @@ TimeZone* system_time_zone(GlobalObject& global_object)
154154
auto identifier = default_time_zone();
155155

156156
// 2. Return ! CreateTemporalTimeZone(identifier).
157-
return TRY_OR_DISCARD(create_temporal_time_zone(global_object, identifier));
157+
return MUST(create_temporal_time_zone(global_object, identifier));
158158
}
159159

160160
// 2.3.2 SystemUTCEpochNanoseconds ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemutcepochnanoseconds

Userland/Libraries/LibJS/Runtime/Temporal/Now.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class Now final : public Object {
2020
virtual ~Now() override = default;
2121

2222
private:
23-
JS_DECLARE_OLD_NATIVE_FUNCTION(time_zone);
24-
JS_DECLARE_OLD_NATIVE_FUNCTION(instant);
25-
JS_DECLARE_OLD_NATIVE_FUNCTION(plain_date_time);
26-
JS_DECLARE_OLD_NATIVE_FUNCTION(plain_date_time_iso);
27-
JS_DECLARE_OLD_NATIVE_FUNCTION(zoned_date_time);
28-
JS_DECLARE_OLD_NATIVE_FUNCTION(zoned_date_time_iso);
29-
JS_DECLARE_OLD_NATIVE_FUNCTION(plain_date);
30-
JS_DECLARE_OLD_NATIVE_FUNCTION(plain_date_iso);
31-
JS_DECLARE_OLD_NATIVE_FUNCTION(plain_time_iso);
23+
JS_DECLARE_NATIVE_FUNCTION(time_zone);
24+
JS_DECLARE_NATIVE_FUNCTION(instant);
25+
JS_DECLARE_NATIVE_FUNCTION(plain_date_time);
26+
JS_DECLARE_NATIVE_FUNCTION(plain_date_time_iso);
27+
JS_DECLARE_NATIVE_FUNCTION(zoned_date_time);
28+
JS_DECLARE_NATIVE_FUNCTION(zoned_date_time_iso);
29+
JS_DECLARE_NATIVE_FUNCTION(plain_date);
30+
JS_DECLARE_NATIVE_FUNCTION(plain_date_iso);
31+
JS_DECLARE_NATIVE_FUNCTION(plain_time_iso);
3232
};
3333

3434
TimeZone* system_time_zone(GlobalObject&);

0 commit comments

Comments
 (0)