|
|
|
@ -17,7 +17,6 @@ use crate::{
|
|
|
|
|
property::{Attribute, PropertyDescriptor, PropertyKey}, |
|
|
|
|
BoaProfiler, Context, JsBigInt, JsString, JsSymbol, Value, |
|
|
|
|
}; |
|
|
|
|
use rustc_hash::FxHashMap; |
|
|
|
|
use std::{ |
|
|
|
|
any::Any, |
|
|
|
|
fmt::{self, Debug, Display}, |
|
|
|
@ -30,11 +29,11 @@ mod tests;
|
|
|
|
|
|
|
|
|
|
mod gcobject; |
|
|
|
|
mod internal_methods; |
|
|
|
|
mod iter; |
|
|
|
|
mod property_map; |
|
|
|
|
|
|
|
|
|
use crate::builtins::object::for_in_iterator::ForInIterator; |
|
|
|
|
pub use gcobject::{GcObject, RecursionLimiter, Ref, RefMut}; |
|
|
|
|
pub use iter::*; |
|
|
|
|
pub use property_map::*; |
|
|
|
|
|
|
|
|
|
/// Static `prototype`, usually set on constructors as a key to point to their respective prototype object.
|
|
|
|
|
pub static PROTOTYPE: &str = "prototype"; |
|
|
|
@ -67,11 +66,7 @@ impl<T: Any + Debug + Trace> NativeObject for T {
|
|
|
|
|
pub struct Object { |
|
|
|
|
/// The type of the object.
|
|
|
|
|
pub data: ObjectData, |
|
|
|
|
indexed_properties: FxHashMap<u32, PropertyDescriptor>, |
|
|
|
|
/// Properties
|
|
|
|
|
string_properties: FxHashMap<JsString, PropertyDescriptor>, |
|
|
|
|
/// Symbol Properties
|
|
|
|
|
symbol_properties: FxHashMap<JsSymbol, PropertyDescriptor>, |
|
|
|
|
properties: PropertyMap, |
|
|
|
|
/// Instance prototype `__proto__`.
|
|
|
|
|
prototype: Value, |
|
|
|
|
/// Whether it can have new properties added to it.
|
|
|
|
@ -142,9 +137,7 @@ impl Default for Object {
|
|
|
|
|
fn default() -> Self { |
|
|
|
|
Self { |
|
|
|
|
data: ObjectData::Ordinary, |
|
|
|
|
indexed_properties: FxHashMap::default(), |
|
|
|
|
string_properties: FxHashMap::default(), |
|
|
|
|
symbol_properties: FxHashMap::default(), |
|
|
|
|
properties: PropertyMap::default(), |
|
|
|
|
prototype: Value::null(), |
|
|
|
|
extensible: true, |
|
|
|
|
} |
|
|
|
@ -164,9 +157,7 @@ impl Object {
|
|
|
|
|
|
|
|
|
|
Self { |
|
|
|
|
data: ObjectData::Function(function), |
|
|
|
|
indexed_properties: FxHashMap::default(), |
|
|
|
|
string_properties: FxHashMap::default(), |
|
|
|
|
symbol_properties: FxHashMap::default(), |
|
|
|
|
properties: PropertyMap::default(), |
|
|
|
|
prototype, |
|
|
|
|
extensible: true, |
|
|
|
|
} |
|
|
|
@ -191,9 +182,7 @@ impl Object {
|
|
|
|
|
pub fn boolean(value: bool) -> Self { |
|
|
|
|
Self { |
|
|
|
|
data: ObjectData::Boolean(value), |
|
|
|
|
indexed_properties: FxHashMap::default(), |
|
|
|
|
string_properties: FxHashMap::default(), |
|
|
|
|
symbol_properties: FxHashMap::default(), |
|
|
|
|
properties: PropertyMap::default(), |
|
|
|
|
prototype: Value::null(), |
|
|
|
|
extensible: true, |
|
|
|
|
} |
|
|
|
@ -204,9 +193,7 @@ impl Object {
|
|
|
|
|
pub fn number(value: f64) -> Self { |
|
|
|
|
Self { |
|
|
|
|
data: ObjectData::Number(value), |
|
|
|
|
indexed_properties: FxHashMap::default(), |
|
|
|
|
string_properties: FxHashMap::default(), |
|
|
|
|
symbol_properties: FxHashMap::default(), |
|
|
|
|
properties: PropertyMap::default(), |
|
|
|
|
prototype: Value::null(), |
|
|
|
|
extensible: true, |
|
|
|
|
} |
|
|
|
@ -220,9 +207,7 @@ impl Object {
|
|
|
|
|
{ |
|
|
|
|
Self { |
|
|
|
|
data: ObjectData::String(value.into()), |
|
|
|
|
indexed_properties: FxHashMap::default(), |
|
|
|
|
string_properties: FxHashMap::default(), |
|
|
|
|
symbol_properties: FxHashMap::default(), |
|
|
|
|
properties: PropertyMap::default(), |
|
|
|
|
prototype: Value::null(), |
|
|
|
|
extensible: true, |
|
|
|
|
} |
|
|
|
@ -233,9 +218,7 @@ impl Object {
|
|
|
|
|
pub fn bigint(value: JsBigInt) -> Self { |
|
|
|
|
Self { |
|
|
|
|
data: ObjectData::BigInt(value), |
|
|
|
|
indexed_properties: FxHashMap::default(), |
|
|
|
|
string_properties: FxHashMap::default(), |
|
|
|
|
symbol_properties: FxHashMap::default(), |
|
|
|
|
properties: PropertyMap::default(), |
|
|
|
|
prototype: Value::null(), |
|
|
|
|
extensible: true, |
|
|
|
|
} |
|
|
|
@ -249,9 +232,7 @@ impl Object {
|
|
|
|
|
{ |
|
|
|
|
Self { |
|
|
|
|
data: ObjectData::NativeObject(Box::new(value)), |
|
|
|
|
indexed_properties: FxHashMap::default(), |
|
|
|
|
string_properties: FxHashMap::default(), |
|
|
|
|
symbol_properties: FxHashMap::default(), |
|
|
|
|
properties: PropertyMap::default(), |
|
|
|
|
prototype: Value::null(), |
|
|
|
|
extensible: true, |
|
|
|
|
} |
|
|
|
@ -610,6 +591,11 @@ impl Object {
|
|
|
|
|
_ => None, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
pub fn properties(&self) -> &PropertyMap { |
|
|
|
|
&self.properties |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The functions binding.
|
|
|
|
|