mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
LibJS: Only allow Calendar this value in Temporal.Calendar.prototype.id
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/2644fc6
This commit is contained in:
parent
1f7c196788
commit
247d2f7cc4
Notes:
sideshowbarker
2024-07-17 22:39:22 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/247d2f7cc4d Pull-request: https://github.com/SerenityOS/serenity/pull/11298 Reviewed-by: https://github.com/IdanHo ✅
@ -66,10 +66,11 @@ void CalendarPrototype::initialize(GlobalObject& global_object)
|
||||
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::id_getter)
|
||||
{
|
||||
// 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))) };
|
||||
}
|
||||
|
||||
// 12.4.4 Temporal.Calendar.prototype.dateFromFields ( fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.datefromfields
|
||||
|
@ -3,8 +3,12 @@ describe("correct behavior", () => {
|
||||
const calendar = new Temporal.Calendar("iso8601");
|
||||
expect(calendar.id).toBe("iso8601");
|
||||
});
|
||||
});
|
||||
|
||||
test("works with any this value", () => {
|
||||
expect(Reflect.get(Temporal.Calendar.prototype, "id", "foo")).toBe("foo");
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.Calendar object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.Calendar.prototype, "id", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.Calendar");
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user