LibJS: Implement Temporal.PlainDateTime.prototype.microsecond
This commit is contained in:
parent
b2f66a06ac
commit
23bf840326
Notes:
sideshowbarker
2024-07-18 07:46:06 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/23bf840326b Pull-request: https://github.com/SerenityOS/serenity/pull/9097 Reviewed-by: https://github.com/linusg ✅
3 changed files with 29 additions and 0 deletions
|
@ -36,6 +36,7 @@ void PlainDateTimePrototype::initialize(GlobalObject& global_object)
|
|||
define_native_accessor(vm.names.minute, minute_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.second, second_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.millisecond, millisecond_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.microsecond, microsecond_getter, {}, Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
|
@ -185,6 +186,19 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::millisecond_getter)
|
|||
return Value(date_time->iso_millisecond());
|
||||
}
|
||||
|
||||
// 5.3.12 get Temporal.PlainDateTime.prototype.microsecond, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.microsecond
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::microsecond_getter)
|
||||
{
|
||||
// 1. Let dateTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
||||
auto* date_time = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Return 𝔽(dateTime.[[ISOMicrosecond]]).
|
||||
return Value(date_time->iso_microsecond());
|
||||
}
|
||||
|
||||
// 5.3.35 Temporal.PlainDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::value_of)
|
||||
{
|
||||
|
|
|
@ -28,6 +28,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(minute_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(second_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(millisecond_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(microsecond_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_plain_date);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_iso_fields);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 30, 1, 4, 32, 111, 420);
|
||||
expect(plainDateTime.microsecond).toBe(420);
|
||||
});
|
||||
});
|
||||
|
||||
test("errors", () => {
|
||||
test("this value must be a Temporal.PlainDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDateTime.prototype, "microsecond", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainDateTime");
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue