diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h index aa49d29b86..bf9a9e0279 100644 --- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -308,6 +308,7 @@ namespace JS { P(revoke) \ P(round) \ P(seal) \ + P(second) \ P(seconds) \ P(set) \ P(setBigInt64) \ diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp index 07d4d4d995..ab02e6dead 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp @@ -29,6 +29,7 @@ void PlainTimePrototype::initialize(GlobalObject& global_object) define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable); define_native_accessor(vm.names.hour, hour_getter, {}, Attribute::Configurable); define_native_accessor(vm.names.minute, minute_getter, {}, Attribute::Configurable); + define_native_accessor(vm.names.second, second_getter, {}, Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.valueOf, value_of, 0, attr); @@ -86,6 +87,19 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::minute_getter) return Value(temporal_time->iso_minute()); } +// 4.3.6 get Temporal.PlainTime.prototype.second, https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.second +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); + if (vm.exception()) + return {}; + + // 3. Return 𝔽(temporalTime.[[ISOSecond]]). + return Value(temporal_time->iso_second()); +} + // 4.3.23 Temporal.PlainTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::value_of) { diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h index 82a98e7ea4..d58afaef13 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h @@ -22,6 +22,7 @@ private: JS_DECLARE_NATIVE_FUNCTION(calendar_getter); JS_DECLARE_NATIVE_FUNCTION(hour_getter); JS_DECLARE_NATIVE_FUNCTION(minute_getter); + JS_DECLARE_NATIVE_FUNCTION(second_getter); JS_DECLARE_NATIVE_FUNCTION(value_of); }; diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.prototype.second.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.prototype.second.js new file mode 100644 index 0000000000..eab47af61e --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.prototype.second.js @@ -0,0 +1,14 @@ +describe("correct behavior", () => { + test("basic functionality", () => { + const plainTime = new Temporal.PlainTime(0, 0, 12); + expect(plainTime.second).toBe(12); + }); +}); + +test("errors", () => { + test("this value must be a Temporal.PlainTime object", () => { + expect(() => { + Reflect.get(Temporal.PlainTime.prototype, "second", "foo"); + }).toThrowWithMessage(TypeError, "Not a Temporal.PlainTime"); + }); +});