LibJS: Implement Temporal.PlainYearMonth.prototype.valueOf
This commit is contained in:
parent
35f22dcf79
commit
b64ccb95ec
Notes:
github-actions[bot]
2024-11-22 18:56:17 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/b64ccb95ec7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2496
3 changed files with 20 additions and 0 deletions
Libraries/LibJS
Runtime/Temporal
Tests/builtins/Temporal/PlainYearMonth
|
@ -50,6 +50,7 @@ void PlainYearMonthPrototype::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);
|
||||
}
|
||||
|
||||
// 9.3.3 get Temporal.PlainYearMonth.prototype.calendarId, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.calendarid
|
||||
|
@ -289,4 +290,11 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_json)
|
|||
return PrimitiveString::create(vm, temporal_year_month_to_string(year_month, ShowCalendar::Auto));
|
||||
}
|
||||
|
||||
// 9.3.22 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.
|
||||
return vm.throw_completion<TypeError>(ErrorType::Convert, "Temporal.PlainYearMonth", "a primitive value");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,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 plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
expect(() => {
|
||||
plainYearMonth.valueOf();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Cannot convert Temporal.PlainYearMonth to a primitive value"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue