From 5a3e1b8e6903c825e50597a218532d417f1dfef9 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Fri, 24 Jan 2020 13:29:09 +0530 Subject: [PATCH] rename compartment to realm --- components/config/prefs.rs | 3 -- components/script/body.rs | 10 ++-- components/script/devtools.rs | 2 +- components/script/dom/audiobuffer.rs | 2 +- components/script/dom/audiocontext.rs | 10 ++-- components/script/dom/baseaudiocontext.rs | 10 ++-- components/script/dom/bindings/callback.rs | 4 +- .../script/dom/bindings/codegen/Bindings.conf | 50 +++++++++---------- .../dom/bindings/codegen/CodegenRust.py | 44 ++++++++-------- .../dom/bindings/codegen/Configuration.py | 2 +- .../script/dom/bindings/structuredclone.rs | 2 +- components/script/dom/bluetooth.rs | 17 +++---- components/script/dom/bluetoothdevice.rs | 6 +-- .../dom/bluetoothremotegattcharacteristic.rs | 18 +++---- .../dom/bluetoothremotegattdescriptor.rs | 10 ++-- .../script/dom/bluetoothremotegattserver.rs | 6 +-- .../script/dom/customelementregistry.rs | 14 +++--- .../script/dom/dedicatedworkerglobalscope.rs | 2 +- components/script/dom/document.rs | 17 +++---- components/script/dom/eventsource.rs | 2 +- components/script/dom/eventtarget.rs | 2 +- components/script/dom/filereader.rs | 2 +- components/script/dom/gpu.rs | 10 ++-- components/script/dom/gpuadapter.rs | 6 +-- components/script/dom/htmlmediaelement.rs | 6 +-- components/script/dom/mediadevices.rs | 10 ++-- components/script/dom/mediasession.rs | 6 +-- .../script/dom/navigationpreloadmanager.rs | 18 +++---- components/script/dom/navigator.rs | 6 +-- components/script/dom/offlineaudiocontext.rs | 6 +-- components/script/dom/permissions.rs | 9 ++-- components/script/dom/promise.rs | 10 ++-- components/script/dom/rtcpeerconnection.rs | 30 ++++------- .../script/dom/serviceworkercontainer.rs | 6 +-- .../script/dom/serviceworkerglobalscope.rs | 2 +- components/script/dom/testbinding.rs | 10 ++-- components/script/dom/testworklet.rs | 4 +- components/script/dom/vrdisplay.rs | 10 ++-- components/script/dom/window.rs | 4 +- components/script/dom/windowproxy.rs | 6 +-- components/script/dom/worker.rs | 2 +- components/script/dom/workerglobalscope.rs | 4 +- components/script/dom/worklet.rs | 6 +-- components/script/dom/xr.rs | 6 +-- components/script/dom/xrinputsource.rs | 2 +- .../script/dom/xrinputsourceschangeevent.rs | 2 +- components/script/dom/xrsession.rs | 8 +-- components/script/dom/xrviewerpose.rs | 2 +- components/script/fetch.rs | 6 +-- components/script/lib.rs | 4 +- .../script/{compartments.rs => realms.rs} | 26 +++++----- components/script/script_module.rs | 16 +++--- components/script/script_thread.rs | 6 +-- resources/prefs.json | 1 - 54 files changed, 226 insertions(+), 259 deletions(-) rename components/script/{compartments.rs => realms.rs} (60%) diff --git a/components/config/prefs.rs b/components/config/prefs.rs index 4196a8cce2ce..841e244d51c9 100644 --- a/components/config/prefs.rs +++ b/components/config/prefs.rs @@ -377,9 +377,6 @@ mod gen { slice_ms: i64, }, low_frequency_heap_growth: i64, - per_compartment: { - enabled: bool, - }, per_zone: { enabled: bool, }, diff --git a/components/script/body.rs b/components/script/body.rs index 06b864fa4e92..d5a63d7bcf03 100644 --- a/components/script/body.rs +++ b/components/script/body.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::{AlreadyInCompartment, InCompartment}; use crate::dom::bindings::cell::Ref; use crate::dom::bindings::codegen::Bindings::FormDataBinding::FormDataMethods; use crate::dom::bindings::error::{Error, Fallible}; @@ -14,6 +13,7 @@ use crate::dom::blob::{normalize_type_string, Blob}; use crate::dom::formdata::FormData; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; +use crate::realms::{AlreadyInRealm, InRealm}; use crate::script_runtime::JSContext; use js::jsapi::Heap; use js::jsapi::JSObject; @@ -52,11 +52,9 @@ pub enum FetchedData { // https://fetch.spec.whatwg.org/#concept-body-consume-body #[allow(unrooted_must_root)] pub fn consume_body(object: &T, body_type: BodyType) -> Rc { - let in_compartment_proof = AlreadyInCompartment::assert(&object.global()); - let promise = Promise::new_in_current_compartment( - &object.global(), - InCompartment::Already(&in_compartment_proof), - ); + let in_realm_proof = AlreadyInRealm::assert(&object.global()); + let promise = + Promise::new_in_current_realm(&object.global(), InRealm::Already(&in_realm_proof)); // Step 1 if object.get_body_used() || object.is_locked() { diff --git a/components/script/devtools.rs b/components/script/devtools.rs index 401a56ea0890..2298883c555e 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods; use crate::dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; @@ -17,6 +16,7 @@ use crate::dom::element::Element; use crate::dom::globalscope::GlobalScope; use crate::dom::node::{window_from_node, Node, ShadowIncluding}; use crate::dom::window::Window; +use crate::realms::enter_realm; use crate::script_thread::Documents; use devtools_traits::{AutoMargins, ComputedNodeLayout, TimelineMarkerType}; use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker}; diff --git a/components/script/dom/audiobuffer.rs b/components/script/dom/audiobuffer.rs index a3ef575b820a..fb598068998f 100644 --- a/components/script/dom/audiobuffer.rs +++ b/components/script/dom/audiobuffer.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::audionode::MAX_CHANNEL_COUNT; use crate::dom::bindings::cell::{DomRefCell, Ref}; use crate::dom::bindings::codegen::Bindings::AudioBufferBinding::{ @@ -13,6 +12,7 @@ use crate::dom::bindings::num::Finite; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::window::Window; +use crate::realms::enter_realm; use crate::script_runtime::JSContext; use dom_struct::dom_struct; use js::jsapi::JS_GetArrayBufferViewBuffer; diff --git a/components/script/dom/audiocontext.rs b/components/script/dom/audiocontext.rs index a72f326d9161..d5b1c3bdb56d 100644 --- a/components/script/dom/audiocontext.rs +++ b/components/script/dom/audiocontext.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::baseaudiocontext::{BaseAudioContext, BaseAudioContextOptions}; use crate::dom::bindings::codegen::Bindings::AudioContextBinding; use crate::dom::bindings::codegen::Bindings::AudioContextBinding::{ @@ -24,6 +23,7 @@ use crate::dom::htmlmediaelement::HTMLMediaElement; use crate::dom::mediaelementaudiosourcenode::MediaElementAudioSourceNode; use crate::dom::promise::Promise; use crate::dom::window::Window; +use crate::realms::InRealm; use crate::task_source::TaskSource; use dom_struct::dom_struct; use msg::constellation_msg::PipelineId; @@ -127,9 +127,9 @@ impl AudioContextMethods for AudioContext { } // https://webaudio.github.io/web-audio-api/#dom-audiocontext-suspend - fn Suspend(&self, comp: InCompartment) -> Rc { + fn Suspend(&self, comp: InRealm) -> Rc { // Step 1. - let promise = Promise::new_in_current_compartment(&self.global(), comp); + let promise = Promise::new_in_current_realm(&self.global(), comp); // Step 2. if self.context.control_thread_state() == ProcessingState::Closed { @@ -188,9 +188,9 @@ impl AudioContextMethods for AudioContext { } // https://webaudio.github.io/web-audio-api/#dom-audiocontext-close - fn Close(&self, comp: InCompartment) -> Rc { + fn Close(&self, comp: InRealm) -> Rc { // Step 1. - let promise = Promise::new_in_current_compartment(&self.global(), comp); + let promise = Promise::new_in_current_realm(&self.global(), comp); // Step 2. if self.context.control_thread_state() == ProcessingState::Closed { diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs index 925f5a9d27cb..c84d62f6dc3e 100644 --- a/components/script/dom/baseaudiocontext.rs +++ b/components/script/dom/baseaudiocontext.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::analysernode::AnalyserNode; use crate::dom::audiobuffer::AudioBuffer; use crate::dom::audiobuffersourcenode::AudioBufferSourceNode; @@ -47,6 +46,7 @@ use crate::dom::pannernode::PannerNode; use crate::dom::promise::Promise; use crate::dom::stereopannernode::StereoPannerNode; use crate::dom::window::Window; +use crate::realms::InRealm; use crate::task_source::TaskSource; use dom_struct::dom_struct; use js::rust::CustomAutoRooterGuard; @@ -282,9 +282,9 @@ impl BaseAudioContextMethods for BaseAudioContext { } /// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-resume - fn Resume(&self, comp: InCompartment) -> Rc { + fn Resume(&self, comp: InRealm) -> Rc { // Step 1. - let promise = Promise::new_in_current_compartment(&self.global(), comp); + let promise = Promise::new_in_current_realm(&self.global(), comp); // Step 2. if self.audio_context_impl.lock().unwrap().state() == ProcessingState::Closed { @@ -437,10 +437,10 @@ impl BaseAudioContextMethods for BaseAudioContext { audio_data: CustomAutoRooterGuard, decode_success_callback: Option>, decode_error_callback: Option>, - comp: InCompartment, + comp: InRealm, ) -> Rc { // Step 1. - let promise = Promise::new_in_current_compartment(&self.global(), comp); + let promise = Promise::new_in_current_realm(&self.global(), comp); let global = self.global(); let window = global.as_window(); diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index fe6b8d36d396..6a69fb782090 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -205,7 +205,7 @@ impl CallbackInterface { } } -/// Wraps the reflector for `p` into the compartment of `cx`. +/// Wraps the reflector for `p` into the realm of `cx`. pub fn wrap_call_this_object(cx: JSContext, p: &T, mut rval: MutableHandleObject) { rval.set(p.reflector().get_jsobject().get()); assert!(!rval.get().is_null()); @@ -225,7 +225,7 @@ pub struct CallSetup { exception_global: DomRoot, /// The `JSContext` used for the call. cx: JSContext, - /// The compartment we were in before the call. + /// The realm we were in before the call. old_realm: *mut Realm, /// The exception handling used for the call. handling: ExceptionHandling, diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 3a5f8576cef6..b1e6f6823ff4 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -44,7 +44,7 @@ DOMInterfaces = { #FIXME(jdm): This should be 'register': False, but then we don't generate enum types 'TestBinding': { - 'inCompartments': ['PromiseAttribute', 'PromiseNativeHandler'], + 'inRealms': ['PromiseAttribute', 'PromiseNativeHandler'], }, 'URL': { @@ -57,99 +57,99 @@ DOMInterfaces = { }, 'Window': { - 'inCompartments': ['Fetch'], + 'inRealms': ['Fetch'], }, 'WorkerGlobalScope': { - 'inCompartments': ['Fetch'], + 'inRealms': ['Fetch'], }, 'CustomElementRegistry': { - 'inCompartments': ['WhenDefined'], + 'inRealms': ['WhenDefined'], }, 'AudioContext': { - 'inCompartments': ['Suspend', 'Close'], + 'inRealms': ['Suspend', 'Close'], }, 'NavigationPreloadManager': { - 'inCompartments': ['Enable', 'Disable', 'SetHeaderValue', 'GetState'], + 'inRealms': ['Enable', 'Disable', 'SetHeaderValue', 'GetState'], }, 'HTMLMediaElement': { - 'inCompartments': ['Play'], + 'inRealms': ['Play'], }, 'BluetoothRemoteGATTDescriptor': { - 'inCompartments': ['ReadValue', 'WriteValue'], + 'inRealms': ['ReadValue', 'WriteValue'], }, 'OfflineAudioContext': { - 'inCompartments': ['StartRendering'], + 'inRealms': ['StartRendering'], }, 'BluetoothRemoteGATTServer': { - 'inCompartments': ['Connect'], + 'inRealms': ['Connect'], }, 'ServiceWorkerContainer': { - 'inCompartments': ['Register'], + 'inRealms': ['Register'], }, 'Navigator': { - 'inCompartments': ['GetVRDisplays'], + 'inRealms': ['GetVRDisplays'], }, 'MediaDevices': { - 'inCompartments': ['GetUserMedia'], + 'inRealms': ['GetUserMedia'], }, 'XRSession': { - 'inCompartments': ['UpdateRenderState', 'RequestReferenceSpace'], + 'inRealms': ['UpdateRenderState', 'RequestReferenceSpace'], }, 'Bluetooth': { - 'inCompartments': ['RequestDevice', 'GetAvailability'], + 'inRealms': ['RequestDevice', 'GetAvailability'], }, 'BaseAudioContext': { - 'inCompartments': ['Resume', 'DecodeAudioData'], + 'inRealms': ['Resume', 'DecodeAudioData'], }, 'RTCPeerConnection': { - 'inCompartments': ['AddIceCandidate', 'CreateOffer', 'CreateAnswer', 'SetLocalDescription', 'SetRemoteDescription'], + 'inRealms': ['AddIceCandidate', 'CreateOffer', 'CreateAnswer', 'SetLocalDescription', 'SetRemoteDescription'], }, 'BluetoothRemoteGATTCharacteristic': { - 'inCompartments': ['ReadValue', 'WriteValue', 'StartNotifications', 'StopNotifications'], + 'inRealms': ['ReadValue', 'WriteValue', 'StartNotifications', 'StopNotifications'], }, 'VRDisplay': { - 'inCompartments': ['RequestPresent', 'ExitPresent'], + 'inRealms': ['RequestPresent', 'ExitPresent'], }, 'Worklet': { - 'inCompartments': ['AddModule'], + 'inRealms': ['AddModule'], }, 'TestWorklet': { - 'inCompartments': ['AddModule'], + 'inRealms': ['AddModule'], }, 'BluetoothDevice': { - 'inCompartments': ['WatchAdvertisements'], + 'inRealms': ['WatchAdvertisements'], }, 'XR': { - 'inCompartments': ['SupportsSessionMode', 'RequestSession'], + 'inRealms': ['SupportsSessionMode', 'RequestSession'], }, 'GPU': { - 'inCompartments': ['RequestAdapter'], + 'inRealms': ['RequestAdapter'], }, 'GPUAdapter': { - 'inCompartments': ['RequestDevice'], + 'inRealms': ['RequestDevice'], } } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index d79bc073e769..ce1487d5fa62 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -771,14 +771,14 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type, # # 1) Normal call to API with a Promise argument. This is a case the # spec covers, and we should be using the current Realm's - # Promise. That means the current compartment. + # Promise. That means the current realm. # 2) Promise return value from a callback or callback interface. # This is in theory a case the spec covers but in practice it # really doesn't define behavior here because it doesn't define # what Realm we're in after the callback returns, which is when # the argument conversion happens. We will use the current - # compartment, which is the compartment of the callable (which - # may itself be a cross-compartment wrapper itself), which makes + # realm, which is the realm of the callable (which + # may itself be a cross-realm wrapper itself), which makes # as much sense as anything else. In practice, such an API would # once again be providing a Promise to signal completion of an # operation, which would then not be exposed to anyone other than @@ -3397,8 +3397,8 @@ def __init__(self, errorResult, arguments, argsPre, returnType, if "cx" not in argsPre and needsCx: args.prepend(CGGeneric("cx")) - if nativeMethodName in descriptor.inCompartmentMethods: - args.append(CGGeneric("InCompartment::in_compartment(&AlreadyInCompartment::assert_for_cx(cx))")) + if nativeMethodName in descriptor.inRealmMethods: + args.append(CGGeneric("InRealm::in_realm(&AlreadyInRealm::assert_for_cx(cx))")) # Build up our actual call self.cgRoot = CGList([], "\n") @@ -5671,7 +5671,7 @@ def definition_body(self): // Step 2 https://html.spec.whatwg.org/multipage/#htmlconstructor // The custom element definition cannot use an element interface as its constructor -// The new_target might be a cross-compartment wrapper. Get the underlying object +// The new_target might be a cross-realm wrapper. Get the underlying object // so we can do the spec's object-identity checks. rooted!(in(*cx) let new_target = UnwrapObjectDynamic(args.new_target().to_object(), *cx, 1)); if new_target.is_null() { @@ -5697,11 +5697,11 @@ def definition_body(self): if !proto_val.is_object() { // Step 7 of https://html.spec.whatwg.org/multipage/#htmlconstructor. // This fallback behavior is designed to match analogous behavior for the - // JavaScript built-ins. So we enter the compartment of our underlying + // JavaScript built-ins. So we enter the realm of our underlying // newTarget object and fall back to the prototype object from that global. // XXX The spec says to use GetFunctionRealm(), which is not actually // the same thing as what we have here (e.g. in the case of scripted callable proxies - // whose target is not same-compartment with the proxy, or bound functions, etc). + // whose target is not same-realm with the proxy, or bound functions, etc). // https://bugzilla.mozilla.org/show_bug.cgi?id=1317658 rooted!(in(*cx) let global_object = CurrentGlobalOrNull(*cx)); @@ -5712,7 +5712,7 @@ def definition_body(self): }; } -// Wrap prototype in this context since it is from the newTarget compartment +// Wrap prototype in this context since it is from the newTarget realm if !JS_WrapObject(*cx, prototype.handle_mut()) { return false; } @@ -5770,15 +5770,15 @@ class CGInterfaceTrait(CGThing): def __init__(self, descriptor): CGThing.__init__(self) - def attribute_arguments(needCx, argument=None, inCompartment=False): + def attribute_arguments(needCx, argument=None, inRealm=False): if needCx: yield "cx", "SafeJSContext" if argument: yield "value", argument_type(descriptor, argument) - if inCompartment: - yield "_comp", "InCompartment" + if inRealm: + yield "_comp", "InRealm" def members(): for m in descriptor.interface.members: @@ -5790,7 +5790,7 @@ def members(): infallible = 'infallible' in descriptor.getExtendedAttributes(m) for idx, (rettype, arguments) in enumerate(m.signatures()): arguments = method_arguments(descriptor, rettype, arguments, - inCompartment=name in descriptor.inCompartmentMethods) + inRealm=name in descriptor.inRealmMethods) rettype = return_type(descriptor, rettype, infallible) yield name + ('_' * idx), arguments, rettype elif m.isAttr() and not m.isStatic(): @@ -5799,7 +5799,7 @@ def members(): yield (name, attribute_arguments( typeNeedsCx(m.type, True), - inCompartment=name in descriptor.inCompartmentMethods + inRealm=name in descriptor.inRealmMethods ), return_type(descriptor, m.type, infallible)) @@ -5814,7 +5814,7 @@ def members(): attribute_arguments( typeNeedsCx(m.type, False), m.type, - inCompartment=name in descriptor.inCompartmentMethods + inRealm=name in descriptor.inRealmMethods ), rettype) @@ -5831,7 +5831,7 @@ def members(): if not rettype.nullable(): rettype = IDLNullableType(rettype.location, rettype) arguments = method_arguments(descriptor, rettype, arguments, - inCompartment=name in descriptor.inCompartmentMethods) + inRealm=name in descriptor.inRealmMethods) # If this interface 'supports named properties', then we # should be able to access 'supported property names' @@ -5842,7 +5842,7 @@ def members(): yield "SupportedPropertyNames", [], "Vec" else: arguments = method_arguments(descriptor, rettype, arguments, - inCompartment=name in descriptor.inCompartmentMethods) + inRealm=name in descriptor.inRealmMethods) rettype = return_type(descriptor, rettype, infallible) yield name, arguments, rettype @@ -6138,8 +6138,8 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'crate::dom::windowproxy::WindowProxy', 'crate::dom::globalscope::GlobalScope', 'crate::mem::malloc_size_of_including_raw_self', - 'crate::compartments::InCompartment', - 'crate::compartments::AlreadyInCompartment', + 'crate::realms::InRealm', + 'crate::realms::AlreadyInRealm', 'crate::script_runtime::JSContext as SafeJSContext', 'libc', 'servo_config::pref', @@ -6861,7 +6861,7 @@ def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, var return declType.define() -def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, trailing=None, inCompartment=False): +def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, trailing=None, inRealm=False): if needCx(returnType, arguments, passJSBits): yield "cx", "SafeJSContext" @@ -6873,8 +6873,8 @@ def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, if trailing: yield trailing - if inCompartment: - yield "_comp", "InCompartment" + if inRealm: + yield "_comp", "InRealm" def return_type(descriptorProvider, rettype, infallible): diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py index 84d8bd974aa7..b3e1e0c8289d 100644 --- a/components/script/dom/bindings/codegen/Configuration.py +++ b/components/script/dom/bindings/codegen/Configuration.py @@ -220,7 +220,7 @@ def __init__(self, config, interface, desc): self.concreteType = typeName self.register = desc.get('register', True) self.path = desc.get('path', pathDefault) - self.inCompartmentMethods = [name for name in desc.get('inCompartments', [])] + self.inRealmMethods = [name for name in desc.get('inRealms', [])] self.bindingPath = 'crate::dom::bindings::codegen::Bindings::%s' % ('::'.join([ifaceName + 'Binding'] * 2)) self.outerObjectHook = desc.get('outerObjectHook', 'None') self.proxy = False diff --git a/components/script/dom/bindings/structuredclone.rs b/components/script/dom/bindings/structuredclone.rs index 4bbb320ac5c5..82f7a4a7989f 100644 --- a/components/script/dom/bindings/structuredclone.rs +++ b/components/script/dom/bindings/structuredclone.rs @@ -5,7 +5,6 @@ //! This module implements structured cloning, as defined by [HTML] //! (https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data). -use crate::compartments::enter_realm; use crate::dom::bindings::conversions::{root_from_object, ToJSValConvertible}; use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::reflector::DomObject; @@ -15,6 +14,7 @@ use crate::dom::bindings::transferable::Transferable; use crate::dom::blob::Blob; use crate::dom::globalscope::GlobalScope; use crate::dom::messageport::MessagePort; +use crate::realms::enter_realm; use crate::script_runtime::JSContext as SafeJSContext; use js::glue::CopyJSStructuredCloneData; use js::glue::DeleteJSAutoStructuredCloneBuffer; diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index d28717e3eaf3..c769cfcef943 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -7,7 +7,7 @@ use bluetooth_traits::{BluetoothResponse, BluetoothResponseResult}; use bluetooth_traits::blocklist::{Blocklist, uuid_is_blocklisted}; use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence}; use bluetooth_traits::scanfilter::{RequestDeviceoptions, ServiceUUIDSequence}; -use crate::compartments::{AlreadyInCompartment, InCompartment}; +use crate::realms::{AlreadyInRealm, InRealm}; use crate::dom::bindings::cell::{DomRefCell, Ref}; use crate::dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothDataFilterInit}; use crate::dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions}; @@ -291,11 +291,8 @@ where T: AsyncBluetoothListener + DomObject + 'static, F: FnOnce(StringOrUnsignedLong) -> Fallible, { - let in_compartment_proof = AlreadyInCompartment::assert(&attribute.global()); - let p = Promise::new_in_current_compartment( - &attribute.global(), - InCompartment::Already(&in_compartment_proof), - ); + let in_realm_proof = AlreadyInRealm::assert(&attribute.global()); + let p = Promise::new_in_current_realm(&attribute.global(), InRealm::Already(&in_realm_proof)); let result_uuid = if let Some(u) = uuid { // Step 1. @@ -534,8 +531,8 @@ impl From for Error { impl BluetoothMethods for Bluetooth { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice - fn RequestDevice(&self, option: &RequestDeviceOptions, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn RequestDevice(&self, option: &RequestDeviceOptions, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // Step 1. if (option.filters.is_some() && option.acceptAllDevices) || (option.filters.is_none() && !option.acceptAllDevices) @@ -552,8 +549,8 @@ impl BluetoothMethods for Bluetooth { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-getavailability - fn GetAvailability(&self, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn GetAvailability(&self, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // Step 1. We did not override the method // Step 2 - 3. in handle_response let sender = response_async(&p, self); diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetoothdevice.rs index 09da75426c1c..3ba192aa36fb 100644 --- a/components/script/dom/bluetoothdevice.rs +++ b/components/script/dom/bluetoothdevice.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::BluetoothDeviceBinding; use crate::dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods; @@ -22,6 +21,7 @@ use crate::dom::bluetoothremotegattservice::BluetoothRemoteGATTService; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; +use crate::realms::InRealm; use bluetooth_traits::{BluetoothCharacteristicMsg, BluetoothDescriptorMsg}; use bluetooth_traits::{BluetoothRequest, BluetoothResponse, BluetoothServiceMsg}; use dom_struct::dom_struct; @@ -278,8 +278,8 @@ impl BluetoothDeviceMethods for BluetoothDevice { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-watchadvertisements - fn WatchAdvertisements(&self, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn WatchAdvertisements(&self, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); let sender = response_async(&p, self); // TODO: Step 1. // Note: Steps 2 - 3 are implemented in components/bluetooth/lib.rs in watch_advertisements function diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index d50e4b548949..d5e700a0949e 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding::BluetoothCharacteristicPropertiesMethods; use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding; @@ -24,6 +23,7 @@ use crate::dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID}; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; +use crate::realms::InRealm; use bluetooth_traits::blocklist::{uuid_is_blocklisted, Blocklist}; use bluetooth_traits::{BluetoothRequest, BluetoothResponse, GATTType}; use dom_struct::dom_struct; @@ -138,8 +138,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue - fn ReadValue(&self, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn ReadValue(&self, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // Step 1. if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) { @@ -171,8 +171,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue - fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // Step 1. if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) { @@ -222,8 +222,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications - fn StartNotifications(&self, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn StartNotifications(&self, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // Step 1. if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) { @@ -259,8 +259,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-stopnotifications - fn StopNotifications(&self, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn StopNotifications(&self, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); let sender = response_async(&p, self); // TODO: Step 3 - 4: Implement `active notification context set` for BluetoothRemoteGATTCharacteristic, diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs index 7cc53159d21e..9680ea75cd3a 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetoothremotegattdescriptor.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::BluetoothRemoteGATTCharacteristicMethods; use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding; @@ -20,6 +19,7 @@ use crate::dom::bluetoothremotegattcharacteristic::{ }; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; +use crate::realms::InRealm; use bluetooth_traits::blocklist::{uuid_is_blocklisted, Blocklist}; use bluetooth_traits::{BluetoothRequest, BluetoothResponse}; use dom_struct::dom_struct; @@ -94,8 +94,8 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue - fn ReadValue(&self, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn ReadValue(&self, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // Step 1. if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) { @@ -126,8 +126,8 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue - fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // Step 1. if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) { diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs index 52fc0bbf44da..76270373d736 100644 --- a/components/script/dom/bluetoothremotegattserver.rs +++ b/components/script/dom/bluetoothremotegattserver.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods; use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding; use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods; @@ -15,6 +14,7 @@ use crate::dom::bluetoothdevice::BluetoothDevice; use crate::dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID}; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; +use crate::realms::InRealm; use bluetooth_traits::{BluetoothRequest, BluetoothResponse, GATTType}; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; @@ -71,9 +71,9 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect #[allow(unsafe_code)] - fn Connect(&self, comp: InCompartment) -> Rc { + fn Connect(&self, comp: InRealm) -> Rc { // Step 1. - let p = Promise::new_in_current_compartment(&self.global(), comp); + let p = Promise::new_in_current_realm(&self.global(), comp); let sender = response_async(&p, self); // TODO: Step 3: Check if the UA is currently using the Bluetooth system. diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index 7a6e269a38d3..aa002cd5f945 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::callback::{CallbackContainer, ExceptionHandling}; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::CustomElementRegistryBinding; @@ -31,6 +30,7 @@ use crate::dom::node::{document_from_node, window_from_node, Node, ShadowIncludi use crate::dom::promise::Promise; use crate::dom::window::Window; use crate::microtask::Microtask; +use crate::realms::InRealm; use crate::script_runtime::JSContext; use crate::script_thread::ScriptThread; use dom_struct::dom_struct; @@ -417,20 +417,20 @@ impl CustomElementRegistryMethods for CustomElementRegistry { } /// - fn WhenDefined(&self, name: DOMString, comp: InCompartment) -> Rc { + fn WhenDefined(&self, name: DOMString, comp: InRealm) -> Rc { let global_scope = self.window.upcast::(); let name = LocalName::from(&*name); // Step 1 if !is_valid_custom_element_name(&name) { - let promise = Promise::new_in_current_compartment(&global_scope, comp); + let promise = Promise::new_in_current_realm(&global_scope, comp); promise.reject_native(&DOMException::new(&global_scope, DOMErrorName::SyntaxError)); return promise; } // Step 2 if self.definitions.borrow().contains_key(&name) { - let promise = Promise::new_in_current_compartment(&global_scope, comp); + let promise = Promise::new_in_current_realm(&global_scope, comp); promise.resolve_native(&UndefinedValue()); return promise; } @@ -440,7 +440,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry { // Steps 4, 5 let promise = map.get(&name).cloned().unwrap_or_else(|| { - let promise = Promise::new_in_current_compartment(&global_scope, comp); + let promise = Promise::new_in_current_realm(&global_scope, comp); map.insert(name, promise.clone()); promise }); @@ -535,7 +535,7 @@ impl CustomElementDefinition { rooted!(in(*cx) let constructor = ObjectValue(self.constructor.callback())); rooted!(in(*cx) let mut element = ptr::null_mut::()); { - // Go into the constructor's compartment + // Go into the constructor's realm let _ac = JSAutoRealm::new(*cx, self.constructor.callback()); let args = HandleValueArray::new(); if unsafe { !Construct1(*cx, constructor.handle(), &args, element.handle_mut()) } { @@ -676,7 +676,7 @@ fn run_upgrade_constructor( { // Step 8.1 TODO when shadow DOM exists - // Go into the constructor's compartment + // Go into the constructor's realm let _ac = JSAutoRealm::new(*cx, constructor.callback()); let args = HandleValueArray::new(); // Step 8.2 diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index ad0e7445f0f5..4185802e7bd2 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::devtools; use crate::dom::abstractworker::{SimpleWorkerErrorHandler, WorkerScriptMsg}; use crate::dom::abstractworkerglobalscope::{run_worker_event_loop, WorkerEventLoopMethods}; @@ -27,6 +26,7 @@ use crate::dom::messageevent::MessageEvent; use crate::dom::worker::{TrustedWorkerAddress, Worker}; use crate::dom::workerglobalscope::WorkerGlobalScope; use crate::fetch::load_whole_resource; +use crate::realms::enter_realm; use crate::script_runtime::ScriptThreadEventCategory::WorkerEvent; use crate::script_runtime::{ new_child_runtime, CommonScriptMsg, JSContext as SafeJSContext, Runtime, ScriptChan, ScriptPort, diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 16f22c1dfa81..98e7663bbf1b 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::{AlreadyInCompartment, InCompartment}; use crate::document_loader::{DocumentLoader, LoadType}; use crate::dom::activation::{synthetic_click_activation, ActivationSource}; use crate::dom::attr::Attr; @@ -97,6 +96,7 @@ use crate::dom::wheelevent::WheelEvent; use crate::dom::window::{ReflowReason, Window}; use crate::dom::windowproxy::WindowProxy; use crate::fetch::FetchCanceller; +use crate::realms::{AlreadyInRealm, InRealm}; use crate::script_runtime::JSContext; use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use crate::script_thread::{MainThreadScriptMsg, ScriptThread}; @@ -3170,11 +3170,9 @@ impl Document { // https://fullscreen.spec.whatwg.org/#dom-element-requestfullscreen pub fn enter_fullscreen(&self, pending: &Element) -> Rc { // Step 1 - let in_compartment_proof = AlreadyInCompartment::assert(&self.global()); - let promise = Promise::new_in_current_compartment( - &self.global(), - InCompartment::Already(&in_compartment_proof), - ); + let in_realm_proof = AlreadyInRealm::assert(&self.global()); + let promise = + Promise::new_in_current_realm(&self.global(), InRealm::Already(&in_realm_proof)); let mut error = false; // Step 4 @@ -3241,11 +3239,8 @@ impl Document { pub fn exit_fullscreen(&self) -> Rc { let global = self.global(); // Step 1 - let in_compartment_proof = AlreadyInCompartment::assert(&global); - let promise = Promise::new_in_current_compartment( - &global, - InCompartment::Already(&in_compartment_proof), - ); + let in_realm_proof = AlreadyInRealm::assert(&global); + let promise = Promise::new_in_current_realm(&global, InRealm::Already(&in_realm_proof)); // Step 2 if self.fullscreen_element.get().is_none() { promise.reject_error(Error::Type(String::from("fullscreen is null"))); diff --git a/components/script/dom/eventsource.rs b/components/script/dom/eventsource.rs index 1b471a856310..c3e3bbc339bc 100644 --- a/components/script/dom/eventsource.rs +++ b/components/script/dom/eventsource.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::EventSourceBinding::{ EventSourceInit, EventSourceMethods, Wrap, @@ -20,6 +19,7 @@ use crate::dom::messageevent::MessageEvent; use crate::dom::performanceresourcetiming::InitiatorType; use crate::fetch::{create_a_potential_cors_request, FetchCanceller}; use crate::network_listener::{self, NetworkListener, PreInvoke, ResourceTimingListener}; +use crate::realms::enter_realm; use crate::task_source::{TaskSource, TaskSourceName}; use crate::timers::OneshotTimerCallback; use dom_struct::dom_struct; diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 9106587ec312..396ffb75441c 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::beforeunloadevent::BeforeUnloadEvent; use crate::dom::bindings::callback::{CallbackContainer, CallbackFunction, ExceptionHandling}; use crate::dom::bindings::cell::DomRefCell; @@ -34,6 +33,7 @@ use crate::dom::htmlformelement::FormControlElementHelpers; use crate::dom::node::document_from_node; use crate::dom::virtualmethods::VirtualMethods; use crate::dom::window::Window; +use crate::realms::enter_realm; use dom_struct::dom_struct; use fnv::FnvHasher; use js::jsapi::{JSAutoRealm, JSFunction, JS_GetFunctionObject, SourceText}; diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index ce828435c4b9..557b2def7615 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use crate::dom::bindings::codegen::Bindings::FileReaderBinding::{ @@ -22,6 +21,7 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::progressevent::ProgressEvent; +use crate::realms::enter_realm; use crate::script_runtime::JSContext; use crate::task_source::file_reading::FileReadingTask; use crate::task_source::{TaskSource, TaskSourceName}; diff --git a/components/script/dom/gpu.rs b/components/script/dom/gpu.rs index 0a6d6ca2dcf8..8f129e14c30c 100644 --- a/components/script/dom/gpu.rs +++ b/components/script/dom/gpu.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::GPUBinding::GPURequestAdapterOptions; use crate::dom::bindings::codegen::Bindings::GPUBinding::{self, GPUMethods, GPUPowerPreference}; use crate::dom::bindings::error::Error; @@ -13,6 +12,7 @@ use crate::dom::bindings::str::DOMString; use crate::dom::globalscope::GlobalScope; use crate::dom::gpuadapter::GPUAdapter; use crate::dom::promise::Promise; +use crate::realms::InRealm; use crate::task_source::{TaskSource, TaskSourceName}; use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcSender}; @@ -104,13 +104,9 @@ pub fn response_async( impl GPUMethods for GPU { // https://gpuweb.github.io/gpuweb/#dom-gpu-requestadapter - fn RequestAdapter( - &self, - options: &GPURequestAdapterOptions, - comp: InCompartment, - ) -> Rc { + fn RequestAdapter(&self, options: &GPURequestAdapterOptions, comp: InRealm) -> Rc { let global = &self.global(); - let promise = Promise::new_in_current_compartment(global, comp); + let promise = Promise::new_in_current_realm(global, comp); let sender = response_async(&promise, self); let power_preference = match options.powerPreference { Some(GPUPowerPreference::Low_power) => wgpu::instance::PowerPreference::LowPower, diff --git a/components/script/dom/gpuadapter.rs b/components/script/dom/gpuadapter.rs index c4eebe0c5d51..f8ea0083153a 100644 --- a/components/script/dom/gpuadapter.rs +++ b/components/script/dom/gpuadapter.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::{ self, GPUAdapterMethods, GPUDeviceDescriptor, }; @@ -15,6 +14,7 @@ use crate::dom::gpu::response_async; use crate::dom::gpu::AsyncWGPUListener; use crate::dom::gpudevice::GPUDevice; use crate::dom::promise::Promise; +use crate::realms::InRealm; use crate::script_runtime::JSContext as SafeJSContext; use dom_struct::dom_struct; use js::jsapi::{Heap, JSObject}; @@ -78,8 +78,8 @@ impl GPUAdapterMethods for GPUAdapter { } /// https://gpuweb.github.io/gpuweb/#dom-gpuadapter-requestdevice - fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&self.global(), comp); + fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&self.global(), comp); let sender = response_async(&promise, self); let desc = wgpu::instance::DeviceDescriptor { extensions: wgpu::instance::Extensions { diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 500e54e38671..e8cd7737a2e7 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::document_loader::{LoadBlocker, LoadType}; use crate::dom::attr::Attr; use crate::dom::audiotrack::AudioTrack; @@ -63,6 +62,7 @@ use crate::dom::virtualmethods::VirtualMethods; use crate::fetch::{create_a_potential_cors_request, FetchCanceller}; use crate::microtask::{Microtask, MicrotaskRunnable}; use crate::network_listener::{self, NetworkListener, PreInvoke, ResourceTimingListener}; +use crate::realms::InRealm; use crate::script_thread::ScriptThread; use crate::task_source::TaskSource; use dom_struct::dom_struct; @@ -2105,8 +2105,8 @@ impl HTMLMediaElementMethods for HTMLMediaElement { } // https://html.spec.whatwg.org/multipage/#dom-media-play - fn Play(&self, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&self.global(), comp); + fn Play(&self, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&self.global(), comp); // Step 1. // FIXME(nox): Reject promise if not allowed to play. diff --git a/components/script/dom/mediadevices.rs b/components/script/dom/mediadevices.rs index 6cdc5eb7e04a..c1d45e36d308 100644 --- a/components/script/dom/mediadevices.rs +++ b/components/script/dom/mediadevices.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::MediaDevicesBinding::MediaStreamConstraints; use crate::dom::bindings::codegen::Bindings::MediaDevicesBinding::{self, MediaDevicesMethods}; use crate::dom::bindings::codegen::UnionTypes::BooleanOrMediaTrackConstraints; @@ -16,6 +15,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::mediastream::MediaStream; use crate::dom::mediastreamtrack::MediaStreamTrack; use crate::dom::promise::Promise; +use crate::realms::InRealm; use dom_struct::dom_struct; use servo_media::streams::capture::{Constrain, ConstrainRange, MediaTrackConstraintSet}; use servo_media::streams::MediaStreamType; @@ -46,12 +46,8 @@ impl MediaDevices { impl MediaDevicesMethods for MediaDevices { /// https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia #[allow(unsafe_code)] - fn GetUserMedia( - &self, - constraints: &MediaStreamConstraints, - comp: InCompartment, - ) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn GetUserMedia(&self, constraints: &MediaStreamConstraints, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); let media = ServoMedia::get().unwrap(); let stream = MediaStream::new(&self.global()); if let Some(constraints) = convert_constraints(&constraints.audio) { diff --git a/components/script/dom/mediasession.rs b/components/script/dom/mediasession.rs index 8dfc88a1c04d..c8df282f3647 100644 --- a/components/script/dom/mediasession.rs +++ b/components/script/dom/mediasession.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::{AlreadyInCompartment, InCompartment}; use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementMethods; @@ -22,6 +21,7 @@ use crate::dom::bindings::str::DOMString; use crate::dom::htmlmediaelement::HTMLMediaElement; use crate::dom::mediametadata::MediaMetadata; use crate::dom::window::Window; +use crate::realms::{AlreadyInRealm, InRealm}; use dom_struct::dom_struct; use embedder_traits::MediaMetadata as EmbedderMediaMetadata; use embedder_traits::MediaSessionEvent; @@ -85,8 +85,8 @@ impl MediaSession { if let Some(media) = self.media_instance.get() { match action { MediaSessionActionType::Play => { - let in_compartment_proof = AlreadyInCompartment::assert(&self.global()); - media.Play(InCompartment::Already(&in_compartment_proof)); + let in_realm_proof = AlreadyInRealm::assert(&self.global()); + media.Play(InRealm::Already(&in_realm_proof)); }, MediaSessionActionType::Pause => { media.Pause(); diff --git a/components/script/dom/navigationpreloadmanager.rs b/components/script/dom/navigationpreloadmanager.rs index 94a9f0056c65..78104ec7c453 100644 --- a/components/script/dom/navigationpreloadmanager.rs +++ b/components/script/dom/navigationpreloadmanager.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::NavigationPreloadManagerBinding::NavigationPreloadState; use crate::dom::bindings::codegen::Bindings::NavigationPreloadManagerBinding::{ NavigationPreloadManagerMethods, Wrap, @@ -14,6 +13,7 @@ use crate::dom::domexception::{DOMErrorName, DOMException}; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::dom::serviceworkerregistration::ServiceWorkerRegistration; +use crate::realms::InRealm; use dom_struct::dom_struct; use js::jsval::UndefinedValue; use std::rc::Rc; @@ -44,8 +44,8 @@ impl NavigationPreloadManager { impl NavigationPreloadManagerMethods for NavigationPreloadManager { // https://w3c.github.io/ServiceWorker/#navigation-preload-manager-enable - fn Enable(&self, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&*self.global(), comp); + fn Enable(&self, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&*self.global(), comp); // 2. if self.serviceworker_registration.active().is_none() { @@ -66,8 +66,8 @@ impl NavigationPreloadManagerMethods for NavigationPreloadManager { } // https://w3c.github.io/ServiceWorker/#navigation-preload-manager-disable - fn Disable(&self, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&*self.global(), comp); + fn Disable(&self, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&*self.global(), comp); // 2. if self.serviceworker_registration.active().is_none() { @@ -88,8 +88,8 @@ impl NavigationPreloadManagerMethods for NavigationPreloadManager { } // https://w3c.github.io/ServiceWorker/#navigation-preload-manager-setheadervalue - fn SetHeaderValue(&self, value: ByteString, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&*self.global(), comp); + fn SetHeaderValue(&self, value: ByteString, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&*self.global(), comp); // 2. if self.serviceworker_registration.active().is_none() { @@ -110,8 +110,8 @@ impl NavigationPreloadManagerMethods for NavigationPreloadManager { } // https://w3c.github.io/ServiceWorker/#navigation-preload-manager-getstate - fn GetState(&self, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&*self.global(), comp); + fn GetState(&self, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&*self.global(), comp); // 2. let mut state = NavigationPreloadState::empty(); diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index cb8fb2365cdb..47bf1e6845aa 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::NavigatorBinding; use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods; use crate::dom::bindings::error::Error; @@ -22,6 +21,7 @@ use crate::dom::promise::Promise; use crate::dom::serviceworkercontainer::ServiceWorkerContainer; use crate::dom::window::Window; use crate::dom::xr::XR; +use crate::realms::InRealm; use dom_struct::dom_struct; use std::rc::Rc; @@ -172,8 +172,8 @@ impl NavigatorMethods for Navigator { } // https://w3c.github.io/webvr/spec/1.1/#navigator-getvrdisplays-attribute - fn GetVRDisplays(&self, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&self.global(), comp); + fn GetVRDisplays(&self, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&self.global(), comp); let displays = self.Xr().get_displays(); match displays { Ok(displays) => promise.resolve_native(&displays), diff --git a/components/script/dom/offlineaudiocontext.rs b/components/script/dom/offlineaudiocontext.rs index 63ec3ffdbe2e..a524595d6eaa 100644 --- a/components/script/dom/offlineaudiocontext.rs +++ b/components/script/dom/offlineaudiocontext.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::audiobuffer::{AudioBuffer, MAX_SAMPLE_RATE, MIN_SAMPLE_RATE}; use crate::dom::audionode::MAX_CHANNEL_COUNT; use crate::dom::baseaudiocontext::{BaseAudioContext, BaseAudioContextOptions}; @@ -21,6 +20,7 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::offlineaudiocompletionevent::OfflineAudioCompletionEvent; use crate::dom::promise::Promise; use crate::dom::window::Window; +use crate::realms::InRealm; use crate::task_source::TaskSource; use dom_struct::dom_struct; use msg::constellation_msg::PipelineId; @@ -127,8 +127,8 @@ impl OfflineAudioContextMethods for OfflineAudioContext { } // https://webaudio.github.io/web-audio-api/#dom-offlineaudiocontext-startrendering - fn StartRendering(&self, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&self.global(), comp); + fn StartRendering(&self, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&self.global(), comp); if self.rendering_started.get() { promise.reject_error(Error::InvalidState); return promise; diff --git a/components/script/dom/permissions.rs b/components/script/dom/permissions.rs index 66fe3f01be7c..cb91fb692f9a 100644 --- a/components/script/dom/permissions.rs +++ b/components/script/dom/permissions.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::{AlreadyInCompartment, InCompartment}; use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionDescriptor; use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionStatusMethods; use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::{ @@ -17,6 +16,7 @@ use crate::dom::bluetoothpermissionresult::BluetoothPermissionResult; use crate::dom::globalscope::GlobalScope; use crate::dom::permissionstatus::PermissionStatus; use crate::dom::promise::Promise; +use crate::realms::{AlreadyInRealm, InRealm}; use crate::script_runtime::JSContext; use dom_struct::dom_struct; use js::conversions::ConversionResult; @@ -97,11 +97,8 @@ impl Permissions { let p = match promise { Some(promise) => promise, None => { - let in_compartment_proof = AlreadyInCompartment::assert(&self.global()); - Promise::new_in_current_compartment( - &self.global(), - InCompartment::Already(&in_compartment_proof), - ) + let in_realm_proof = AlreadyInRealm::assert(&self.global()); + Promise::new_in_current_realm(&self.global(), InRealm::Already(&in_realm_proof)) }, }; diff --git a/components/script/dom/promise.rs b/components/script/dom/promise.rs index 785c1be89395..f3671a5057f9 100644 --- a/components/script/dom/promise.rs +++ b/components/script/dom/promise.rs @@ -11,13 +11,13 @@ //! native Promise values that refer to the same JS value yet are distinct native objects //! (ie. address equality for the native objects is meaningless). -use crate::compartments::{enter_realm, InCompartment}; use crate::dom::bindings::conversions::root_from_object; use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::reflector::{DomObject, MutDomObject, Reflector}; use crate::dom::bindings::utils::AsCCharPtrPtr; use crate::dom::globalscope::GlobalScope; use crate::dom::promisenativehandler::PromiseNativeHandler; +use crate::realms::{enter_realm, InRealm}; use crate::script_runtime::JSContext as SafeJSContext; use dom_struct::dom_struct; use js::conversions::ToJSValConvertible; @@ -83,12 +83,12 @@ impl Drop for Promise { impl Promise { pub fn new(global: &GlobalScope) -> Rc { - let compartment = enter_realm(&*global); - let comp = InCompartment::Entered(&compartment); - Promise::new_in_current_compartment(global, comp) + let realm = enter_realm(&*global); + let comp = InRealm::Entered(&realm); + Promise::new_in_current_realm(global, comp) } - pub fn new_in_current_compartment(global: &GlobalScope, _comp: InCompartment) -> Rc { + pub fn new_in_current_realm(global: &GlobalScope, _comp: InRealm) -> Rc { let cx = global.get_cx(); rooted!(in(*cx) let mut obj = ptr::null_mut::()); Promise::create_js_promise(cx, HandleObject::null(), obj.handle_mut()); diff --git a/components/script/dom/rtcpeerconnection.rs b/components/script/dom/rtcpeerconnection.rs index 13ac289263d4..ae246cae5b47 100644 --- a/components/script/dom/rtcpeerconnection.rs +++ b/components/script/dom/rtcpeerconnection.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::RTCIceCandidateInit; use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding; @@ -33,6 +32,7 @@ use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent; use crate::dom::rtcsessiondescription::RTCSessionDescription; use crate::dom::rtctrackevent::RTCTrackEvent; use crate::dom::window::Window; +use crate::realms::InRealm; use crate::task::TaskCanceller; use crate::task_source::networking::NetworkingTaskSource; use crate::task_source::TaskSource; @@ -454,8 +454,8 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { ); /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addicecandidate - fn AddIceCandidate(&self, candidate: &RTCIceCandidateInit, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn AddIceCandidate(&self, candidate: &RTCIceCandidateInit, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); if candidate.sdpMid.is_none() && candidate.sdpMLineIndex.is_none() { p.reject_error(Error::Type(format!( "one of sdpMid and sdpMLineIndex must be set" @@ -489,8 +489,8 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { } /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-createoffer - fn CreateOffer(&self, _options: &RTCOfferOptions, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn CreateOffer(&self, _options: &RTCOfferOptions, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); if self.closed.get() { p.reject_error(Error::InvalidState); return p; @@ -501,8 +501,8 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { } /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-createoffer - fn CreateAnswer(&self, _options: &RTCAnswerOptions, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn CreateAnswer(&self, _options: &RTCAnswerOptions, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); if self.closed.get() { p.reject_error(Error::InvalidState); return p; @@ -523,13 +523,9 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { } /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-setlocaldescription - fn SetLocalDescription( - &self, - desc: &RTCSessionDescriptionInit, - comp: InCompartment, - ) -> Rc { + fn SetLocalDescription(&self, desc: &RTCSessionDescriptionInit, comp: InRealm) -> Rc { // XXXManishearth validate the current state - let p = Promise::new_in_current_compartment(&self.global(), comp); + let p = Promise::new_in_current_realm(&self.global(), comp); let this = Trusted::new(self); let desc: SessionDescription = desc.into(); let trusted_promise = TrustedPromise::new(p.clone()); @@ -560,13 +556,9 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { } /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-setremotedescription - fn SetRemoteDescription( - &self, - desc: &RTCSessionDescriptionInit, - comp: InCompartment, - ) -> Rc { + fn SetRemoteDescription(&self, desc: &RTCSessionDescriptionInit, comp: InRealm) -> Rc { // XXXManishearth validate the current state - let p = Promise::new_in_current_compartment(&self.global(), comp); + let p = Promise::new_in_current_realm(&self.global(), comp); let this = Trusted::new(self); let desc: SessionDescription = desc.into(); let trusted_promise = TrustedPromise::new(p.clone()); diff --git a/components/script/dom/serviceworkercontainer.rs b/components/script/dom/serviceworkercontainer.rs index ed1b79a5c8a8..66ff8e738f73 100644 --- a/components/script/dom/serviceworkercontainer.rs +++ b/components/script/dom/serviceworkercontainer.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::ServiceWorkerContainerBinding::RegistrationOptions; use crate::dom::bindings::codegen::Bindings::ServiceWorkerContainerBinding::{ ServiceWorkerContainerMethods, Wrap, @@ -16,6 +15,7 @@ use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::dom::serviceworker::ServiceWorker; +use crate::realms::InRealm; use crate::script_thread::ScriptThread; use crate::serviceworkerjob::{Job, JobType}; use dom_struct::dom_struct; @@ -59,10 +59,10 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer { &self, script_url: USVString, options: &RegistrationOptions, - comp: InCompartment, + comp: InRealm, ) -> Rc { // A: Step 1 - let promise = Promise::new_in_current_compartment(&*self.global(), comp); + let promise = Promise::new_in_current_realm(&*self.global(), comp); let USVString(ref script_url) = script_url; let api_base_url = self.global().api_base_url(); // A: Step 3-5 diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index ada042c17ac1..5e63093e6178 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::devtools; use crate::dom::abstractworker::WorkerScriptMsg; use crate::dom::abstractworkerglobalscope::{run_worker_event_loop, WorkerEventLoopMethods}; @@ -23,6 +22,7 @@ use crate::dom::messageevent::MessageEvent; use crate::dom::worker::TrustedWorkerAddress; use crate::dom::workerglobalscope::WorkerGlobalScope; use crate::fetch::load_whole_resource; +use crate::realms::enter_realm; use crate::script_runtime::{ new_rt_and_cx, CommonScriptMsg, JSContext as SafeJSContext, Runtime, ScriptChan, }; diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 52018d73b6f5..c77b7cd994d4 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -4,7 +4,6 @@ // check-tidy: no specs after this line -use crate::compartments::InCompartment; use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function; @@ -49,6 +48,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler}; use crate::dom::url::URL; +use crate::realms::InRealm; use crate::script_runtime::JSContext as SafeJSContext; use crate::timers::OneshotTimerCallback; use dom_struct::dom_struct; @@ -990,7 +990,7 @@ impl TestBindingMethods for TestBinding { &self, resolve: Option>, reject: Option>, - comp: InCompartment, + comp: InRealm, ) -> Rc { let global = self.global(); let handler = PromiseNativeHandler::new( @@ -998,7 +998,7 @@ impl TestBindingMethods for TestBinding { resolve.map(SimpleHandler::new), reject.map(SimpleHandler::new), ); - let p = Promise::new_in_current_compartment(&global, comp); + let p = Promise::new_in_current_realm(&global, comp); p.append_native_handler(&handler); return p; @@ -1021,8 +1021,8 @@ impl TestBindingMethods for TestBinding { } } - fn PromiseAttribute(&self, comp: InCompartment) -> Rc { - Promise::new_in_current_compartment(&self.global(), comp) + fn PromiseAttribute(&self, comp: InRealm) -> Rc { + Promise::new_in_current_realm(&self.global(), comp) } fn AcceptPromise(&self, _promise: &Promise) {} diff --git a/components/script/dom/testworklet.rs b/components/script/dom/testworklet.rs index 5d44203d0240..74c4a0fb156f 100644 --- a/components/script/dom/testworklet.rs +++ b/components/script/dom/testworklet.rs @@ -3,7 +3,6 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ // check-tidy: no specs after this line -use crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::TestWorkletBinding::TestWorkletMethods; use crate::dom::bindings::codegen::Bindings::TestWorkletBinding::Wrap; use crate::dom::bindings::codegen::Bindings::WorkletBinding::WorkletBinding::WorkletMethods; @@ -18,6 +17,7 @@ use crate::dom::promise::Promise; use crate::dom::window::Window; use crate::dom::worklet::Worklet; use crate::dom::workletglobalscope::WorkletGlobalScopeType; +use crate::realms::InRealm; use crate::script_thread::ScriptThread; use dom_struct::dom_struct; use std::rc::Rc; @@ -57,7 +57,7 @@ impl TestWorkletMethods for TestWorklet { &self, moduleURL: USVString, options: &WorkletOptions, - comp: InCompartment, + comp: InRealm, ) -> Rc { self.worklet.AddModule(moduleURL, options, comp) } diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs index d10c4bede115..f595952b07ab 100644 --- a/components/script/dom/vrdisplay.rs +++ b/components/script/dom/vrdisplay.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods; @@ -33,6 +32,7 @@ use crate::dom::vrframedata::VRFrameData; use crate::dom::vrpose::VRPose; use crate::dom::vrstageparameters::VRStageParameters; use crate::dom::webglrenderingcontext::{WebGLMessageSender, WebGLRenderingContext}; +use crate::realms::InRealm; use crate::script_runtime::CommonScriptMsg; use crate::script_runtime::ScriptThreadEventCategory::WebVREvent; use crate::task_source::{TaskSource, TaskSourceName}; @@ -322,8 +322,8 @@ impl VRDisplayMethods for VRDisplay { } // https://w3c.github.io/webvr/#dom-vrdisplay-requestpresent - fn RequestPresent(&self, layers: Vec, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&self.global(), comp); + fn RequestPresent(&self, layers: Vec, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&self.global(), comp); // TODO: WebVR spec: this method must be called in response to a user gesture // WebVR spec: If canPresent is false the promise MUST be rejected @@ -386,8 +386,8 @@ impl VRDisplayMethods for VRDisplay { } // https://w3c.github.io/webvr/#dom-vrdisplay-exitpresent - fn ExitPresent(&self, comp: InCompartment) -> Rc { - let promise = Promise::new_in_current_compartment(&self.global(), comp); + fn ExitPresent(&self, comp: InRealm) -> Rc { + let promise = Promise::new_in_current_realm(&self.global(), comp); // WebVR spec: If the VRDisplay is not presenting the promise MUST be rejected. if !self.presenting.get() { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 03102968cc44..dc30017e7d14 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::DocumentBinding::{ DocumentMethods, DocumentReadyState, @@ -57,6 +56,7 @@ use crate::dom::workletglobalscope::WorkletGlobalScopeType; use crate::fetch; use crate::layout_image::fetch_image_for_layout; use crate::microtask::MicrotaskQueue; +use crate::realms::InRealm; use crate::script_runtime::{ CommonScriptMsg, JSContext, Runtime, ScriptChan, ScriptPort, ScriptThreadEventCategory, }; @@ -1259,7 +1259,7 @@ impl WindowMethods for Window { &self, input: RequestOrUSVString, init: RootedTraceableBox, - comp: InCompartment, + comp: InRealm, ) -> Rc { fetch::Fetch(&self.upcast(), input, init, comp) } diff --git a/components/script/dom/windowproxy.rs b/components/script/dom/windowproxy.rs index 21e40f799894..24afc54a133f 100644 --- a/components/script/dom/windowproxy.rs +++ b/components/script/dom/windowproxy.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::conversions::{root_from_handleobject, ToJSValConvertible}; use crate::dom::bindings::error::{throw_dom_exception, Error}; @@ -18,6 +17,7 @@ use crate::dom::document::Document; use crate::dom::element::Element; use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window; +use crate::realms::enter_realm; use crate::script_runtime::JSContext as SafeJSContext; use crate::script_thread::ScriptThread; use dom_struct::dom_struct; @@ -586,10 +586,10 @@ impl WindowProxy { // Brain transpant the window proxy. // We need to do this, because the Window and WindowProxy - // objects need to be in the same compartment. + // objects need to be in the same realm. // JS_TransplantObject does this by copying the contents // of the old window proxy to the new window proxy, then - // making the old window proxy a cross-compartment wrapper + // making the old window proxy a cross-realm wrapper // pointing to the new window proxy. rooted!(in(*cx) let new_js_proxy = NewWindowProxy(*cx, window_jsobject, handler)); debug!( diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index a35efd3ef3b8..86fb9e57b406 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::abstractworker::SimpleWorkerErrorHandler; use crate::dom::abstractworker::WorkerScriptMsg; use crate::dom::bindings::codegen::Bindings::MessagePortBinding::PostMessageOptions; @@ -23,6 +22,7 @@ use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::messageevent::MessageEvent; use crate::dom::workerglobalscope::prepare_workerscope_init; +use crate::realms::enter_realm; use crate::script_runtime::JSContext; use crate::task::TaskOnce; use crossbeam_channel::{unbounded, Sender}; diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 0b8d7e334785..8be351ab3941 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::cell::{DomRefCell, Ref}; use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit; use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction; @@ -26,6 +25,7 @@ use crate::dom::window::{base64_atob, base64_btoa}; use crate::dom::workerlocation::WorkerLocation; use crate::dom::workernavigator::WorkerNavigator; use crate::fetch; +use crate::realms::InRealm; use crate::script_runtime::JSContext; use crate::script_runtime::{get_reports, CommonScriptMsg, Runtime, ScriptChan, ScriptPort}; use crate::task::TaskCanceller; @@ -354,7 +354,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope { &self, input: RequestOrUSVString, init: RootedTraceableBox, - comp: InCompartment, + comp: InRealm, ) -> Rc { fetch::Fetch(self.upcast(), input, init, comp) } diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs index 196864f55270..227d9d97c817 100644 --- a/components/script/dom/worklet.rs +++ b/components/script/dom/worklet.rs @@ -10,7 +10,6 @@ //! thread pool implementation, which only performs GC or code loading on //! a backup thread, not on the primary worklet thread. -use crate::compartments::InCompartment; use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestCredentials; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; use crate::dom::bindings::codegen::Bindings::WorkletBinding::WorkletMethods; @@ -34,6 +33,7 @@ use crate::dom::workletglobalscope::WorkletGlobalScopeInit; use crate::dom::workletglobalscope::WorkletGlobalScopeType; use crate::dom::workletglobalscope::WorkletTask; use crate::fetch::load_whole_resource; +use crate::realms::InRealm; use crate::script_runtime::new_rt_and_cx; use crate::script_runtime::CommonScriptMsg; use crate::script_runtime::Runtime; @@ -115,11 +115,11 @@ impl WorkletMethods for Worklet { &self, module_url: USVString, options: &WorkletOptions, - comp: InCompartment, + comp: InRealm, ) -> Rc { // Step 1. let global = self.window.upcast(); - let promise = Promise::new_in_current_compartment(&global, comp); + let promise = Promise::new_in_current_realm(&global, comp); // Step 3. let module_url_record = match self.window.Document().base_url().join(&module_url.0) { diff --git a/components/script/dom/xr.rs b/components/script/dom/xr.rs index 46bcc46b0900..00f86203b266 100644 --- a/components/script/dom/xr.rs +++ b/components/script/dom/xr.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods; use crate::dom::bindings::codegen::Bindings::XRBinding; @@ -25,6 +24,7 @@ use crate::dom::vrdisplay::VRDisplay; use crate::dom::vrdisplayevent::VRDisplayEvent; use crate::dom::xrsession::XRSession; use crate::dom::xrtest::XRTest; +use crate::realms::InRealm; use crate::script_thread::ScriptThread; use crate::task_source::TaskSource; use dom_struct::dom_struct; @@ -161,11 +161,11 @@ impl XRMethods for XR { &self, mode: XRSessionMode, init: RootedTraceableBox, - comp: InCompartment, + comp: InRealm, ) -> Rc { let global = self.global(); let window = global.as_window(); - let promise = Promise::new_in_current_compartment(&global, comp); + let promise = Promise::new_in_current_realm(&global, comp); if mode != XRSessionMode::Inline { if !ScriptThread::is_user_interacting() { diff --git a/components/script/dom/xrinputsource.rs b/components/script/dom/xrinputsource.rs index e0da8bea5505..d67945040b12 100644 --- a/components/script/dom/xrinputsource.rs +++ b/components/script/dom/xrinputsource.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding; use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{ XRHandedness, XRInputSourceMethods, XRTargetRayMode, @@ -12,6 +11,7 @@ use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom}; use crate::dom::globalscope::GlobalScope; use crate::dom::xrsession::XRSession; use crate::dom::xrspace::XRSpace; +use crate::realms::enter_realm; use crate::script_runtime::JSContext; use dom_struct::dom_struct; use js::conversions::ToJSValConvertible; diff --git a/components/script/dom/xrinputsourceschangeevent.rs b/components/script/dom/xrinputsourceschangeevent.rs index b3275cd800cf..d05f359dc4da 100644 --- a/components/script/dom/xrinputsourceschangeevent.rs +++ b/components/script/dom/xrinputsourceschangeevent.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::bindings::codegen::Bindings::EventBinding::EventBinding::EventMethods; use crate::dom::bindings::codegen::Bindings::XRInputSourcesChangeEventBinding::{ self, XRInputSourcesChangeEventMethods, @@ -16,6 +15,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window; use crate::dom::xrinputsource::XRInputSource; use crate::dom::xrsession::XRSession; +use crate::realms::enter_realm; use crate::script_runtime::JSContext; use dom_struct::dom_struct; use js::conversions::ToJSValConvertible; diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index 3f7f09baa9c0..4814eb379fff 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::InCompartment; use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorBinding::NavigatorMethods; @@ -38,6 +37,7 @@ use crate::dom::xrrenderstate::XRRenderState; use crate::dom::xrsessionevent::XRSessionEvent; use crate::dom::xrspace::XRSpace; use crate::dom::xrwebgllayer::XRWebGLLayer; +use crate::realms::InRealm; use crate::task_source::TaskSource; use dom_struct::dom_struct; use euclid::{Rect, RigidTransform3D, Transform3D}; @@ -453,7 +453,7 @@ impl XRSessionMethods for XRSession { } /// https://immersive-web.github.io/webxr/#dom-xrsession-updaterenderstate - fn UpdateRenderState(&self, init: &XRRenderStateInit, _: InCompartment) -> ErrorResult { + fn UpdateRenderState(&self, init: &XRRenderStateInit, _: InRealm) -> ErrorResult { // Step 2 if self.ended.get() { return Err(Error::InvalidState); @@ -545,8 +545,8 @@ impl XRSessionMethods for XRSession { } /// https://immersive-web.github.io/webxr/#dom-xrsession-requestreferencespace - fn RequestReferenceSpace(&self, ty: XRReferenceSpaceType, comp: InCompartment) -> Rc { - let p = Promise::new_in_current_compartment(&self.global(), comp); + fn RequestReferenceSpace(&self, ty: XRReferenceSpaceType, comp: InRealm) -> Rc { + let p = Promise::new_in_current_realm(&self.global(), comp); // https://immersive-web.github.io/webxr/#create-a-reference-space diff --git a/components/script/dom/xrviewerpose.rs b/components/script/dom/xrviewerpose.rs index 6e11944b7885..4391b677130f 100644 --- a/components/script/dom/xrviewerpose.rs +++ b/components/script/dom/xrviewerpose.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::enter_realm; use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye; use crate::dom::bindings::codegen::Bindings::XRViewerPoseBinding; use crate::dom::bindings::codegen::Bindings::XRViewerPoseBinding::XRViewerPoseMethods; @@ -13,6 +12,7 @@ use crate::dom::xrpose::XRPose; use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrsession::{cast_transform, ApiViewerPose, XRSession}; use crate::dom::xrview::XRView; +use crate::realms::enter_realm; use crate::script_runtime::JSContext; use dom_struct::dom_struct; use js::conversions::ToJSValConvertible; diff --git a/components/script/fetch.rs b/components/script/fetch.rs index d03976bf94d3..8a8007471d98 100644 --- a/components/script/fetch.rs +++ b/components/script/fetch.rs @@ -2,7 +2,6 @@ * 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 crate::compartments::{enter_realm, InCompartment}; use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInfo; use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit; use crate::dom::bindings::codegen::Bindings::ResponseBinding::ResponseBinding::ResponseMethods; @@ -23,6 +22,7 @@ use crate::dom::serviceworkerglobalscope::ServiceWorkerGlobalScope; use crate::network_listener::{ self, submit_timing_data, NetworkListener, PreInvoke, ResourceTimingListener, }; +use crate::realms::{enter_realm, InRealm}; use crate::task_source::TaskSourceName; use ipc_channel::ipc; use ipc_channel::router::ROUTER; @@ -137,12 +137,12 @@ pub fn Fetch( global: &GlobalScope, input: RequestInfo, init: RootedTraceableBox, - comp: InCompartment, + comp: InRealm, ) -> Rc { let core_resource_thread = global.core_resource_thread(); // Step 1 - let promise = Promise::new_in_current_compartment(global, comp); + let promise = Promise::new_in_current_realm(global, comp); let response = Response::new(global); // Step 2 diff --git a/components/script/lib.rs b/components/script/lib.rs index e74af20db422..c01fd6dbd602 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -64,8 +64,6 @@ pub mod document_loader; mod dom; #[warn(deprecated)] mod canvas_state; -#[warn(deprecated)] -mod compartments; mod euclidext; #[warn(deprecated)] pub mod fetch; @@ -82,6 +80,8 @@ mod microtask; #[warn(deprecated)] mod network_listener; #[warn(deprecated)] +mod realms; +#[warn(deprecated)] mod script_module; #[warn(deprecated)] pub mod script_runtime; diff --git a/components/script/compartments.rs b/components/script/realms.rs similarity index 60% rename from components/script/compartments.rs rename to components/script/realms.rs index 7b45f38c56a9..280e615e412b 100644 --- a/components/script/compartments.rs +++ b/components/script/realms.rs @@ -7,38 +7,38 @@ use crate::dom::globalscope::GlobalScope; use crate::script_runtime::JSContext; use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm}; -pub struct AlreadyInCompartment(()); +pub struct AlreadyInRealm(()); -impl AlreadyInCompartment { +impl AlreadyInRealm { #![allow(unsafe_code)] - pub fn assert(global: &GlobalScope) -> AlreadyInCompartment { + pub fn assert(global: &GlobalScope) -> AlreadyInRealm { unsafe { assert!(!GetCurrentRealmOrNull(*global.get_cx()).is_null()); } - AlreadyInCompartment(()) + AlreadyInRealm(()) } - pub fn assert_for_cx(cx: JSContext) -> AlreadyInCompartment { + pub fn assert_for_cx(cx: JSContext) -> AlreadyInRealm { unsafe { assert!(!GetCurrentRealmOrNull(*cx).is_null()); } - AlreadyInCompartment(()) + AlreadyInRealm(()) } } #[derive(Clone, Copy)] -pub enum InCompartment<'a> { - Already(&'a AlreadyInCompartment), +pub enum InRealm<'a> { + Already(&'a AlreadyInRealm), Entered(&'a JSAutoRealm), } -impl<'a> InCompartment<'a> { - pub fn in_compartment(token: &AlreadyInCompartment) -> InCompartment { - InCompartment::Already(token) +impl<'a> InRealm<'a> { + pub fn in_realm(token: &AlreadyInRealm) -> InRealm { + InRealm::Already(token) } - pub fn entered(token: &JSAutoRealm) -> InCompartment { - InCompartment::Entered(token) + pub fn entered(token: &JSAutoRealm) -> InRealm { + InRealm::Entered(token) } } diff --git a/components/script/script_module.rs b/components/script/script_module.rs index 686583d92195..e22763e195a7 100644 --- a/components/script/script_module.rs +++ b/components/script/script_module.rs @@ -5,7 +5,6 @@ //! The script module mod contains common traits and structs //! related to `type=module` for script thread or worker threads. -use crate::compartments::{enter_realm, AlreadyInCompartment, InCompartment}; use crate::document_loader::LoadType; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; @@ -32,6 +31,7 @@ use crate::dom::window::Window; use crate::dom::worker::TrustedWorkerAddress; use crate::network_listener::{self, NetworkListener}; use crate::network_listener::{PreInvoke, ResourceTimingListener}; +use crate::realms::{enter_realm, AlreadyInRealm, InRealm}; use crate::task::TaskBox; use crate::task_source::TaskSourceName; use encoding_rs::UTF_8; @@ -325,8 +325,8 @@ impl ModuleTree { ))), ); - let _compartment = enter_realm(&*owner.global()); - AlreadyInCompartment::assert(&*owner.global()); + let _realm = enter_realm(&*owner.global()); + AlreadyInRealm::assert(&*owner.global()); let _ais = AutoIncumbentScript::new(&*owner.global()); let promise = promise.as_ref().unwrap(); @@ -724,11 +724,11 @@ impl ModuleOwner { ))), ); - let compartment = enter_realm(&*self.global()); - let comp = InCompartment::Entered(&compartment); + let realm = enter_realm(&*self.global()); + let comp = InRealm::Entered(&realm); let _ais = AutoIncumbentScript::new(&*self.global()); - let promise = Promise::new_in_current_compartment(&self.global(), comp); + let promise = Promise::new_in_current_realm(&self.global(), comp); promise.append_native_handler(&handler); @@ -1324,8 +1324,8 @@ fn fetch_module_descendants_and_link( unsafe { let global = owner.global(); - let _compartment = enter_realm(&*global); - AlreadyInCompartment::assert(&*global); + let _realm = enter_realm(&*global); + AlreadyInRealm::assert(&*global); let _ais = AutoIncumbentScript::new(&*global); let abv = CreateAutoObjectVector(*global.get_cx()); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 9ce99c264412..bcc7b10f8c7b 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -17,7 +17,6 @@ //! a page runs its course and the script thread returns to processing events in the main event //! loop. -use crate::compartments::enter_realm; use crate::devtools; use crate::document_loader::DocumentLoader; use crate::dom::bindings::cell::DomRefCell; @@ -69,6 +68,7 @@ use crate::dom::worklet::WorkletThreadPool; use crate::dom::workletglobalscope::WorkletGlobalScopeInit; use crate::fetch::FetchCanceller; use crate::microtask::{Microtask, MicrotaskQueue}; +use crate::realms::enter_realm; use crate::script_runtime::{get_reports, new_rt_and_cx, JSContext, Runtime, ScriptPort}; use crate::script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use crate::serviceworkerjob::{Job, JobQueue}; @@ -701,7 +701,7 @@ pub struct ScriptThread { /// In the event of thread panic, all data on the stack runs its destructor. However, there /// are no reachable, owning pointers to the DOM memory, so it never gets freed by default /// when the script thread fails. The ScriptMemoryFailsafe uses the destructor bomb pattern -/// to forcibly tear down the JS compartments for pages associated with the failing ScriptThread. +/// to forcibly tear down the JS realms for pages associated with the failing ScriptThread. struct ScriptMemoryFailsafe<'a> { owner: Option<&'a ScriptThread>, } @@ -2264,7 +2264,7 @@ impl ScriptThread { warn!("resize sent to nonexistent pipeline"); } - // exit_fullscreen creates a new JS promise object, so we need to have entered a compartment + // exit_fullscreen creates a new JS promise object, so we need to have entered a realm fn handle_exit_fullscreen(&self, id: PipelineId) { let document = self.documents.borrow().find_document(id); if let Some(document) = document { diff --git a/resources/prefs.json b/resources/prefs.json index e8d9fdc95020..2f2c6e2271cc 100644 --- a/resources/prefs.json +++ b/resources/prefs.json @@ -62,7 +62,6 @@ "js.mem.gc.incremental.enabled": true, "js.mem.gc.incremental.slice_ms": 10, "js.mem.gc.low_frequency_heap_growth": 150, - "js.mem.gc.per_compartment.enabled": true, "js.mem.gc.per_zone.enabled": false, "js.mem.gc.zeal.frequency": 100, "js.mem.gc.zeal.level": 0,