-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move ObjectHeapData to types/language/object/data
- Loading branch information
Showing
7 changed files
with
47 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Object>, | ||
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) | ||
} | ||
} |