diff --git a/nova_vm/src/builtins.rs b/nova_vm/src/builtins.rs index a840bcf34..2ab3a0bc5 100644 --- a/nova_vm/src/builtins.rs +++ b/nova_vm/src/builtins.rs @@ -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, diff --git a/nova_vm/src/builtins/array.rs b/nova_vm/src/builtins/array.rs index b20cca7a3..24ad3458d 100644 --- a/nova_vm/src/builtins/array.rs +++ b/nova_vm/src/builtins/array.rs @@ -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, + // 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 { diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index 5931ce412..92d3c411c 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -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, @@ -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}, }; diff --git a/nova_vm/src/heap/array.rs b/nova_vm/src/heap/array.rs index b4c120770..a91144cbf 100644 --- a/nova_vm/src/heap/array.rs +++ b/nova_vm/src/heap/array.rs @@ -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::{ @@ -14,13 +11,6 @@ use crate::{ types::{Object, PropertyKey, Value}, }; -#[derive(Debug, Clone, Copy)] -pub struct ArrayHeapData { - pub object_index: Option, - // 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"); diff --git a/nova_vm/src/heap/indexes.rs b/nova_vm/src/heap/indexes.rs index eb360dbc7..1d0348e30 100644 --- a/nova_vm/src/heap/indexes.rs +++ b/nova_vm/src/heap/indexes.rs @@ -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;