diff --git a/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp b/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp index bdbdb8a9966..d1130e1f962 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp +++ b/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp @@ -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(ErrorType::Convert, "Temporal.PlainYearMonth", "a primitive value"); +} + } diff --git a/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h b/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h index 2696ec31438..30a9fd1ddbe 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h +++ b/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h @@ -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); }; } diff --git a/Libraries/LibJS/Tests/builtins/Temporal/PlainYearMonth/PlainYearMonth.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Temporal/PlainYearMonth/PlainYearMonth.prototype.valueOf.js new file mode 100644 index 00000000000..6c3d2d191f4 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Temporal/PlainYearMonth/PlainYearMonth.prototype.valueOf.js @@ -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" + ); + }); +});