Rename Promise::new to Promise::new_in_current_compartment

This commit is contained in:
Aron Zwaan 2019-03-30 21:03:20 +01:00
parent 6fa1853bb1
commit 782b58587a
25 changed files with 93 additions and 51 deletions

View file

@ -399,20 +399,21 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
}
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-whendefined>
#[allow(unsafe_code)]
fn WhenDefined(&self, name: DOMString) -> 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(global_scope);
let promise = unsafe { Promise::new_in_current_compartment(global_scope) };
promise.reject_native(&DOMException::new(global_scope, DOMErrorName::SyntaxError));
return promise;
}
// Step 2
if self.definitions.borrow().contains_key(&name) {
let promise = Promise::new(global_scope);
let promise = unsafe { Promise::new_in_current_compartment(global_scope) };
promise.resolve_native(&UndefinedValue());
return promise;
}
@ -422,7 +423,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
// Steps 4, 5
let promise = map.get(&name).cloned().unwrap_or_else(|| {
let promise = Promise::new(global_scope);
let promise = unsafe { Promise::new_in_current_compartment(global_scope) };
map.insert(name, promise.clone());
promise
});