mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
LibJS: Implement Temporal.PlainTime.prototype.minute
This commit is contained in:
parent
524a56f7b6
commit
574f474d27
4 changed files with 30 additions and 0 deletions
|
@ -265,6 +265,7 @@ namespace JS {
|
|||
P(microseconds) \
|
||||
P(milliseconds) \
|
||||
P(min) \
|
||||
P(minute) \
|
||||
P(minutes) \
|
||||
P(month) \
|
||||
P(monthCode) \
|
||||
|
|
|
@ -28,6 +28,7 @@ void PlainTimePrototype::initialize(GlobalObject& global_object)
|
|||
|
||||
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.hour, hour_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.minute, minute_getter, {}, Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
|
@ -72,6 +73,19 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::hour_getter)
|
|||
return Value(temporal_time->iso_hour());
|
||||
}
|
||||
|
||||
// 4.3.5 get Temporal.PlainTime.prototype.minute, https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.minute
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::minute_getter)
|
||||
{
|
||||
// 1. Let temporalTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
||||
auto* temporal_time = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Return 𝔽(temporalTime.[[ISOMinute]]).
|
||||
return Value(temporal_time->iso_minute());
|
||||
}
|
||||
|
||||
// 4.3.23 Temporal.PlainTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::value_of)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(hour_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(minute_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainTime = new Temporal.PlainTime(0, 12);
|
||||
expect(plainTime.minute).toBe(12);
|
||||
});
|
||||
});
|
||||
|
||||
test("errors", () => {
|
||||
test("this value must be a Temporal.PlainTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainTime.prototype, "minute", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainTime");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue