Пример #1
0
// https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsregistry-get
ScriptValue CustomElementRegistry::get(const AtomicString& name) {
  CustomElementDefinition* definition = definitionForName(name);
  if (!definition) {
    // Binding layer converts |ScriptValue()| to script specific value,
    // e.g. |undefined| for v8.
    return ScriptValue();
  }
  return definition->getConstructorForScript();
}
Пример #2
0
CustomElementDefinition* CustomElementRegistry::definitionFor(
    const CustomElementDescriptor& desc) const {
  CustomElementDefinition* definition = definitionForName(desc.name());
  if (!definition)
    return nullptr;
  // The definition for a customized built-in element, such as
  // <button is="my-button"> should not be provided for an
  // autonomous element, such as <my-button>, even though the
  // name "my-button" matches.
  return definition->descriptor() == desc ? definition : nullptr;
}
Пример #3
0
HTMLElement* CustomElement::createCustomElementAsync(Document& document, const QualifiedName& tagName)
{
    CHECK(shouldCreateCustomElement(document, tagName));

    // To create an element:
    // https://dom.spec.whatwg.org/#concept-create-element
    // 6. If definition is non-null, then:
    // 6.2. If the synchronous custom elements flag is not set:
    if (CustomElementDefinition* definition = definitionForName(document, tagName))
        return definition->createElementAsync(document, tagName);

    return createUndefinedElement(document, tagName);
}
Пример #4
0
HTMLElement* CustomElement::createCustomElementSync(Document& document, const QualifiedName& tagName)
{
    CHECK(shouldCreateCustomElement(document, tagName));

    // When invoked from "create an element for a token":
    // https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token
    // 7. If this step throws an exception, then report the exception,
    // and let element be instead a new element that implements
    // HTMLUnknownElement.
    if (CustomElementDefinition* definition = definitionForName(document, tagName))
        return definition->createElementSync(document, tagName);

    return createUndefinedElement(document, tagName);
}
Пример #5
0
// https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsregistry-whendefined
ScriptPromise CustomElementRegistry::whenDefined(
    ScriptState* scriptState,
    const AtomicString& name,
    ExceptionState& exceptionState) {
  if (throwIfInvalidName(name, exceptionState))
    return ScriptPromise();
  CustomElementDefinition* definition = definitionForName(name);
  if (definition)
    return ScriptPromise::castUndefined(scriptState);
  ScriptPromiseResolver* resolver = m_whenDefinedPromiseMap.get(name);
  if (resolver)
    return resolver->promise();
  ScriptPromiseResolver* newResolver =
      ScriptPromiseResolver::create(scriptState);
  m_whenDefinedPromiseMap.add(name, newResolver);
  return newResolver->promise();
}