@ -88,6 +88,9 @@ pub(crate) trait JsObjectType:
/// 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" ;
/// A type alias for an object prototype.
///
/// A `None` values means that the prototype is the `null` value.
pub type JsPrototype = Option < JsObject > ;
pub type JsPrototype = Option < JsObject > ;
/// This trait allows Rust types to be passed around as objects.
/// This trait allows Rust types to be passed around as objects.
@ -104,12 +107,12 @@ pub trait NativeObject: Debug + Any + Trace {
impl < T : Any + Debug + Trace > NativeObject for T {
impl < T : Any + Debug + Trace > NativeObject for T {
#[ inline ]
#[ inline ]
fn as_any ( & self ) -> & dyn Any {
fn as_any ( & self ) -> & dyn Any {
self as & dyn Any
self
}
}
#[ inline ]
#[ inline ]
fn as_mut_any ( & mut self ) -> & mut dyn Any {
fn as_mut_any ( & mut self ) -> & mut dyn Any {
self as & mut dyn Any
self
}
}
}
}
@ -142,10 +145,18 @@ unsafe impl Trace for Object {
/// The representation of private object elements.
/// The representation of private object elements.
#[ derive(Clone, Debug, Trace, Finalize) ]
#[ derive(Clone, Debug, Trace, Finalize) ]
pub enum PrivateElement {
pub enum PrivateElement {
/// A private field.
Field ( JsValue ) ,
Field ( JsValue ) ,
/// A private method.
Method ( JsObject ) ,
Method ( JsObject ) ,
/// A private element accessor.
Accessor {
Accessor {
/// A getter function.
getter : Option < JsObject > ,
getter : Option < JsObject > ,
/// A setter function.
setter : Option < JsObject > ,
setter : Option < JsObject > ,
} ,
} ,
}
}
@ -160,40 +171,109 @@ pub struct ObjectData {
/// Defines the different types of objects.
/// Defines the different types of objects.
#[ derive(Debug, Finalize) ]
#[ derive(Debug, Finalize) ]
pub enum ObjectKind {
pub enum ObjectKind {
/// The `AsyncFromSyncIterator` object kind.
AsyncFromSyncIterator ( AsyncFromSyncIterator ) ,
AsyncFromSyncIterator ( AsyncFromSyncIterator ) ,
/// The `AsyncGenerator` object kind.
AsyncGenerator ( AsyncGenerator ) ,
AsyncGenerator ( AsyncGenerator ) ,
/// The `AsyncGeneratorFunction` object kind.
AsyncGeneratorFunction ( Function ) ,
AsyncGeneratorFunction ( Function ) ,
/// The `Array` object kind.
Array ,
Array ,
/// The `ArrayIterator` object kind.
ArrayIterator ( ArrayIterator ) ,
ArrayIterator ( ArrayIterator ) ,
/// The `ArrayBuffer` object kind.
ArrayBuffer ( ArrayBuffer ) ,
ArrayBuffer ( ArrayBuffer ) ,
/// The `Map` object kind.
Map ( OrderedMap < JsValue > ) ,
Map ( OrderedMap < JsValue > ) ,
/// The `MapIterator` object kind.
MapIterator ( MapIterator ) ,
MapIterator ( MapIterator ) ,
/// The `RegExp` object kind.
RegExp ( Box < RegExp > ) ,
RegExp ( Box < RegExp > ) ,
/// The `RegExpStringIterator` object kind.
RegExpStringIterator ( RegExpStringIterator ) ,
RegExpStringIterator ( RegExpStringIterator ) ,
/// The `BigInt` object kind.
BigInt ( JsBigInt ) ,
BigInt ( JsBigInt ) ,
/// The `Boolean` object kind.
Boolean ( bool ) ,
Boolean ( bool ) ,
/// The `DataView` object kind.
DataView ( DataView ) ,
DataView ( DataView ) ,
/// The `ForInIterator` object kind.
ForInIterator ( ForInIterator ) ,
ForInIterator ( ForInIterator ) ,
/// The `Function` object kind.
Function ( Function ) ,
Function ( Function ) ,
/// The `BoundFunction` object kind.
BoundFunction ( BoundFunction ) ,
BoundFunction ( BoundFunction ) ,
/// The `Generator` object kind.
Generator ( Generator ) ,
Generator ( Generator ) ,
/// The `GeneratorFunction` object kind.
GeneratorFunction ( Function ) ,
GeneratorFunction ( Function ) ,
/// The `Set` object kind.
Set ( OrderedSet < JsValue > ) ,
Set ( OrderedSet < JsValue > ) ,
/// The `SetIterator` object kind.
SetIterator ( SetIterator ) ,
SetIterator ( SetIterator ) ,
/// The `String` object kind.
String ( JsString ) ,
String ( JsString ) ,
/// The `StringIterator` object kind.
StringIterator ( StringIterator ) ,
StringIterator ( StringIterator ) ,
/// The `Number` object kind.
Number ( f64 ) ,
Number ( f64 ) ,
/// The `Symbol` object kind.
Symbol ( JsSymbol ) ,
Symbol ( JsSymbol ) ,
/// The `Error` object kind.
Error ( ErrorKind ) ,
Error ( ErrorKind ) ,
/// The ordinary object kind.
Ordinary ,
Ordinary ,
/// The `Proxy` object kind.
Proxy ( Proxy ) ,
Proxy ( Proxy ) ,
/// The `Date` object kind.
Date ( Date ) ,
Date ( Date ) ,
/// The `Global` object kind.
Global ,
Global ,
/// The arguments exotic object kind.
Arguments ( Arguments ) ,
Arguments ( Arguments ) ,
/// The rust native object kind.
NativeObject ( Box < dyn NativeObject > ) ,
NativeObject ( Box < dyn NativeObject > ) ,
/// The integer-indexed exotic object kind.
IntegerIndexed ( IntegerIndexed ) ,
IntegerIndexed ( IntegerIndexed ) ,
/// The `Promise` object kind.
Promise ( Promise ) ,
Promise ( Promise ) ,
/// The `WeakRef` object kind.
WeakRef ( WeakGc < GcCell < Object > > ) ,
WeakRef ( WeakGc < GcCell < Object > > ) ,
/// The `Intl.DateTimeFormat` object kind.
#[ cfg(feature = " intl " ) ]
#[ cfg(feature = " intl " ) ]
DateTimeFormat ( Box < DateTimeFormat > ) ,
DateTimeFormat ( Box < DateTimeFormat > ) ,
}
}
@ -269,6 +349,7 @@ impl ObjectData {
}
}
/// Create the `Array` object data and reference its exclusive internal methods
/// Create the `Array` object data and reference its exclusive internal methods
#[ must_use ]
pub fn array ( ) -> Self {
pub fn array ( ) -> Self {
Self {
Self {
kind : ObjectKind ::Array ,
kind : ObjectKind ::Array ,
@ -293,6 +374,7 @@ impl ObjectData {
}
}
/// Create the `Map` object data
/// Create the `Map` object data
#[ must_use ]
pub fn map ( map : OrderedMap < JsValue > ) -> Self {
pub fn map ( map : OrderedMap < JsValue > ) -> Self {
Self {
Self {
kind : ObjectKind ::Map ( map ) ,
kind : ObjectKind ::Map ( map ) ,
@ -309,6 +391,7 @@ impl ObjectData {
}
}
/// Create the `RegExp` object data
/// Create the `RegExp` object data
#[ must_use ]
pub fn reg_exp ( reg_exp : Box < RegExp > ) -> Self {
pub fn reg_exp ( reg_exp : Box < RegExp > ) -> Self {
Self {
Self {
kind : ObjectKind ::RegExp ( reg_exp ) ,
kind : ObjectKind ::RegExp ( reg_exp ) ,
@ -325,6 +408,7 @@ impl ObjectData {
}
}
/// Create the `BigInt` object data
/// Create the `BigInt` object data
#[ must_use ]
pub fn big_int ( big_int : JsBigInt ) -> Self {
pub fn big_int ( big_int : JsBigInt ) -> Self {
Self {
Self {
kind : ObjectKind ::BigInt ( big_int ) ,
kind : ObjectKind ::BigInt ( big_int ) ,
@ -333,6 +417,7 @@ impl ObjectData {
}
}
/// Create the `Boolean` object data
/// Create the `Boolean` object data
#[ must_use ]
pub fn boolean ( boolean : bool ) -> Self {
pub fn boolean ( boolean : bool ) -> Self {
Self {
Self {
kind : ObjectKind ::Boolean ( boolean ) ,
kind : ObjectKind ::Boolean ( boolean ) ,
@ -409,6 +494,7 @@ impl ObjectData {
}
}
/// Create the `Set` object data
/// Create the `Set` object data
#[ must_use ]
pub fn set ( set : OrderedSet < JsValue > ) -> Self {
pub fn set ( set : OrderedSet < JsValue > ) -> Self {
Self {
Self {
kind : ObjectKind ::Set ( set ) ,
kind : ObjectKind ::Set ( set ) ,
@ -425,6 +511,7 @@ impl ObjectData {
}
}
/// Create the `String` object data and reference its exclusive internal methods
/// Create the `String` object data and reference its exclusive internal methods
#[ must_use ]
pub fn string ( string : JsString ) -> Self {
pub fn string ( string : JsString ) -> Self {
Self {
Self {
kind : ObjectKind ::String ( string ) ,
kind : ObjectKind ::String ( string ) ,
@ -441,6 +528,7 @@ impl ObjectData {
}
}
/// Create the `Number` object data
/// Create the `Number` object data
#[ must_use ]
pub fn number ( number : f64 ) -> Self {
pub fn number ( number : f64 ) -> Self {
Self {
Self {
kind : ObjectKind ::Number ( number ) ,
kind : ObjectKind ::Number ( number ) ,
@ -449,6 +537,7 @@ impl ObjectData {
}
}
/// Create the `Symbol` object data
/// Create the `Symbol` object data
#[ must_use ]
pub fn symbol ( symbol : JsSymbol ) -> Self {
pub fn symbol ( symbol : JsSymbol ) -> Self {
Self {
Self {
kind : ObjectKind ::Symbol ( symbol ) ,
kind : ObjectKind ::Symbol ( symbol ) ,
@ -465,6 +554,7 @@ impl ObjectData {
}
}
/// Create the `Ordinary` object data
/// Create the `Ordinary` object data
#[ must_use ]
pub fn ordinary ( ) -> Self {
pub fn ordinary ( ) -> Self {
Self {
Self {
kind : ObjectKind ::Ordinary ,
kind : ObjectKind ::Ordinary ,
@ -487,6 +577,7 @@ impl ObjectData {
}
}
/// Create the `Date` object data
/// Create the `Date` object data
#[ must_use ]
pub fn date ( date : Date ) -> Self {
pub fn date ( date : Date ) -> Self {
Self {
Self {
kind : ObjectKind ::Date ( date ) ,
kind : ObjectKind ::Date ( date ) ,
@ -495,6 +586,7 @@ impl ObjectData {
}
}
/// Create the `Global` object data
/// Create the `Global` object data
#[ must_use ]
pub fn global ( ) -> Self {
pub fn global ( ) -> Self {
Self {
Self {
kind : ObjectKind ::Global ,
kind : ObjectKind ::Global ,
@ -523,6 +615,7 @@ impl ObjectData {
}
}
/// Create the `NativeObject` object data
/// Create the `NativeObject` object data
#[ must_use ]
pub fn native_object ( native_object : Box < dyn NativeObject > ) -> Self {
pub fn native_object ( native_object : Box < dyn NativeObject > ) -> Self {
Self {
Self {
kind : ObjectKind ::NativeObject ( native_object ) ,
kind : ObjectKind ::NativeObject ( native_object ) ,
@ -540,6 +633,7 @@ impl ObjectData {
/// Create the `DateTimeFormat` object data
/// Create the `DateTimeFormat` object data
#[ cfg(feature = " intl " ) ]
#[ cfg(feature = " intl " ) ]
#[ must_use ]
pub fn date_time_format ( date_time_fmt : Box < DateTimeFormat > ) -> Self {
pub fn date_time_format ( date_time_fmt : Box < DateTimeFormat > ) -> Self {
Self {
Self {
kind : ObjectKind ::DateTimeFormat ( date_time_fmt ) ,
kind : ObjectKind ::DateTimeFormat ( date_time_fmt ) ,
@ -615,14 +709,15 @@ impl Default for Object {
}
}
impl Object {
impl Object {
/// Returns the kind of the object.
#[ inline ]
#[ inline ]
pub fn kind ( & self ) -> & ObjectKind {
pub const fn kind ( & self ) -> & ObjectKind {
& self . data . kind
& self . data . kind
}
}
/// Checks if it's an `AsyncFromSyncIterator` object.
/// Checks if it's an `AsyncFromSyncIterator` object.
#[ inline ]
#[ inline ]
pub fn is_async_from_sync_iterator ( & self ) -> bool {
pub const fn is_async_from_sync_iterator ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -634,7 +729,7 @@ impl Object {
/// Returns a reference to the `AsyncFromSyncIterator` data on the object.
/// Returns a reference to the `AsyncFromSyncIterator` data on the object.
#[ inline ]
#[ inline ]
pub fn as_async_from_sync_iterator ( & self ) -> Option < & AsyncFromSyncIterator > {
pub const fn as_async_from_sync_iterator ( & self ) -> Option < & AsyncFromSyncIterator > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::AsyncFromSyncIterator ( ref async_from_sync_iterator ) ,
kind : ObjectKind ::AsyncFromSyncIterator ( ref async_from_sync_iterator ) ,
@ -646,7 +741,7 @@ impl Object {
/// Checks if it's an `AsyncGenerator` object.
/// Checks if it's an `AsyncGenerator` object.
#[ inline ]
#[ inline ]
pub fn is_async_generator ( & self ) -> bool {
pub const fn is_async_generator ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -658,7 +753,7 @@ impl Object {
/// Returns a reference to the async generator data on the object.
/// Returns a reference to the async generator data on the object.
#[ inline ]
#[ inline ]
pub fn as_async_generator ( & self ) -> Option < & AsyncGenerator > {
pub const fn as_async_generator ( & self ) -> Option < & AsyncGenerator > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::AsyncGenerator ( ref async_generator ) ,
kind : ObjectKind ::AsyncGenerator ( ref async_generator ) ,
@ -680,9 +775,9 @@ impl Object {
}
}
}
}
/// Checks if i t an `Array` object.
/// Checks if the object is a `Array` object.
#[ inline ]
#[ inline ]
pub fn is_array ( & self ) -> bool {
pub const fn is_array ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -692,37 +787,14 @@ impl Object {
)
)
}
}
/// Checks if it is an `ArrayIterator` object.
#[ inline ]
pub fn is_array_iterator ( & self ) -> bool {
matches! (
self . data ,
ObjectData {
kind : ObjectKind ::ArrayIterator ( _ ) ,
..
}
)
}
#[ inline ]
#[ inline ]
pub fn as_array_iterator ( & self ) -> Option < & ArrayIterator > {
pub ( crate ) const fn has_viewed_array_buffer ( & self ) -> bool {
match self . data {
ObjectData {
kind : ObjectKind ::ArrayIterator ( ref iter ) ,
..
} = > Some ( iter ) ,
_ = > None ,
}
}
#[ inline ]
pub ( crate ) fn has_viewed_array_buffer ( & self ) -> bool {
self . is_typed_array ( ) | | self . is_data_view ( )
self . is_typed_array ( ) | | self . is_data_view ( )
}
}
/// Checks if i t an `DataView` object.
/// Checks if the object is a `DataView` object.
#[ inline ]
#[ inline ]
pub fn is_data_view ( & self ) -> bool {
pub const fn is_data_view ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -732,9 +804,9 @@ impl Object {
)
)
}
}
/// Checks if i t an `ArrayBuffer` object.
/// Checks if the object is a `ArrayBuffer` object.
#[ inline ]
#[ inline ]
pub fn is_array_buffer ( & self ) -> bool {
pub const fn is_array_buffer ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -744,8 +816,9 @@ impl Object {
)
)
}
}
/// Gets the array buffer data if the object is a `ArrayBuffer`.
#[ inline ]
#[ inline ]
pub fn as_array_buffer ( & self ) -> Option < & ArrayBuffer > {
pub const fn as_array_buffer ( & self ) -> Option < & ArrayBuffer > {
match & self . data {
match & self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::ArrayBuffer ( buffer ) ,
kind : ObjectKind ::ArrayBuffer ( buffer ) ,
@ -755,6 +828,7 @@ impl Object {
}
}
}
}
/// Gets the mutable array buffer data if the object is a `ArrayBuffer`.
#[ inline ]
#[ inline ]
pub fn as_array_buffer_mut ( & mut self ) -> Option < & mut ArrayBuffer > {
pub fn as_array_buffer_mut ( & mut self ) -> Option < & mut ArrayBuffer > {
match & mut self . data {
match & mut self . data {
@ -766,6 +840,31 @@ impl Object {
}
}
}
}
/// Checks if the object is a `ArrayIterator` object.
#[ inline ]
pub const fn is_array_iterator ( & self ) -> bool {
matches! (
self . data ,
ObjectData {
kind : ObjectKind ::ArrayIterator ( _ ) ,
..
}
)
}
/// Gets the array-iterator data if the object is a `ArrayIterator`.
#[ inline ]
pub const fn as_array_iterator ( & self ) -> Option < & ArrayIterator > {
match self . data {
ObjectData {
kind : ObjectKind ::ArrayIterator ( ref iter ) ,
..
} = > Some ( iter ) ,
_ = > None ,
}
}
/// Gets the mutable array-iterator data if the object is a `ArrayIterator`.
#[ inline ]
#[ inline ]
pub fn as_array_iterator_mut ( & mut self ) -> Option < & mut ArrayIterator > {
pub fn as_array_iterator_mut ( & mut self ) -> Option < & mut ArrayIterator > {
match & mut self . data {
match & mut self . data {
@ -777,6 +876,7 @@ impl Object {
}
}
}
}
/// Gets the mutable string-iterator data if the object is a `StringIterator`.
#[ inline ]
#[ inline ]
pub fn as_string_iterator_mut ( & mut self ) -> Option < & mut StringIterator > {
pub fn as_string_iterator_mut ( & mut self ) -> Option < & mut StringIterator > {
match & mut self . data {
match & mut self . data {
@ -788,6 +888,7 @@ impl Object {
}
}
}
}
/// Gets the mutable regexp-string-iterator data if the object is a `RegExpStringIterator`.
#[ inline ]
#[ inline ]
pub fn as_regexp_string_iterator_mut ( & mut self ) -> Option < & mut RegExpStringIterator > {
pub fn as_regexp_string_iterator_mut ( & mut self ) -> Option < & mut RegExpStringIterator > {
match & mut self . data {
match & mut self . data {
@ -799,8 +900,9 @@ impl Object {
}
}
}
}
/// Gets the for-in-iterator data if the object is a `ForInIterator`.
#[ inline ]
#[ inline ]
pub fn as_for_in_iterator ( & self ) -> Option < & ForInIterator > {
pub const fn as_for_in_iterator ( & self ) -> Option < & ForInIterator > {
match & self . data {
match & self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::ForInIterator ( iter ) ,
kind : ObjectKind ::ForInIterator ( iter ) ,
@ -810,6 +912,7 @@ impl Object {
}
}
}
}
/// Gets the mutable for-in-iterator data if the object is a `ForInIterator`.
#[ inline ]
#[ inline ]
pub fn as_for_in_iterator_mut ( & mut self ) -> Option < & mut ForInIterator > {
pub fn as_for_in_iterator_mut ( & mut self ) -> Option < & mut ForInIterator > {
match & mut self . data {
match & mut self . data {
@ -821,9 +924,9 @@ impl Object {
}
}
}
}
/// Checks if it is a `Map` object.pub
/// Checks if the object is a `Map` object.
#[ inline ]
#[ inline ]
pub fn is_map ( & self ) -> bool {
pub const fn is_map ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -833,8 +936,9 @@ impl Object {
)
)
}
}
/// Gets the map data if the object is a `Map`.
#[ inline ]
#[ inline ]
pub fn as_map_ref ( & self ) -> Option < & OrderedMap < JsValue > > {
pub const fn as_map ( & self ) -> Option < & OrderedMap < JsValue > > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Map ( ref map ) ,
kind : ObjectKind ::Map ( ref map ) ,
@ -844,6 +948,7 @@ impl Object {
}
}
}
}
/// Gets the mutable map data if the object is a `Map`.
#[ inline ]
#[ inline ]
pub fn as_map_mut ( & mut self ) -> Option < & mut OrderedMap < JsValue > > {
pub fn as_map_mut ( & mut self ) -> Option < & mut OrderedMap < JsValue > > {
match & mut self . data {
match & mut self . data {
@ -855,8 +960,9 @@ impl Object {
}
}
}
}
/// Checks if the object is a `MapIterator` object.
#[ inline ]
#[ inline ]
pub fn is_map_iterator ( & self ) -> bool {
pub const fn is_map_iterator ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -866,8 +972,9 @@ impl Object {
)
)
}
}
/// Gets the map iterator data if the object is a `MapIterator`.
#[ inline ]
#[ inline ]
pub fn as_map_iterator_ref ( & self ) -> Option < & MapIterator > {
pub const fn as_map_iterator_ref ( & self ) -> Option < & MapIterator > {
match & self . data {
match & self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::MapIterator ( iter ) ,
kind : ObjectKind ::MapIterator ( iter ) ,
@ -877,6 +984,7 @@ impl Object {
}
}
}
}
/// Gets the mutable map iterator data if the object is a `MapIterator`.
#[ inline ]
#[ inline ]
pub fn as_map_iterator_mut ( & mut self ) -> Option < & mut MapIterator > {
pub fn as_map_iterator_mut ( & mut self ) -> Option < & mut MapIterator > {
match & mut self . data {
match & mut self . data {
@ -888,8 +996,9 @@ impl Object {
}
}
}
}
/// Checks if the object is a `Set` object.
#[ inline ]
#[ inline ]
pub fn is_set ( & self ) -> bool {
pub const fn is_set ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -899,20 +1008,9 @@ impl Object {
)
)
}
}
/// Checks if it is an `SetIterator` object.
/// Gets the set data if the object is a `Set`.
#[ inline ]
pub fn is_set_iterator ( & self ) -> bool {
matches! (
self . data ,
ObjectData {
kind : ObjectKind ::SetIterator ( _ ) ,
..
}
)
}
#[ inline ]
#[ inline ]
pub fn as_set_ref ( & self ) -> Option < & OrderedSet < JsValue > > {
pub const fn as_set ( & self ) -> Option < & OrderedSet < JsValue > > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Set ( ref set ) ,
kind : ObjectKind ::Set ( ref set ) ,
@ -922,6 +1020,7 @@ impl Object {
}
}
}
}
/// Gets the mutable set data if the object is a `Set`.
#[ inline ]
#[ inline ]
pub fn as_set_mut ( & mut self ) -> Option < & mut OrderedSet < JsValue > > {
pub fn as_set_mut ( & mut self ) -> Option < & mut OrderedSet < JsValue > > {
match & mut self . data {
match & mut self . data {
@ -933,6 +1032,19 @@ impl Object {
}
}
}
}
/// Checks if the object is a `SetIterator` object.
#[ inline ]
pub const fn is_set_iterator ( & self ) -> bool {
matches! (
self . data ,
ObjectData {
kind : ObjectKind ::SetIterator ( _ ) ,
..
}
)
}
/// Gets the mutable set iterator data if the object is a `SetIterator`.
#[ inline ]
#[ inline ]
pub fn as_set_iterator_mut ( & mut self ) -> Option < & mut SetIterator > {
pub fn as_set_iterator_mut ( & mut self ) -> Option < & mut SetIterator > {
match & mut self . data {
match & mut self . data {
@ -944,9 +1056,9 @@ impl Object {
}
}
}
}
/// Checks if it a `String` object.
/// Checks if the object is a `String` object.
#[ inline ]
#[ inline ]
pub fn is_string ( & self ) -> bool {
pub const fn is_string ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -956,6 +1068,7 @@ impl Object {
)
)
}
}
/// Gets the string data if the object is a `String`.
#[ inline ]
#[ inline ]
pub fn as_string ( & self ) -> Option < JsString > {
pub fn as_string ( & self ) -> Option < JsString > {
match self . data {
match self . data {
@ -967,9 +1080,9 @@ impl Object {
}
}
}
}
/// Checks if it a `Function` object.
/// Checks if the object is a `Function` object.
#[ inline ]
#[ inline ]
pub fn is_function ( & self ) -> bool {
pub const fn is_function ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -979,8 +1092,9 @@ impl Object {
)
)
}
}
/// Gets the function data if the object is a `Function`.
#[ inline ]
#[ inline ]
pub fn as_function ( & self ) -> Option < & Function > {
pub const fn as_function ( & self ) -> Option < & Function > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind :
kind :
@ -991,6 +1105,7 @@ impl Object {
}
}
}
}
/// Gets the mutable function data if the object is a `Function`.
#[ inline ]
#[ inline ]
pub fn as_function_mut ( & mut self ) -> Option < & mut Function > {
pub fn as_function_mut ( & mut self ) -> Option < & mut Function > {
match self . data {
match self . data {
@ -1004,8 +1119,9 @@ impl Object {
}
}
}
}
/// Gets the bound function data if the object is a `BoundFunction`.
#[ inline ]
#[ inline ]
pub fn as_bound_function ( & self ) -> Option < & BoundFunction > {
pub const fn as_bound_function ( & self ) -> Option < & BoundFunction > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::BoundFunction ( ref bound_function ) ,
kind : ObjectKind ::BoundFunction ( ref bound_function ) ,
@ -1015,9 +1131,9 @@ impl Object {
}
}
}
}
/// Checks if it' s a `Generator` object.
/// Checks if the object i s a `Generator` object.
#[ inline ]
#[ inline ]
pub fn is_generator ( & self ) -> bool {
pub const fn is_generator ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1027,9 +1143,9 @@ impl Object {
)
)
}
}
/// Returns a reference to the generator data on the object .
/// Gets the generator data if the object is a `Generator` .
#[ inline ]
#[ inline ]
pub fn as_generator ( & self ) -> Option < & Generator > {
pub const fn as_generator ( & self ) -> Option < & Generator > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Generator ( ref generator ) ,
kind : ObjectKind ::Generator ( ref generator ) ,
@ -1039,7 +1155,7 @@ impl Object {
}
}
}
}
/// Returns a mutable reference to the generator data on the object .
/// Gets the mutable generator data if the object is a `Generator` .
#[ inline ]
#[ inline ]
pub fn as_generator_mut ( & mut self ) -> Option < & mut Generator > {
pub fn as_generator_mut ( & mut self ) -> Option < & mut Generator > {
match self . data {
match self . data {
@ -1051,9 +1167,9 @@ impl Object {
}
}
}
}
/// Checks if it a Symbol object.
/// Checks if the object is a `Symbol` object.
#[ inline ]
#[ inline ]
pub fn is_symbol ( & self ) -> bool {
pub const fn is_symbol ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1063,6 +1179,7 @@ impl Object {
)
)
}
}
/// Gets the error data if the object is a `Symbol`.
#[ inline ]
#[ inline ]
pub fn as_symbol ( & self ) -> Option < JsSymbol > {
pub fn as_symbol ( & self ) -> Option < JsSymbol > {
match self . data {
match self . data {
@ -1074,9 +1191,9 @@ impl Object {
}
}
}
}
/// Checks if i t an Error object.
/// Checks if the object is a ` Error` object.
#[ inline ]
#[ inline ]
pub fn is_error ( & self ) -> bool {
pub const fn is_error ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1086,8 +1203,9 @@ impl Object {
)
)
}
}
/// Gets the error data if the object is a `Error`.
#[ inline ]
#[ inline ]
pub fn as_error ( & self ) -> Option < ErrorKind > {
pub const fn as_error ( & self ) -> Option < ErrorKind > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Error ( e ) ,
kind : ObjectKind ::Error ( e ) ,
@ -1097,9 +1215,9 @@ impl Object {
}
}
}
}
/// Checks if it a Boolean object.
/// Checks if the object is a `Boolean` object.
#[ inline ]
#[ inline ]
pub fn is_boolean ( & self ) -> bool {
pub const fn is_boolean ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1109,8 +1227,9 @@ impl Object {
)
)
}
}
/// Gets the boolean data if the object is a `Boolean`.
#[ inline ]
#[ inline ]
pub fn as_boolean ( & self ) -> Option < bool > {
pub const fn as_boolean ( & self ) -> Option < bool > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Boolean ( boolean ) ,
kind : ObjectKind ::Boolean ( boolean ) ,
@ -1120,9 +1239,9 @@ impl Object {
}
}
}
}
/// Checks if it a `Number` object.
/// Checks if the object is a `Number` object.
#[ inline ]
#[ inline ]
pub fn is_number ( & self ) -> bool {
pub const fn is_number ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1132,8 +1251,9 @@ impl Object {
)
)
}
}
/// Gets the number data if the object is a `Number`.
#[ inline ]
#[ inline ]
pub fn as_number ( & self ) -> Option < f64 > {
pub const fn as_number ( & self ) -> Option < f64 > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Number ( number ) ,
kind : ObjectKind ::Number ( number ) ,
@ -1143,9 +1263,9 @@ impl Object {
}
}
}
}
/// Checks if it a `BigInt` object.
/// Checks if the object is a `BigInt` object.
#[ inline ]
#[ inline ]
pub fn is_bigint ( & self ) -> bool {
pub const fn is_bigint ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1155,8 +1275,9 @@ impl Object {
)
)
}
}
/// Gets the bigint data if the object is a `BigInt`.
#[ inline ]
#[ inline ]
pub fn as_bigint ( & self ) -> Option < & JsBigInt > {
pub const fn as_bigint ( & self ) -> Option < & JsBigInt > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::BigInt ( ref bigint ) ,
kind : ObjectKind ::BigInt ( ref bigint ) ,
@ -1166,8 +1287,9 @@ impl Object {
}
}
}
}
/// Checks if the object is a `Date` object.
#[ inline ]
#[ inline ]
pub fn is_date ( & self ) -> bool {
pub const fn is_date ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1177,8 +1299,9 @@ impl Object {
)
)
}
}
/// Gets the date data if the object is a `Date`.
#[ inline ]
#[ inline ]
pub fn as_date ( & self ) -> Option < & Date > {
pub const fn as_date ( & self ) -> Option < & Date > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Date ( ref date ) ,
kind : ObjectKind ::Date ( ref date ) ,
@ -1188,6 +1311,7 @@ impl Object {
}
}
}
}
/// Gets the mutable date data if the object is a `Date`.
#[ inline ]
#[ inline ]
pub fn as_date_mut ( & mut self ) -> Option < & mut Date > {
pub fn as_date_mut ( & mut self ) -> Option < & mut Date > {
match self . data {
match self . data {
@ -1201,7 +1325,7 @@ impl Object {
/// Checks if it a `RegExp` object.
/// Checks if it a `RegExp` object.
#[ inline ]
#[ inline ]
pub fn is_regexp ( & self ) -> bool {
pub const fn is_regexp ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1213,7 +1337,7 @@ impl Object {
/// Gets the regexp data if the object is a regexp.
/// Gets the regexp data if the object is a regexp.
#[ inline ]
#[ inline ]
pub fn as_regexp ( & self ) -> Option < & RegExp > {
pub const fn as_regexp ( & self ) -> Option < & RegExp > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::RegExp ( ref regexp ) ,
kind : ObjectKind ::RegExp ( ref regexp ) ,
@ -1225,7 +1349,7 @@ impl Object {
/// Checks if it a `TypedArray` object.
/// Checks if it a `TypedArray` object.
#[ inline ]
#[ inline ]
pub fn is_typed_array ( & self ) -> bool {
pub const fn is_typed_array ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1235,8 +1359,9 @@ impl Object {
)
)
}
}
/// Gets the data view data if the object is a `DataView`.
#[ inline ]
#[ inline ]
pub fn as_data_view ( & self ) -> Option < & DataView > {
pub const fn as_data_view ( & self ) -> Option < & DataView > {
match & self . data {
match & self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::DataView ( data_view ) ,
kind : ObjectKind ::DataView ( data_view ) ,
@ -1246,6 +1371,7 @@ impl Object {
}
}
}
}
/// Gets the mutable data view data if the object is a `DataView`.
#[ inline ]
#[ inline ]
pub fn as_data_view_mut ( & mut self ) -> Option < & mut DataView > {
pub fn as_data_view_mut ( & mut self ) -> Option < & mut DataView > {
match & mut self . data {
match & mut self . data {
@ -1259,7 +1385,7 @@ impl Object {
/// Checks if it is an `Arguments` object.
/// Checks if it is an `Arguments` object.
#[ inline ]
#[ inline ]
pub fn is_arguments ( & self ) -> bool {
pub const fn is_arguments ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1271,7 +1397,7 @@ impl Object {
/// Gets the mapped arguments data if this is a mapped arguments object.
/// Gets the mapped arguments data if this is a mapped arguments object.
#[ inline ]
#[ inline ]
pub fn as_mapped_arguments ( & self ) -> Option < & ParameterMap > {
pub const fn as_mapped_arguments ( & self ) -> Option < & ParameterMap > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Arguments ( Arguments ::Mapped ( ref args ) ) ,
kind : ObjectKind ::Arguments ( Arguments ::Mapped ( ref args ) ) ,
@ -1295,7 +1421,7 @@ impl Object {
/// Gets the typed array data (integer indexed object) if this is a typed array.
/// Gets the typed array data (integer indexed object) if this is a typed array.
#[ inline ]
#[ inline ]
pub fn as_typed_array ( & self ) -> Option < & IntegerIndexed > {
pub const fn as_typed_array ( & self ) -> Option < & IntegerIndexed > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::IntegerIndexed ( ref integer_indexed_object ) ,
kind : ObjectKind ::IntegerIndexed ( ref integer_indexed_object ) ,
@ -1319,7 +1445,7 @@ impl Object {
/// Checks if it an ordinary object.
/// Checks if it an ordinary object.
#[ inline ]
#[ inline ]
pub fn is_ordinary ( & self ) -> bool {
pub const fn is_ordinary ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1331,7 +1457,7 @@ impl Object {
/// Checks if it's an proxy object.
/// Checks if it's an proxy object.
#[ inline ]
#[ inline ]
pub fn is_proxy ( & self ) -> bool {
pub const fn is_proxy ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1341,8 +1467,9 @@ impl Object {
)
)
}
}
/// Gets the proxy data if the object is a `Proxy`.
#[ inline ]
#[ inline ]
pub fn as_proxy ( & self ) -> Option < & Proxy > {
pub const fn as_proxy ( & self ) -> Option < & Proxy > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Proxy ( ref proxy ) ,
kind : ObjectKind ::Proxy ( ref proxy ) ,
@ -1352,6 +1479,7 @@ impl Object {
}
}
}
}
/// Gets the mutable proxy data if the object is a `Proxy`.
#[ inline ]
#[ inline ]
pub fn as_proxy_mut ( & mut self ) -> Option < & mut Proxy > {
pub fn as_proxy_mut ( & mut self ) -> Option < & mut Proxy > {
match self . data {
match self . data {
@ -1365,7 +1493,7 @@ impl Object {
/// Gets the prototype instance of this object.
/// Gets the prototype instance of this object.
#[ inline ]
#[ inline ]
pub fn prototype ( & self ) -> & JsPrototype {
pub const fn prototype ( & self ) -> & JsPrototype {
& self . prototype
& self . prototype
}
}
@ -1390,7 +1518,7 @@ impl Object {
/// Returns `true` if it holds an Rust type that implements `NativeObject`.
/// Returns `true` if it holds an Rust type that implements `NativeObject`.
#[ inline ]
#[ inline ]
pub fn is_native_object ( & self ) -> bool {
pub const fn is_native_object ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1400,6 +1528,7 @@ impl Object {
)
)
}
}
/// Gets the native object data if the object is a `NativeObject`.
#[ inline ]
#[ inline ]
pub fn as_native_object ( & self ) -> Option < & dyn NativeObject > {
pub fn as_native_object ( & self ) -> Option < & dyn NativeObject > {
match self . data {
match self . data {
@ -1413,7 +1542,7 @@ impl Object {
/// Checks if it is a `Promise` object.
/// Checks if it is a `Promise` object.
#[ inline ]
#[ inline ]
pub fn is_promise ( & self ) -> bool {
pub const fn is_promise ( & self ) -> bool {
matches! (
matches! (
self . data ,
self . data ,
ObjectData {
ObjectData {
@ -1423,9 +1552,9 @@ impl Object {
)
)
}
}
/// Gets the promise data if the object is a promise .
/// Gets the promise data if the object is a `Promise` .
#[ inline ]
#[ inline ]
pub fn as_promise ( & self ) -> Option < & Promise > {
pub const fn as_promise ( & self ) -> Option < & Promise > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::Promise ( ref promise ) ,
kind : ObjectKind ::Promise ( ref promise ) ,
@ -1435,6 +1564,7 @@ impl Object {
}
}
}
}
/// Gets the mutable promise data if the object is a `Promise`.
#[ inline ]
#[ inline ]
pub fn as_promise_mut ( & mut self ) -> Option < & mut Promise > {
pub fn as_promise_mut ( & mut self ) -> Option < & mut Promise > {
match self . data {
match self . data {
@ -1448,7 +1578,7 @@ impl Object {
/// Gets the `WeakRef`data if the object is a `WeakRef`.
/// Gets the `WeakRef`data if the object is a `WeakRef`.
#[ inline ]
#[ inline ]
pub fn as_weak_ref ( & self ) -> Option < & WeakGc < GcCell < Object > > > {
pub const fn as_weak_ref ( & self ) -> Option < & WeakGc < GcCell < Self > > > {
match self . data {
match self . data {
ObjectData {
ObjectData {
kind : ObjectKind ::WeakRef ( ref weak_ref ) ,
kind : ObjectKind ::WeakRef ( ref weak_ref ) ,
@ -1505,8 +1635,9 @@ impl Object {
}
}
}
}
/// Returns the properties of the object.
#[ inline ]
#[ inline ]
pub fn properties ( & self ) -> & PropertyMap {
pub const fn properties ( & self ) -> & PropertyMap {
& self . properties
& self . properties
}
}
@ -1755,7 +1886,7 @@ impl<'context> FunctionBuilder<'context> {
/// The default is `0`.
/// The default is `0`.
#[ inline ]
#[ inline ]
#[ must_use ]
#[ must_use ]
pub fn length ( mut self , length : usize ) -> Self {
pub const fn length ( mut self , length : usize ) -> Self {
self . length = length ;
self . length = length ;
self
self
}
}