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

This commit is contained in:
Linus Groh 2021-07-22 19:54:18 +01:00
parent 591ee813fb
commit 78acc976a6
Notes: sideshowbarker 2024-07-18 08:33:24 +09:00
3 changed files with 24 additions and 0 deletions

View file

@ -23,6 +23,17 @@ void PlainDateTimePrototype::initialize(GlobalObject& global_object)
// 5.3.2 Temporal.PlainDateTime.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.PlainDateTime"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.valueOf, value_of, 0, attr);
}
// 5.3.35 Temporal.PlainDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.valueof
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::value_of)
{
// 1. Throw a TypeError exception.
vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.PlainDateTime", "a primitive value");
return {};
}
}

View file

@ -17,6 +17,9 @@ public:
explicit PlainDateTimePrototype(GlobalObject&);
virtual void initialize(GlobalObject&) override;
virtual ~PlainDateTimePrototype() override = default;
private:
JS_DECLARE_NATIVE_FUNCTION(value_of);
};
}

View file

@ -0,0 +1,10 @@
test("errors", () => {
test("throws TypeError", () => {
expect(() => {
new Temporal.PlainDateTime(2021, 7, 22, 19, 54, 38).valueOf();
}).toThrowWithMessage(
TypeError,
"Cannot convert Temporal.PlainDateTime to a primitive value"
);
});
});