1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:37:34 +00:00

LibJS: Implement Temporal.PlainMonthDay.prototype.valueOf()

This commit is contained in:
Linus Groh 2021-08-15 01:10:47 +01:00
parent c2ed3ad66b
commit 7fb05eb878
3 changed files with 23 additions and 0 deletions

View file

@ -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 {};
}
}

View file

@ -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);
};
}

View file

@ -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"
);
});
});