mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-30 13:19:47 +00:00
LibJS: Implement Temporal.PlainYearMonth.prototype.valueOf
This commit is contained in:
committed by
Andreas Kling
parent
35f22dcf79
commit
b64ccb95ec
@@ -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"
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user