Skip to content

Commit ab64d9c

Browse files
authored
feat: atomics behind atomics feature to complete atomic things (#444)
* feat: atomics behind atomics feature * feat: atomics feat depend on ab and sab
1 parent f1e4e28 commit ab64d9c

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

nova_vm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ unicode-normalization = { workspace = true }
2424
wtf8 = { workspace = true }
2525

2626
[features]
27-
default = ["math", "json", "date", "array-buffer", "shared-array-buffer", "weak-refs"]
27+
default = ["math", "json", "date", "array-buffer", "shared-array-buffer", "weak-refs", "atomics"]
2828
math = []
2929
json = ["sonic-rs"]
3030
date = []
3131
array-buffer = []
3232
shared-array-buffer = []
3333
weak-refs = []
34+
atomics = ["array-buffer", "shared-array-buffer"]
3435
typescript = []
3536

3637
[build-dependencies]

nova_vm/src/ecmascript/builtins/structured_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#[cfg(feature = "array-buffer")]
66
pub(crate) mod array_buffer_objects;
7+
#[cfg(feature = "atomics")]
78
pub(crate) mod atomics_object;
89
#[cfg(feature = "array-buffer")]
910
pub(crate) mod data_view_objects;

nova_vm/src/ecmascript/execution/realm.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -982,17 +982,19 @@ pub(crate) fn set_default_global_bindings(
982982
// 19.4 Other Properties of the Global Object
983983
{
984984
// 19.4.1 Atomics
985-
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Atomics);
986-
let value = agent.get_realm(realm_id).intrinsics().atomics();
987-
let desc = PropertyDescriptor {
988-
value: Some(value.into_value()),
989-
writable: Some(true),
990-
enumerable: Some(false),
991-
configurable: Some(true),
992-
..Default::default()
993-
};
994-
define_property_or_throw(agent, global, name, desc)?;
995-
985+
#[cfg(feature = "atomics")]
986+
{
987+
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Atomics);
988+
let value = agent.get_realm(realm_id).intrinsics().atomics();
989+
let desc = PropertyDescriptor {
990+
value: Some(value.into_value()),
991+
writable: Some(true),
992+
enumerable: Some(false),
993+
configurable: Some(true),
994+
..Default::default()
995+
};
996+
define_property_or_throw(agent, global, name, desc)?;
997+
}
996998
// 19.4.2 JSON
997999
#[cfg(feature = "json")]
9981000
{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use crate::ecmascript::builtins::numbers_and_dates::date_objects::{
2222
};
2323
#[cfg(feature = "math")]
2424
use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject;
25+
#[cfg(feature = "atomics")]
26+
use crate::ecmascript::builtins::structured_data::atomics_object::AtomicsObject;
2527
#[cfg(feature = "json")]
2628
use crate::ecmascript::builtins::structured_data::json_object::JSONObject;
2729
#[cfg(feature = "shared-array-buffer")]
@@ -96,7 +98,6 @@ use crate::{
9698
},
9799
primitive_objects::PrimitiveObject,
98100
reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject},
99-
structured_data::atomics_object::AtomicsObject,
100101
text_processing::{
101102
regexp_objects::{
102103
regexp_constructor::RegExpConstructor, regexp_prototype::RegExpPrototype,
@@ -149,7 +150,6 @@ use crate::{
149150
IntrinsicObjectIndexes, IntrinsicPrimitiveObjectIndexes, WorkQueues,
150151
},
151152
};
152-
153153
#[derive(Debug, Clone)]
154154
pub(crate) struct Intrinsics {
155155
pub(crate) object_index_base: ObjectIndex,
@@ -329,6 +329,7 @@ impl Intrinsics {
329329
DataViewPrototype::create_intrinsic(agent, realm);
330330
#[cfg(feature = "array-buffer")]
331331
DataViewConstructor::create_intrinsic(agent, realm);
332+
#[cfg(feature = "atomics")]
332333
AtomicsObject::create_intrinsic(agent, realm);
333334
#[cfg(feature = "json")]
334335
JSONObject::create_intrinsic(agent, realm);
@@ -612,6 +613,7 @@ impl Intrinsics {
612613
}
613614

614615
/// %Atomics%
616+
#[cfg(feature = "atomics")]
615617
pub(crate) fn atomics(&self) -> OrdinaryObject {
616618
IntrinsicObjectIndexes::AtomicsObject
617619
.get_object_index(self.object_index_base)
@@ -1618,6 +1620,7 @@ impl HeapMarkAndSweep for Intrinsics {
16181620
self.async_generator_function().mark_values(queues);
16191621
self.async_generator_prototype().mark_values(queues);
16201622
self.async_iterator_prototype().mark_values(queues);
1623+
#[cfg(feature = "atomics")]
16211624
self.atomics().mark_values(queues);
16221625
self.big_int_prototype().mark_values(queues);
16231626
self.big_int().mark_values(queues);

nova_vm/src/heap/heap_constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub(crate) enum IntrinsicObjectIndexes {
7474
SharedArrayBufferPrototype,
7575
#[cfg(feature = "array-buffer")]
7676
DataViewPrototype,
77+
#[cfg(feature = "atomics")]
7778
AtomicsObject,
7879
JSONObject,
7980

0 commit comments

Comments
 (0)