Skip to content

Commit c47c660

Browse files
committed
LibJS: Convert Temporal.PlainDateTime.prototype to be a PrototypeObject
1 parent 0a30705 commit c47c660

File tree

2 files changed

+35
-47
lines changed

2 files changed

+35
-47
lines changed

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

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace JS::Temporal {
1717

1818
// 5.3 Properties of the Temporal.PlainDateTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindatetime-prototype-object
1919
PlainDateTimePrototype::PlainDateTimePrototype(GlobalObject& global_object)
20-
: Object(*global_object.object_prototype())
20+
: PrototypeObject(*global_object.object_prototype())
2121
{
2222
}
2323

@@ -65,25 +65,12 @@ void PlainDateTimePrototype::initialize(GlobalObject& global_object)
6565
define_native_function(vm.names.getISOFields, get_iso_fields, 0, attr);
6666
}
6767

68-
static PlainDateTime* typed_this(GlobalObject& global_object)
69-
{
70-
auto& vm = global_object.vm();
71-
auto* this_object = vm.this_value(global_object).to_object(global_object);
72-
if (!this_object)
73-
return {};
74-
if (!is<PlainDateTime>(this_object)) {
75-
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainDateTime");
76-
return {};
77-
}
78-
return static_cast<PlainDateTime*>(this_object);
79-
}
80-
8168
// 5.3.3 get Temporal.PlainDateTime.prototype.calendar, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.calendar
8269
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::calendar_getter)
8370
{
8471
// 1. Let dateTime be the this value.
8572
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
86-
auto* date_time = typed_this(global_object);
73+
auto* date_time = typed_this_object(global_object);
8774
if (vm.exception())
8875
return {};
8976

@@ -96,7 +83,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::year_getter)
9683
{
9784
// 1. Let dateTime be the this value.
9885
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
99-
auto* date_time = typed_this(global_object);
86+
auto* date_time = typed_this_object(global_object);
10087
if (vm.exception())
10188
return {};
10289

@@ -112,7 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::month_getter)
11299
{
113100
// 1. Let dateTime be the this value.
114101
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
115-
auto* date_time = typed_this(global_object);
102+
auto* date_time = typed_this_object(global_object);
116103
if (vm.exception())
117104
return {};
118105

@@ -128,7 +115,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::month_code_getter)
128115
{
129116
// 1. Let dateTime be the this value.
130117
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
131-
auto* date_time = typed_this(global_object);
118+
auto* date_time = typed_this_object(global_object);
132119
if (vm.exception())
133120
return {};
134121

@@ -144,7 +131,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_getter)
144131
{
145132
// 1. Let dateTime be the this value.
146133
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
147-
auto* date_time = typed_this(global_object);
134+
auto* date_time = typed_this_object(global_object);
148135
if (vm.exception())
149136
return {};
150137

@@ -160,7 +147,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::hour_getter)
160147
{
161148
// 1. Let dateTime be the this value.
162149
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
163-
auto* date_time = typed_this(global_object);
150+
auto* date_time = typed_this_object(global_object);
164151
if (vm.exception())
165152
return {};
166153

@@ -173,7 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::minute_getter)
173160
{
174161
// 1. Let dateTime be the this value.
175162
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
176-
auto* date_time = typed_this(global_object);
163+
auto* date_time = typed_this_object(global_object);
177164
if (vm.exception())
178165
return {};
179166

@@ -186,7 +173,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::second_getter)
186173
{
187174
// 1. Let dateTime be the this value.
188175
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
189-
auto* date_time = typed_this(global_object);
176+
auto* date_time = typed_this_object(global_object);
190177
if (vm.exception())
191178
return {};
192179

@@ -199,7 +186,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::millisecond_getter)
199186
{
200187
// 1. Let dateTime be the this value.
201188
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
202-
auto* date_time = typed_this(global_object);
189+
auto* date_time = typed_this_object(global_object);
203190
if (vm.exception())
204191
return {};
205192

@@ -212,7 +199,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::microsecond_getter)
212199
{
213200
// 1. Let dateTime be the this value.
214201
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
215-
auto* date_time = typed_this(global_object);
202+
auto* date_time = typed_this_object(global_object);
216203
if (vm.exception())
217204
return {};
218205

@@ -225,7 +212,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::nanosecond_getter)
225212
{
226213
// 1. Let dateTime be the this value.
227214
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
228-
auto* date_time = typed_this(global_object);
215+
auto* date_time = typed_this_object(global_object);
229216
if (vm.exception())
230217
return {};
231218

@@ -238,7 +225,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_of_week_getter)
238225
{
239226
// 1. Let dateTime be the this value.
240227
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
241-
auto* date_time = typed_this(global_object);
228+
auto* date_time = typed_this_object(global_object);
242229
if (vm.exception())
243230
return {};
244231

@@ -254,7 +241,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_of_year_getter)
254241
{
255242
// 1. Let dateTime be the this value.
256243
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
257-
auto* date_time = typed_this(global_object);
244+
auto* date_time = typed_this_object(global_object);
258245
if (vm.exception())
259246
return {};
260247

@@ -270,7 +257,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::week_of_year_getter)
270257
{
271258
// 1. Let dateTime be the this value.
272259
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
273-
auto* date_time = typed_this(global_object);
260+
auto* date_time = typed_this_object(global_object);
274261
if (vm.exception())
275262
return {};
276263

@@ -286,7 +273,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_week_getter)
286273
{
287274
// 1. Let dateTime be the this value.
288275
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
289-
auto* date_time = typed_this(global_object);
276+
auto* date_time = typed_this_object(global_object);
290277
if (vm.exception())
291278
return {};
292279

@@ -302,7 +289,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_month_getter)
302289
{
303290
// 1. Let dateTime be the this value.
304291
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
305-
auto* date_time = typed_this(global_object);
292+
auto* date_time = typed_this_object(global_object);
306293
if (vm.exception())
307294
return {};
308295

@@ -318,7 +305,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::days_in_year_getter)
318305
{
319306
// 1. Let dateTime be the this value.
320307
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
321-
auto* date_time = typed_this(global_object);
308+
auto* date_time = typed_this_object(global_object);
322309
if (vm.exception())
323310
return {};
324311

@@ -334,7 +321,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::months_in_year_getter)
334321
{
335322
// 1. Let dateTime be the this value.
336323
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
337-
auto* date_time = typed_this(global_object);
324+
auto* date_time = typed_this_object(global_object);
338325
if (vm.exception())
339326
return {};
340327

@@ -350,7 +337,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::in_leap_year_getter)
350337
{
351338
// 1. Let dateTime be the this value.
352339
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
353-
auto* date_time = typed_this(global_object);
340+
auto* date_time = typed_this_object(global_object);
354341
if (vm.exception())
355342
return {};
356343

@@ -366,7 +353,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::era_getter)
366353
{
367354
// 1. Let plainDateTime be the this value.
368355
// 2. Perform ? RequireInternalSlot(plainDateTime, [[InitializedTemporalDateTime]]).
369-
auto* plain_date_time = typed_this(global_object);
356+
auto* plain_date_time = typed_this_object(global_object);
370357
if (vm.exception())
371358
return {};
372359

@@ -382,7 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::era_year_getter)
382369
{
383370
// 1. Let plainDateTime be the this value.
384371
// 2. Perform ? RequireInternalSlot(plainDateTime, [[InitializedTemporalDateTime]]).
385-
auto* plain_date_time = typed_this(global_object);
372+
auto* plain_date_time = typed_this_object(global_object);
386373
if (vm.exception())
387374
return {};
388375

@@ -398,7 +385,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_plain_time)
398385
{
399386
// 1. Let dateTime be the this value.
400387
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
401-
auto* date_time = typed_this(global_object);
388+
auto* date_time = typed_this_object(global_object);
402389
if (vm.exception())
403390
return {};
404391

@@ -422,7 +409,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_plain_date)
422409
{
423410
// 1. Let dateTime be the this value.
424411
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
425-
auto* date_time = typed_this(global_object);
412+
auto* date_time = typed_this_object(global_object);
426413
if (vm.exception())
427414
return {};
428415

@@ -445,7 +432,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_calendar)
445432
{
446433
// 1. Let dateTime be the this value.
447434
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
448-
auto* date_time = typed_this(global_object);
435+
auto* date_time = typed_this_object(global_object);
449436
if (vm.exception())
450437
return {};
451438

@@ -463,7 +450,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::equals)
463450
{
464451
// 1. Let dateTime be the this value.
465452
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
466-
auto* date_time = typed_this(global_object);
453+
auto* date_time = typed_this_object(global_object);
467454
if (vm.exception())
468455
return {};
469456

@@ -496,7 +483,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_date)
496483
{
497484
// 1. Let dateTime be the this value.
498485
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
499-
auto* date_time = typed_this(global_object);
486+
auto* date_time = typed_this_object(global_object);
500487
if (vm.exception())
501488
return {};
502489

@@ -509,7 +496,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_year_month)
509496
{
510497
// 1. Let dateTime be the this value.
511498
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
512-
auto* date_time = typed_this(global_object);
499+
auto* date_time = typed_this_object(global_object);
513500
if (vm.exception())
514501
return {};
515502

@@ -535,7 +522,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_month_day)
535522
{
536523
// 1. Let dateTime be the this value.
537524
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
538-
auto* date_time = typed_this(global_object);
525+
auto* date_time = typed_this_object(global_object);
539526
if (vm.exception())
540527
return {};
541528

@@ -561,7 +548,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_time)
561548
{
562549
// 1. Let dateTime be the this value.
563550
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
564-
auto* date_time = typed_this(global_object);
551+
auto* date_time = typed_this_object(global_object);
565552
if (vm.exception())
566553
return {};
567554

@@ -574,7 +561,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::get_iso_fields)
574561
{
575562
// 1. Let dateTime be the this value.
576563
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
577-
auto* date_time = typed_this(global_object);
564+
auto* date_time = typed_this_object(global_object);
578565
if (vm.exception())
579566
return {};
580567

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
#pragma once
88

9-
#include <LibJS/Runtime/Object.h>
9+
#include <LibJS/Runtime/PrototypeObject.h>
10+
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
1011

1112
namespace JS::Temporal {
1213

13-
class PlainDateTimePrototype final : public Object {
14-
JS_OBJECT(PlainDateTimePrototype, Object);
14+
class PlainDateTimePrototype final : public PrototypeObject<PlainDateTimePrototype, PlainDateTime> {
15+
JS_PROTOTYPE_OBJECT(PlainDateTimePrototype, PlainDateTime, Temporal.PlainDateTime);
1516

1617
public:
1718
explicit PlainDateTimePrototype(GlobalObject&);

0 commit comments

Comments
 (0)