script_bindings/realms.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::ptr::NonNull;
6
7use js::context::JSContext;
8use js::realm::AutoRealm;
9
10use crate::DomTypes;
11use crate::reflector::DomObject;
12
13pub fn enter_auto_realm<'cx, D: DomTypes>(
14 cx: &'cx mut JSContext,
15 object: &impl DomObject,
16) -> AutoRealm<'cx> {
17 AutoRealm::new(
18 cx,
19 NonNull::new(object.reflector().get_jsobject().get()).unwrap(),
20 )
21}