Use the newly added inCompartments option everywhere it can be

This commit is contained in:
Bastien Orivel 2019-05-25 17:00:10 +02:00
parent 0b29caa554
commit 292d468cd1
22 changed files with 216 additions and 259 deletions

View file

@ -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::callback::{CallbackContainer, ExceptionHandling};
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::CustomElementRegistryBinding;
@ -415,28 +415,20 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
}
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-whendefined>
fn WhenDefined(&self, name: DOMString) -> Rc<Promise> {
fn WhenDefined(&self, name: DOMString, comp: InCompartment) -> Rc<Promise> {
let global_scope = self.window.upcast::<GlobalScope>();
let name = LocalName::from(&*name);
// Step 1
if !is_valid_custom_element_name(&name) {
let in_compartment_proof = AlreadyInCompartment::assert(&global_scope);
let promise = Promise::new_in_current_compartment(
&global_scope,
InCompartment::Already(&in_compartment_proof),
);
let promise = Promise::new_in_current_compartment(&global_scope, comp);
promise.reject_native(&DOMException::new(&global_scope, DOMErrorName::SyntaxError));
return promise;
}
// Step 2
if self.definitions.borrow().contains_key(&name) {
let in_compartment_proof = AlreadyInCompartment::assert(&global_scope);
let promise = Promise::new_in_current_compartment(
&global_scope,
InCompartment::Already(&in_compartment_proof),
);
let promise = Promise::new_in_current_compartment(&global_scope, comp);
promise.resolve_native(&UndefinedValue());
return promise;
}
@ -446,11 +438,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
// Steps 4, 5
let promise = map.get(&name).cloned().unwrap_or_else(|| {
let in_compartment_proof = AlreadyInCompartment::assert(&global_scope);
let promise = Promise::new_in_current_compartment(
&global_scope,
InCompartment::Already(&in_compartment_proof),
);
let promise = Promise::new_in_current_compartment(&global_scope, comp);
map.insert(name, promise.clone());
promise
});