Skip to content

Commit

Permalink
chore(heap): Move FunctionHeapData to ecmascript/types/language/function
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Oct 29, 2023
1 parent cb35c79 commit 025709b
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 46 deletions.
4 changes: 3 additions & 1 deletion nova_vm/src/ecmascript/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod language;
mod spec;

pub(crate) use language::{BigIntHeapData, NumberHeapData, ObjectHeapData, StringHeapData};
pub(crate) use language::{
BigIntHeapData, FunctionHeapData, NumberHeapData, ObjectHeapData, StringHeapData,
};
pub use language::{Function, InternalMethods, Number, Object, PropertyKey, String, Value};
pub use spec::{Base, PropertyDescriptor, Reference, ReferencedName};

Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/ecmascript/types/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod string;
mod value;

pub use bigint::{BigInt, BigIntHeapData};
pub use function::Function;
pub use function::{Function, FunctionHeapData};
pub use number::{Number, NumberHeapData};
pub use object::{InternalMethods, Object, ObjectHeapData, PropertyKey, PropertyStorage};
pub use string::{String, StringHeapData};
Expand Down
4 changes: 4 additions & 0 deletions nova_vm/src/ecmascript/types/language/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
mod data;

use super::{Object, Value};
use crate::heap::indexes::FunctionIndex;

pub use data::FunctionHeapData;

/// https://tc39.es/ecma262/#function-object
#[derive(Clone, Copy)]
pub struct Function(pub FunctionIndex);
Expand Down
15 changes: 15 additions & 0 deletions nova_vm/src/ecmascript/types/language/function/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::{ecmascript::types::Value, heap::indexes::ObjectIndex};

#[derive(Debug, Clone)]
pub struct FunctionHeapData {
pub(crate) object_index: Option<ObjectIndex>,
pub(crate) length: u8,
pub initial_name: Value,
// pub behaviour: Behaviour,
// TODO: Should we create a `BoundFunctionHeapData` for an exotic object
// that allows setting fields and other deoptimizations?
// pub(super) uses_arguments: bool,
// pub(super) bound: Option<Box<[Value]>>,
// pub(super) visible: Option<Vec<Value>>,
// TODO: Should name be here as an "internal slot" of sorts?
}
6 changes: 3 additions & 3 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use self::{
ElementsVector,
},
error::{initialize_error_heap, ErrorHeapData},
function::{initialize_function_heap, FunctionHeapData},
function::initialize_function_heap,
heap_constants::{
FIRST_CONSTRUCTOR_INDEX, LAST_BUILTIN_OBJECT_INDEX, LAST_WELL_KNOWN_SYMBOL_INDEX,
},
Expand All @@ -46,8 +46,8 @@ use crate::ecmascript::{
builtins::ArrayHeapData,
execution::{Environments, Realm, RealmIdentifier},
types::{
BigIntHeapData, Function, Number, NumberHeapData, Object, ObjectHeapData, PropertyKey,
String, StringHeapData, Value,
BigIntHeapData, Function, FunctionHeapData, Number, NumberHeapData, Object, ObjectHeapData,
PropertyKey, String, StringHeapData, Value,
},
};
use wtf8::{Wtf8, Wtf8Buf};
Expand Down
7 changes: 2 additions & 5 deletions nova_vm/src/heap/array.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use super::{
function::FunctionHeapData, heap_constants::WellKnownSymbolIndexes, indexes::FunctionIndex,
object::ObjectEntry,
};
use super::{heap_constants::WellKnownSymbolIndexes, indexes::FunctionIndex, object::ObjectEntry};
use crate::{
ecmascript::{
execution::JsResult,
types::{Object, PropertyKey, Value},
types::{FunctionHeapData, Object, PropertyKey, Value},
},
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Expand Down
7 changes: 2 additions & 5 deletions nova_vm/src/heap/array_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use super::{
function::FunctionHeapData, heap_constants::WellKnownSymbolIndexes, indexes::ObjectIndex,
object::ObjectEntry,
};
use super::{heap_constants::WellKnownSymbolIndexes, indexes::ObjectIndex, object::ObjectEntry};
use crate::{
ecmascript::types::{Object, PropertyKey, Value},
ecmascript::types::{FunctionHeapData, Object, PropertyKey, Value},
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
Expand Down
3 changes: 1 addition & 2 deletions nova_vm/src/heap/date.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use super::{
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
ecmascript::{
execution::JsResult,
types::{Object, PropertyKey, Value},
types::{FunctionHeapData, Object, PropertyKey, Value},
},
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Expand Down
3 changes: 1 addition & 2 deletions nova_vm/src/heap/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::{
function::FunctionHeapData,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
ecmascript::{
execution::JsResult,
types::{Object, PropertyKey, Value},
types::{FunctionHeapData, Object, PropertyKey, Value},
},
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Expand Down
22 changes: 2 additions & 20 deletions nova_vm/src/heap/function.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
use super::{
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use super::{heap_constants::WellKnownSymbolIndexes, indexes::FunctionIndex, object::ObjectEntry};
use crate::{
ecmascript::{
execution::JsResult,
types::{Object, PropertyKey, Value},
types::{FunctionHeapData, Object, PropertyKey, Value},
},
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
},
};

#[derive(Debug, Clone)]
pub struct FunctionHeapData {
pub(crate) object_index: Option<ObjectIndex>,
pub(crate) length: u8,
pub initial_name: Value,
// pub behaviour: Behaviour,
// TODO: Should we create a `BoundFunctionHeapData` for an exotic object
// that allows setting fields and other deoptimizations?
// pub(super) uses_arguments: bool,
// pub(super) bound: Option<Box<[Value]>>,
// pub(super) visible: Option<Vec<Value>>,
// TODO: Should name be here as an "internal slot" of sorts?
}

pub fn initialize_function_heap(heap: &mut Heap) {
let entries = vec![ObjectEntry::new_constructor_prototype_entry(
heap,
Expand Down
11 changes: 6 additions & 5 deletions nova_vm/src/heap/indexes.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::array_buffer::ArrayBufferHeapData;
use super::{
date::DateHeapData, error::ErrorHeapData, function::FunctionHeapData, regexp::RegExpHeapData,
symbol::SymbolHeapData,
date::DateHeapData, error::ErrorHeapData, regexp::RegExpHeapData, symbol::SymbolHeapData,
};
use crate::ecmascript::builtins::ArrayHeapData;
use crate::ecmascript::types::{
BigIntHeapData, NumberHeapData, ObjectHeapData, StringHeapData, Value,
use crate::ecmascript::{
builtins::ArrayHeapData,
types::{
BigIntHeapData, FunctionHeapData, NumberHeapData, ObjectHeapData, StringHeapData, Value,
},
};
use crate::Heap;
use core::fmt::Debug;
Expand Down
3 changes: 1 addition & 2 deletions nova_vm/src/heap/regexp.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use super::{
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
ecmascript::{
execution::JsResult,
types::{Object, PropertyKey, Value},
types::{FunctionHeapData, Object, PropertyKey, Value},
},
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Expand Down

0 comments on commit 025709b

Please sign in to comment.