Skip to content

Commit

Permalink
Add Realm::create_with_default_global_bindings
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 9, 2023
1 parent 348c757 commit f44e897
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 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,
},
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 Expand Up @@ -276,6 +279,21 @@ impl Realm {
intl::PluralRules::init(self);
}
}

/// Create a new Realm with the default global bindings.
pub fn create_with_default_global_bindings(
hooks: &dyn HostHooks,
root_shape: &RootShape,
context: &mut Context<'_>,
) -> JsResult<Self> {
let realm = Self::create(hooks, root_shape);

let old_realm = context.enter_realm(realm);

set_default_global_bindings(context)?;

Ok(context.enter_realm(old_realm))
}
}

/// Abstract operation [`SetDefaultGlobalBindings ( realmRec )`][spec].
Expand Down

0 comments on commit f44e897

Please sign in to comment.