Skip to content

Commit

Permalink
Add Context::create_realm. (#3369)
Browse files Browse the repository at this point in the history
Provides a function for creating Realms with the default global bindings.
  • Loading branch information
johnyob authored Oct 16, 2023
1 parent 9030417 commit b6ff658
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions boa_engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ impl<'host> Context<'host> {
std::mem::replace(&mut self.realm, realm)
}

/// Create a new Realm with the default global bindings.
pub fn create_realm(&mut self) -> JsResult<Realm> {
let realm = Realm::create(&*self.host_hooks, &self.root_shape);

let old_realm = self.enter_realm(realm);

builtins::set_default_global_bindings(self)?;

Ok(self.enter_realm(old_realm))
}

/// Get the [`RootShape`].
#[inline]
#[must_use]
Expand Down

0 comments on commit b6ff658

Please sign in to comment.