Skip to content

Commit

Permalink
Add Context::create_realm.
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 committed Oct 11, 2023
1 parent 348c757 commit c5efb41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions boa_engine/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ use crate::{
weak_map::WeakMap,
weak_set::WeakSet,
},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
context::{
intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
HostHooks,

Check warning on line 100 in boa_engine/src/builtins/mod.rs

View workflow job for this annotation

GitHub Actions / Coverage

unused imports: `HostHooks`, `RootShape`

Check warning on line 100 in boa_engine/src/builtins/mod.rs

View workflow job for this annotation

GitHub Actions / Coverage

unused imports: `HostHooks`, `RootShape`

Check warning on line 100 in boa_engine/src/builtins/mod.rs

View workflow job for this annotation

GitHub Actions / Coverage

unused imports: `HostHooks`, `RootShape`
},
js_string,
native_function::{NativeFunction, NativeFunctionPointer},
object::{
shape::{property_table::PropertyTableInner, slot::SlotAttributes},
shape::{property_table::PropertyTableInner, slot::SlotAttributes, RootShape},
FunctionBinding, JsFunction, JsObject, JsPrototype, Object, ObjectData, ObjectKind,
CONSTRUCTOR, PROTOTYPE,
},
Expand Down
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 c5efb41

Please sign in to comment.