mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
LibJS: Implement Temporal.ZonedDateTime.prototype.valueOf()
This commit is contained in:
parent
3e909c0c49
commit
20300bd7c4
Notes:
sideshowbarker
2024-07-18 07:26:36 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/20300bd7c41 Pull-request: https://github.com/SerenityOS/serenity/pull/9228 Reviewed-by: https://github.com/IdanHo ✅
@ -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…
Reference in New Issue
Block a user