mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibJS: Implement Temporal.PlainTime.prototype.hour
This commit is contained in:
parent
a8dd1b9480
commit
524a56f7b6
4 changed files with 30 additions and 0 deletions
|
@ -210,6 +210,7 @@ namespace JS {
|
||||||
P(hasIndices) \
|
P(hasIndices) \
|
||||||
P(hasOwn) \
|
P(hasOwn) \
|
||||||
P(hasOwnProperty) \
|
P(hasOwnProperty) \
|
||||||
|
P(hour) \
|
||||||
P(hours) \
|
P(hours) \
|
||||||
P(hypot) \
|
P(hypot) \
|
||||||
P(id) \
|
P(id) \
|
||||||
|
|
|
@ -27,6 +27,7 @@ void PlainTimePrototype::initialize(GlobalObject& global_object)
|
||||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.PlainTime"), Attribute::Configurable);
|
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.PlainTime"), Attribute::Configurable);
|
||||||
|
|
||||||
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||||
|
define_native_accessor(vm.names.hour, hour_getter, {}, Attribute::Configurable);
|
||||||
|
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||||
|
@ -58,6 +59,19 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::calendar_getter)
|
||||||
return Value(&temporal_time->calendar());
|
return Value(&temporal_time->calendar());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4.3.4 get Temporal.PlainTime.prototype.hour, https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.hour
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::hour_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.[[ISOHour]]).
|
||||||
|
return Value(temporal_time->iso_hour());
|
||||||
|
}
|
||||||
|
|
||||||
// 4.3.23 Temporal.PlainTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof
|
// 4.3.23 Temporal.PlainTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof
|
||||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::value_of)
|
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::value_of)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(hour_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
describe("correct behavior", () => {
|
||||||
|
test("basic functionality", () => {
|
||||||
|
const plainTime = new Temporal.PlainTime(12);
|
||||||
|
expect(plainTime.hour).toBe(12);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("errors", () => {
|
||||||
|
test("this value must be a Temporal.PlainTime object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Reflect.get(Temporal.PlainTime.prototype, "hour", "foo");
|
||||||
|
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainTime");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue