mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
LibJS: Implement Temporal.PlainYearMonth.prototype.valueOf()
This commit is contained in:
parent
d9ed0f1f47
commit
5a260fcad1
3 changed files with 23 additions and 0 deletions
|
@ -35,6 +35,9 @@ void PlainYearMonthPrototype::initialize(GlobalObject& global_object)
|
||||||
define_native_accessor(vm.names.daysInMonth, days_in_month_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.daysInMonth, days_in_month_getter, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.monthsInYear, months_in_year_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.monthsInYear, months_in_year_getter, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable);
|
||||||
|
|
||||||
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
|
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PlainYearMonth* typed_this(GlobalObject& global_object)
|
static PlainYearMonth* typed_this(GlobalObject& global_object)
|
||||||
|
@ -175,4 +178,12 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::in_leap_year_getter)
|
||||||
return Value(calendar_in_leap_year(global_object, calendar, *year_month));
|
return Value(calendar_in_leap_year(global_object, calendar, *year_month));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 9.3.20 Temporal.PlainYearMonth.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.valueof
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::value_of)
|
||||||
|
{
|
||||||
|
// 1. Throw a TypeError exception.
|
||||||
|
vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.PlainYearMonth", "a primitive value");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter);
|
JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(months_in_year_getter);
|
JS_DECLARE_NATIVE_FUNCTION(months_in_year_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(in_leap_year_getter);
|
JS_DECLARE_NATIVE_FUNCTION(in_leap_year_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
describe("errors", () => {
|
||||||
|
test("throws TypeError", () => {
|
||||||
|
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||||
|
expect(() => {
|
||||||
|
plainYearMonth.valueOf();
|
||||||
|
}).toThrowWithMessage(
|
||||||
|
TypeError,
|
||||||
|
"Cannot convert Temporal.PlainYearMonth to a primitive value"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue