Skip to content

Commit 0f3b4a6

Browse files
committed
fix oversights in previous commit
1 parent b8588d0 commit 0f3b4a6

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

nova_vm/src/ecmascript/builtins/ordinary.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,10 @@ pub(crate) fn ordinary_object_create_with_intrinsics<'a>(
16881688
agent.heap.create(InstantHeapData::default()).into_object()
16891689
}
16901690
#[cfg(feature = "temporal")]
1691-
ProtoIntrinsics::TemporalPlainTime => todo!(),
1691+
ProtoIntrinsics::TemporalPlainTime => agent
1692+
.heap
1693+
.create(PlainTimeHeapData::default())
1694+
.into_object(),
16921695
ProtoIntrinsics::TypeError => agent
16931696
.heap
16941697
.create(ErrorHeapData::new(ExceptionType::TypeError, None, None))

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ use crate::{
66
execution::{Agent, ProtoIntrinsics},
77
types::{InternalMethods, InternalSlots, Object, OrdinaryObject, Value},
88
},
9-
engine::context::bindable_handle,
9+
engine::{
10+
context::{Bindable, bindable_handle},
11+
rootable::{HeapRootData, HeapRootRef, Rootable},
12+
},
1013
heap::{
11-
CompactionLists, HeapMarkAndSweep, HeapSweepWeakReference, WorkQueues, indexes::BaseIndex,
14+
CompactionLists, CreateHeapData, Heap, HeapMarkAndSweep, HeapSweepWeakReference,
15+
WorkQueues, indexes::BaseIndex,
1216
},
1317
};
1418

@@ -19,10 +23,6 @@ pub(crate) mod data;
1923
pub struct TemporalPlainTime<'a>(BaseIndex<'a, PlainTimeHeapData<'static>>);
2024

2125
impl TemporalPlainTime<'_> {
22-
pub(crate) fn inner_plain_date_time(self, agent: &Agent) -> &temporal_rs::PlainTime {
23-
&agent[self].plain_time
24-
}
25-
2626
//TODO
2727
pub(crate) const fn _def() -> Self {
2828
TemporalPlainTime(BaseIndex::from_u32_index(0))
@@ -109,6 +109,29 @@ impl IndexMut<TemporalPlainTime<'_>> for Vec<PlainTimeHeapData<'static>> {
109109
}
110110
}
111111

112+
impl Rootable for TemporalPlainTime<'_> {
113+
type RootRepr = HeapRootRef;
114+
115+
fn to_root_repr(value: Self) -> Result<Self::RootRepr, HeapRootData> {
116+
Err(HeapRootData::PlainTime(value.unbind()))
117+
}
118+
119+
fn from_root_repr(value: &Self::RootRepr) -> Result<Self, HeapRootRef> {
120+
Err(*value)
121+
}
122+
123+
fn from_heap_ref(heap_ref: HeapRootRef) -> Self::RootRepr {
124+
heap_ref
125+
}
126+
127+
fn from_heap_data(heap_data: HeapRootData) -> Option<Self> {
128+
match heap_data {
129+
HeapRootData::PlainTime(object) => Some(object),
130+
_ => None,
131+
}
132+
}
133+
}
134+
112135
impl HeapMarkAndSweep for TemporalPlainTime<'static> {
113136
fn mark_values(&self, queues: &mut WorkQueues) {
114137
queues.plain_times.push(*self);
@@ -124,3 +147,11 @@ impl HeapSweepWeakReference for TemporalPlainTime<'static> {
124147
compactions.plain_times.shift_weak_index(self.0).map(Self)
125148
}
126149
}
150+
151+
impl<'a> CreateHeapData<PlainTimeHeapData<'a>, TemporalPlainTime<'a>> for Heap {
152+
fn create(&mut self, data: PlainTimeHeapData<'a>) -> TemporalPlainTime<'a> {
153+
self.plain_times.push(data.unbind());
154+
self.alloc_counter += core::mem::size_of::<PlainTimeHeapData<'static>>();
155+
TemporalPlainTime(BaseIndex::last_t(&self.plain_times))
156+
}
157+
}

nova_vm/src/ecmascript/types/language/object.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ use crate::ecmascript::builtins::date::Date;
4040
use crate::ecmascript::builtins::{weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet};
4141
#[cfg(feature = "temporal")]
4242
use crate::ecmascript::{
43-
builtins::temporal::plain_time::{self, TemporalPlainTime},
44-
types::PLAIN_TIME_DISCRIMINANT,
43+
builtins::temporal::plain_time::TemporalPlainTime, types::PLAIN_TIME_DISCRIMINANT,
4544
};
4645
#[cfg(feature = "proposal-float16array")]
4746
use crate::ecmascript::{builtins::typed_array::Float16Array, types::FLOAT_16_ARRAY_DISCRIMINANT};

nova_vm/src/engine/rootable.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ use crate::{
108108
promise_resolving_functions::BuiltinPromiseResolvingFunction,
109109
},
110110
proxy::Proxy,
111-
temporal::plain_time,
112111
text_processing::string_objects::string_iterator_objects::StringIterator,
113112
},
114113
execution::{
@@ -143,7 +142,9 @@ pub mod private {
143142
#[cfg(feature = "date")]
144143
use crate::ecmascript::builtins::date::Date;
145144
#[cfg(feature = "temporal")]
146-
use crate::ecmascript::builtins::temporal::instant::TemporalInstant;
145+
use crate::ecmascript::builtins::temporal::{
146+
instant::TemporalInstant, plain_time::TemporalPlainTime,
147+
};
147148
#[cfg(feature = "array-buffer")]
148149
use crate::ecmascript::builtins::{
149150
ArrayBuffer,
@@ -239,6 +240,8 @@ pub mod private {
239240
impl RootableSealed for Date<'_> {}
240241
#[cfg(feature = "temporal")]
241242
impl RootableSealed for TemporalInstant<'_> {}
243+
#[cfg(feature = "temporal")]
244+
impl RootableSealed for TemporalPlainTime<'_> {}
242245
impl RootableSealed for ECMAScriptFunction<'_> {}
243246
impl RootableSealed for EmbedderObject<'_> {}
244247
impl RootableSealed for Error<'_> {}

0 commit comments

Comments
 (0)