mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Implement Temporal.PlainMonthDay.prototype.valueOf
This commit is contained in:
parent
9823f43827
commit
d1a988930f
3 changed files with 20 additions and 0 deletions
|
@ -40,6 +40,7 @@ void PlainMonthDayPrototype::initialize(Realm& realm)
|
|||
define_native_function(realm, vm.names.toString, to_string, 0, attr);
|
||||
define_native_function(realm, vm.names.toLocaleString, to_locale_string, 0, attr);
|
||||
define_native_function(realm, vm.names.toJSON, to_json, 0, attr);
|
||||
define_native_function(realm, vm.names.valueOf, value_of, 0, attr);
|
||||
}
|
||||
|
||||
// 10.3.3 get Temporal.PlainMonthDay.prototype.calendarId, https://tc39.es/proposal-temporal/#sec-get-temporal.plainmonthday.prototype.calendarid
|
||||
|
@ -172,4 +173,11 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_json)
|
|||
return PrimitiveString::create(vm, temporal_month_day_to_string(month_day, ShowCalendar::Auto));
|
||||
}
|
||||
|
||||
// 10.3.11 Temporal.PlainMonthDay.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::value_of)
|
||||
{
|
||||
// 1. Throw a TypeError exception.
|
||||
return vm.throw_completion<TypeError>(ErrorType::Convert, "Temporal.PlainMonthDay", "a primitive value");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
describe("errors", () => {
|
||||
test("throws TypeError", () => {
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(() => {
|
||||
plainMonthDay.valueOf();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Cannot convert Temporal.PlainMonthDay to a primitive value"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue