diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index 475679802d..0b338ab873 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp @@ -92,15 +92,16 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_string_for) JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_plain_date_time_for) { // 1. Let timeZone be the this value. - auto time_zone = vm.this_value(global_object); + // 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimeZone]]). + auto* time_zone = TRY(typed_this_object(global_object)); - // 2. Set instant to ? ToTemporalInstant(instant). + // 3. Set instant to ? ToTemporalInstant(instant). auto* instant = TRY(to_temporal_instant(global_object, vm.argument(0))); - // 3. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). + // 4. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike). auto* calendar = TRY(to_temporal_calendar_with_iso_default(global_object, vm.argument(1))); - // 4. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar). + // 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar). return TRY(builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar)); } diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.getPlainDateTimeFor.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.getPlainDateTimeFor.js index 470d61cd5d..5ca0d5d7b7 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.getPlainDateTimeFor.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.getPlainDateTimeFor.js @@ -26,35 +26,21 @@ describe("correct behavior", () => { const plainDateTime = timeZone.getPlainDateTimeFor(instant, calendar); expect(plainDateTime.calendar).toBe(calendar); }); - - test("non-TimeZone this value", () => { - const timeZoneLike = { - getOffsetNanosecondsFor() { - return 123; - }, - }; - const instant = new Temporal.Instant(0n); - const plainDateTime = Temporal.TimeZone.prototype.getPlainDateTimeFor.call( - timeZoneLike, - instant - ); - expect(plainDateTime.year).toBe(1970); - expect(plainDateTime.month).toBe(1); - expect(plainDateTime.day).toBe(1); - expect(plainDateTime.hour).toBe(0); - expect(plainDateTime.minute).toBe(0); - expect(plainDateTime.second).toBe(0); - expect(plainDateTime.millisecond).toBe(0); - expect(plainDateTime.microsecond).toBe(0); - expect(plainDateTime.nanosecond).toBe(123); - }); }); describe("errors", () => { - test("custom time zone doesn't have a getOffsetNanosecondsFor function", () => { + test("time zone doesn't have a getOffsetNanosecondsFor function", () => { + const timeZone = new Temporal.TimeZone("UTC"); + timeZone.getOffsetNanosecondsFor = undefined; const instant = new Temporal.Instant(1n); expect(() => { - Temporal.TimeZone.prototype.getPlainDateTimeFor.call({}, instant); + timeZone.getPlainDateTimeFor(instant); }).toThrowWithMessage(TypeError, "null is not a function"); }); + + test("this value must be a Temporal.TimeZone object", () => { + expect(() => { + Temporal.TimeZone.prototype.getPlainDateTimeFor.call("foo"); + }).toThrowWithMessage(TypeError, "Not an object of type Temporal.TimeZone"); + }); });