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