v8::Handle<v8::Object> CustomElementHelpers::CreateWrapperFunction::invoke(Element* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) const
{
    if (element->isHTMLElement()) {
        if (m_html)
            return m_html(toHTMLElement(element), creationContext, isolate);
        return createV8HTMLFallbackWrapper(toHTMLUnknownElement(toHTMLElement(element)), creationContext, isolate);
    } else if (element->isSVGElement()) {
        if (m_svg)
            return m_svg(toSVGElement(element), creationContext, isolate);
        return createV8SVGFallbackWrapper(toSVGElement(element), creationContext, isolate);
    }

    ASSERT(0);
    return v8::Handle<v8::Object>();
}
Exemple #2
0
v8::Handle<v8::Object> V8CustomElement::createWrapper(PassRefPtr<Element> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    ASSERT(impl);

    RefPtr<CustomElementConstructor> constructor = CustomElementRegistry::constructorOf(impl.get());
    if (!constructor) {
        v8::Handle<v8::Value> wrapperValue = WebCore::toV8(toHTMLUnknownElement(toHTMLElement(impl.get())), creationContext, isolate);
        if (!wrapperValue.IsEmpty() && wrapperValue->IsObject())
            return v8::Handle<v8::Object>::Cast(wrapperValue);
        return v8::Handle<v8::Object>();
    }

    // The constructor and registered lifecycle callbacks should be visible only from main world.
    // FIXME: This shouldn't be needed once each custom element has its own FunctionTemplate
    // https://bugs.webkit.org/show_bug.cgi?id=108138
    if (!CustomElementHelpers::isFeatureAllowed(creationContext->CreationContext())) {
        v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &V8HTMLElement::info, impl.get(), isolate);
        if (!wrapper.IsEmpty())
            V8DOMWrapper::associateObjectWithWrapper(impl, &V8HTMLElement::info, wrapper, isolate, WrapperConfiguration::Dependent);
        return wrapper;
    }

    v8::Handle<v8::Value> constructorValue = WebCore::toV8(constructor.get(), creationContext, isolate);
    if (constructorValue.IsEmpty() || !constructorValue->IsObject())
        return v8::Handle<v8::Object>();
    v8::Handle<v8::Object> constructorWapper = v8::Handle<v8::Object>::Cast(constructorValue);
    v8::Handle<v8::Object> prototype = v8::Handle<v8::Object>::Cast(constructorWapper->Get(v8::String::NewSymbol("prototype")));
    WrapperTypeInfo* typeInfo = findWrapperTypeOf(prototype);
    if (!typeInfo)
        return v8::Handle<v8::Object>();

    v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, typeInfo, impl.get(), isolate);
    if (wrapper.IsEmpty())
        return v8::Handle<v8::Object>();

    wrapper->SetPrototype(prototype);
    V8DOMWrapper::associateObjectWithWrapper(impl, typeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
    return wrapper;
}
v8::Handle<v8::Object> createFallbackWrapper<HTMLElement>(HTMLElement* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    return createV8HTMLFallbackWrapper(toHTMLUnknownElement(element), creationContext, isolate);
}