mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibJS: Implement Temporal.PlainMonthDay.prototype.day
This commit is contained in:
parent
9551aa17d3
commit
c2ed3ad66b
3 changed files with 32 additions and 0 deletions
|
@ -29,6 +29,7 @@ void PlainMonthDayPrototype::initialize(GlobalObject& global_object)
|
||||||
|
|
||||||
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
||||||
|
define_native_accessor(vm.names.day, day_getter, {}, Attribute::Configurable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PlainMonthDay* typed_this(GlobalObject& global_object)
|
static PlainMonthDay* typed_this(GlobalObject& global_object)
|
||||||
|
@ -73,4 +74,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::month_code_getter)
|
||||||
return js_string(vm, calendar_month_code(global_object, calendar, *month_day));
|
return js_string(vm, calendar_month_code(global_object, calendar, *month_day));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 10.3.5 get Temporal.PlainMonthDay.prototype.day, https://tc39.es/proposal-temporal/#sec-get-temporal.plainmonthday.prototype.day
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::day_getter)
|
||||||
|
{
|
||||||
|
// 1. Let monthDay be the this value.
|
||||||
|
// 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
||||||
|
auto* month_day = typed_this(global_object);
|
||||||
|
if (vm.exception())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 3. Let calendar be monthDay.[[Calendar]].
|
||||||
|
auto& calendar = month_day->calendar();
|
||||||
|
|
||||||
|
// 4. Return 𝔽(? CalendarDay(calendar, monthDay)).
|
||||||
|
return Value(calendar_day(global_object, calendar, *month_day));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(day_getter);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
describe("correct behavior", () => {
|
||||||
|
test("basic functionality", () => {
|
||||||
|
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||||
|
expect(plainMonthDay.day).toBe(6);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("errors", () => {
|
||||||
|
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Reflect.get(Temporal.PlainMonthDay.prototype, "day", "foo");
|
||||||
|
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainMonthDay");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue