diff options
author | Luke Wilde <lukew@serenityos.org> | 2021-12-18 23:06:43 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-12-19 00:13:01 +0000 |
commit | 6c8c34ed6c00b9f66850bc6dc6fa0e3b357d2bfd (patch) | |
tree | cec64be6f54d6cd8c571d7028c4312a8ccabd386 /Userland/Libraries/LibJS | |
parent | 803e96f0c5e3eecec839ededad38559b2b0ec11e (diff) | |
download | serenity-6c8c34ed6c00b9f66850bc6dc6fa0e3b357d2bfd.zip |
LibJS: Only allow TimeZone this value in Temporal.TimeZone#id
This is a normative change in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/2644fc6
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.id.js | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index abf53e0b5f..4e13169c37 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp @@ -48,10 +48,11 @@ void TimeZonePrototype::initialize(GlobalObject& global_object) JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::id_getter) { // 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))); } // 11.4.4 Temporal.TimeZone.prototype.getOffsetNanosecondsFor ( instant ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getoffsetnanosecondsfor diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.id.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.id.js index 7a85daf14c..7da702bbca 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.id.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.id.js @@ -3,8 +3,12 @@ describe("correct behavior", () => { const timeZone = new Temporal.TimeZone("UTC"); expect(timeZone.id).toBe("UTC"); }); +}); - test("works with any this value", () => { - expect(Reflect.get(Temporal.TimeZone.prototype, "id", "foo")).toBe("foo"); +describe("errors", () => { + test("this value must be a Temporal.TimeZone object", () => { + expect(() => { + Reflect.get(Temporal.TimeZone.prototype, "id", "foo"); + }).toThrowWithMessage(TypeError, "Not an object of type Temporal.TimeZone"); }); }); |