diff options
author | Bastien Orivel <eijebong@bananium.fr> | 2019-05-24 22:24:41 +0200 |
---|---|---|
committer | Bastien Orivel <eijebong@bananium.fr> | 2019-05-24 23:02:38 +0200 |
commit | 7dbff6efb7ce93ecfb04883cd1dffa24a03ed0ad (patch) | |
tree | 6cecd1c857227a6d61188689c143d7bf99a50d0b /components | |
parent | 2181872973ce49b50ed2dd077c4fdde6f4c5d019 (diff) | |
download | servo-7dbff6efb7ce93ecfb04883cd1dffa24a03ed0ad.tar.gz servo-7dbff6efb7ce93ecfb04883cd1dffa24a03ed0ad.zip |
Add an inCompartments config for bindings
Diffstat (limited to 'components')
-rw-r--r-- | components/script/compartments.rs | 9 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/Bindings.conf | 8 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 15 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/Configuration.py | 1 | ||||
-rw-r--r-- | components/script/dom/window.rs | 4 | ||||
-rw-r--r-- | components/script/dom/workerglobalscope.rs | 4 | ||||
-rw-r--r-- | components/script/fetch.rs | 6 |
7 files changed, 37 insertions, 10 deletions
diff --git a/components/script/compartments.rs b/components/script/compartments.rs index 552b7573d83..3c57e753eb7 100644 --- a/components/script/compartments.rs +++ b/components/script/compartments.rs @@ -3,7 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::dom::globalscope::GlobalScope; -use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm}; +use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm, JSContext}; pub struct AlreadyInCompartment(()); @@ -15,6 +15,13 @@ impl AlreadyInCompartment { } AlreadyInCompartment(()) } + + pub fn assert_for_cx(cx: *mut JSContext) -> AlreadyInCompartment { + unsafe { + assert!(!GetCurrentRealmOrNull(cx).is_null()); + } + AlreadyInCompartment(()) + } } #[derive(Clone, Copy)] diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index d23583b76ef..0f847e4eead 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -40,6 +40,14 @@ DOMInterfaces = { 'WindowProxy' : { 'path': 'crate::dom::windowproxy::WindowProxy', 'register': False, +}, + +'Window': { + 'inCompartments': ['Fetch'], +}, + +'WorkerGlobalScope': { + 'inCompartments': ['Fetch'], } } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 27bfdce71b4..9032012dea7 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -3316,6 +3316,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))")); # Build up our actual call self.cgRoot = CGList([], "\n") @@ -5640,7 +5642,7 @@ class CGInterfaceTrait(CGThing): name = CGSpecializedMethod.makeNativeName(descriptor, m) infallible = 'infallible' in descriptor.getExtendedAttributes(m) for idx, (rettype, arguments) in enumerate(m.signatures()): - arguments = method_arguments(descriptor, rettype, arguments) + arguments = method_arguments(descriptor, rettype, arguments, inCompartment=name in descriptor.inCompartmentMethods) rettype = return_type(descriptor, rettype, infallible) yield name + ('_' * idx), arguments, rettype elif m.isAttr() and not m.isStatic(): @@ -5671,7 +5673,7 @@ class CGInterfaceTrait(CGThing): if operation.isGetter(): if not rettype.nullable(): rettype = IDLNullableType(rettype.location, rettype) - arguments = method_arguments(descriptor, rettype, arguments) + arguments = method_arguments(descriptor, rettype, arguments, inCompartment=name in descriptor.inCompartmentMethods) # If this interface 'supports named properties', then we # should be able to access 'supported property names' @@ -5681,7 +5683,7 @@ class CGInterfaceTrait(CGThing): if operation.isNamed(): yield "SupportedPropertyNames", [], "Vec<DOMString>" else: - arguments = method_arguments(descriptor, rettype, arguments) + arguments = method_arguments(descriptor, rettype, arguments, inCompartment=name in descriptor.inCompartmentMethods) rettype = return_type(descriptor, rettype, infallible) yield name, arguments, rettype @@ -5975,6 +5977,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', 'libc', 'servo_config::pref', 'servo_config::prefs', @@ -6676,7 +6680,7 @@ def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, var return declType.define() -def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, trailing=None): +def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, trailing=None, inCompartment=False): if needCx(returnType, arguments, passJSBits): yield "cx", "*mut JSContext" @@ -6688,6 +6692,9 @@ def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, if trailing: yield trailing + if inCompartment: + yield "_comp", "InCompartment" + def return_type(descriptorProvider, rettype, infallible): result = getRetvalDeclarationForType(rettype, descriptorProvider) diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py index 47a65d37d4b..81f61a648f1 100644 --- a/components/script/dom/bindings/codegen/Configuration.py +++ b/components/script/dom/bindings/codegen/Configuration.py @@ -223,6 +223,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.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/window.rs b/components/script/dom/window.rs index 64a01a57baa..881c126da1f 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -2,6 +2,7 @@ * 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, @@ -1144,8 +1145,9 @@ impl WindowMethods for Window { &self, input: RequestOrUSVString, init: RootedTraceableBox<RequestInit>, + comp: InCompartment, ) -> Rc<Promise> { - fetch::Fetch(&self.upcast(), input, init) + fetch::Fetch(&self.upcast(), input, init, comp) } fn TestRunner(&self) -> DomRoot<TestRunner> { diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 3ea44c99936..572bebff905 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -2,6 +2,7 @@ * 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::FunctionBinding::Function; use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit; @@ -368,8 +369,9 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope { &self, input: RequestOrUSVString, init: RootedTraceableBox<RequestInit>, + comp: InCompartment, ) -> Rc<Promise> { - fetch::Fetch(self.upcast(), input, init) + fetch::Fetch(self.upcast(), input, init, comp) } // https://w3c.github.io/hr-time/#the-performance-attribute diff --git a/components/script/fetch.rs b/components/script/fetch.rs index e7011707227..a8f11b1b251 100644 --- a/components/script/fetch.rs +++ b/components/script/fetch.rs @@ -2,7 +2,7 @@ * 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::compartments::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; @@ -134,12 +134,12 @@ pub fn Fetch( global: &GlobalScope, input: RequestInfo, init: RootedTraceableBox<RequestInit>, + comp: InCompartment, ) -> Rc<Promise> { let core_resource_thread = global.core_resource_thread(); // Step 1 - let aic = AlreadyInCompartment::assert(global); - let promise = Promise::new_in_current_compartment(global, InCompartment::Already(&aic)); + let promise = Promise::new_in_current_compartment(global, comp); let response = Response::new(global); // Step 2 |