Skip to content

Commit

Permalink
Add Object::set_native_object
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyob committed Nov 24, 2023
1 parent 07e2356 commit b4867bb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions boa_engine/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ use boa_gc::{custom_trace, Finalize, Trace, WeakGc};
use std::{
any::{Any, TypeId},
fmt::{self, Debug},
mem,
ops::{Deref, DerefMut},
};

Expand Down Expand Up @@ -1990,6 +1991,19 @@ impl Object {
}
}

/// Sets the native object data returning the previous data, if the
/// object is a 'NativeObject'.
#[inline]
pub fn set_native_object_data<T: NativeObject>(
&mut self,
data: T,
) -> Option<Box<dyn NativeObject>> {
match self.kind {
ObjectKind::NativeObject(ref mut object) => Some(mem::replace(object, Box::new(data))),
_ => None,
}
}

/// Checks if it is a `Promise` object.
#[inline]
#[must_use]
Expand Down

0 comments on commit b4867bb

Please sign in to comment.