Skip to content

Commit d85a2f8

Browse files
authored
feat(ecmascript): get PlainTime.prototype.second (#961)
1 parent e1654db commit d85a2f8

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

nova_vm/src/builtin_strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ get description
184184
#[cfg(feature = "temporal")]get minute
185185
#[cfg(feature = "regexp")]get multiline
186186
#[cfg(feature = "array-buffer")]get resizable
187+
#[cfg(feature = "temporal")]get second
187188
get size
188189
#[cfg(feature = "regexp")]get source
189190
#[cfg(feature = "regexp")]get sticky
@@ -370,6 +371,7 @@ revocable
370371
#[cfg(feature = "temporal")]roundingIncrement
371372
seal
372373
#[cfg(feature = "regexp")]search
374+
#[cfg(feature = "temporal")]second
373375
#[cfg(feature = "temporal")]seconds
374376
set
375377
#[cfg(feature = "set")]Set

nova_vm/src/ecmascript/builtins/temporal/plain_time/plain_time_prototype.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ impl Builtin for TemporalPlainTimePrototypeGetMinute {
2323
}
2424
impl BuiltinGetter for TemporalPlainTimePrototypeGetMinute {}
2525

26+
struct TemporalPlainTimePrototypeGetSecond;
27+
impl Builtin for TemporalPlainTimePrototypeGetSecond {
28+
const NAME: String<'static> = BUILTIN_STRING_MEMORY.get_second;
29+
const KEY: Option<PropertyKey<'static>> = Some(BUILTIN_STRING_MEMORY.second.to_property_key());
30+
const LENGTH: u8 = 0;
31+
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalPlainTimePrototype::get_second);
32+
}
33+
impl BuiltinGetter for TemporalPlainTimePrototypeGetSecond {}
34+
2635
impl TemporalPlainTimePrototype {
2736
/// ### [4.3.4 get Temporal.PlainTime.prototype.minute](https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.minute)
2837
pub(crate) fn get_minute<'gc>(
@@ -39,6 +48,21 @@ impl TemporalPlainTimePrototype {
3948
let value = plain_time.inner_plain_time(agent).minute();
4049
Ok(value.into())
4150
}
51+
/// ### [4.3.5 get Temporal.PlainTime.prototype.second](https://tc39.es/proposal-temporal/#sec-get-temporal.plaintime.prototype.second)
52+
pub(crate) fn get_second<'gc>(
53+
agent: &mut Agent,
54+
this_value: Value,
55+
_: ArgumentsList,
56+
gc: GcScope<'gc, '_>,
57+
) -> JsResult<'gc, Value<'gc>> {
58+
let gc = gc.into_nogc();
59+
// 1. Let plainTime be the this value.
60+
// 2. Perform ? RequireInternalSlot(plainTime, [[InitializedTemporalTime]]).
61+
let plain_time = require_internal_slot_temporal_plain_time(agent, this_value, gc)?;
62+
// 3. Return 𝔽(plainTime.[[Time]].[[Second]]).
63+
let value = plain_time.inner_plain_time(agent).second();
64+
Ok(value.into())
65+
}
4266

4367
pub(crate) fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, _: NoGcScope) {
4468
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
@@ -47,10 +71,11 @@ impl TemporalPlainTimePrototype {
4771
let plain_time_constructor = intrinsics.temporal_plain_time();
4872

4973
OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
50-
.with_property_capacity(3)
74+
.with_property_capacity(4)
5175
.with_prototype(object_prototype)
5276
.with_constructor_property(plain_time_constructor)
5377
.with_builtin_function_getter_property::<TemporalPlainTimePrototypeGetMinute>()
78+
.with_builtin_function_getter_property::<TemporalPlainTimePrototypeGetSecond>()
5479
.with_property(|builder| {
5580
builder
5681
.with_key(WellKnownSymbols::ToStringTag.into())

tests/expectations.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4022,8 +4022,6 @@
40224022
"built-ins/Temporal/PlainTime/prototype/round/smallestunit-string-shorthand.js": "FAIL",
40234023
"built-ins/Temporal/PlainTime/prototype/round/smallestunit-wrong-type.js": "FAIL",
40244024
"built-ins/Temporal/PlainTime/prototype/round/subclassing-ignored.js": "FAIL",
4025-
"built-ins/Temporal/PlainTime/prototype/second/branding.js": "FAIL",
4026-
"built-ins/Temporal/PlainTime/prototype/second/prop-desc.js": "FAIL",
40274025
"built-ins/Temporal/PlainTime/prototype/since/argument-cast.js": "FAIL",
40284026
"built-ins/Temporal/PlainTime/prototype/since/argument-number.js": "FAIL",
40294027
"built-ins/Temporal/PlainTime/prototype/since/argument-string-calendar-annotation-invalid-key.js": "FAIL",
@@ -7075,4 +7073,4 @@
70757073
"staging/sm/syntax/yield-as-identifier.js": "FAIL",
70767074
"staging/source-phase-imports/import-source-source-text-module.js": "FAIL",
70777075
"staging/top-level-await/tla-hang-entry.js": "FAIL"
7078-
}
7076+
}

tests/metrics.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"results": {
33
"crash": 52,
4-
"fail": 6969,
5-
"pass": 40331,
4+
"fail": 6967,
5+
"pass": 40333,
66
"skip": 3326,
77
"timeout": 18,
88
"unresolved": 37

0 commit comments

Comments
 (0)