diff options
author | Luke Wilde <lukew@serenityos.org> | 2021-12-18 22:53:52 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-12-19 00:13:01 +0000 |
commit | 803e96f0c5e3eecec839ededad38559b2b0ec11e (patch) | |
tree | e85f056ec48837ae7ce8cba627144629beae4320 /Userland/Libraries | |
parent | 5277646f46959b8036aab61925f3b860c0df4985 (diff) | |
download | serenity-803e96f0c5e3eecec839ededad38559b2b0ec11e.zip |
LibJS: Only allow Calendar this value in Temporal.Calendar#toJSON
This is a normative change in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/2644fc6
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.toJSON.js | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 24d709556b..fcbd858ebc 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -575,10 +575,11 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_string) JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json) { // 1. Let calendar be the this value. - auto calendar = vm.this_value(global_object); + // 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + auto* calendar = TRY(typed_this_object(global_object)); - // 2. Return ? ToString(calendar). - return js_string(vm, TRY(calendar.to_string(global_object))); + // 3. Return ? ToString(calendar). + return js_string(vm, TRY(Value(calendar).to_string(global_object))); } // 15.6.2.6 Temporal.Calendar.prototype.era ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.era diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.toJSON.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.toJSON.js index 703283b897..6470c47bcf 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.toJSON.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Calendar/Calendar.prototype.toJSON.js @@ -7,8 +7,12 @@ describe("correct behavior", () => { const calendar = new Temporal.Calendar("iso8601"); expect(calendar.toJSON()).toBe("iso8601"); }); +}); - test("works with any this value", () => { - expect(Temporal.Calendar.prototype.toJSON.call("foo")).toBe("foo"); +describe("errors", () => { + test("this value must be a Temporal.Calendar object", () => { + expect(() => { + Temporal.Calendar.prototype.toJSON.call("foo"); + }).toThrowWithMessage(TypeError, "Not an object of type Temporal.Calendar"); }); }); |