Skip to content

Commit ab9ad81

Browse files
authored
feat: array buffer feature (#433)
* feat: array buffer feature * feat: add dataview * feat: typedarray
1 parent 149dff9 commit ab9ad81

File tree

18 files changed

+885
-258
lines changed

18 files changed

+885
-258
lines changed

nova_vm/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ oxc_syntax = { workspace = true }
1919
rand = { workspace = true }
2020
ryu-js = { workspace = true }
2121
small_string = { path = "../small_string" }
22-
sonic-rs = { workspace = true, optional = true}
22+
sonic-rs = { workspace = true, optional = true }
2323
wtf8 = { workspace = true }
2424

2525
[features]
26-
default = ["math", "json", "date"]
26+
default = ["math", "json", "date", "array-buffer"]
2727
math = []
2828
json = ["sonic-rs"]
2929
date = []
30-
30+
array-buffer = []
3131
typescript = []
3232

3333
[build-dependencies]

nova_vm/src/ecmascript/builtins.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
1111
pub(crate) mod arguments;
1212
mod array;
13+
#[cfg(feature = "array-buffer")]
1314
mod array_buffer;
1415
pub mod bound_function;
1516
mod builtin_constructor;
1617
mod builtin_function;
1718
pub(crate) mod control_abstraction_objects;
19+
#[cfg(feature = "array-buffer")]
1820
pub(crate) mod data_view;
1921
#[cfg(feature = "date")]
2022
pub mod date;
@@ -40,6 +42,7 @@ pub(crate) mod set;
4042
pub(crate) mod shared_array_buffer;
4143
pub(crate) mod structured_data;
4244
pub(crate) mod text_processing;
45+
#[cfg(feature = "array-buffer")]
4346
pub(crate) mod typed_array;
4447
pub(crate) mod weak_map;
4548
pub(crate) mod weak_ref;
@@ -49,7 +52,9 @@ pub(crate) use arguments::*;
4952
pub(crate) use array::abstract_operations::*;
5053
pub use array::Array;
5154
pub(crate) use array::{ArrayHeapData, SealableElementsVector};
55+
#[cfg(feature = "array-buffer")]
5256
pub use array_buffer::ArrayBuffer;
57+
#[cfg(feature = "array-buffer")]
5358
pub(crate) use array_buffer::ArrayBufferHeapData;
5459
pub use builtin_constructor::BuiltinConstructorFunction;
5560
pub(crate) use builtin_constructor::{create_builtin_constructor, BuiltinConstructorArgs};

nova_vm/src/ecmascript/builtins/indexed_collections.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
pub(crate) mod array_objects;
6+
#[cfg(feature = "array-buffer")]
67
pub(crate) mod typed_array_objects;

nova_vm/src/ecmascript/builtins/indexed_collections/array_objects/array_iterator_objects/array_iterator_prototype.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl ArrayIteratorPrototype {
5353
let len: i64 = match array {
5454
// i. If array has a [[TypedArrayName]] internal slot, then
5555
// TODO!
56+
#[cfg(feature = "array-buffer")]
5657
Object::Int8Array(_)
5758
| Object::Uint8Array(_)
5859
| Object::Uint8ClampedArray(_)

nova_vm/src/ecmascript/builtins/ordinary.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use crate::{
2828
use super::date::data::DateHeapData;
2929
use super::{
3030
control_abstraction_objects::generator_objects::GeneratorHeapData,
31-
data_view::data::DataViewHeapData,
3231
error::ErrorHeapData,
3332
finalization_registry::data::FinalizationRegistryHeapData,
3433
indexed_collections::array_objects::array_iterator_objects::array_iterator::ArrayIteratorHeapData,
@@ -42,11 +41,14 @@ use super::{
4241
regexp::RegExpHeapData,
4342
set::data::SetHeapData,
4443
shared_array_buffer::data::SharedArrayBufferHeapData,
45-
typed_array::data::TypedArrayHeapData,
4644
weak_map::data::WeakMapHeapData,
4745
weak_ref::data::WeakRefHeapData,
4846
weak_set::data::WeakSetHeapData,
49-
ArrayBufferHeapData, ArrayHeapData,
47+
ArrayHeapData,
48+
};
49+
#[cfg(feature = "array-buffer")]
50+
use super::{
51+
data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData,
5052
};
5153

5254
impl Index<OrdinaryObject> for Agent {
@@ -801,6 +803,7 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
801803

802804
let object = match proto_intrinsics {
803805
ProtoIntrinsics::Array => agent.heap.create(ArrayHeapData::default()).into_object(),
806+
#[cfg(feature = "array-buffer")]
804807
ProtoIntrinsics::ArrayBuffer => agent
805808
.heap
806809
.create(ArrayBufferHeapData::default())
@@ -889,23 +892,28 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
889892
.into_object(),
890893
ProtoIntrinsics::AsyncFunction => todo!(),
891894
ProtoIntrinsics::AsyncGeneratorFunction => todo!(),
895+
#[cfg(feature = "array-buffer")]
892896
ProtoIntrinsics::BigInt64Array => agent
893897
.heap
894898
.create(TypedArrayHeapData::default())
895899
.into_object(),
900+
#[cfg(feature = "array-buffer")]
896901
ProtoIntrinsics::BigUint64Array => agent
897902
.heap
898903
.create(TypedArrayHeapData::default())
899904
.into_object(),
905+
#[cfg(feature = "array-buffer")]
900906
ProtoIntrinsics::DataView => agent.heap.create(DataViewHeapData::default()).into_object(),
901907
ProtoIntrinsics::FinalizationRegistry => agent
902908
.heap
903909
.create(FinalizationRegistryHeapData::default())
904910
.into_object(),
911+
#[cfg(feature = "array-buffer")]
905912
ProtoIntrinsics::Float32Array => agent
906913
.heap
907914
.create(TypedArrayHeapData::default())
908915
.into_object(),
916+
#[cfg(feature = "array-buffer")]
909917
ProtoIntrinsics::Float64Array => agent
910918
.heap
911919
.create(TypedArrayHeapData::default())
@@ -915,14 +923,17 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
915923
.create(GeneratorHeapData::default())
916924
.into_object(),
917925
ProtoIntrinsics::GeneratorFunction => todo!(),
926+
#[cfg(feature = "array-buffer")]
918927
ProtoIntrinsics::Int16Array => agent
919928
.heap
920929
.create(TypedArrayHeapData::default())
921930
.into_object(),
931+
#[cfg(feature = "array-buffer")]
922932
ProtoIntrinsics::Int32Array => agent
923933
.heap
924934
.create(TypedArrayHeapData::default())
925935
.into_object(),
936+
#[cfg(feature = "array-buffer")]
926937
ProtoIntrinsics::Int8Array => agent
927938
.heap
928939
.create(TypedArrayHeapData::default())
@@ -943,14 +954,17 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
943954
.heap
944955
.create(SharedArrayBufferHeapData::default())
945956
.into_object(),
957+
#[cfg(feature = "array-buffer")]
946958
ProtoIntrinsics::Uint16Array => agent
947959
.heap
948960
.create(TypedArrayHeapData::default())
949961
.into_object(),
962+
#[cfg(feature = "array-buffer")]
950963
ProtoIntrinsics::Uint32Array => agent
951964
.heap
952965
.create(TypedArrayHeapData::default())
953966
.into_object(),
967+
#[cfg(feature = "array-buffer")]
954968
ProtoIntrinsics::Uint8Array => agent
955969
.heap
956970
.create(TypedArrayHeapData::default())
@@ -1033,15 +1047,19 @@ pub(crate) fn get_prototype_from_constructor(
10331047
ProtoIntrinsics::AggregateError => Some(intrinsics.aggregate_error().into_function()),
10341048
ProtoIntrinsics::Array => Some(intrinsics.array().into_function()),
10351049
ProtoIntrinsics::ArrayIterator => None,
1050+
#[cfg(feature = "array-buffer")]
10361051
ProtoIntrinsics::ArrayBuffer => Some(intrinsics.array_buffer().into_function()),
10371052
ProtoIntrinsics::AsyncFunction => Some(intrinsics.async_function().into_function()),
10381053
ProtoIntrinsics::AsyncGeneratorFunction => {
10391054
Some(intrinsics.async_generator_function().into_function())
10401055
}
10411056
ProtoIntrinsics::BigInt => Some(intrinsics.big_int().into_function()),
1057+
#[cfg(feature = "array-buffer")]
10421058
ProtoIntrinsics::BigInt64Array => Some(intrinsics.big_int64_array().into_function()),
1059+
#[cfg(feature = "array-buffer")]
10431060
ProtoIntrinsics::BigUint64Array => Some(intrinsics.big_uint64_array().into_function()),
10441061
ProtoIntrinsics::Boolean => Some(intrinsics.boolean().into_function()),
1062+
#[cfg(feature = "array-buffer")]
10451063
ProtoIntrinsics::DataView => Some(intrinsics.data_view().into_function()),
10461064
#[cfg(feature = "date")]
10471065
ProtoIntrinsics::Date => Some(intrinsics.date().into_function()),
@@ -1050,15 +1068,20 @@ pub(crate) fn get_prototype_from_constructor(
10501068
ProtoIntrinsics::FinalizationRegistry => {
10511069
Some(intrinsics.finalization_registry().into_function())
10521070
}
1071+
#[cfg(feature = "array-buffer")]
10531072
ProtoIntrinsics::Float32Array => Some(intrinsics.float32_array().into_function()),
1073+
#[cfg(feature = "array-buffer")]
10541074
ProtoIntrinsics::Float64Array => Some(intrinsics.float64_array().into_function()),
10551075
ProtoIntrinsics::Function => Some(intrinsics.function().into_function()),
10561076
ProtoIntrinsics::Generator => None,
10571077
ProtoIntrinsics::GeneratorFunction => {
10581078
Some(intrinsics.generator_function().into_function())
10591079
}
1080+
#[cfg(feature = "array-buffer")]
10601081
ProtoIntrinsics::Int16Array => Some(intrinsics.int16_array().into_function()),
1082+
#[cfg(feature = "array-buffer")]
10611083
ProtoIntrinsics::Int32Array => Some(intrinsics.int32_array().into_function()),
1084+
#[cfg(feature = "array-buffer")]
10621085
ProtoIntrinsics::Int8Array => Some(intrinsics.int8_array().into_function()),
10631086
ProtoIntrinsics::Map => Some(intrinsics.map().into_function()),
10641087
ProtoIntrinsics::MapIterator => None,
@@ -1077,8 +1100,11 @@ pub(crate) fn get_prototype_from_constructor(
10771100
ProtoIntrinsics::Symbol => Some(intrinsics.symbol().into_function()),
10781101
ProtoIntrinsics::SyntaxError => Some(intrinsics.syntax_error().into_function()),
10791102
ProtoIntrinsics::TypeError => Some(intrinsics.type_error().into_function()),
1103+
#[cfg(feature = "array-buffer")]
10801104
ProtoIntrinsics::Uint16Array => Some(intrinsics.uint16_array().into_function()),
1105+
#[cfg(feature = "array-buffer")]
10811106
ProtoIntrinsics::Uint32Array => Some(intrinsics.uint32_array().into_function()),
1107+
#[cfg(feature = "array-buffer")]
10821108
ProtoIntrinsics::Uint8Array => Some(intrinsics.uint8_array().into_function()),
10831109
ProtoIntrinsics::UriError => Some(intrinsics.uri_error().into_function()),
10841110
ProtoIntrinsics::WeakMap => Some(intrinsics.weak_map().into_function()),

nova_vm/src/ecmascript/builtins/structured_data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
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+
#[cfg(feature = "array-buffer")]
56
pub(crate) mod array_buffer_objects;
67
pub(crate) mod atomics_object;
8+
#[cfg(feature = "array-buffer")]
79
pub(crate) mod data_view_objects;
810
#[cfg(feature = "json")]
911
pub(crate) mod json_object;

0 commit comments

Comments
 (0)