mirror of
https://github.com/lexmount/moli.git
synced 2026-11-25 08:02:28 +00:00
refactor(dom): separate registry data from native element state
This commit is contained in:
@@ -427,10 +427,10 @@ pub(in crate::context_bootstrap) fn custom_elements_when_defined_callback<'s>(
|
||||
let Some(registry_key) = custom_elements::registry_store_key(scope, args.this()) else {
|
||||
return;
|
||||
};
|
||||
match unsafe { &mut *host_ptr }
|
||||
let registry = unsafe { &mut *host_ptr }
|
||||
.custom_elements_mut_for_registry_key(registry_key)
|
||||
.when_defined(scope, &name)
|
||||
{
|
||||
.registry_data();
|
||||
match registry.when_defined(scope, &name) {
|
||||
Some(promise) => rv.set(promise.into()),
|
||||
None => rv.set_undefined(),
|
||||
}
|
||||
|
||||
@@ -3,16 +3,20 @@ use super::construction::CustomElementConstructionStack;
|
||||
pub(crate) use super::definition_error::CustomElementDefineError;
|
||||
use crate::dom::custom_elements::is_valid_custom_element_name as is_valid_dom_custom_element_name;
|
||||
use moli_dom::native::DomStringValue;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
collections::{HashMap, HashSet},
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
pub(super) struct CustomElementDefinition {
|
||||
pub(super) constructor: v8::Global<v8::Function>,
|
||||
pub(super) observed_attributes: Vec<String>,
|
||||
pub(super) observed_attributes: Rc<[String]>,
|
||||
pub(super) callbacks: CustomElementCallbacks,
|
||||
pub(super) disables_shadow: bool,
|
||||
pub(super) disables_internals: bool,
|
||||
pub(super) form_associated: bool,
|
||||
pub(super) extends_local_name: Option<String>,
|
||||
pub(super) extends_local_name: Option<Rc<str>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -41,15 +45,44 @@ pub(super) struct PendingInitialAttribute {
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct CustomElementRegistryData {
|
||||
pub(super) definitions: RefCell<HashMap<String, Rc<CustomElementDefinition>>>,
|
||||
pub(super) pending_when_defined: RefCell<HashMap<String, PendingWhenDefined>>,
|
||||
pub(super) definition_is_running: Cell<bool>,
|
||||
}
|
||||
|
||||
// A registry's definitions and promises can be shared by different native DOM
|
||||
// owners. Native handles and construction stacks always belong to one owner.
|
||||
pub(crate) struct CustomElementStore {
|
||||
pub(super) definitions: HashMap<String, CustomElementDefinition>,
|
||||
pub(super) registry: Rc<CustomElementRegistryData>,
|
||||
pub(super) upgraded_handles: HashSet<DomHandle>,
|
||||
pub(super) upgraded_definition_names: HashMap<DomHandle, String>,
|
||||
pub(super) form_association_states: HashMap<DomHandle, Option<DomHandle>>,
|
||||
pub(super) form_disabled_states: HashMap<DomHandle, bool>,
|
||||
pub(super) pending_when_defined: HashMap<String, PendingWhenDefined>,
|
||||
pub(super) construction_stack: CustomElementConstructionStack,
|
||||
pub(super) definition_is_running: bool,
|
||||
}
|
||||
|
||||
impl Default for CustomElementStore {
|
||||
fn default() -> Self {
|
||||
Self::for_registry(Rc::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl CustomElementStore {
|
||||
pub(crate) fn for_registry(registry: Rc<CustomElementRegistryData>) -> Self {
|
||||
Self {
|
||||
registry,
|
||||
upgraded_handles: HashSet::new(),
|
||||
upgraded_definition_names: HashMap::new(),
|
||||
form_association_states: HashMap::new(),
|
||||
form_disabled_states: HashMap::new(),
|
||||
construction_stack: CustomElementConstructionStack::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn registry_data(&self) -> Rc<CustomElementRegistryData> {
|
||||
self.registry.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_valid_custom_element_name(name: &str) -> bool {
|
||||
|
||||
@@ -35,11 +35,11 @@ pub(super) fn build_custom_element_definition<'s>(
|
||||
|
||||
Ok(CustomElementDefinition {
|
||||
constructor: v8::Global::new(scope, constructor),
|
||||
observed_attributes,
|
||||
observed_attributes: observed_attributes.into(),
|
||||
callbacks,
|
||||
disables_shadow,
|
||||
disables_internals,
|
||||
form_associated,
|
||||
extends_local_name,
|
||||
extends_local_name: extends_local_name.map(Into::into),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
use super::super::{document_runtime::DomHandle, native_bridge::PageScriptHost};
|
||||
use super::definition::{CustomElementDefinition, CustomElementStore};
|
||||
use super::definition_name_for_handle;
|
||||
use std::rc::Rc;
|
||||
|
||||
impl CustomElementStore {
|
||||
pub(crate) fn definition_extends_local_name(&self, name: &str) -> Option<&str> {
|
||||
self.definitions
|
||||
.get(name)
|
||||
.and_then(|definition| definition.extends_local_name.as_deref())
|
||||
pub(crate) fn definition_extends_local_name(&self, name: &str) -> Option<Rc<str>> {
|
||||
self.registry
|
||||
.definition(name)
|
||||
.and_then(|definition| definition.extends_local_name.clone())
|
||||
}
|
||||
|
||||
pub(crate) fn has_autonomous_definition(&self, local_name: &str) -> bool {
|
||||
self.definitions
|
||||
.get(local_name)
|
||||
self.registry
|
||||
.definition(local_name)
|
||||
.is_some_and(|definition| definition.extends_local_name.is_none())
|
||||
}
|
||||
|
||||
pub(super) fn has_definition(&self, name: &str) -> bool {
|
||||
self.definitions.contains_key(name)
|
||||
self.registry.definitions.borrow().contains_key(name)
|
||||
}
|
||||
|
||||
pub(super) fn observed_attributes_for_definition(&self, name: &str) -> Option<&[String]> {
|
||||
self.definitions
|
||||
.get(name)
|
||||
.map(|definition| definition.observed_attributes.as_slice())
|
||||
pub(super) fn observed_attributes_for_definition(&self, name: &str) -> Option<Rc<[String]>> {
|
||||
self.registry
|
||||
.definition(name)
|
||||
.map(|definition| definition.observed_attributes.clone())
|
||||
}
|
||||
|
||||
pub(super) fn observes_attribute_for_handle(
|
||||
@@ -46,15 +47,15 @@ impl CustomElementStore {
|
||||
is_name: Option<&str>,
|
||||
) -> bool {
|
||||
let definition = if self.has_autonomous_definition(local_name) {
|
||||
self.definitions.get(local_name)
|
||||
self.registry.definition(local_name)
|
||||
} else {
|
||||
let is_name = match is_name {
|
||||
Some(is_name) => is_name,
|
||||
None => return false,
|
||||
};
|
||||
self.definition_extends_local_name(is_name)
|
||||
.filter(|extends_local_name| *extends_local_name == local_name)
|
||||
.and_then(|_| self.definitions.get(is_name))
|
||||
.filter(|extends_local_name| extends_local_name.as_ref() == local_name)
|
||||
.and_then(|_| self.registry.definition(is_name))
|
||||
};
|
||||
definition.is_some_and(|definition| definition.form_associated)
|
||||
}
|
||||
@@ -66,10 +67,10 @@ impl CustomElementStore {
|
||||
) -> bool {
|
||||
self.upgraded_definition_names
|
||||
.get(&handle)
|
||||
.and_then(|name| self.definitions.get(name))
|
||||
.and_then(|name| self.registry.definition(name))
|
||||
.or_else(|| {
|
||||
definition_name_for_handle(host_ptr, handle)
|
||||
.and_then(|candidate| self.definitions.get(&candidate))
|
||||
.and_then(|candidate| self.registry.definition(&candidate))
|
||||
})
|
||||
.is_some_and(|definition| definition.disables_shadow)
|
||||
}
|
||||
@@ -83,7 +84,7 @@ impl CustomElementStore {
|
||||
return false;
|
||||
}
|
||||
definition_name_for_handle(host_ptr, handle)
|
||||
.and_then(|name| self.definitions.get(&name))
|
||||
.and_then(|name| self.registry.definition(&name))
|
||||
.is_some_and(|definition| {
|
||||
definition.extends_local_name.is_none() && !definition.disables_internals
|
||||
})
|
||||
@@ -93,11 +94,11 @@ impl CustomElementStore {
|
||||
&self,
|
||||
host_ptr: *mut PageScriptHost,
|
||||
handle: DomHandle,
|
||||
) -> Option<&CustomElementDefinition> {
|
||||
) -> Option<Rc<CustomElementDefinition>> {
|
||||
let name = self.upgraded_definition_names.get(&handle)?;
|
||||
self.definitions.get(name).or_else(|| {
|
||||
self.registry.definition(name).or_else(|| {
|
||||
definition_name_for_handle(host_ptr, handle)
|
||||
.and_then(|candidate| self.definitions.get(&candidate))
|
||||
.and_then(|candidate| self.registry.definition(&candidate))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use super::super::util::v8_string;
|
||||
use super::CustomElementRegistryKey;
|
||||
use super::definition::{CustomElementStore, PendingWhenDefined};
|
||||
use super::definition::{
|
||||
CustomElementDefinition, CustomElementRegistryData, CustomElementStore, PendingWhenDefined,
|
||||
};
|
||||
use super::definition_builder::{
|
||||
build_custom_element_definition, constructor_source_is_non_constructable,
|
||||
is_supported_built_in_extends_target,
|
||||
@@ -8,6 +10,10 @@ use super::definition_builder::{
|
||||
use super::definition_error::CustomElementDefineError;
|
||||
use crate::dom::custom_elements::is_valid_custom_element_name;
|
||||
use crate::native_bridge::PageScriptHost;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub(crate) fn define_custom_element_for_registry<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
@@ -28,14 +34,17 @@ pub(crate) fn define_custom_element_for_registry<'s>(
|
||||
return Err(CustomElementDefineError::InvalidName(name.to_owned()));
|
||||
}
|
||||
|
||||
let registry = unsafe { &mut *host_ptr }
|
||||
.custom_elements_mut_for_registry_key(registry_key)
|
||||
.registry_data();
|
||||
{
|
||||
let store = unsafe { &mut *host_ptr }.custom_elements_mut_for_registry_key(registry_key);
|
||||
if store.definitions.contains_key(name) {
|
||||
let definitions = registry.definitions.borrow();
|
||||
if definitions.contains_key(name) {
|
||||
return Err(CustomElementDefineError::NameAlreadyDefined(
|
||||
name.to_owned(),
|
||||
));
|
||||
}
|
||||
if store.definitions.values().any(|definition| {
|
||||
if definitions.values().any(|definition| {
|
||||
let registered_constructor = v8::Local::new(scope, &definition.constructor);
|
||||
registered_constructor.strict_equals(constructor.into())
|
||||
}) {
|
||||
@@ -48,30 +57,21 @@ pub(crate) fn define_custom_element_for_registry<'s>(
|
||||
extends_local_name.to_owned(),
|
||||
));
|
||||
}
|
||||
if store.definition_is_running {
|
||||
if registry.definition_is_running.get() {
|
||||
return Err(CustomElementDefineError::DefinitionAlreadyRunning);
|
||||
}
|
||||
store.definition_is_running = true;
|
||||
registry.definition_is_running.set(true);
|
||||
}
|
||||
|
||||
// Constructor property access can synchronously call define() again. Do
|
||||
// not retain a Rust reference to the registry store across that re-entry.
|
||||
// not retain a native store reference or a definition-table borrow across
|
||||
// that re-entry. The registry data itself remains stable if a page retires.
|
||||
let definition_result = build_custom_element_definition(scope, constructor, extends_local_name);
|
||||
unsafe { &mut *host_ptr }
|
||||
.custom_elements_mut_for_registry_key(registry_key)
|
||||
.definition_is_running = false;
|
||||
registry.definition_is_running.set(false);
|
||||
|
||||
let definition = definition_result?;
|
||||
let disables_shadow = definition.disables_shadow;
|
||||
let pending = {
|
||||
let store = unsafe { &mut *host_ptr }.custom_elements_mut_for_registry_key(registry_key);
|
||||
store.definitions.insert(name.to_owned(), definition);
|
||||
store.pending_when_defined.remove(name)
|
||||
};
|
||||
if let Some(pending) = pending {
|
||||
let resolver = v8::Local::new(scope, &pending.resolver);
|
||||
let _ = resolver.resolve(scope, constructor.into());
|
||||
}
|
||||
registry.install_definition(scope, name, definition);
|
||||
Ok(disables_shadow)
|
||||
}
|
||||
|
||||
@@ -81,9 +81,7 @@ impl CustomElementStore {
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
name: &str,
|
||||
) -> Option<v8::Local<'s, v8::Function>> {
|
||||
self.definitions
|
||||
.get(name)
|
||||
.map(|definition| v8::Local::new(scope, &definition.constructor))
|
||||
self.registry.definition_constructor(scope, name)
|
||||
}
|
||||
|
||||
pub(crate) fn get<'s>(
|
||||
@@ -117,17 +115,58 @@ impl CustomElementStore {
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
constructor: v8::Local<'_, v8::Function>,
|
||||
) -> Option<(String, Option<String>)> {
|
||||
self.definitions
|
||||
self.registry
|
||||
.definitions
|
||||
.borrow()
|
||||
.iter()
|
||||
.find(|(_, definition)| {
|
||||
let registered_constructor = v8::Local::new(scope, &definition.constructor);
|
||||
registered_constructor.strict_equals(constructor.into())
|
||||
})
|
||||
.map(|(name, definition)| (name.clone(), definition.extends_local_name.clone()))
|
||||
.map(|(name, definition)| {
|
||||
(
|
||||
name.clone(),
|
||||
definition.extends_local_name.as_deref().map(str::to_owned),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl CustomElementRegistryData {
|
||||
pub(super) fn definition(&self, name: &str) -> Option<Rc<CustomElementDefinition>> {
|
||||
self.definitions.borrow().get(name).cloned()
|
||||
}
|
||||
|
||||
fn definition_constructor<'s>(
|
||||
&self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
name: &str,
|
||||
) -> Option<v8::Local<'s, v8::Function>> {
|
||||
self.definition(name)
|
||||
.map(|definition| v8::Local::new(scope, &definition.constructor))
|
||||
}
|
||||
|
||||
pub(super) fn install_definition(
|
||||
&self,
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
name: &str,
|
||||
definition: CustomElementDefinition,
|
||||
) {
|
||||
let constructor = v8::Local::new(scope, &definition.constructor);
|
||||
self.definitions
|
||||
.borrow_mut()
|
||||
.insert(name.to_owned(), Rc::new(definition));
|
||||
let pending = self.pending_when_defined.borrow_mut().remove(name);
|
||||
if let Some(pending) = pending {
|
||||
// Promise resolution reads constructor.then and can re-enter this
|
||||
// registry. Both table borrows must end before executing it.
|
||||
let resolver = v8::Local::new(scope, &pending.resolver);
|
||||
let _ = resolver.resolve(scope, constructor.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn when_defined<'s>(
|
||||
&mut self,
|
||||
&self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
name: &str,
|
||||
) -> Option<v8::Local<'s, v8::Promise>> {
|
||||
@@ -137,13 +176,13 @@ impl CustomElementStore {
|
||||
return Some(resolver.get_promise(scope));
|
||||
}
|
||||
|
||||
if let Some(pending) = self.pending_when_defined.get(name) {
|
||||
if let Some(pending) = self.pending_when_defined.borrow().get(name) {
|
||||
return Some(v8::Local::new(scope, &pending.promise));
|
||||
}
|
||||
|
||||
let resolver = v8::PromiseResolver::new(scope)?;
|
||||
let promise = resolver.get_promise(scope);
|
||||
self.pending_when_defined.insert(
|
||||
self.pending_when_defined.borrow_mut().insert(
|
||||
name.to_owned(),
|
||||
PendingWhenDefined {
|
||||
promise: v8::Global::new(scope, promise),
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
use super::*;
|
||||
use crate::document_runtime::DomHandle;
|
||||
|
||||
fn test_constructor<'s>(
|
||||
_scope: &mut v8::PinScope<'s, '_>,
|
||||
_args: v8::FunctionCallbackArguments<'s>,
|
||||
_rv: v8::ReturnValue<'s>,
|
||||
) {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_data_shares_definitions_and_promises_without_sharing_native_handles() {
|
||||
crate::ensure_v8_for_test();
|
||||
let mut isolate = v8::Isolate::new(Default::default());
|
||||
let scope = std::pin::pin!(v8::HandleScope::new(&mut isolate));
|
||||
let scope = &mut scope.init();
|
||||
let context = v8::Context::new(scope, Default::default());
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
|
||||
let mut source = CustomElementStore::default();
|
||||
let target = CustomElementStore::for_registry(source.registry_data());
|
||||
let unrelated = CustomElementStore::default();
|
||||
let registry = source.registry_data();
|
||||
let source_promise = registry.when_defined(scope, "x-shared").unwrap();
|
||||
let target_promise = target
|
||||
.registry_data()
|
||||
.when_defined(scope, "x-shared")
|
||||
.unwrap();
|
||||
assert_eq!(source_promise, target_promise);
|
||||
|
||||
let constructor = v8::Function::new(scope, test_constructor).unwrap();
|
||||
let definition = build_custom_element_definition(scope, constructor, None)
|
||||
.expect("build a real registry definition");
|
||||
registry.install_definition(scope, "x-shared", definition);
|
||||
assert_eq!(source_promise.state(), v8::PromiseState::Fulfilled);
|
||||
assert!(
|
||||
source_promise
|
||||
.result(scope)
|
||||
.strict_equals(constructor.into())
|
||||
);
|
||||
assert_eq!(source.get(scope, "x-shared"), Some(constructor));
|
||||
assert_eq!(target.get(scope, "x-shared"), Some(constructor));
|
||||
assert!(unrelated.get(scope, "x-shared").is_none());
|
||||
|
||||
let handle = DomHandle::new(7);
|
||||
source.mark_upgraded_handle(handle, "x-shared");
|
||||
source.set_form_association_state(handle, Some(DomHandle::new(8)));
|
||||
source.set_form_disabled_state(handle, true);
|
||||
assert!(source.owns_custom_element_handle(handle));
|
||||
assert!(!target.owns_custom_element_handle(handle));
|
||||
assert!(!target.is_upgraded_handle(handle));
|
||||
assert_eq!(target.form_association_state(handle), None);
|
||||
assert_eq!(target.form_disabled_state(handle), None);
|
||||
|
||||
let pending_handle = DomHandle::new(9);
|
||||
let wrapper = v8::Object::new(scope);
|
||||
source.begin_construction(scope, constructor, wrapper, pending_handle);
|
||||
assert!(source.has_pending_wrapper_for(scope, constructor));
|
||||
assert!(!target.has_pending_wrapper_for(scope, constructor));
|
||||
source.mark_failed_construction_handle(pending_handle);
|
||||
assert!(!target.is_failed_construction_handle(pending_handle));
|
||||
|
||||
drop(source);
|
||||
drop(registry);
|
||||
assert_eq!(target.get(scope, "x-shared"), Some(constructor));
|
||||
assert!(!target.is_subtree_lifecycle_quiescent());
|
||||
assert!(!target.owns_custom_element_handle(handle));
|
||||
}
|
||||
@@ -9,7 +9,7 @@ impl CustomElementStore {
|
||||
/// `customElements.define(...)` at all, in which case every appendChild /
|
||||
/// insertBefore can skip the recursive subtree scan entirely.
|
||||
pub(crate) fn is_subtree_lifecycle_quiescent(&self) -> bool {
|
||||
self.definitions.is_empty() && self.upgraded_handles.is_empty()
|
||||
self.registry.definitions.borrow().is_empty() && self.upgraded_handles.is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn begin_construction(
|
||||
|
||||
@@ -26,7 +26,9 @@ pub(crate) fn create_element_for_document_local_name_is_and_registry<'s>(
|
||||
if unsafe { &*host_ptr }
|
||||
.custom_elements_for_registry_key(registry_key)
|
||||
.and_then(|store| store.definition_extends_local_name(is_name))
|
||||
.is_some_and(|extends_local_name| extends_local_name == local_name) =>
|
||||
.is_some_and(|extends_local_name| {
|
||||
extends_local_name.as_ref() == local_name
|
||||
}) =>
|
||||
{
|
||||
return create_custom_element_for_registry_key(
|
||||
scope,
|
||||
|
||||
@@ -117,7 +117,7 @@ pub(super) fn definition_name_for_handle(
|
||||
None => element.attribute("is"),
|
||||
}?;
|
||||
let extends_local_name = custom_elements.definition_extends_local_name(is_name)?;
|
||||
(extends_local_name == local_name).then(|| is_name.to_owned())
|
||||
(extends_local_name.as_ref() == local_name).then(|| is_name.to_owned())
|
||||
}
|
||||
|
||||
pub(crate) fn is_form_associated_custom_element_handle(
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(super) fn lookup_parser_custom_element_definition_for_token(
|
||||
let definition_name = match is_name {
|
||||
Some(is_name) => store
|
||||
.definition_extends_local_name(is_name)
|
||||
.filter(|extends_local_name| *extends_local_name == local_name)
|
||||
.filter(|extends_local_name| extends_local_name.as_ref() == local_name)
|
||||
.map(|_| is_name.to_owned())?,
|
||||
None if store.has_autonomous_definition(local_name) => local_name.to_owned(),
|
||||
None => return None,
|
||||
|
||||
@@ -210,7 +210,7 @@ fn detached_query_matches_defined_pseudo<'s>(
|
||||
if let Some(is_name) = is_name.as_deref() {
|
||||
return store
|
||||
.and_then(|store| store.definition_extends_local_name(is_name))
|
||||
.is_some_and(|extends_local_name| extends_local_name == local_name);
|
||||
.is_some_and(|extends_local_name| extends_local_name.as_ref() == local_name);
|
||||
}
|
||||
if is_valid_custom_element_name(&local_name) {
|
||||
return store.is_some_and(|store| store.has_autonomous_definition(&local_name));
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
(() => {
|
||||
const registry = new CustomElementRegistry();
|
||||
const pending = registry.whenDefined('x-resolving');
|
||||
class Resolving extends HTMLElement {}
|
||||
let reads = 0;
|
||||
const observations = [];
|
||||
Object.defineProperty(Resolving, 'then', {get() {
|
||||
reads++;
|
||||
observations.push(registry.get('x-resolving') === Resolving);
|
||||
const name = 'x-reentrant-' + reads;
|
||||
const Nested = class extends HTMLElement {};
|
||||
registry.define(name, Nested);
|
||||
observations.push(registry.get(name) === Nested);
|
||||
registry.whenDefined(name);
|
||||
return undefined;
|
||||
}});
|
||||
registry.define('x-resolving', Resolving);
|
||||
const ready = registry.whenDefined('x-resolving');
|
||||
let fulfilled = 0;
|
||||
pending.then(value => { if (value === Resolving) fulfilled++; });
|
||||
ready.then(value => { if (value === Resolving) fulfilled++; });
|
||||
globalThis.registryPromiseReentryFacts = () =>
|
||||
JSON.stringify({reads, observations, fulfilled});
|
||||
return 'ready';
|
||||
})()
|
||||
+12
@@ -1,5 +1,17 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn custom_element_registry_promise_resolution_allows_constructor_then_getter_reentry() {
|
||||
let mut vm = new_storage_test_vm("https://registry-promise-reentry.test/");
|
||||
vm.eval(include_str!("registry_promise_reentry.js"))
|
||||
.expect("constructor.then may re-enter both registry resolution paths");
|
||||
assert_eq!(
|
||||
vm.eval("registryPromiseReentryFacts()")
|
||||
.expect("promise resolution facts after the checkpoint"),
|
||||
r#"{"reads":2,"observations":[true,true,true,true],"fulfilled":2}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scoped_registry_define_upgrades_associated_connected_nodes() {
|
||||
let mut vm = new_storage_test_vm("https://example.com/");
|
||||
|
||||
Reference in New Issue
Block a user