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
3 changes: 2 additions & 1 deletion nova_vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ sonic-rs = { workspace = true, optional = true}
wtf8 = { workspace = true }

[features]
default = ["math", "json"]
default = ["math", "json", "date"]
math = []
json = ["sonic-rs"]
date = []

typescript = []

Expand Down
1 change: 1 addition & 0 deletions nova_vm/src/ecmascript/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod builtin_constructor;
mod builtin_function;
pub(crate) mod control_abstraction_objects;
pub(crate) mod data_view;
#[cfg(feature = "date")]
pub mod date;
mod ecmascript_function;
pub(crate) mod embedder_object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl ObjectPrototype {
// 5. If isArray is true, let builtinTag be "Array".
Value::Array(_) => Ok(BUILTIN_STRING_MEMORY._object_Array_.into_value()),
// 12. Else if O has a [[DateValue]] internal slot, let builtinTag be "Date".
#[cfg(feature = "date")]
Value::Date(_) => Ok(BUILTIN_STRING_MEMORY._object_Date_.into_value()),
// 8. Else if O has an [[ErrorData]] internal slot, let builtinTag be "Error".
Value::Error(_) => Ok(BUILTIN_STRING_MEMORY._object_Error_.into_value()),
Expand Down
1 change: 1 addition & 0 deletions nova_vm/src/ecmascript/builtins/numbers_and_dates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

pub mod bigint_objects;
#[cfg(feature = "date")]
pub mod date_objects;
#[cfg(feature = "math")]
pub mod math_object;
Expand Down
5 changes: 4 additions & 1 deletion nova_vm/src/ecmascript/builtins/ordinary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ use crate::{
heap::{CompactionLists, CreateHeapData, HeapMarkAndSweep, WellKnownSymbolIndexes, WorkQueues},
};

#[cfg(feature = "date")]
use super::date::data::DateHeapData;
use super::{
control_abstraction_objects::generator_objects::GeneratorHeapData,
data_view::data::DataViewHeapData,
date::data::DateHeapData,
error::ErrorHeapData,
finalization_registry::data::FinalizationRegistryHeapData,
indexed_collections::array_objects::array_iterator_objects::array_iterator::ArrayIteratorHeapData,
Expand Down Expand Up @@ -824,6 +825,7 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
.heap
.create(ErrorHeapData::new(ExceptionType::EvalError, None, None))
.into_object(),
#[cfg(feature = "date")]
ProtoIntrinsics::Date => agent.heap.create(DateHeapData::new_invalid()).into_object(),
ProtoIntrinsics::Function => todo!(),
ProtoIntrinsics::Number => agent
Expand Down Expand Up @@ -1041,6 +1043,7 @@ pub(crate) fn get_prototype_from_constructor(
ProtoIntrinsics::BigUint64Array => Some(intrinsics.big_uint64_array().into_function()),
ProtoIntrinsics::Boolean => Some(intrinsics.boolean().into_function()),
ProtoIntrinsics::DataView => Some(intrinsics.data_view().into_function()),
#[cfg(feature = "date")]
ProtoIntrinsics::Date => Some(intrinsics.date().into_function()),
ProtoIntrinsics::Error => Some(intrinsics.error().into_function()),
ProtoIntrinsics::EvalError => Some(intrinsics.eval_error().into_function()),
Expand Down
27 changes: 15 additions & 12 deletions nova_vm/src/ecmascript/execution/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,18 +574,20 @@ pub(crate) fn set_default_global_bindings(
};
define_property_or_throw(agent, global, name, desc)?;

// 19.3.9 Date ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Date);
let value = agent.get_realm(realm_id).intrinsics().date();
let desc = PropertyDescriptor {
value: Some(value.into_value()),
writable: Some(true),
enumerable: Some(false),
configurable: Some(true),
..Default::default()
};
define_property_or_throw(agent, global, name, desc)?;

#[cfg(feature = "date")]
{
// 19.3.9 Date ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Date);
let value = agent.get_realm(realm_id).intrinsics().date();
let desc = PropertyDescriptor {
value: Some(value.into_value()),
writable: Some(true),
enumerable: Some(false),
configurable: Some(true),
..Default::default()
};
define_property_or_throw(agent, global, name, desc)?;
}
// 19.3.10 Error ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Error);
let value = agent.get_realm(realm_id).intrinsics().error();
Expand Down Expand Up @@ -1171,6 +1173,7 @@ mod test {
if let Some((missing_builtin_index, _)) = missing_builtin {
panic_builtin_function_missing(missing_builtin_index);
}
#[cfg(feature = "date")]
assert!(agent.heap.dates.is_empty());
assert!(agent.heap.ecmascript_functions.is_empty());
assert_eq!(agent.heap.environments.declarative.len(), 1);
Expand Down
17 changes: 16 additions & 1 deletion nova_vm/src/ecmascript/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ use crate::{
bigint_objects::{
bigint_constructor::BigIntConstructor, bigint_prototype::BigIntPrototype,
},
date_objects::{date_constructor::DateConstructor, date_prototype::DatePrototype},
number_objects::{
number_constructor::NumberConstructor, number_prototype::NumberPrototype,
},
Expand All @@ -142,6 +141,11 @@ use crate::{
};

use super::RealmIdentifier;

#[cfg(feature = "date")]
use crate::ecmascript::builtins::numbers_and_dates::date_objects::{
date_constructor::DateConstructor, date_prototype::DatePrototype,
};
#[cfg(feature = "math")]
use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject;
#[cfg(feature = "json")]
Expand Down Expand Up @@ -172,6 +176,7 @@ pub enum ProtoIntrinsics {
BigUint64Array,
Boolean,
DataView,
#[cfg(feature = "date")]
Date,
Error,
EvalError,
Expand Down Expand Up @@ -262,7 +267,9 @@ impl Intrinsics {
BigIntConstructor::create_intrinsic(agent, realm);
#[cfg(feature = "math")]
MathObject::create_intrinsic(agent, realm);
#[cfg(feature = "date")]
DatePrototype::create_intrinsic(agent, realm);
#[cfg(feature = "date")]
DateConstructor::create_intrinsic(agent, realm);
StringPrototype::create_intrinsic(agent, realm);
StringConstructor::create_intrinsic(agent, realm);
Expand Down Expand Up @@ -331,6 +338,7 @@ impl Intrinsics {
ProtoIntrinsics::BigInt => self.big_int_prototype().into(),
ProtoIntrinsics::Boolean => self.boolean_prototype().into(),
ProtoIntrinsics::Error => self.error_prototype().into(),
#[cfg(feature = "date")]
ProtoIntrinsics::Date => self.date_prototype().into(),
ProtoIntrinsics::EvalError => self.eval_error_prototype().into(),
ProtoIntrinsics::Function => self.function_prototype().into(),
Expand Down Expand Up @@ -652,27 +660,31 @@ impl Intrinsics {
IntrinsicConstructorIndexes::DataView.get_object_index(self.object_index_base)
}

#[cfg(feature = "date")]
/// %Date.prototype.toUTCString%
pub(crate) fn date_prototype_to_utcstring(&self) -> BuiltinFunction {
IntrinsicFunctionIndexes::DatePrototypeToUTCString
.get_builtin_function_index(self.builtin_function_index_base)
.into()
}

#[cfg(feature = "date")]
/// %Date.prototype%
pub(crate) fn date_prototype(&self) -> OrdinaryObject {
IntrinsicObjectIndexes::DatePrototype
.get_object_index(self.object_index_base)
.into()
}

#[cfg(feature = "date")]
/// %Date%
pub(crate) fn date(&self) -> BuiltinFunction {
IntrinsicConstructorIndexes::Date
.get_builtin_function_index(self.builtin_function_index_base)
.into()
}

#[cfg(feature = "date")]
pub(crate) fn date_base_object(&self) -> ObjectIndex {
IntrinsicConstructorIndexes::Date.get_object_index(self.object_index_base)
}
Expand Down Expand Up @@ -1513,8 +1525,11 @@ impl HeapMarkAndSweep for Intrinsics {
self.boolean().mark_values(queues);
self.data_view_prototype().mark_values(queues);
self.data_view().mark_values(queues);
#[cfg(feature = "date")]
self.date_prototype_to_utcstring().mark_values(queues);
#[cfg(feature = "date")]
self.date_prototype().mark_values(queues);
#[cfg(feature = "date")]
self.date().mark_values(queues);
self.decode_uri().mark_values(queues);
self.decode_uri_component().mark_values(queues);
Expand Down
Loading