Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Object::set_native_object_data #3480

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading