From 6e5d6060fa5a91fc08d4c495737bb0656e24a227 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 13 Sep 2021 18:31:40 +0100 Subject: [PATCH] LibJS: Convert Temporal.PlainMonthDay.prototype to be a PrototypeObject --- .../Temporal/PlainMonthDayPrototype.cpp | 31 ++++++------------- .../Runtime/Temporal/PlainMonthDayPrototype.h | 7 +++-- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp index 16a584c0f1..83436c278e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp +++ b/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 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); } -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(this_object)) { - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainMonthDay"); - return {}; - } - return static_cast(this_object); -} - // 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) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; @@ -72,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::month_code_getter) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; @@ -88,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::day_getter) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; @@ -104,7 +91,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::equals) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; @@ -134,7 +121,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_string) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; @@ -162,7 +149,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_locale_string) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; @@ -179,7 +166,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_json) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; @@ -204,7 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields) { // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). - auto* month_day = typed_this(global_object); + auto* month_day = typed_this_object(global_object); if (vm.exception()) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h index e512fe24a2..727a48f49b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h @@ -6,12 +6,13 @@ #pragma once -#include +#include +#include namespace JS::Temporal { -class PlainMonthDayPrototype final : public Object { - JS_OBJECT(PlainMonthDayPrototype, Object); +class PlainMonthDayPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(PlainMonthDayPrototype, PlainMonthDay, Temporal.PlainMonthDay); public: explicit PlainMonthDayPrototype(GlobalObject&);