diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-13 18:33:19 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-13 19:07:26 +0100 |
commit | 06f3defcf51460bb692bea93ebeaf63b037d61b7 (patch) | |
tree | 515e2c42a70c52d5139e8386e842c332384f3a09 /Userland/Libraries/LibJS | |
parent | 6e5d6060fa5a91fc08d4c495737bb0656e24a227 (diff) | |
download | serenity-06f3defcf51460bb692bea93ebeaf63b037d61b7.zip |
LibJS: Convert Temporal.PlainTime.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp | 43 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h | 7 |
2 files changed, 19 insertions, 31 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp index 78c9b6d535..563d458ef3 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp @@ -16,7 +16,7 @@ namespace JS::Temporal { // 4.3 Properties of the Temporal.PlainTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaintime-prototype-object PlainTimePrototype::PlainTimePrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : PrototypeObject(*global_object.object_prototype()) { } @@ -48,25 +48,12 @@ void PlainTimePrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.valueOf, value_of, 0, attr); } -static PlainTime* 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<PlainTime>(this_object)) { - vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainTime"); - return {}; - } - return static_cast<PlainTime*>(this_object); -} - // 4.3.3 get Temporal.PlainTime.prototype.calendar, https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.calendar JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::calendar_getter) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -79,7 +66,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::hour_getter) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -92,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::minute_getter) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -105,7 +92,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::second_getter) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -118,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::millisecond_getter) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -131,7 +118,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::microsecond_getter) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -144,7 +131,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::nanosecond_getter) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -157,7 +144,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -266,7 +253,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::equals) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -308,7 +295,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_plain_date_time) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -326,7 +313,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::get_iso_fields) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -363,7 +350,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_string) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -395,7 +382,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_locale_string) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; @@ -409,7 +396,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_json) { // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). - auto* temporal_time = typed_this(global_object); + auto* temporal_time = typed_this_object(global_object); if (vm.exception()) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h index 725473fcb7..b732aff2e0 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h @@ -6,12 +6,13 @@ #pragma once -#include <LibJS/Runtime/Object.h> +#include <LibJS/Runtime/PrototypeObject.h> +#include <LibJS/Runtime/Temporal/PlainTime.h> namespace JS::Temporal { -class PlainTimePrototype final : public Object { - JS_OBJECT(PlainTimePrototype, Object); +class PlainTimePrototype final : public PrototypeObject<PlainTimePrototype, PlainTime> { + JS_PROTOTYPE_OBJECT(PlainTimePrototype, PlainTime, Temporal.PlainTime); public: explicit PlainTimePrototype(GlobalObject&); |