void CustomElementRegistry::registerElement(CustomElementConstructorBuilder* constructorBuilder, const AtomicString& userSuppliedName, ExceptionCode& ec)
{
    RefPtr<CustomElementRegistry> protect(this);

    if (!constructorBuilder->isFeatureAllowed())
        return;

    AtomicString type = userSuppliedName.lower();
    if (!isValidName(type)) {
        ec = INVALID_CHARACTER_ERR;
        return;
    }

    if (!constructorBuilder->validateOptions()) {
        ec = INVALID_STATE_ERR;
        return;
    }

    QualifiedName tagName = nullQName();
    if (!constructorBuilder->findTagName(type, tagName)) {
        ec = NAMESPACE_ERR;
        return;
    }
    ASSERT(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.namespaceURI() == SVGNames::svgNamespaceURI);

    if (m_definitions.contains(type)) {
        ec = INVALID_STATE_ERR;
        return;
    }

    RefPtr<CustomElementCallback> lifecycleCallbacks = constructorBuilder->createCallback(document());

    // Consulting the constructor builder could execute script and
    // kill the document.
    if (!document()) {
        ec = INVALID_STATE_ERR;
        return;
    }

    RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create(type, tagName.localName(), tagName.namespaceURI(), lifecycleCallbacks);

    if (!constructorBuilder->createConstructor(document(), definition.get())) {
        ec = NOT_SUPPORTED_ERR;
        return;
    }

    m_definitions.add(definition->type(), definition);

    // Upgrade elements that were waiting for this definition.
    CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidates.takeUpgradeCandidatesFor(definition.get());
    constructorBuilder->didRegisterDefinition(definition.get(), upgradeCandidates);

    for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCandidates.begin(); it != upgradeCandidates.end(); ++it) {
        (*it)->setNeedsStyleRecalc(); // :unresolved has changed

        enqueueReadyCallback(lifecycleCallbacks.get(), *it);
    }
}
 virtual void SetUp()
 {
     document = Document::create();
     document->animationClock().resetTimeForTesting();
     element = Element::create(nullQName() , document.get());
     platformTiming = new MockPlatformTiming;
     timeline = DocumentTimeline::create(document.get(), adoptPtr(platformTiming));
     timeline->setZeroTime(0);
     ASSERT_EQ(0, timeline->currentTime());
 }