mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
At the start of the script we create first (and only[^1]) safe `JSContext`, from where we should pass it down to every code that needs the cx. This PR brings it all the way down to message handlers. There is clear separation between functions that use new model `&mut JSContext` and the ones that use the old model (usually they take can_gc). [^1]: Another place of construction are SM hooks (that pass us down raw JSContext), but to reach that point we already needed to call another function that takes `&mut JSContext`, so one can look at this case as reentering/reborrowing (we derive new shorter `&mut JSContext` from the old one). Testing: This is just refactor, but should covered by WPT tests. Part of #40600 Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
21 lines
744 B
Rust
21 lines
744 B
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use js::context::JSContext;
|
|
use js::jsapi::JSAutoRealm;
|
|
use js::realm::AutoRealm;
|
|
pub(crate) use script_bindings::realms::{AlreadyInRealm, InRealm};
|
|
use script_bindings::reflector::DomObject;
|
|
|
|
pub(crate) fn enter_realm(object: &impl DomObject) -> JSAutoRealm {
|
|
script_bindings::realms::enter_realm::<crate::DomTypeHolder>(object)
|
|
}
|
|
|
|
pub(crate) fn enter_auto_realm<'cx>(
|
|
cx: &'cx mut JSContext,
|
|
object: &impl DomObject,
|
|
) -> AutoRealm<'cx> {
|
|
script_bindings::realms::enter_auto_realm::<crate::DomTypeHolder>(cx, object)
|
|
}
|