Skip to content

Commit d02319f

Browse files
Added Placeholders for InstantConstructor%Temporal.Instant% and InstantPrototype%Temporal.Instant.Prototype% as well as heap data and handles
1 parent d713b50 commit d02319f

File tree

5 files changed

+186
-82
lines changed

5 files changed

+186
-82
lines changed

nova_vm/src/builtin_strings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ isSealed
248248
#[cfg(feature = "array-buffer")]isView
249249
isWellFormed
250250
#[cfg(feature = "annex-b-string")]italics
251+
#[cfg(feature = "temporal")]Instant
251252
Iterator
252253
iterator
253254
join
@@ -317,6 +318,14 @@ prototype
317318
Proxy
318319
push
319320
race
321+
#[cfg(feature = "temporal")]PlainDateTime
322+
#[cfg(feature = "temporal")]PlainDate
323+
#[cfg(feature = "temporal")]PlainTime
324+
#[cfg(feature = "temporal")]PlainYearMonth
325+
#[cfg(feature = "temporal")]PlainMonthDay
326+
#[cfg(feature = "temporal")]Duration
327+
#[cfg(feature = "temporal")]ZonedDateTime
328+
#[cfg(feature = "temporal")]Now
320329
#[cfg(feature = "math")]random
321330
RangeError
322331
raw

nova_vm/src/ecmascript/builtins/temporal.rs

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
6-
use temporal_rs::{Instant, Duration, /* etc */};
7-
8-
use core::f64::consts;
9-
use std::thread::Builder;
5+
pub mod instant;
106

117
use crate::{
128
ecmascript::{
@@ -38,7 +34,7 @@ impl TemporalObject {
3834
let this = intrinsics.temporal();
3935

4036
let builders = OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
41-
.with_property_capacity(1)
37+
.with_property_capacity(2)
4238
.with_prototype(object_prototype)
4339
.with_property(|builder| {
4440
builder
@@ -48,58 +44,7 @@ impl TemporalObject {
4844
.with_configurable(true)
4945
.build()
5046
})
47+
.with_builtin_function_property::<instant::InstantConstructor>()
5148
.build();
5249
}
53-
}
54-
55-
56-
57-
/*
58-
struct TemporalPlainDateTime;
59-
impl Builtin for TemporalPlainDateTime {
60-
const NAME: String<'static> = BUILTIN_STRING_MEMORY.PlainDateTime;
61-
const LENGTH: u8 = 1;
62-
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalObject::PlainDateTime);
63-
}
64-
65-
struct TemporalPlainDate;
66-
impl Builtin for TemporalPlainDate {
67-
const NAME: String<'static> = BUILTIN_STRING_MEMORY.PlainDate;
68-
const LENGTH: u8 = 1;
69-
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalObject::PlainDate);
70-
}
71-
72-
struct TemporalPlainTime;
73-
impl Builtin for TemporalPlainTime {
74-
const NAME: String<'static> = BUILTIN_STRING_MEMORY.PlainTime;
75-
const LENGTH: u8 = 1;
76-
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalObject::PlainTime);
77-
}
78-
79-
struct TemporalPlainYearMonth;
80-
impl Builtin for TemporalPlainYearMonth {
81-
const NAME: String<'static> = BUILTIN_STRING_MEMORY.PlainYearMonth;
82-
const LENGTH: u8 = 1;
83-
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalObject::PlainYearMonth);
84-
}
85-
86-
struct TemporalPlainMonthDay;
87-
impl Builtin for TemporalPlainMonthDay {
88-
const NAME: String<'static> = BUILTIN_STRING_MEMORY.PlainMonthDay;
89-
const LENGTH: u8 = 1;
90-
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalObject::PlainMonthDay);
91-
}
92-
93-
struct TemporalDuration;
94-
impl Builtin for TemporalDuration {
95-
const NAME: String<'static> = BUILTIN_STRING_MEMORY.Duration;
96-
const LENGTH: u8 = 1;
97-
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalObject::Duration);
98-
}
99-
100-
struct TemporalZonedDateTime;
101-
impl Builtin for TemporalZonedDateTime {
102-
const NAME: String<'static> = BUILTIN_STRING_MEMORY.ZonedDateTime;
103-
const LENGTH: u8 = 1;
104-
const BEHAVIOUR: Behaviour = Behaviour::Regular(TemporalObject::ZonedDateTime);
105-
}*/
50+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
use crate::{
2+
ecmascript::{
3+
builders::{builtin_function_builder::BuiltinFunctionBuilder, ordinary_object_builder::OrdinaryObjectBuilder},
4+
builtins::{
5+
ArgumentsList, Behaviour, Builtin, BuiltinIntrinsicConstructor
6+
},
7+
execution::{agent::{Agent}, JsResult, Realm},
8+
types::{
9+
InternalSlots, IntoObject, Object, OrdinaryObject, String, Value, BUILTIN_STRING_MEMORY
10+
},
11+
},
12+
engine::context::{bindable_handle, GcScope, NoGcScope},
13+
heap::{indexes::BaseIndex, CompactionLists, CreateHeapData, Heap, HeapMarkAndSweep, IntrinsicConstructorIndexes, WorkQueues},
14+
};
15+
/// Constructor function object for %Temporal.Instant%.
16+
pub(crate) struct InstantConstructor;
17+
impl Builtin for InstantConstructor {
18+
const NAME: String<'static> = BUILTIN_STRING_MEMORY.Instant;
19+
const LENGTH: u8 = 1;
20+
const BEHAVIOUR: Behaviour = Behaviour::Constructor(InstantConstructor::construct);
21+
}
22+
impl BuiltinIntrinsicConstructor for InstantConstructor {
23+
const INDEX: IntrinsicConstructorIndexes = IntrinsicConstructorIndexes::TemporalInstant;
24+
}
25+
26+
impl InstantConstructor {
27+
fn construct<'gc>(agent: &mut Agent, this_value: Value, args: ArgumentsList, new_target: Option<Object>, gc: GcScope<'gc, '_>) -> JsResult<'gc, Value<'gc>> {
28+
todo!();
29+
}
30+
pub(crate) fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, gc: NoGcScope) {
31+
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
32+
let instant_prototype = intrinsics.temporal_instant_prototype();
33+
34+
BuiltinFunctionBuilder::new_intrinsic_constructor::<InstantConstructor>(agent, realm)
35+
.with_property_capacity(1)
36+
.with_prototype_property(instant_prototype.into_object())
37+
.build();
38+
39+
}
40+
}
41+
/// %Temporal.Instant.Prototype%
42+
pub(crate) struct InstantPrototype;
43+
44+
impl InstantPrototype {
45+
pub fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, gc: NoGcScope) {
46+
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
47+
let this = intrinsics.temporal_instant_prototype();
48+
let object_prototype = intrinsics.object_prototype();
49+
let instant_constructor = intrinsics.temporal_instant();
50+
51+
OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
52+
.with_property_capacity(1) // TODO add correct property capacity
53+
.with_prototype(object_prototype)
54+
.with_constructor_property(instant_constructor)
55+
// TODO add all prototype methods
56+
.build();
57+
}
58+
}
59+
/// HEAP DATA
60+
#[derive(Debug, Clone, Copy)]
61+
pub(crate) struct InstantValue(/*TODO:BigInt*/);
62+
63+
impl InstantValue {
64+
// TODO
65+
}
66+
#[derive(Debug, Clone, Copy)]
67+
pub struct InstantHeapData<'a> {
68+
pub(crate) object_index: Option<OrdinaryObject<'a>>,
69+
pub(crate) date: InstantValue,
70+
}
71+
72+
impl InstantHeapData<'_> {
73+
// TODO
74+
}
75+
76+
bindable_handle!(InstantHeapData);
77+
78+
impl HeapMarkAndSweep for InstantHeapData<'static> {
79+
fn mark_values(&self, queues: &mut crate::heap::WorkQueues) {
80+
todo!()
81+
}
82+
fn sweep_values(&mut self, compactions: &crate::heap::CompactionLists) {
83+
todo!()
84+
}
85+
}
86+
87+
// HANDLES
88+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
89+
pub struct Instant<'a>(BaseIndex<'a, InstantHeapData<'static>>);
90+
impl Instant<'_> {
91+
//TODO
92+
pub(crate) const fn _def() -> Self {
93+
todo!()
94+
}
95+
}
96+
bindable_handle!(Instant);
97+
98+
impl<'a> From<Instant<'a>> for Value<'a> {
99+
fn from(v: Instant<'a>) -> Self { todo!() }
100+
}
101+
impl<'a> From<Instant<'a>> for Object<'a> {
102+
fn from(v: Instant<'a>) -> Self { todo!() }
103+
}
104+
impl<'a> TryFrom<Value<'a>> for Instant<'a> {
105+
type Error = ();
106+
fn try_from(v: Value<'a>) -> Result<Self, ()> {
107+
todo!()
108+
}
109+
}
110+
impl<'a> TryFrom<Object<'a>> for Instant<'a> {
111+
type Error = ();
112+
fn try_from(o: Object<'a>) -> Result<Self, ()> {
113+
todo!()
114+
}
115+
}
116+
117+
// TODO impl trait bounds properly
118+
impl<'a> InternalSlots<'a> for Instant<'a> {
119+
// TODO: Add TemporalInstant to ProtoIntrinsics
120+
//const DEFAULT_PROTOTYPE: ProtoIntrinsics = ProtoIntrinsics::TemporalInstant;
121+
fn get_backing_object(self, agent: &Agent) -> Option<OrdinaryObject<'static>> {
122+
todo!()
123+
}
124+
fn set_backing_object(self, agent: &mut Agent, backing_object: OrdinaryObject<'static>) {
125+
todo!()
126+
}
127+
128+
}
129+
130+
impl HeapMarkAndSweep for Instant<'static> {
131+
fn mark_values(&self, queues: &mut WorkQueues) {
132+
todo!()
133+
}
134+
fn sweep_values(&mut self, compactions: &CompactionLists) {
135+
todo!()
136+
}
137+
}
138+
139+
impl<'a> CreateHeapData<InstantHeapData<'a>, Instant<'a>> for Heap {
140+
fn create(&mut self, data: InstantHeapData<'a>) -> Instant<'a> {
141+
todo!()
142+
}
143+
}

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ use crate::ecmascript::builtins::structured_data::shared_array_buffer_objects::{
4040
shared_array_buffer_prototype::SharedArrayBufferPrototype,
4141
};
4242
#[cfg(feature = "temporal")]
43-
use crate::ecmascript::builtins::temporal::TemporalObject;
43+
use crate::ecmascript::builtins::temporal::{
44+
instant::InstantConstructor, instant::InstantPrototype, TemporalObject
45+
};
4446
#[cfg(feature = "regexp")]
4547
use crate::ecmascript::builtins::text_processing::regexp_objects::{
4648
regexp_constructor::RegExpConstructor, regexp_prototype::RegExpPrototype,
@@ -65,7 +67,6 @@ use crate::ecmascript::builtins::{
6567
use crate::{
6668
ecmascript::{
6769
builtins::{
68-
Array, BuiltinFunction,
6970
control_abstraction_objects::{
7071
async_function_objects::{
7172
async_function_constructor::AsyncFunctionConstructor,
@@ -88,31 +89,22 @@ use crate::{
8889
promise_objects::{
8990
promise_constructor::PromiseConstructor, promise_prototype::PromisePrototype,
9091
},
91-
},
92-
global_object::GlobalObject,
93-
indexed_collections::array_objects::{
92+
}, global_object::GlobalObject, indexed_collections::array_objects::{
9493
array_constructor::ArrayConstructor,
9594
array_iterator_objects::array_iterator_prototype::ArrayIteratorPrototype,
9695
array_prototype::ArrayPrototype,
97-
},
98-
iteration::iterator_constructor::IteratorConstructor,
99-
keyed_collections::map_objects::{
96+
}, iteration::iterator_constructor::IteratorConstructor, keyed_collections::map_objects::{
10097
map_constructor::MapConstructor,
10198
map_iterator_objects::map_iterator_prototype::MapIteratorPrototype,
10299
map_prototype::MapPrototype,
103-
},
104-
managing_memory::finalization_registry_objects::{
100+
}, managing_memory::finalization_registry_objects::{
105101
finalization_registry_constructor::FinalizationRegistryConstructor,
106102
finalization_registry_prototype::FinalizationRegistryPrototype,
107-
},
108-
ordinary::shape::ObjectShape,
109-
primitive_objects::{PrimitiveObject, PrimitiveObjectHeapData},
110-
reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject},
111-
text_processing::string_objects::{
103+
}, ordinary::shape::ObjectShape, primitive_objects::{PrimitiveObject, PrimitiveObjectHeapData}, reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject}, text_processing::string_objects::{
112104
string_constructor::StringConstructor,
113105
string_iterator_objects::StringIteratorPrototype,
114106
string_prototype::StringPrototype,
115-
},
107+
}, Array, BuiltinFunction
116108
},
117109
execution::Agent,
118110
fundamental_objects::{
@@ -148,10 +140,7 @@ use crate::{
148140
},
149141
engine::context::NoGcScope,
150142
heap::{
151-
CompactionLists, HeapMarkAndSweep, IntrinsicConstructorIndexes, IntrinsicFunctionIndexes,
152-
IntrinsicObjectIndexes, IntrinsicObjectShapes, IntrinsicPrimitiveObjectIndexes, WorkQueues,
153-
indexes::BaseIndex, intrinsic_function_count, intrinsic_object_count,
154-
intrinsic_primitive_object_count,
143+
indexes::BaseIndex, intrinsic_function_count, intrinsic_object_count, intrinsic_primitive_object_count, CompactionLists, HeapMarkAndSweep, IntrinsicConstructorIndexes, IntrinsicFunctionIndexes, IntrinsicObjectIndexes, IntrinsicObjectShapes, IntrinsicPrimitiveObjectIndexes, WorkQueues
155144
},
156145
};
157146
#[derive(Debug, Clone)]
@@ -308,9 +297,12 @@ impl Intrinsics {
308297
#[cfg(feature = "math")]
309298
MathObject::create_intrinsic(agent, realm, gc);
310299

311-
#[cfg(feature = "temporal")]
312-
TemporalObject::create_intrinsic(agent, realm, gc);
313-
300+
#[cfg(feature = "temporal")] {
301+
TemporalObject::create_intrinsic(agent, realm, gc);
302+
// Instant
303+
InstantConstructor::create_intrinsic(agent, realm, gc);
304+
InstantPrototype::create_intrinsic(agent, realm, gc);
305+
}
314306

315307
#[cfg(feature = "date")]
316308
DatePrototype::create_intrinsic(agent, realm);
@@ -1017,6 +1009,15 @@ impl Intrinsics {
10171009
IntrinsicObjectIndexes::TemporalObject.get_backing_object(self.object_index_base)
10181010
}
10191011

1012+
/// %Temporal.Instant%
1013+
pub(crate) const fn temporal_instant(&self) -> BuiltinFunction<'static> {
1014+
IntrinsicConstructorIndexes::TemporalInstant.get_builtin_function(self.builtin_function_index_base)
1015+
}
1016+
/// %Temporal.Instant.Prototype%
1017+
pub(crate) const fn temporal_instant_prototype(&self) -> OrdinaryObject<'static> {
1018+
IntrinsicObjectIndexes::TemporalInstantPrototype.get_backing_object(self.object_index_base)
1019+
}
1020+
10201021
/// %Number.prototype%
10211022
pub(crate) fn number_prototype(&self) -> PrimitiveObject<'static> {
10221023
IntrinsicPrimitiveObjectIndexes::NumberPrototype

nova_vm/src/heap/heap_constants.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub(crate) enum IntrinsicObjectIndexes {
3636
DatePrototype,
3737
#[cfg(feature = "temporal")]
3838
TemporalObject,
39+
#[cfg(feature = "temporal")]
40+
TemporalInstant,
41+
#[cfg(feature = "temporal")]
42+
TemporalInstantPrototype,
3943
// Text processing
4044
#[cfg(feature = "regexp")]
4145
RegExpPrototype,
@@ -172,6 +176,8 @@ pub(crate) enum IntrinsicConstructorIndexes {
172176
BigInt,
173177
#[cfg(feature = "date")]
174178
Date,
179+
#[cfg(feature = "temporal")]
180+
TemporalInstant,
175181

176182
// Text processing
177183
String,

0 commit comments

Comments
 (0)