Skip to content

Commit b4867bb

Browse files
committed
Add Object::set_native_object
1 parent 07e2356 commit b4867bb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

boa_engine/src/object/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use boa_gc::{custom_trace, Finalize, Trace, WeakGc};
7878
use std::{
7979
any::{Any, TypeId},
8080
fmt::{self, Debug},
81+
mem,
8182
ops::{Deref, DerefMut},
8283
};
8384

@@ -1990,6 +1991,19 @@ impl Object {
19901991
}
19911992
}
19921993

1994+
/// Sets the native object data returning the previous data, if the
1995+
/// object is a 'NativeObject'.
1996+
#[inline]
1997+
pub fn set_native_object_data<T: NativeObject>(
1998+
&mut self,
1999+
data: T,
2000+
) -> Option<Box<dyn NativeObject>> {
2001+
match self.kind {
2002+
ObjectKind::NativeObject(ref mut object) => Some(mem::replace(object, Box::new(data))),
2003+
_ => None,
2004+
}
2005+
}
2006+
19932007
/// Checks if it is a `Promise` object.
19942008
#[inline]
19952009
#[must_use]

0 commit comments

Comments
 (0)