mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
LibJS: Only allow Calendar this value in Temporal.Calendar#toJSON
This is a normative change in the Temporal spec.
See: 2644fc6
This commit is contained in:
parent
5277646f46
commit
803e96f0c5
2 changed files with 10 additions and 5 deletions
|
@ -575,10 +575,11 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_string)
|
||||||
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json)
|
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json)
|
||||||
{
|
{
|
||||||
// 1. Let calendar be the this value.
|
// 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).
|
// 3. Return ? ToString(calendar).
|
||||||
return js_string(vm, TRY(calendar.to_string(global_object)));
|
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
|
// 15.6.2.6 Temporal.Calendar.prototype.era ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.era
|
||||||
|
|
|
@ -7,8 +7,12 @@ describe("correct behavior", () => {
|
||||||
const calendar = new Temporal.Calendar("iso8601");
|
const calendar = new Temporal.Calendar("iso8601");
|
||||||
expect(calendar.toJSON()).toBe("iso8601");
|
expect(calendar.toJSON()).toBe("iso8601");
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("works with any this value", () => {
|
describe("errors", () => {
|
||||||
expect(Temporal.Calendar.prototype.toJSON.call("foo")).toBe("foo");
|
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");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue