diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index d3a87100..5931ce41 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -37,14 +37,14 @@ use self::{ indexes::{BaseIndex, FunctionIndex, NumberIndex, ObjectIndex, StringIndex}, math::initialize_math_object, number::{initialize_number_heap, NumberHeapData}, - object::{initialize_object_heap, ObjectEntry, ObjectHeapData, PropertyDescriptor}, + object::{initialize_object_heap, ObjectEntry, PropertyDescriptor}, regexp::{initialize_regexp_heap, RegExpHeapData}, string::initialize_string_heap, symbol::{initialize_symbol_heap, SymbolHeapData}, }; use crate::{ execution::{Environments, Realm, RealmIdentifier}, - types::{Function, Number, Object, PropertyKey, String, StringHeapData, Value}, + types::{Function, Number, Object, ObjectHeapData, PropertyKey, String, StringHeapData, Value}, }; use wtf8::{Wtf8, Wtf8Buf}; diff --git a/nova_vm/src/heap/indexes.rs b/nova_vm/src/heap/indexes.rs index ba1fe4a8..eb360dbc 100644 --- a/nova_vm/src/heap/indexes.rs +++ b/nova_vm/src/heap/indexes.rs @@ -1,10 +1,10 @@ use super::array_buffer::ArrayBufferHeapData; use super::{ array::ArrayHeapData, bigint::BigIntHeapData, date::DateHeapData, error::ErrorHeapData, - function::FunctionHeapData, number::NumberHeapData, object::ObjectHeapData, - regexp::RegExpHeapData, symbol::SymbolHeapData, + function::FunctionHeapData, number::NumberHeapData, regexp::RegExpHeapData, + symbol::SymbolHeapData, }; -use crate::types::{StringHeapData, Value}; +use crate::types::{ObjectHeapData, StringHeapData, Value}; use crate::Heap; use core::fmt::Debug; use std::hash::{Hash, Hasher}; diff --git a/nova_vm/src/heap/object.rs b/nova_vm/src/heap/object.rs index 0bd9edee..d9b31bb2 100644 --- a/nova_vm/src/heap/object.rs +++ b/nova_vm/src/heap/object.rs @@ -1,7 +1,4 @@ -use super::{ - element_array::ElementsVector, - indexes::{FunctionIndex, ObjectIndex, SymbolIndex}, -}; +use super::indexes::{FunctionIndex, ObjectIndex, SymbolIndex}; use crate::{ execution::JsResult, heap::{ @@ -203,48 +200,6 @@ impl PropertyDescriptor { } } -#[derive(Debug, Clone, Copy)] -pub struct ObjectHeapData { - pub extensible: bool, - pub prototype: Option, - pub keys: ElementsVector, - pub values: ElementsVector, -} - -impl ObjectHeapData { - pub fn new( - extensible: bool, - prototype: Value, - keys: ElementsVector, - values: ElementsVector, - ) -> Self { - let prototype = if prototype.is_null() { - None - } else { - // TODO: Throw error. - Some(Object::try_from(prototype).unwrap()) - }; - Self { - extensible, - // TODO: Number, Boolean, etc. objects exist. These can all be - // modeled with their own heap vector or alternatively by adding - // a [[PrimitiveValue]] field to objects: Normally this field is None - // to signal that the object is its own primitive value. For - // Number objects etc the field is Some(Value). - // TODO: Move prototype and key vector into shapes - prototype, - // TODO: Consider using SmallVec<[Option; 3]> or such? - keys, - values, - } - } - - pub fn has(&self, heap: &Heap, key: Value) -> bool { - debug_assert!(key.is_string() || key.is_number() || key.is_symbol()); - heap.elements.has(self.keys, key) - } -} - pub fn initialize_object_heap(heap: &mut Heap) { let entries = vec![ ObjectEntry::new_prototype_function_entry(heap, "assign", 1, true), diff --git a/nova_vm/src/types.rs b/nova_vm/src/types.rs index 0507c298..2ce6fd4c 100644 --- a/nova_vm/src/types.rs +++ b/nova_vm/src/types.rs @@ -1,6 +1,7 @@ mod language; mod spec; +pub(crate) use language::ObjectHeapData; pub(crate) use language::StringHeapData; pub use language::{Function, InternalMethods, Number, Object, PropertyKey, String, Value}; pub use spec::{Base, PropertyDescriptor, Reference, ReferencedName}; diff --git a/nova_vm/src/types/language.rs b/nova_vm/src/types/language.rs index 89815acc..f430d83d 100644 --- a/nova_vm/src/types/language.rs +++ b/nova_vm/src/types/language.rs @@ -8,7 +8,7 @@ mod value; pub use bigint::BigInt; pub use function::Function; pub use number::Number; -pub use object::{InternalMethods, Object, ObjectData, PropertyKey, PropertyStorage}; +pub use object::{InternalMethods, Object, ObjectHeapData, PropertyKey, PropertyStorage}; pub(crate) use string::data::StringHeapData; pub use string::String; pub use value::Value; diff --git a/nova_vm/src/types/language/object.rs b/nova_vm/src/types/language/object.rs index 92b985f9..1a7a9e18 100644 --- a/nova_vm/src/types/language/object.rs +++ b/nova_vm/src/types/language/object.rs @@ -17,7 +17,7 @@ use crate::{ Heap, }; -pub use data::ObjectData; +pub use data::ObjectHeapData; pub use internal_methods::InternalMethods; pub use property_key::PropertyKey; pub use property_storage::PropertyStorage; diff --git a/nova_vm/src/types/language/object/data.rs b/nova_vm/src/types/language/object/data.rs index 4ab49cd6..64c8b6a1 100644 --- a/nova_vm/src/types/language/object/data.rs +++ b/nova_vm/src/types/language/object/data.rs @@ -1,10 +1,43 @@ use super::Object; +use crate::{heap::element_array::ElementsVector, types::Value, Heap}; -#[derive(Debug)] -pub struct ObjectData { - /// [[Prototype]] +#[derive(Debug, Clone, Copy)] +pub struct ObjectHeapData { + pub extensible: bool, pub prototype: Option, + pub keys: ElementsVector, + pub values: ElementsVector, +} - /// [[Extensible]] - pub extensible: bool, +impl ObjectHeapData { + pub fn new( + extensible: bool, + prototype: Value, + keys: ElementsVector, + values: ElementsVector, + ) -> Self { + let prototype = if prototype.is_null() { + None + } else { + // TODO: Throw error. + Some(Object::try_from(prototype).unwrap()) + }; + Self { + extensible, + // TODO: Number, Boolean, etc. objects exist. These can all be + // modeled with their own heap vector or alternatively by adding + // a [[PrimitiveValue]] field to objects: Normally this field is None + // to signal that the object is its own primitive value. For + // Number objects etc the field is Some(Value). + // TODO: Move prototype and key vector into shapes + prototype, + keys, + values, + } + } + + pub fn has(&self, heap: &Heap, key: Value) -> bool { + debug_assert!(key.is_string() || key.is_number() || key.is_symbol()); + heap.elements.has(self.keys, key) + } }