diff --git a/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp index 10a3ce9cea2..c7ab1fb7a22 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp +++ b/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp @@ -62,6 +62,7 @@ void PlainDatePrototype::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); } // 3.3.3 get Temporal.PlainDate.prototype.calendarId, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindate.prototype.calendarid @@ -401,4 +402,11 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_json) return PrimitiveString::create(vm, temporal_date_to_string(temporal_date, ShowCalendar::Auto)); } +// 3.3.33 Temporal.PlainDate.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.valueof +JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::value_of) +{ + // 1. Throw a TypeError exception. + return vm.throw_completion(ErrorType::Convert, "Temporal.PlainDate", "a primitive value"); +} + } diff --git a/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.h b/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.h index 21ac80246cc..1a02652a1b2 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.h +++ b/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.h @@ -51,6 +51,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/PlainDate/PlainDate.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.valueOf.js new file mode 100644 index 00000000000..a3c39118ab5 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.valueOf.js @@ -0,0 +1,7 @@ +describe("errors", () => { + test("throws TypeError", () => { + expect(() => { + new Temporal.PlainDate(2021, 7, 21).valueOf(); + }).toThrowWithMessage(TypeError, "Cannot convert Temporal.PlainDate to a primitive value"); + }); +});