mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Resolve whenDefined
with the class constructor
This commit is contained in:
parent
03fb9c5d6e
commit
312479f816
3 changed files with 20 additions and 22 deletions
|
@ -395,7 +395,13 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
|
|||
|
||||
// Step 16, 16.3
|
||||
if let Some(promise) = self.when_defined.borrow_mut().remove(&name) {
|
||||
promise.resolve_native(&UndefinedValue());
|
||||
unsafe {
|
||||
rooted!(in(*cx) let mut constructor = UndefinedValue());
|
||||
definition
|
||||
.constructor
|
||||
.to_jsval(*cx, constructor.handle_mut());
|
||||
promise.resolve_native(&constructor.get());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -416,6 +422,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
|
|||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-whendefined>
|
||||
#[allow(unsafe_code)]
|
||||
fn WhenDefined(&self, name: DOMString, comp: InRealm) -> Rc<Promise> {
|
||||
let global_scope = self.window.upcast::<GlobalScope>();
|
||||
let name = LocalName::from(&*name);
|
||||
|
@ -428,10 +435,17 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
|
|||
}
|
||||
|
||||
// Step 2
|
||||
if self.definitions.borrow().contains_key(&name) {
|
||||
let promise = Promise::new_in_current_realm(&global_scope, comp);
|
||||
promise.resolve_native(&UndefinedValue());
|
||||
return promise;
|
||||
if let Some(definition) = self.definitions.borrow().get(&LocalName::from(&*name)) {
|
||||
unsafe {
|
||||
let cx = global_scope.get_cx();
|
||||
rooted!(in(*cx) let mut constructor = UndefinedValue());
|
||||
definition
|
||||
.constructor
|
||||
.to_jsval(*cx, constructor.handle_mut());
|
||||
let promise = Promise::new_in_current_realm(&global_scope, comp);
|
||||
promise.resolve_native(&constructor.get());
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3
|
||||
|
|
|
@ -10,7 +10,7 @@ interface CustomElementRegistry {
|
|||
|
||||
any get(DOMString name);
|
||||
|
||||
Promise<void> whenDefined(DOMString name);
|
||||
Promise<CustomElementConstructor> whenDefined(DOMString name);
|
||||
|
||||
[CEReactions] void upgrade(Node root);
|
||||
};
|
||||
|
|
|
@ -32,19 +32,3 @@
|
|||
|
||||
[customElements.define must not throw when defining another custom element in a different global object during Get(constructor, "prototype")]
|
||||
expected: FAIL
|
||||
|
||||
[A promise returned by customElements.whenDefined must be resolved by "define"]
|
||||
expected: FAIL
|
||||
|
||||
[customElements.whenDefined must return a new resolved promise each time invoked when the registry contains the entry with the given name]
|
||||
expected: FAIL
|
||||
|
||||
[A promise returned by customElements.whenDefined must be resolved with the defined class once such class is defined]
|
||||
expected: FAIL
|
||||
|
||||
[customElements.whenDefined must return a resolved promise when the registry contains the entry with the given name]
|
||||
expected: FAIL
|
||||
|
||||
[A promise returned by customElements.whenDefined must be resolved with the defined class]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue