@ -26,13 +26,17 @@ pub type RefMut<'a, T, U> = boa_gc::RefMut<'a, T, U>;
/// Garbage collected `Object`.
/// Garbage collected `Object`.
#[ derive(Trace, Finalize, Clone, Default) ]
#[ derive(Trace, Finalize, Clone, Default) ]
pub struct JsObject ( Gc < boa_gc ::Cell < Object > > ) ;
pub struct JsObject {
inner : Gc < boa_gc ::Cell < Object > > ,
}
impl JsObject {
impl JsObject {
/// Create a new `JsObject` from an internal `Object`.
/// Create a new `JsObject` from an internal `Object`.
#[ inline ]
#[ inline ]
fn from_object ( object : Object ) -> Self {
fn from_object ( object : Object ) -> Self {
Self ( Gc ::new ( boa_gc ::Cell ::new ( object ) ) )
Self {
inner : Gc ::new ( boa_gc ::Cell ::new ( object ) ) ,
}
}
}
/// Create a new empty `JsObject`, with `prototype` set to `JsValue::Null`
/// Create a new empty `JsObject`, with `prototype` set to `JsValue::Null`
@ -90,7 +94,7 @@ impl JsObject {
/// This is the non-panicking variant of [`borrow`](#method.borrow).
/// This is the non-panicking variant of [`borrow`](#method.borrow).
#[ inline ]
#[ inline ]
pub fn try_borrow ( & self ) -> StdResult < Ref < ' _ , Object > , BorrowError > {
pub fn try_borrow ( & self ) -> StdResult < Ref < ' _ , Object > , BorrowError > {
self . 0 .try_borrow ( ) . map_err ( | _ | BorrowError )
self . inner . try_borrow ( ) . map_err ( | _ | BorrowError )
}
}
/// Mutably borrows the object, returning an error if the value is currently borrowed.
/// Mutably borrows the object, returning an error if the value is currently borrowed.
@ -101,7 +105,7 @@ impl JsObject {
/// This is the non-panicking variant of [`borrow_mut`](#method.borrow_mut).
/// This is the non-panicking variant of [`borrow_mut`](#method.borrow_mut).
#[ inline ]
#[ inline ]
pub fn try_borrow_mut ( & self ) -> StdResult < RefMut < ' _ , Object , Object > , BorrowMutError > {
pub fn try_borrow_mut ( & self ) -> StdResult < RefMut < ' _ , Object , Object > , BorrowMutError > {
self . 0 .try_borrow_mut ( ) . map_err ( | _ | BorrowMutError )
self . inner . try_borrow_mut ( ) . map_err ( | _ | BorrowMutError )
}
}
/// Checks if the garbage collected memory is the same.
/// Checks if the garbage collected memory is the same.
@ -669,7 +673,7 @@ Cannot both specify accessors and a value or writable attribute",
impl AsRef < boa_gc ::Cell < Object > > for JsObject {
impl AsRef < boa_gc ::Cell < Object > > for JsObject {
#[ inline ]
#[ inline ]
fn as_ref ( & self ) -> & boa_gc ::Cell < Object > {
fn as_ref ( & self ) -> & boa_gc ::Cell < Object > {
& * self . 0
& * self . inner
}
}
}
}
@ -798,7 +802,7 @@ impl Debug for JsObject {
// Instead, we check if the object has appeared before in the entire graph. This means that objects will appear
// Instead, we check if the object has appeared before in the entire graph. This means that objects will appear
// at most once, hopefully making things a bit clearer.
// at most once, hopefully making things a bit clearer.
if ! limiter . visited & & ! limiter . live {
if ! limiter . visited & & ! limiter . live {
f . debug_tuple ( "JsObject" ) . field ( & self . 0 ) . finish ( )
f . debug_tuple ( "JsObject" ) . field ( & self . inner ) . finish ( )
} else {
} else {
f . write_str ( "{ ... }" )
f . write_str ( "{ ... }" )
}
}