v8::Handle<v8::Object> V8TestNamedConstructor::wrapSlow(PassRefPtr<TestNamedConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    v8::Handle<v8::Object> wrapper;
    Document* document = 0;
    UNUSED_PARAM(document);

    v8::Handle<v8::Context> context;
    if (!creationContext.IsEmpty() && creationContext->CreationContext() != v8::Context::GetCurrent()) {
        // For performance, we enter the context only if the currently running context
        // is different from the context that we are about to enter.
        context = v8::Local<v8::Context>::New(creationContext->CreationContext());
        ASSERT(!context.IsEmpty());
        context->Enter();
    }

    wrapper = V8DOMWrapper::instantiateV8Object(document, &info, impl.get());

    if (!context.IsEmpty())
        context->Exit();

    if (UNLIKELY(wrapper.IsEmpty()))
        return wrapper;
    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::setJSWrapperForActiveDOMObject(impl, wrapper, isolate);
    if (!hasDependentLifetime)
        wrapperHandle.MarkIndependent();
    return wrapper;
}
Exemplo n.º 2
0
void ScriptPromisePropertyBase::resolveOrRejectInternal(v8::Handle<v8::Promise::Resolver> resolver)
{
    switch (m_state) {
    case Pending:
        ASSERT_NOT_REACHED();
        break;
    case Resolved:
        resolver->Resolve(resolvedValue(m_isolate, resolver->CreationContext()->Global()));
        break;
    case Rejected:
        resolver->Reject(rejectedValue(m_isolate, resolver->CreationContext()->Global()));
        break;
    }
}
Exemplo n.º 3
0
 explicit V8WrapperInstantiationScope(v8::Handle<v8::Object> creationContext)
     : m_didEnterContext(false)
     , m_context(v8::Context::GetCurrent())
 {
     if (creationContext.IsEmpty())
         return;
     v8::Handle<v8::Context> contextForWrapper = creationContext->CreationContext();
     // For performance, we enter the context only if the currently running context
     // is different from the context that we are about to enter.
     if (contextForWrapper == m_context)
         return;
     m_context = v8::Local<v8::Context>::New(contextForWrapper);
     m_didEnterContext = true;
     m_context->Enter();
 }
Exemplo n.º 4
0
 explicit V8WrapperInstantiationScope(v8::Handle<v8::Object> creationContext)
     : m_didEnterContext(false)
     , m_context(v8::Context::GetCurrent())
 {
     // FIXME: Remove all empty creationContexts from caller sites.
     // If a creationContext is empty, we will end up creating a new object
     // in the context currently entered. This is wrong.
     if (creationContext.IsEmpty())
         return;
     v8::Handle<v8::Context> contextForWrapper = creationContext->CreationContext();
     // For performance, we enter the context only if the currently running context
     // is different from the context that we are about to enter.
     if (contextForWrapper == m_context)
         return;
     m_context = v8::Local<v8::Context>::New(contextForWrapper);
     m_didEnterContext = true;
     m_context->Enter();
 }
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
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;
}