Przeglądaj źródła

LibJS: Convert Temporal.PlainMonthDay.prototype to be a PrototypeObject

Linus Groh 3 lat temu
rodzic
commit
6e5d6060fa

+ 9 - 22
Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp

@@ -15,7 +15,7 @@ namespace JS::Temporal {
 
 
 // 10.3 Properties of the Temporal.PlainMonthDay Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainmonthday-prototype-object
 // 10.3 Properties of the Temporal.PlainMonthDay Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainmonthday-prototype-object
 PlainMonthDayPrototype::PlainMonthDayPrototype(GlobalObject& global_object)
 PlainMonthDayPrototype::PlainMonthDayPrototype(GlobalObject& global_object)
-    : Object(*global_object.object_prototype())
+    : PrototypeObject(*global_object.object_prototype())
 {
 {
 }
 }
 
 
@@ -41,25 +41,12 @@ void PlainMonthDayPrototype::initialize(GlobalObject& global_object)
     define_native_function(vm.names.getISOFields, get_iso_fields, 0, attr);
     define_native_function(vm.names.getISOFields, get_iso_fields, 0, attr);
 }
 }
 
 
-static PlainMonthDay* typed_this(GlobalObject& global_object)
-{
-    auto& vm = global_object.vm();
-    auto* this_object = vm.this_value(global_object).to_object(global_object);
-    if (!this_object)
-        return {};
-    if (!is<PlainMonthDay>(this_object)) {
-        vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainMonthDay");
-        return {};
-    }
-    return static_cast<PlainMonthDay*>(this_object);
-}
-
 // 10.3.3 get Temporal.PlainMonthDay.prototype.calendar, https://tc39.es/proposal-temporal/#sec-get-temporal.plainmonthday.prototype.calendar
 // 10.3.3 get Temporal.PlainMonthDay.prototype.calendar, https://tc39.es/proposal-temporal/#sec-get-temporal.plainmonthday.prototype.calendar
 JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::calendar_getter)
 JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::calendar_getter)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 
@@ -72,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::month_code_getter)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 
@@ -88,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::day_getter)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 
@@ -104,7 +91,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::equals)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 
@@ -134,7 +121,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_string)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 
@@ -162,7 +149,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_locale_string)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 
@@ -179,7 +166,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_json)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 
@@ -204,7 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields)
 {
 {
     // 1. Let monthDay be the this value.
     // 1. Let monthDay be the this value.
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
     // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
-    auto* month_day = typed_this(global_object);
+    auto* month_day = typed_this_object(global_object);
     if (vm.exception())
     if (vm.exception())
         return {};
         return {};
 
 

+ 4 - 3
Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h

@@ -6,12 +6,13 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <LibJS/Runtime/Object.h>
+#include <LibJS/Runtime/PrototypeObject.h>
+#include <LibJS/Runtime/Temporal/PlainMonthDay.h>
 
 
 namespace JS::Temporal {
 namespace JS::Temporal {
 
 
-class PlainMonthDayPrototype final : public Object {
-    JS_OBJECT(PlainMonthDayPrototype, Object);
+class PlainMonthDayPrototype final : public PrototypeObject<PlainMonthDayPrototype, PlainMonthDay> {
+    JS_PROTOTYPE_OBJECT(PlainMonthDayPrototype, PlainMonthDay, Temporal.PlainMonthDay);
 
 
 public:
 public:
     explicit PlainMonthDayPrototype(GlobalObject&);
     explicit PlainMonthDayPrototype(GlobalObject&);