From 64811ab7b64c83034ac48f07fc6d10175eefa8c4 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 20 Nov 2024 18:12:23 -0500 Subject: [PATCH] LibJS: Implement Temporal.PlainMonthDay.prototype.valueOf --- .../LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp | 8 ++++++++ .../LibJS/Runtime/Temporal/PlainMonthDayPrototype.h | 1 + .../PlainMonthDay/PlainMonthDay.prototype.valueOf.js | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.valueOf.js diff --git a/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp index f8f92146ac6..325dc5e7745 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp +++ b/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp @@ -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(ErrorType::Convert, "Temporal.PlainMonthDay", "a primitive value"); +} + } diff --git a/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h b/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h index ace7fbc8005..2780f77aa8c 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h +++ b/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h @@ -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); }; } diff --git a/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.valueOf.js new file mode 100644 index 00000000000..f8f48e07fc3 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.valueOf.js @@ -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" + ); + }); +});