From b6ff65885ef10ad7a40ce43e15c5f895913bfddc Mon Sep 17 00:00:00 2001 From: Alistair Date: Mon, 16 Oct 2023 15:03:02 +0100 Subject: [PATCH] Add `Context::create_realm`. (#3369) Provides a function for creating Realms with the default global bindings. --- boa_engine/src/context/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/boa_engine/src/context/mod.rs b/boa_engine/src/context/mod.rs index 32dd3008f7..721527e436 100644 --- a/boa_engine/src/context/mod.rs +++ b/boa_engine/src/context/mod.rs @@ -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 { + 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]