Skip to content

Commit

Permalink
chore(heap): Move ArrayHeapData to builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Oct 26, 2023
1 parent f1ee408 commit 570afb1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
8 changes: 7 additions & 1 deletion nova_vm/src/builtins.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
//! # 10 Ordinary and Exotic Objects Behaviours
//!
//! Currently only contains code related to subsections 10.2, 10.3 and 10.4.
//!
//! https://tc39.es/ecma262/#sec-ordinary-and-exotic-objects-behaviours
mod array;
mod builtin_function;
mod ecmascript_function;
mod number;
pub mod ordinary;

pub use array::ArrayConstructor;
pub use array::{ArrayConstructor, ArrayHeapData};
pub use builtin_function::{
create_builtin_function, todo_builtin, ArgumentsList, Behaviour, Builtin, BuiltinFunctionArgs,
ConstructorFn, RegularFn as JsFunction, RegularFn,
Expand Down
18 changes: 18 additions & 0 deletions nova_vm/src/builtins/array.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
//! ### 10.4.2 Array Exotic Objects
//!
//! https://tc39.es/ecma262/#sec-array-exotic-objects
use super::{create_builtin_function, ArgumentsList, Behaviour, Builtin, BuiltinFunctionArgs};
use crate::{
execution::{Agent, JsResult},
heap::{element_array::ElementsVector, indexes::ObjectIndex},
types::{Object, Value},
};

/// An Array is an exotic object that gives special treatment to array index property keys (see 6.1.7).
/// A property whose property name is an array index is also called an element. Every Array has a
/// non-configurable "**length**" property whose value is always a non-negative integral Number whose
/// mathematical value is strictly less than 2**32.
#[derive(Debug, Clone, Copy)]
pub struct ArrayHeapData {
pub object_index: Option<ObjectIndex>,
// TODO: Use enum { ElementsVector, SmallVec<[Value; 3]> }
// to get some inline benefit together with a 32 byte size
// for ArrayHeapData to fit two in one cache line.
pub elements: ElementsVector,
}

pub struct ArrayConstructor;

impl Builtin for ArrayConstructor {
Expand Down
3 changes: 2 additions & 1 deletion nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod symbol;

pub use self::heap_constants::BuiltinObjectIndexes;
use self::{
array::{initialize_array_heap, ArrayHeapData},
array::initialize_array_heap,
array_buffer::{initialize_array_buffer_heap, ArrayBufferHeapData},
bigint::{initialize_bigint_heap, BigIntHeapData},
boolean::initialize_boolean_heap,
Expand All @@ -43,6 +43,7 @@ use self::{
symbol::{initialize_symbol_heap, SymbolHeapData},
};
use crate::{
builtins::ArrayHeapData,
execution::{Environments, Realm, RealmIdentifier},
types::{Function, Number, Object, ObjectHeapData, PropertyKey, String, StringHeapData, Value},
};
Expand Down
12 changes: 1 addition & 11 deletions nova_vm/src/heap/array.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{
element_array::ElementsVector,
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
function::FunctionHeapData, heap_constants::WellKnownSymbolIndexes, indexes::FunctionIndex,
object::ObjectEntry,
};
use crate::{
Expand All @@ -14,13 +11,6 @@ use crate::{
types::{Object, PropertyKey, Value},
};

#[derive(Debug, Clone, Copy)]
pub struct ArrayHeapData {
pub object_index: Option<ObjectIndex>,
// TODO: Use SmallVec<[Value; 4]>
pub elements: ElementsVector,
}

pub fn initialize_array_heap(heap: &mut Heap) {
let species_function_name = Value::from_str(heap, "get [Symbol.species]");
let at_key = PropertyKey::from_str(heap, "at");
Expand Down
6 changes: 3 additions & 3 deletions nova_vm/src/heap/indexes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::array_buffer::ArrayBufferHeapData;
use super::{
array::ArrayHeapData, bigint::BigIntHeapData, date::DateHeapData, error::ErrorHeapData,
function::FunctionHeapData, number::NumberHeapData, regexp::RegExpHeapData,
symbol::SymbolHeapData,
bigint::BigIntHeapData, date::DateHeapData, error::ErrorHeapData, function::FunctionHeapData,
number::NumberHeapData, regexp::RegExpHeapData, symbol::SymbolHeapData,
};
use crate::builtins::ArrayHeapData;
use crate::types::{ObjectHeapData, StringHeapData, Value};
use crate::Heap;
use core::fmt::Debug;
Expand Down

0 comments on commit 570afb1

Please sign in to comment.