mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibJS: Implement Temporal.PlainDateTime.prototype.dayOfWeek
This commit is contained in:
parent
518a9f3eab
commit
c41b7b27c9
3 changed files with 32 additions and 0 deletions
|
@ -38,6 +38,7 @@ void PlainDateTimePrototype::initialize(GlobalObject& global_object)
|
||||||
define_native_accessor(vm.names.millisecond, millisecond_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.millisecond, millisecond_getter, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.microsecond, microsecond_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.microsecond, microsecond_getter, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.nanosecond, nanosecond_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.nanosecond, nanosecond_getter, {}, Attribute::Configurable);
|
||||||
|
define_native_accessor(vm.names.dayOfWeek, day_of_week_getter, {}, Attribute::Configurable);
|
||||||
|
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||||
|
@ -213,6 +214,22 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::nanosecond_getter)
|
||||||
return Value(date_time->iso_nanosecond());
|
return Value(date_time->iso_nanosecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5.3.14 get Temporal.PlainDateTime.prototype.dayOfWeek, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.dayofweek
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_of_week_getter)
|
||||||
|
{
|
||||||
|
// 1. Let dateTime be the this value.
|
||||||
|
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
||||||
|
auto* date_time = typed_this(global_object);
|
||||||
|
if (vm.exception())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 3. Let calendar be dateTime.[[Calendar]].
|
||||||
|
auto& calendar = date_time->calendar();
|
||||||
|
|
||||||
|
// 4. Return ? CalendarDayOfWeek(calendar, dateTime).
|
||||||
|
return calendar_day_of_week(global_object, calendar, *date_time);
|
||||||
|
}
|
||||||
|
|
||||||
// 5.3.35 Temporal.PlainDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.valueof
|
// 5.3.35 Temporal.PlainDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.valueof
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::value_of)
|
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::value_of)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,7 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(millisecond_getter);
|
JS_DECLARE_NATIVE_FUNCTION(millisecond_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(microsecond_getter);
|
JS_DECLARE_NATIVE_FUNCTION(microsecond_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(nanosecond_getter);
|
JS_DECLARE_NATIVE_FUNCTION(nanosecond_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(day_of_week_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_plain_date);
|
JS_DECLARE_NATIVE_FUNCTION(to_plain_date);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(get_iso_fields);
|
JS_DECLARE_NATIVE_FUNCTION(get_iso_fields);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
describe("correct behavior", () => {
|
||||||
|
test("basic functionality", () => {
|
||||||
|
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 30);
|
||||||
|
expect(plainDateTime.dayOfWeek).toBe(5);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("errors", () => {
|
||||||
|
test("this value must be a Temporal.PlainDateTime object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Reflect.get(Temporal.PlainDateTime.prototype, "dayOfWeek", "foo");
|
||||||
|
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainDateTime");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue