diff options
author | Linus Groh <mail@linusgroh.de> | 2021-08-15 01:10:47 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-15 10:36:36 +0100 |
commit | 7fb05eb8788491c978e3cd46d0233004b9942b83 (patch) | |
tree | e5ee20609631b2f37719a2a76302e54f6a0b185b | |
parent | c2ed3ad66bf2f2a3b33d59648861c2233a3c10eb (diff) | |
download | serenity-7fb05eb8788491c978e3cd46d0233004b9942b83.zip |
LibJS: Implement Temporal.PlainMonthDay.prototype.valueOf()
3 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp index 73587cdff4..8df4dd72f0 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp @@ -30,6 +30,9 @@ void PlainMonthDayPrototype::initialize(GlobalObject& global_object) define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable); define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable); define_native_accessor(vm.names.day, day_getter, {}, Attribute::Configurable); + + u8 attr = Attribute::Writable | Attribute::Configurable; + define_native_function(vm.names.valueOf, value_of, 0, attr); } static PlainMonthDay* typed_this(GlobalObject& global_object) @@ -90,4 +93,12 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::day_getter) return Value(calendar_day(global_object, calendar, *month_day)); } +// 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. + vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.PlainMonthDay", "a primitive value"); + return {}; +} + } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h index 037d1c63be..1a3d09f13e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h @@ -22,6 +22,7 @@ private: JS_DECLARE_NATIVE_FUNCTION(calendar_getter); JS_DECLARE_NATIVE_FUNCTION(month_code_getter); JS_DECLARE_NATIVE_FUNCTION(day_getter); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; } diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.valueOf.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.prototype.valueOf.js new file mode 100644 index 0000000000..f8f48e07fc --- /dev/null +++ b/Userland/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" + ); + }); +}); |