Skip to content

Commit 6c24376

Browse files
Merge pull request #9 from sebastianjacmatt/temporal_duration_stubs
plain_time constructor and prototype structs and stubs
2 parents 20d4473 + 2055b9d commit 6c24376

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

nova_vm/src/builtin_strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ SyntaxError
455455
#[cfg(feature = "temporal")]Temporal
456456
#[cfg(feature = "temporal")]Temporal.Duration
457457
#[cfg(feature = "temporal")]Temporal.Instant
458+
#[cfg(feature = "temporal")]Temporal.PlainTime
458459
#[cfg(feature = "math")]tan
459460
#[cfg(feature = "math")]tanh
460461
#[cfg(feature = "regexp")]test

nova_vm/src/ecmascript/builtins/temporal/duration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a> CreateHeapData<DurationHeapData<'a>, TemporalDuration<'a>> for Heap {
166166
/// It creates a Temporal.Duration instance and fills
167167
/// the internal slots with valid values.
168168
/// It performs the following steps when called:
169-
pub(crate) fn create_temporal_duration<'gc>(// years,
169+
pub(crate) fn _create_temporal_duration<'gc>(// years,
170170
// months,
171171
// weeks,
172172
// days,
@@ -449,7 +449,7 @@ pub(crate) fn to_temporal_partial_duration_record<'gc>(
449449
/// duration (a Temporal.Duration) and returns a Temporal.Duration.
450450
/// It returns a new Temporal.Duration instance that is the
451451
/// negation of duration.
452-
pub(crate) fn create_negated_temporal_duration<'gc>(
452+
pub(crate) fn _create_negated_temporal_duration<'gc>(
453453
_agent: &mut Agent,
454454
_item: temporal_rs::Duration,
455455
mut _gc: GcScope<'gc, '_>,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use crate::{
1717
};
1818

1919
pub(crate) mod data;
20+
pub mod plain_time_constructor;
21+
pub mod plain_time_prototype;
2022

2123
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2224
#[repr(transparent)]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use crate::{
2+
ecmascript::{
3+
builders::builtin_function_builder::BuiltinFunctionBuilder,
4+
builtins::{ArgumentsList, Behaviour, Builtin, BuiltinIntrinsicConstructor},
5+
execution::{Agent, JsResult, Realm},
6+
types::{BUILTIN_STRING_MEMORY, IntoObject, Object, String, Value},
7+
},
8+
engine::context::{GcScope, NoGcScope},
9+
heap::IntrinsicConstructorIndexes,
10+
};
11+
12+
pub(crate) struct TemporalPlainTimeConstructor;
13+
14+
impl Builtin for TemporalPlainTimeConstructor {
15+
const NAME: String<'static> = BUILTIN_STRING_MEMORY.PlainTime;
16+
const LENGTH: u8 = 1;
17+
const BEHAVIOUR: Behaviour = Behaviour::Constructor(TemporalPlainTimeConstructor::constructor);
18+
}
19+
20+
impl BuiltinIntrinsicConstructor for TemporalPlainTimeConstructor {
21+
const INDEX: IntrinsicConstructorIndexes = IntrinsicConstructorIndexes::TemporalPlainTime;
22+
}
23+
24+
impl TemporalPlainTimeConstructor {
25+
fn constructor<'gc>(
26+
_agent: &mut Agent,
27+
_: Value,
28+
_args: ArgumentsList,
29+
_new_target: Option<Object>,
30+
mut _gc: GcScope<'gc, '_>,
31+
) -> JsResult<'gc, Value<'gc>> {
32+
unimplemented!()
33+
}
34+
35+
pub(crate) fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, _gc: NoGcScope) {
36+
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
37+
let plain_time_prototype = intrinsics.temporal_plain_time_prototype();
38+
39+
BuiltinFunctionBuilder::new_intrinsic_constructor::<TemporalPlainTimeConstructor>(
40+
agent, realm,
41+
)
42+
.with_property_capacity(1)
43+
.with_prototype_property(plain_time_prototype.into_object())
44+
.build();
45+
}
46+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::{
2+
ecmascript::{
3+
builders::ordinary_object_builder::OrdinaryObjectBuilder,
4+
execution::{Agent, Realm},
5+
types::BUILTIN_STRING_MEMORY,
6+
},
7+
engine::context::NoGcScope,
8+
heap::WellKnownSymbolIndexes,
9+
};
10+
11+
pub(crate) struct TemporalPlainTimePrototype;
12+
impl TemporalPlainTimePrototype {
13+
pub fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, _: NoGcScope) {
14+
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
15+
let this = intrinsics.temporal_plain_time_prototype();
16+
let object_prototype = intrinsics.object_prototype();
17+
let plain_time_constructor = intrinsics.temporal_plain_time();
18+
19+
OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
20+
.with_property_capacity(2)
21+
.with_prototype(object_prototype)
22+
.with_constructor_property(plain_time_constructor)
23+
.with_property(|builder| {
24+
builder
25+
.with_key(WellKnownSymbolIndexes::ToStringTag.into())
26+
.with_value_readonly(BUILTIN_STRING_MEMORY.Temporal_PlainTime.into())
27+
.with_enumerable(false)
28+
.with_configurable(true)
29+
.build()
30+
})
31+
.build();
32+
}
33+
}

nova_vm/src/ecmascript/execution/realm/intrinsics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ use crate::ecmascript::builtins::temporal::{
5050
instant_constructor::TemporalInstantConstructor,
5151
instant_prototype::TemporalInstantPrototype,
5252
},
53+
plain_time::{
54+
plain_time_constructor::TemporalPlainTimeConstructor,
55+
plain_time_prototype::TemporalPlainTimePrototype,
56+
},
5357
};
5458

5559
#[cfg(feature = "regexp")]
@@ -337,6 +341,10 @@ impl Intrinsics {
337341
TemporalDurationPrototype::create_intrinsic(agent, realm, gc);
338342
#[cfg(feature = "temporal")]
339343
TemporalDurationConstructor::create_intrinsic(agent, realm, gc);
344+
#[cfg(feature = "temporal")]
345+
TemporalPlainTimePrototype::create_intrinsic(agent, realm, gc);
346+
#[cfg(feature = "temporal")]
347+
TemporalPlainTimeConstructor::create_intrinsic(agent, realm, gc);
340348
#[cfg(feature = "date")]
341349
DatePrototype::create_intrinsic(agent, realm);
342350
#[cfg(feature = "date")]

0 commit comments

Comments
 (0)