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,11 +23,12 @@ sonic-rs = { workspace = true, optional = true }
wtf8 = { workspace = true }

[features]
default = ["math", "json", "date", "array-buffer"]
default = ["math", "json", "date", "array-buffer", "shared-array-buffer"]
math = []
json = ["sonic-rs"]
date = []
array-buffer = []
shared-array-buffer = []
typescript = []

[build-dependencies]
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 @@ -39,6 +39,7 @@ pub(crate) mod proxy;
pub(crate) mod reflection;
pub(crate) mod regexp;
pub(crate) mod set;
#[cfg(feature = "shared-array-buffer")]
pub(crate) mod shared_array_buffer;
pub(crate) mod structured_data;
pub(crate) mod text_processing;
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 @@ -26,6 +26,8 @@ use crate::{

#[cfg(feature = "date")]
use super::date::data::DateHeapData;
#[cfg(feature = "shared-array-buffer")]
use super::shared_array_buffer::data::SharedArrayBufferHeapData;
use super::{
control_abstraction_objects::generator_objects::GeneratorHeapData,
error::ErrorHeapData,
Expand All @@ -40,7 +42,6 @@ use super::{
promise::data::PromiseHeapData,
regexp::RegExpHeapData,
set::data::SetHeapData,
shared_array_buffer::data::SharedArrayBufferHeapData,
weak_map::data::WeakMapHeapData,
weak_ref::data::WeakRefHeapData,
weak_set::data::WeakSetHeapData,
Expand Down Expand Up @@ -950,6 +951,7 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
.heap
.create(SetIteratorHeapData::default())
.into_object(),
#[cfg(feature = "shared-array-buffer")]
ProtoIntrinsics::SharedArrayBuffer => agent
.heap
.create(SharedArrayBufferHeapData::default())
Expand Down Expand Up @@ -1093,6 +1095,7 @@ pub(crate) fn get_prototype_from_constructor(
ProtoIntrinsics::RegExp => Some(intrinsics.reg_exp().into_function()),
ProtoIntrinsics::Set => Some(intrinsics.set().into_function()),
ProtoIntrinsics::SetIterator => None,
#[cfg(feature = "shared-array-buffer")]
ProtoIntrinsics::SharedArrayBuffer => {
Some(intrinsics.shared_array_buffer().into_function())
}
Expand Down
1 change: 1 addition & 0 deletions nova_vm/src/ecmascript/builtins/structured_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub(crate) mod atomics_object;
pub(crate) mod data_view_objects;
#[cfg(feature = "json")]
pub(crate) mod json_object;
#[cfg(feature = "shared-array-buffer")]
pub(crate) mod shared_array_buffer_objects;
24 changes: 13 additions & 11 deletions nova_vm/src/ecmascript/execution/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,17 +817,19 @@ pub(crate) fn set_default_global_bindings(
define_property_or_throw(agent, global, name, desc)?;

// 19.3.28 SharedArrayBuffer ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.SharedArrayBuffer);
let value = agent.get_realm(realm_id).intrinsics().shared_array_buffer();
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 = "shared-array-buffer")]
{
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.SharedArrayBuffer);
let value = agent.get_realm(realm_id).intrinsics().shared_array_buffer();
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.29 String ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.String);
let value = agent.get_realm(realm_id).intrinsics().string();
Expand Down
74 changes: 40 additions & 34 deletions nova_vm/src/ecmascript/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
// 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 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")]
use crate::ecmascript::builtins::structured_data::json_object::JSONObject;
#[cfg(feature = "shared-array-buffer")]
use crate::ecmascript::builtins::structured_data::shared_array_buffer_objects::{
shared_array_buffer_constructor::SharedArrayBufferConstructor,
shared_array_buffer_prototype::SharedArrayBufferPrototype,
};
#[cfg(feature = "array-buffer")]
use crate::ecmascript::builtins::{
indexed_collections::typed_array_objects::{
typed_array_constructors::{TypedArrayConstructors, TypedArrayPrototypes},
typed_array_intrinsic_object::{TypedArrayIntrinsicObject, TypedArrayPrototype},
},
structured_data::{
array_buffer_objects::{
array_buffer_constructor::ArrayBufferConstructor,
array_buffer_prototype::ArrayBufferPrototype,
},
data_view_objects::{
data_view_constructor::DataViewConstructor, data_view_prototype::DataViewPrototype,
},
},
};
use crate::{
ecmascript::{
builtins::{
Expand Down Expand Up @@ -64,13 +94,7 @@ use crate::{
},
primitive_objects::PrimitiveObject,
reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject},
structured_data::{
atomics_object::AtomicsObject,
shared_array_buffer_objects::{
shared_array_buffer_constructor::SharedArrayBufferConstructor,
shared_array_buffer_prototype::SharedArrayBufferPrototype,
},
},
structured_data::atomics_object::AtomicsObject,
text_processing::{
regexp_objects::{
regexp_constructor::RegExpConstructor, regexp_prototype::RegExpPrototype,
Expand Down Expand Up @@ -124,33 +148,6 @@ 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")]
use crate::ecmascript::builtins::structured_data::json_object::JSONObject;
#[cfg(feature = "array-buffer")]
use crate::ecmascript::builtins::{
indexed_collections::typed_array_objects::{
typed_array_constructors::{TypedArrayConstructors, TypedArrayPrototypes},
typed_array_intrinsic_object::{TypedArrayIntrinsicObject, TypedArrayPrototype},
},
structured_data::{
array_buffer_objects::{
array_buffer_constructor::ArrayBufferConstructor,
array_buffer_prototype::ArrayBufferPrototype,
},
data_view_objects::{
data_view_constructor::DataViewConstructor, data_view_prototype::DataViewPrototype,
},
},
};

#[derive(Debug, Clone)]
pub(crate) struct Intrinsics {
pub(crate) object_index_base: ObjectIndex,
Expand Down Expand Up @@ -208,6 +205,7 @@ pub enum ProtoIntrinsics {
RegExp,
Set,
SetIterator,
#[cfg(feature = "shared-array-buffer")]
SharedArrayBuffer,
String,
Symbol,
Expand Down Expand Up @@ -314,7 +312,9 @@ impl Intrinsics {
ArrayBufferPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "array-buffer")]
ArrayBufferConstructor::create_intrinsic(agent, realm);
#[cfg(feature = "shared-array-buffer")]
SharedArrayBufferPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "shared-array-buffer")]
SharedArrayBufferConstructor::create_intrinsic(agent, realm);
#[cfg(feature = "array-buffer")]
DataViewPrototype::create_intrinsic(agent, realm);
Expand Down Expand Up @@ -402,6 +402,7 @@ impl Intrinsics {
ProtoIntrinsics::RegExp => self.reg_exp_prototype().into(),
ProtoIntrinsics::Set => self.set_prototype().into(),
ProtoIntrinsics::SetIterator => self.set_iterator_prototype().into(),
#[cfg(feature = "shared-array-buffer")]
ProtoIntrinsics::SharedArrayBuffer => self.shared_array_buffer_prototype().into(),
#[cfg(feature = "array-buffer")]
ProtoIntrinsics::Uint16Array => self.uint16_array_prototype().into(),
Expand Down Expand Up @@ -1258,19 +1259,22 @@ impl Intrinsics {
}

/// %SharedArrayBuffer.prototype%
#[cfg(feature = "shared-array-buffer")]
pub(crate) fn shared_array_buffer_prototype(&self) -> OrdinaryObject {
IntrinsicObjectIndexes::SharedArrayBufferPrototype
.get_object_index(self.object_index_base)
.into()
}

/// %SharedArrayBuffer%
#[cfg(feature = "shared-array-buffer")]
pub(crate) fn shared_array_buffer(&self) -> BuiltinFunction {
IntrinsicConstructorIndexes::SharedArrayBuffer
.get_builtin_function_index(self.builtin_function_index_base)
.into()
}

#[cfg(feature = "shared-array-buffer")]
pub(crate) fn shared_array_buffer_base_object(&self) -> ObjectIndex {
IntrinsicConstructorIndexes::SharedArrayBuffer.get_object_index(self.object_index_base)
}
Expand Down Expand Up @@ -1687,7 +1691,9 @@ impl HeapMarkAndSweep for Intrinsics {
self.set_prototype().mark_values(queues);
self.set().mark_values(queues);
self.set_iterator_prototype().mark_values(queues);
#[cfg(feature = "shared-array-buffer")]
self.shared_array_buffer_prototype().mark_values(queues);
#[cfg(feature = "shared-array-buffer")]
self.shared_array_buffer().mark_values(queues);
self.string_prototype_trim_end().mark_values(queues);
self.string_prototype_trim_start().mark_values(queues);
Expand Down
Loading