summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-07-28 18:55:29 +0100
committerLinus Groh <mail@linusgroh.de>2021-07-28 21:57:30 +0100
commit574f474d27a886d64e3d393e5fae10851511c373 (patch)
treebf147ae3915c76731f6066506ec22846836cafbc /Userland
parent524a56f7b6490efd242180f9b094429ae94cdc1e (diff)
downloadserenity-574f474d27a886d64e3d393e5fae10851511c373.zip
LibJS: Implement Temporal.PlainTime.prototype.minute
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h1
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.prototype.minute.js14
4 files changed, 30 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
index 99bdd86118..aa49d29b86 100644
--- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
+++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
@@ -265,6 +265,7 @@ namespace JS {
P(microseconds) \
P(milliseconds) \
P(min) \
+ P(minute) \
P(minutes) \
P(month) \
P(monthCode) \
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
index 5df79684a4..07d4d4d995 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp
@@ -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)
{
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h
index f92c1b15f6..82a98e7ea4 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.h
@@ -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);
};
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.prototype.minute.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.prototype.minute.js
new file mode 100644
index 0000000000..c9fefd1dfe
--- /dev/null
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.prototype.minute.js
@@ -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");
+ });
+});