rename compartment to realm

This commit is contained in:
Kunal Mohan 2020-01-24 13:29:09 +05:30
parent be409233fd
commit 5a3e1b8e69
No known key found for this signature in database
GPG key ID: 2B475A4524237BAC
54 changed files with 226 additions and 259 deletions

View file

@ -377,9 +377,6 @@ mod gen {
slice_ms: i64,
},
low_frequency_heap_growth: i64,
per_compartment: {
enabled: bool,
},
per_zone: {
enabled: bool,
},

View file

@ -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<T: BodyOperations + DomObject>(object: &T, body_type: BodyType) -> Rc<Promise> {
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() {

View file

@ -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};

View file

@ -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;

View file

@ -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<Promise> {
fn Suspend(&self, comp: InRealm) -> Rc<Promise> {
// 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<Promise> {
fn Close(&self, comp: InRealm) -> Rc<Promise> {
// 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 {

View file

@ -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<Promise> {
fn Resume(&self, comp: InRealm) -> Rc<Promise> {
// 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<ArrayBuffer>,
decode_success_callback: Option<Rc<DecodeSuccessCallback>>,
decode_error_callback: Option<Rc<DecodeErrorCallback>>,
comp: InCompartment,
comp: InRealm,
) -> Rc<Promise> {
// 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();

View file

@ -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<T: DomObject>(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<GlobalScope>,
/// 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,

View file

@ -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'],
}
}

View file

@ -771,14 +771,14 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
#
# 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 @@ class CGCallGenerator(CGThing):
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 @@ let global = DomRoot::downcast::<dom::types::%s>(global).unwrap();
// 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 @@ rooted!(in(*cx) let mut prototype = ptr::null_mut::<JSObject>());
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 @@ rooted!(in(*cx) let mut prototype = ptr::null_mut::<JSObject>());
};
}
// 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 @@ class CGInterfaceTrait(CGThing):
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 @@ class CGInterfaceTrait(CGThing):
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 @@ class CGInterfaceTrait(CGThing):
attribute_arguments(
typeNeedsCx(m.type, False),
m.type,
inCompartment=name in descriptor.inCompartmentMethods
inRealm=name in descriptor.inRealmMethods
),
rettype)
@ -5831,7 +5831,7 @@ class CGInterfaceTrait(CGThing):
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 @@ class CGInterfaceTrait(CGThing):
yield "SupportedPropertyNames", [], "Vec<DOMString>"
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):

View file

@ -220,7 +220,7 @@ class Descriptor(DescriptorProvider):
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

View file

@ -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;

View file

@ -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<UUID>,
{
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<BluetoothError> for Error {
impl BluetoothMethods for Bluetooth {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
fn RequestDevice(&self, option: &RequestDeviceOptions, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn RequestDevice(&self, option: &RequestDeviceOptions, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn GetAvailability(&self, comp: InRealm) -> Rc<Promise> {
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);

View file

@ -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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn WatchAdvertisements(&self, comp: InRealm) -> Rc<Promise> {
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

View file

@ -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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn ReadValue(&self, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn StartNotifications(&self, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn StopNotifications(&self, comp: InRealm) -> Rc<Promise> {
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,

View file

@ -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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn ReadValue(&self, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InRealm) -> Rc<Promise> {
let p = Promise::new_in_current_realm(&self.global(), comp);
// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {

View file

@ -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<Promise> {
fn Connect(&self, comp: InRealm) -> Rc<Promise> {
// 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.

View file

@ -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 {
}
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-whendefined>
fn WhenDefined(&self, name: DOMString, comp: InCompartment) -> Rc<Promise> {
fn WhenDefined(&self, name: DOMString, comp: InRealm) -> Rc<Promise> {
let global_scope = self.window.upcast::<GlobalScope>();
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::<JSObject>());
{
// 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

View file

@ -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,

View file

@ -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<Promise> {
// 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<Promise> {
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")));

View file

@ -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;

View file

@ -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};

View file

@ -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};

View file

@ -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<T: AsyncWGPUListener + DomObject + 'static>(
impl GPUMethods for GPU {
// https://gpuweb.github.io/gpuweb/#dom-gpu-requestadapter
fn RequestAdapter(
&self,
options: &GPURequestAdapterOptions,
comp: InCompartment,
) -> Rc<Promise> {
fn RequestAdapter(&self, options: &GPURequestAdapterOptions, comp: InRealm) -> Rc<Promise> {
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,

View file

@ -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<Promise> {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InRealm) -> Rc<Promise> {
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 {

View file

@ -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<Promise> {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
fn Play(&self, comp: InRealm) -> Rc<Promise> {
let promise = Promise::new_in_current_realm(&self.global(), comp);
// Step 1.
// FIXME(nox): Reject promise if not allowed to play.

View file

@ -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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn GetUserMedia(&self, constraints: &MediaStreamConstraints, comp: InRealm) -> Rc<Promise> {
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) {

View file

@ -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();

View file

@ -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<Promise> {
let promise = Promise::new_in_current_compartment(&*self.global(), comp);
fn Enable(&self, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let promise = Promise::new_in_current_compartment(&*self.global(), comp);
fn Disable(&self, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let promise = Promise::new_in_current_compartment(&*self.global(), comp);
fn SetHeaderValue(&self, value: ByteString, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let promise = Promise::new_in_current_compartment(&*self.global(), comp);
fn GetState(&self, comp: InRealm) -> Rc<Promise> {
let promise = Promise::new_in_current_realm(&*self.global(), comp);
// 2.
let mut state = NavigationPreloadState::empty();

View file

@ -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<Promise> {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
fn GetVRDisplays(&self, comp: InRealm) -> Rc<Promise> {
let promise = Promise::new_in_current_realm(&self.global(), comp);
let displays = self.Xr().get_displays();
match displays {
Ok(displays) => promise.resolve_native(&displays),

View file

@ -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<Promise> {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
fn StartRendering(&self, comp: InRealm) -> Rc<Promise> {
let promise = Promise::new_in_current_realm(&self.global(), comp);
if self.rendering_started.get() {
promise.reject_error(Error::InvalidState);
return promise;

View file

@ -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))
},
};

View file

@ -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<Promise> {
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<Promise> {
pub fn new_in_current_realm(global: &GlobalScope, _comp: InRealm) -> Rc<Promise> {
let cx = global.get_cx();
rooted!(in(*cx) let mut obj = ptr::null_mut::<JSObject>());
Promise::create_js_promise(cx, HandleObject::null(), obj.handle_mut());

View file

@ -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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn AddIceCandidate(&self, candidate: &RTCIceCandidateInit, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn CreateOffer(&self, _options: &RTCOfferOptions, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn CreateAnswer(&self, _options: &RTCAnswerOptions, comp: InRealm) -> Rc<Promise> {
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<Promise> {
fn SetLocalDescription(&self, desc: &RTCSessionDescriptionInit, comp: InRealm) -> Rc<Promise> {
// 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<Promise> {
fn SetRemoteDescription(&self, desc: &RTCSessionDescriptionInit, comp: InRealm) -> Rc<Promise> {
// 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());

View file

@ -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<Promise> {
// 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

View file

@ -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,
};

View file

@ -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<Rc<SimpleCallback>>,
reject: Option<Rc<SimpleCallback>>,
comp: InCompartment,
comp: InRealm,
) -> Rc<Promise> {
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> {
Promise::new_in_current_compartment(&self.global(), comp)
fn PromiseAttribute(&self, comp: InRealm) -> Rc<Promise> {
Promise::new_in_current_realm(&self.global(), comp)
}
fn AcceptPromise(&self, _promise: &Promise) {}

View file

@ -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<Promise> {
self.worklet.AddModule(moduleURL, options, comp)
}

View file

@ -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<VRLayer>, comp: InCompartment) -> Rc<Promise> {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
fn RequestPresent(&self, layers: Vec<VRLayer>, comp: InRealm) -> Rc<Promise> {
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<Promise> {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
fn ExitPresent(&self, comp: InRealm) -> Rc<Promise> {
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() {

View file

@ -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<RequestInit>,
comp: InCompartment,
comp: InRealm,
) -> Rc<Promise> {
fetch::Fetch(&self.upcast(), input, init, comp)
}

View file

@ -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!(

View file

@ -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};

View file

@ -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<RequestInit>,
comp: InCompartment,
comp: InRealm,
) -> Rc<Promise> {
fetch::Fetch(self.upcast(), input, init, comp)
}

View file

@ -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<Promise> {
// 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) {

View file

@ -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<XRSessionInit>,
comp: InCompartment,
comp: InRealm,
) -> Rc<Promise> {
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() {

View file

@ -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;

View file

@ -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;

View file

@ -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<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
fn RequestReferenceSpace(&self, ty: XRReferenceSpaceType, comp: InRealm) -> Rc<Promise> {
let p = Promise::new_in_current_realm(&self.global(), comp);
// https://immersive-web.github.io/webxr/#create-a-reference-space

View file

@ -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;

View file

@ -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<RequestInit>,
comp: InCompartment,
comp: InRealm,
) -> Rc<Promise> {
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

View file

@ -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;

View file

@ -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)
}
}

View file

@ -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());

View file

@ -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 {

View file

@ -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,