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 f396607 commit 144918c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
7 changes: 7 additions & 0 deletions nova_vm/src/ecmascript/builtins.rs
Original file line number Diff line number Diff line change
@@ -1,9 +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(crate) use array::data::ArrayHeapData;
pub use array::ArrayConstructor;
pub use builtin_function::{
create_builtin_function, todo_builtin, ArgumentsList, Behaviour, Builtin, BuiltinFunctionArgs,
Expand Down
6 changes: 6 additions & 0 deletions nova_vm/src/ecmascript/builtins/array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! ### 10.4.2 Array Exotic Objects
//!
//! https://tc39.es/ecma262/#sec-array-exotic-objects

pub(crate) mod data;

use super::{create_builtin_function, ArgumentsList, Behaviour, Builtin, BuiltinFunctionArgs};
use crate::ecmascript::{
execution::{Agent, JsResult},
Expand Down
14 changes: 14 additions & 0 deletions nova_vm/src/ecmascript/builtins/array/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::heap::{element_array::ElementsVector, indexes::ObjectIndex};

/// 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,
}
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::ecmascript::{
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 @@ -16,13 +13,6 @@ use crate::{
},
};

#[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::ecmascript::builtins::ArrayHeapData;
use crate::ecmascript::types::{ObjectHeapData, StringHeapData, Value};
use crate::Heap;
use core::fmt::Debug;
Expand Down

0 comments on commit 144918c

Please sign in to comment.