Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nova_vm/src/builtin_strings
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ parseFloat
parseInt
#[cfg(feature = "proposal-atomics-microwait")]pause
#[cfg(feature = "math")]PI
#[cfg(feature = "temporal")]PlainTime
pop
POSITIVE_INFINITY
#[cfg(feature = "math")]pow
Expand Down Expand Up @@ -454,6 +455,7 @@ SyntaxError
#[cfg(feature = "temporal")]Temporal
#[cfg(feature = "temporal")]Temporal.Duration
#[cfg(feature = "temporal")]Temporal.Instant
#[cfg(feature = "temporal")]Temporal.PlainTime
#[cfg(feature = "math")]tan
#[cfg(feature = "math")]tanh
#[cfg(feature = "regexp")]test
Expand Down
6 changes: 5 additions & 1 deletion nova_vm/src/ecmascript/builtins/ordinary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::ecmascript::SharedDataViewRecord;
#[cfg(feature = "array-buffer")]
use crate::ecmascript::try_get_result_into_value;
#[cfg(feature = "temporal")]
use crate::ecmascript::{DurationRecord, InstantRecord};
use crate::ecmascript::{DurationRecord, InstantRecord, PlainTimeRecord};
use crate::{
ecmascript::{
Agent, ArgumentsList, BUILTIN_STRING_MEMORY, ExceptionType, Function, InternalMethods,
Expand Down Expand Up @@ -1657,6 +1657,8 @@ pub(crate) fn ordinary_object_create_with_intrinsics<'a>(
ProtoIntrinsics::TemporalInstant => agent.heap.create(InstantRecord::default()).into(),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalDuration => agent.heap.create(DurationRecord::default()).into(),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalPlainTime => agent.heap.create(PlainTimeRecord::default()).into(),
ProtoIntrinsics::TypeError => agent
.heap
.create(ErrorHeapData::new(ExceptionType::TypeError, None, None))
Expand Down Expand Up @@ -2094,6 +2096,8 @@ fn get_intrinsic_constructor<'a>(
ProtoIntrinsics::TemporalInstant => Some(intrinsics.temporal_instant().into()),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalDuration => Some(intrinsics.temporal_duration().into()),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalPlainTime => Some(intrinsics.temporal_plain_time().into()),
}
}

Expand Down
13 changes: 12 additions & 1 deletion nova_vm/src/ecmascript/builtins/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ mod duration;
mod error;
mod instant;
mod options;
mod plain_time;

pub use duration::*;
pub(crate) use error::*;
pub use instant::*;
pub(crate) use options::*;
pub use plain_time::*;

use temporal_rs::{
options::{DifferenceSettings, RoundingIncrement, RoundingMode, Unit, UnitGroup},
Expand All @@ -36,9 +38,10 @@ impl TemporalObject {

let instant_constructor = intrinsics.temporal_instant();
let duration_constructor = intrinsics.temporal_duration();
let plain_time_constructor = intrinsics.temporal_plain_time();

OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
.with_property_capacity(3)
.with_property_capacity(4)
.with_prototype(object_prototype)
// 1.2.1 Temporal.Instant ( . . . )
.with_property(|builder| {
Expand All @@ -52,6 +55,14 @@ impl TemporalObject {
// 1.2.2 Temporal.PlainDateTime ( . . . )
// 1.2.3 Temporal.PlainDate ( . . . )
// 1.2.4 Temporal.PlainTime ( . . . )
.with_property(|builder| {
builder
.with_key(BUILTIN_STRING_MEMORY.PlainTime.into())
.with_value(plain_time_constructor.into())
.with_enumerable(false)
.with_configurable(true)
.build()
})
// 1.2.5 Temporal.PlainYearMonth ( . . . )
// 1.2.6 Temporal.PlainMonthDay ( . . . )
// 1.2.7 Temporal.Duration ( . . . )
Expand Down
79 changes: 79 additions & 0 deletions nova_vm/src/ecmascript/builtins/temporal/plain_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

mod data;
mod plain_time_constructor;
mod plain_time_prototype;

pub(crate) use data::*;
pub(crate) use plain_time_constructor::*;
pub(crate) use plain_time_prototype::*;

use crate::{
ecmascript::{
Agent, InternalMethods, InternalSlots, OrdinaryObject, ProtoIntrinsics, object_handle,
},
engine::Bindable,
heap::{
ArenaAccess, ArenaAccessMut, BaseIndex, CompactionLists, CreateHeapData, Heap,
HeapMarkAndSweep, HeapSweepWeakReference, WorkQueues, arena_vec_access,
},
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TemporalPlainTime<'a>(BaseIndex<'a, PlainTimeRecord<'static>>);
object_handle!(TemporalPlainTime, PlainTime);
arena_vec_access!(
TemporalPlainTime,
'a,
PlainTimeRecord,
plain_times
);

impl TemporalPlainTime<'_> {
pub(crate) fn _inner_plain_time(self, agent: &Agent) -> &temporal_rs::PlainTime {
&self.unbind().get(agent)._plain_time
}
}

impl<'a> InternalSlots<'a> for TemporalPlainTime<'a> {
const DEFAULT_PROTOTYPE: ProtoIntrinsics = ProtoIntrinsics::TemporalPlainTime;
fn get_backing_object(self, agent: &Agent) -> Option<OrdinaryObject<'static>> {
self.get(agent).object_index.unbind()
}
fn set_backing_object(self, agent: &mut Agent, backing_object: OrdinaryObject<'static>) {
assert!(
self.get_mut(agent)
.object_index
.replace(backing_object)
.is_none()
);
}
}

impl<'a> InternalMethods<'a> for TemporalPlainTime<'a> {}

impl HeapMarkAndSweep for TemporalPlainTime<'static> {
fn mark_values(&self, queues: &mut WorkQueues) {
queues.plain_times.push(*self);
}
fn sweep_values(&mut self, compactions: &CompactionLists) {
compactions.plain_times.shift_index(&mut self.0);
}
}

impl HeapSweepWeakReference for TemporalPlainTime<'static> {
fn sweep_weak_reference(self, compactions: &CompactionLists) -> Option<Self> {
compactions.plain_times.shift_weak_index(self.0).map(Self)
}
}

impl<'a> CreateHeapData<PlainTimeRecord<'a>, TemporalPlainTime<'a>> for Heap {
fn create(&mut self, data: PlainTimeRecord<'a>) -> TemporalPlainTime<'a> {
self.plain_times.push(data.unbind());
self.alloc_counter += core::mem::size_of::<PlainTimeRecord<'static>>();
TemporalPlainTime(BaseIndex::last(&self.plain_times))
}
}
46 changes: 46 additions & 0 deletions nova_vm/src/ecmascript/builtins/temporal/plain_time/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::{
ecmascript::OrdinaryObject,
engine::{NoGcScope, bindable_handle, trivially_bindable},
heap::{CompactionLists, HeapMarkAndSweep, WorkQueues},
};

#[derive(Debug, Clone, Copy)]
pub struct PlainTimeRecord<'a> {
pub(crate) object_index: Option<OrdinaryObject<'a>>,
pub(crate) _plain_time: temporal_rs::PlainTime,
}

impl PlainTimeRecord<'_> {
pub fn default() -> Self {
Self {
object_index: None,
_plain_time: temporal_rs::PlainTime::try_new(0, 0, 0, 0, 0, 0).unwrap(),
}
}
}

trivially_bindable!(temporal_rs::PlainTime);
bindable_handle!(PlainTimeRecord);

impl HeapMarkAndSweep for PlainTimeRecord<'static> {
fn mark_values(&self, queues: &mut WorkQueues) {
let Self {
object_index,
_plain_time: _,
} = self;

object_index.mark_values(queues);
}
fn sweep_values(&mut self, compactions: &CompactionLists) {
let Self {
object_index,
_plain_time: _,
} = self;

object_index.sweep_values(compactions);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::{
ecmascript::{
Agent, ArgumentsList, BUILTIN_STRING_MEMORY, Behaviour, Builtin,
BuiltinIntrinsicConstructor, JsResult, Object, Realm, String, Value,
builders::BuiltinFunctionBuilder,
},
engine::{GcScope, NoGcScope},
heap::IntrinsicConstructorIndexes,
};

/// Constructor function object for %Temporal.PlainTime%.
pub(crate) struct TemporalPlainTimeConstructor;

impl Builtin for TemporalPlainTimeConstructor {
const NAME: String<'static> = BUILTIN_STRING_MEMORY.PlainTime;
const LENGTH: u8 = 0;
const BEHAVIOUR: Behaviour = Behaviour::Constructor(TemporalPlainTimeConstructor::constructor);
}
impl BuiltinIntrinsicConstructor for TemporalPlainTimeConstructor {
const INDEX: IntrinsicConstructorIndexes = IntrinsicConstructorIndexes::TemporalPlainTime;
}

impl TemporalPlainTimeConstructor {
fn constructor<'gc>(
agent: &mut Agent,
_: Value,
_args: ArgumentsList,
_new_target: Option<Object>,
gc: GcScope<'gc, '_>,
) -> JsResult<'gc, Value<'gc>> {
Err(agent.todo("Temporal.PlainTime", gc.into_nogc()))
}

pub(crate) fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, _gc: NoGcScope) {
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
let plain_time_prototype = intrinsics.temporal_plain_time_prototype();

BuiltinFunctionBuilder::new_intrinsic_constructor::<TemporalPlainTimeConstructor>(
agent, realm,
)
.with_property_capacity(1)
.with_prototype_property(plain_time_prototype.into())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::{
ecmascript::{Agent, BUILTIN_STRING_MEMORY, Realm, builders::OrdinaryObjectBuilder},
engine::NoGcScope,
heap::WellKnownSymbols,
};

pub(crate) struct TemporalPlainTimePrototype;
impl TemporalPlainTimePrototype {
pub fn create_intrinsic(agent: &mut Agent, realm: Realm<'static>, _: NoGcScope) {
let intrinsics = agent.get_realm_record_by_id(realm).intrinsics();
let this = intrinsics.temporal_plain_time_prototype();
let object_prototype = intrinsics.object_prototype();
let plain_time_constructor = intrinsics.temporal_plain_time();

OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
.with_property_capacity(2)
.with_prototype(object_prototype)
.with_constructor_property(plain_time_constructor)
.with_property(|builder| {
builder
.with_key(WellKnownSymbols::ToStringTag.into())
.with_value_readonly(BUILTIN_STRING_MEMORY.Temporal_PlainTime.into())
.with_enumerable(false)
.with_configurable(true)
.build()
})
.build();
}
}
39 changes: 28 additions & 11 deletions nova_vm/src/ecmascript/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use crate::ecmascript::{SharedArrayBufferConstructor, SharedArrayBufferPrototype
#[cfg(feature = "temporal")]
use crate::ecmascript::{
TemporalDurationConstructor, TemporalDurationPrototype, TemporalInstantConstructor,
TemporalInstantPrototype, TemporalObject,
TemporalInstantPrototype, TemporalObject, TemporalPlainTimeConstructor,
TemporalPlainTimePrototype,
};
#[cfg(feature = "weak-refs")]
use crate::ecmascript::{
Expand Down Expand Up @@ -140,6 +141,8 @@ pub enum ProtoIntrinsics {
TemporalInstant,
#[cfg(feature = "temporal")]
TemporalDuration,
#[cfg(feature = "temporal")]
TemporalPlainTime,
TypeError,
#[cfg(feature = "array-buffer")]
Uint16Array,
Expand Down Expand Up @@ -220,17 +223,16 @@ impl Intrinsics {
BigIntConstructor::create_intrinsic(agent, realm);
#[cfg(feature = "math")]
MathObject::create_intrinsic(agent, realm, gc);

#[cfg(feature = "temporal")]
TemporalObject::create_intrinsic(agent, realm, gc);
#[cfg(feature = "temporal")]
TemporalInstantPrototype::create_intrinsic(agent, realm, gc);
#[cfg(feature = "temporal")]
TemporalInstantConstructor::create_intrinsic(agent, realm, gc);
#[cfg(feature = "temporal")]
TemporalDurationPrototype::create_intrinsic(agent, realm, gc);
#[cfg(feature = "temporal")]
TemporalDurationConstructor::create_intrinsic(agent, realm, gc);
{
TemporalObject::create_intrinsic(agent, realm, gc);
TemporalInstantPrototype::create_intrinsic(agent, realm, gc);
TemporalInstantConstructor::create_intrinsic(agent, realm, gc);
TemporalDurationPrototype::create_intrinsic(agent, realm, gc);
TemporalDurationConstructor::create_intrinsic(agent, realm, gc);
TemporalPlainTimePrototype::create_intrinsic(agent, realm, gc);
TemporalPlainTimeConstructor::create_intrinsic(agent, realm, gc);
}
#[cfg(feature = "date")]
DatePrototype::create_intrinsic(agent, realm);
#[cfg(feature = "date")]
Expand Down Expand Up @@ -344,6 +346,8 @@ impl Intrinsics {
ProtoIntrinsics::TemporalInstant => self.temporal_instant().into(),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalDuration => self.temporal_duration().into(),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalPlainTime => self.temporal_plain_time().into(),
ProtoIntrinsics::TypeError => self.type_error().into(),
ProtoIntrinsics::URIError => self.uri_error().into(),
ProtoIntrinsics::AggregateError => self.aggregate_error().into(),
Expand Down Expand Up @@ -437,6 +441,8 @@ impl Intrinsics {
ProtoIntrinsics::TemporalInstant => self.temporal_instant_prototype().into(),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalDuration => self.temporal_duration_prototype().into(),
#[cfg(feature = "temporal")]
ProtoIntrinsics::TemporalPlainTime => self.temporal_plain_time_prototype().into(),
ProtoIntrinsics::TypeError => self.type_error_prototype().into(),
ProtoIntrinsics::URIError => self.uri_error_prototype().into(),
ProtoIntrinsics::AggregateError => self.aggregate_error_prototype().into(),
Expand Down Expand Up @@ -970,6 +976,17 @@ impl Intrinsics {
.get_builtin_function(self.builtin_function_index_base)
}

/// %Temporal.PlainTime%
pub(crate) const fn temporal_plain_time(&self) -> BuiltinFunction<'static> {
IntrinsicConstructorIndexes::TemporalPlainTime
.get_builtin_function(self.builtin_function_index_base)
}

/// %Temporal.PlainTime.Prototype%
pub(crate) const fn temporal_plain_time_prototype(&self) -> OrdinaryObject<'static> {
IntrinsicObjectIndexes::TemporalPlainTimePrototype
.get_backing_object(self.object_index_base)
}
/// %Number.prototype%
pub(crate) fn number_prototype(&self) -> PrimitiveObject<'static> {
IntrinsicPrimitiveObjectIndexes::NumberPrototype
Expand Down
Loading