mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:17:45 +00:00
LibJS: Implement Temporal.ZonedDateTime.prototype.valueOf()
This commit is contained in:
parent
3e909c0c49
commit
20300bd7c4
3 changed files with 23 additions and 0 deletions
|
@ -56,6 +56,9 @@ void ZonedDateTimePrototype::initialize(GlobalObject& global_object)
|
|||
define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.offsetNanoseconds, offset_nanoseconds_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.offset, offset_getter, {}, Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
}
|
||||
|
||||
static ZonedDateTime* typed_this(GlobalObject& global_object)
|
||||
|
@ -691,4 +694,12 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::offset_getter)
|
|||
return js_string(vm, move(*offset_string));
|
||||
}
|
||||
|
||||
// 6.3.44 Temporal.ZonedDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::value_of)
|
||||
{
|
||||
// 1. Throw a TypeError exception.
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::Convert, "Temporal.ZonedDateTime", "a primitive value");
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(in_leap_year_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(offset_nanoseconds_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(offset_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
test("errors", () => {
|
||||
test("throws TypeError", () => {
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
expect(() => {
|
||||
new Temporal.ZonedDateTime(0n, timeZone).valueOf();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Cannot convert Temporal.ZonedDateTime to a primitive value"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue