From 9f4e5044c7feb4507e5149c77307e2b610540b56 Mon Sep 17 00:00:00 2001 From: Alistair Date: Tue, 19 Sep 2023 10:29:39 +0100 Subject: [PATCH] Add `Context::create_realm`. 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 32dd3008f71..721527e4369 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]