1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:47:35 +00:00

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

This commit is contained in:
Linus Groh 2021-07-28 18:42:34 +01:00
parent 64b44c7f30
commit ad89a205bc
3 changed files with 21 additions and 0 deletions

View file

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

View file

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

View file

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