v8::Handle<v8::Object> CustomElementWrapper<ElementType, WrapperType>::wrap(PassRefPtrWillBeRawPtr<ElementType> element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationContext, v8::Isolate*)) { ASSERT(DOMDataStore::getWrapper<V8Element>(element.get(), isolate).IsEmpty()); // FIXME: creationContext.IsEmpty() should never happen. Remove // this when callers (like InspectorController::inspect) are fixed // to never pass an empty creation context. v8::Handle<v8::Context> context = creationContext.IsEmpty() ? isolate->GetCurrentContext() : creationContext->CreationContext(); if (!element->isUpgradedCustomElement() || DOMWrapperWorld::world(context).isIsolatedWorld()) return createUpgradeCandidateWrapper(element.get(), creationContext, isolate, createSpecificWrapper); V8PerContextData* perContextData = V8PerContextData::from(context); if (!perContextData) return v8::Handle<v8::Object>(); CustomElementBinding* binding = perContextData->customElementBinding(element->customElementDefinition()); v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, binding->wrapperType(), element.get(), isolate); if (wrapper.IsEmpty()) return v8::Handle<v8::Object>(); wrapper->SetPrototype(binding->prototype()); V8DOMWrapper::associateObjectWithWrapper<WrapperType>(element, binding->wrapperType(), wrapper, isolate, WrapperConfiguration::Dependent); return wrapper; }
v8::Handle<v8::Object> CustomElementHelpers::createWrapper(PassRefPtr<Element> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, const CreateWrapperFunction& createTypeExtensionUpgradeCandidateWrapper) { ASSERT(impl); // FIXME: creationContext.IsEmpty() should never happen. Remove // this when callers (like InspectorController::inspect) are fixed // to never pass an empty creation context. v8::Handle<v8::Context> context = creationContext.IsEmpty() ? isolate->GetCurrentContext() : creationContext->CreationContext(); // 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(context)) { 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; } CustomElementRegistry* registry = impl->document()->registry(); RefPtr<CustomElementDefinition> definition = registry->findFor(impl.get()); if (!definition) return createUpgradeCandidateWrapper(impl, creationContext, isolate, createTypeExtensionUpgradeCandidateWrapper); v8::Handle<v8::Object> prototype = V8PerContextData::from(context)->customElementPrototypes()->get(definition->type()).newLocal(isolate); WrapperTypeInfo* typeInfo = CustomElementHelpers::findWrapperType(prototype); if (!typeInfo) { // FIXME: When can this happen? 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; }