diff --git a/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp b/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp index 4447cb4fa7c..2fdeba377c5 100644 --- a/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp +++ b/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp @@ -46,6 +46,7 @@ void DurationPrototype::initialize(Realm& realm) define_native_function(realm, vm.names.toString, to_string, 0, attr); define_native_function(realm, vm.names.toJSON, to_json, 0, attr); define_native_function(realm, vm.names.toLocaleString, to_locale_string, 0, attr); + define_native_function(realm, vm.names.valueOf, value_of, 0, attr); } // 7.3.3 get Temporal.Duration.prototype.years, https://tc39.es/proposal-temporal/#sec-get-temporal.duration.prototype.years @@ -582,4 +583,11 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::to_locale_string) return PrimitiveString::create(vm, temporal_duration_to_string(duration, Auto {})); } +// 7.3.25 Temporal.Duration.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.valueof +JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::value_of) +{ + // 1. Throw a TypeError exception. + return vm.throw_completion(ErrorType::Convert, "Temporal.Duration", "a primitive value"); +} + } diff --git a/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h b/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h index 7faa80248e8..f6420de0f7a 100644 --- a/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h +++ b/Libraries/LibJS/Runtime/Temporal/DurationPrototype.h @@ -40,6 +40,7 @@ private: JS_DECLARE_NATIVE_FUNCTION(to_string); JS_DECLARE_NATIVE_FUNCTION(to_json); JS_DECLARE_NATIVE_FUNCTION(to_locale_string); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } diff --git a/Libraries/LibJS/Tests/builtins/Temporal/Duration/Duration.prototype.valueOf.js b/Libraries/LibJS/Tests/builtins/Temporal/Duration/Duration.prototype.valueOf.js new file mode 100644 index 00000000000..fb7a69cb6e4 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Temporal/Duration/Duration.prototype.valueOf.js @@ -0,0 +1,7 @@ +describe("errors", () => { + test("throws TypeError", () => { + expect(() => { + new Temporal.Duration().valueOf(); + }).toThrowWithMessage(TypeError, "Cannot convert Temporal.Duration to a primitive value"); + }); +});