diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index 4e13169c37..475679802d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp @@ -230,10 +230,11 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_string) JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::to_json) { // 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. Return ? ToString(timeZone). - return js_string(vm, TRY(time_zone.to_string(global_object))); + // 3. Return ? ToString(timeZone). + return js_string(vm, TRY(Value(time_zone).to_string(global_object))); } } diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toJSON.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toJSON.js index aec6c23e2e..78f803a876 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toJSON.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toJSON.js @@ -7,8 +7,12 @@ describe("correct behavior", () => { const timeZone = new Temporal.TimeZone("UTC"); expect(timeZone.toJSON()).toBe("UTC"); }); +}); - test("works with any this value", () => { - expect(Temporal.TimeZone.prototype.toJSON.call("foo")).toBe("foo"); +describe("errors", () => { + test("this value must be a Temporal.TimeZone object", () => { + expect(() => { + Temporal.TimeZone.prototype.toJSON.call("foo"); + }).toThrowWithMessage(TypeError, "Not an object of type Temporal.TimeZone"); }); });