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

This commit is contained in:
Linus Groh 2021-08-05 21:35:40 +01:00
parent 3e909c0c49
commit 20300bd7c4
Notes: sideshowbarker 2024-07-18 07:26:36 +09:00
3 changed files with 23 additions and 0 deletions

View File

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

View File

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

View File

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