diff --git a/boa_engine/src/object/mod.rs b/boa_engine/src/object/mod.rs index c0e246027d3..c02afa77667 100644 --- a/boa_engine/src/object/mod.rs +++ b/boa_engine/src/object/mod.rs @@ -78,6 +78,7 @@ use boa_gc::{custom_trace, Finalize, Trace, WeakGc}; use std::{ any::{Any, TypeId}, fmt::{self, Debug}, + mem, ops::{Deref, DerefMut}, }; @@ -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( + &mut self, + data: T, + ) -> Option> { + 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]