Changeset 146851 in webkit


Ignore:
Timestamp:
Mar 25, 2013 11:35:06 PM (11 years ago)
Author:
morrita@google.com
Message:

Custom Elements Refactoring: The name V8CustomElement is confusing.
https://bugs.webkit.org/show_bug.cgi?id=113165

Reviewed by Kent Tamura.

This change moves functions from V8CustomElement to CustomElementHelpers and
removes V8CustomElement. V8CustomElement is just a heritage of old design
and no longer makes sense.

No new tests. No behavior change.

  • WebCore.gypi:
  • bindings/v8/CustomElementHelpers.cpp:

(WebCore::CustomElementHelpers::createWrapper):
(WebCore):

  • bindings/v8/CustomElementHelpers.h:

(CustomElementHelpers):
(WebCore::CustomElementHelpers::wrap):
(WebCore):
(WebCore::CustomElementHelpers::constructorOf):

  • bindings/v8/V8CustomElement.cpp: Removed.
  • bindings/v8/V8CustomElement.h: Removed.
  • bindings/v8/custom/V8CustomElementConstructorCustom.cpp:

(WebCore::V8CustomElementConstructor::callAsFunctionCallback):

  • dom/make_names.pl:

(printWrapperFactoryCppFile):

Location:
trunk/Source/WebCore
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r146849 r146851  
     12013-03-25  Hajime Morrita  <morrita@google.com>
     2
     3        Custom Elements Refactoring: The name V8CustomElement is confusing.
     4        https://bugs.webkit.org/show_bug.cgi?id=113165
     5
     6        Reviewed by Kent Tamura.
     7
     8        This change moves functions from V8CustomElement to CustomElementHelpers and
     9        removes V8CustomElement. V8CustomElement is just a heritage of old design
     10        and no longer makes sense.
     11
     12        No new tests. No behavior change.
     13
     14        * WebCore.gypi:
     15        * bindings/v8/CustomElementHelpers.cpp:
     16        (WebCore::CustomElementHelpers::createWrapper):
     17        (WebCore):
     18        * bindings/v8/CustomElementHelpers.h:
     19        (CustomElementHelpers):
     20        (WebCore::CustomElementHelpers::wrap):
     21        (WebCore):
     22        (WebCore::CustomElementHelpers::constructorOf):
     23        * bindings/v8/V8CustomElement.cpp: Removed.
     24        * bindings/v8/V8CustomElement.h: Removed.
     25        * bindings/v8/custom/V8CustomElementConstructorCustom.cpp:
     26        (WebCore::V8CustomElementConstructor::callAsFunctionCallback):
     27        * dom/make_names.pl:
     28        (printWrapperFactoryCppFile):
     29
    1302013-03-25  Eugene Klyuchnikov  <eustas@chromium.org>
    231
  • trunk/Source/WebCore/WebCore.gypi

    r146833 r146851  
    13731373            'bindings/v8/V8Collection.cpp',
    13741374            'bindings/v8/V8Collection.h',
    1375             'bindings/v8/V8CustomElement.cpp',
    1376             'bindings/v8/V8CustomElement.h',
    13771375            'bindings/v8/V8DOMConfiguration.cpp',
    13781376            'bindings/v8/V8DOMConfiguration.h',
  • trunk/Source/WebCore/bindings/v8/CustomElementHelpers.cpp

    r146592 r146851  
    4444#if ENABLE(CUSTOM_ELEMENTS)
    4545
     46v8::Handle<v8::Object> CustomElementHelpers::createWrapper(PassRefPtr<Element> impl, v8::Handle<v8::Object> creationContext, PassRefPtr<CustomElementConstructor> constructor, v8::Isolate* isolate)
     47{
     48    ASSERT(impl);
     49
     50    // The constructor and registered lifecycle callbacks should be visible only from main world.
     51    // FIXME: This shouldn't be needed once each custom element has its own FunctionTemplate
     52    // https://bugs.webkit.org/show_bug.cgi?id=108138
     53    if (!CustomElementHelpers::isFeatureAllowed(creationContext->CreationContext())) {
     54        v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &V8HTMLElement::info, impl.get(), isolate);
     55        if (!wrapper.IsEmpty())
     56            V8DOMWrapper::associateObjectWithWrapper(impl, &V8HTMLElement::info, wrapper, isolate, WrapperConfiguration::Dependent);
     57        return wrapper;
     58    }
     59
     60    v8::Handle<v8::Value> constructorValue = WebCore::toV8(constructor.get(), creationContext, isolate);
     61    if (constructorValue.IsEmpty() || !constructorValue->IsObject())
     62        return v8::Handle<v8::Object>();
     63    v8::Handle<v8::Object> constructorWapper = v8::Handle<v8::Object>::Cast(constructorValue);
     64    v8::Handle<v8::Object> prototype = v8::Handle<v8::Object>::Cast(constructorWapper->Get(v8::String::NewSymbol("prototype")));
     65    WrapperTypeInfo* typeInfo = CustomElementHelpers::findWrapperType(prototype);
     66    if (!typeInfo)
     67        return v8::Handle<v8::Object>();
     68
     69    v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, typeInfo, impl.get(), isolate);
     70    if (wrapper.IsEmpty())
     71        return v8::Handle<v8::Object>();
     72
     73    wrapper->SetPrototype(prototype);
     74    V8DOMWrapper::associateObjectWithWrapper(impl, typeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
     75    return wrapper;
     76}
     77
    4678bool CustomElementHelpers::initializeConstructorWrapper(CustomElementConstructor* constructor, const ScriptValue& prototype, ScriptState* state)
    4779{
  • trunk/Source/WebCore/bindings/v8/CustomElementHelpers.h

    r146583 r146851  
    3232#define CustomElementHelpers_h
    3333
     34#include "CustomElementConstructor.h"
     35#include "CustomElementRegistry.h"
     36#include "Document.h"
    3437#include "ExceptionCode.h"
    3538#include "ScriptValue.h"
     39#include "V8Binding.h"
     40#include "V8DOMWrapper.h"
     41#include "V8HTMLElement.h"
     42#include "V8HTMLUnknownElement.h"
    3643#include <wtf/Forward.h>
     44#include <wtf/PassRefPtr.h>
    3745
    3846namespace WebCore {
     
    5967    static void invokeReadyCallbacksIfNeeded(ScriptExecutionContext*, const Vector<CustomElementInvocation>&);
    6068
     69    //
     70    // You can just use toV8(Node*) to get correct wrapper objects, even for custom elements.
     71    // Then generated ElementWrapperFactories call V8CustomElement::wrap() with proper CustomElementConstructor instances
     72    // accordingly.
     73    //
     74    static v8::Handle<v8::Object> wrap(Element*, v8::Handle<v8::Object> creationContext, PassRefPtr<CustomElementConstructor>, v8::Isolate*);
     75    static PassRefPtr<CustomElementConstructor> constructorOf(Element*);
     76
    6177private:
    6278    static void invokeReadyCallbackIfNeeded(Element*, v8::Handle<v8::Context>);
     79    static v8::Handle<v8::Object> createWrapper(PassRefPtr<Element>, v8::Handle<v8::Object>, PassRefPtr<CustomElementConstructor>, v8::Isolate*);
    6380};
     81
     82inline v8::Handle<v8::Object> CustomElementHelpers::wrap(Element* impl, v8::Handle<v8::Object> creationContext, PassRefPtr<CustomElementConstructor> constructor, v8::Isolate* isolate)
     83{
     84    ASSERT(impl);
     85    ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty());
     86    return CustomElementHelpers::createWrapper(impl, creationContext, constructor, isolate);
     87}
     88
     89inline PassRefPtr<CustomElementConstructor> CustomElementHelpers::constructorOf(Element* element)
     90{
     91    if (CustomElementRegistry* registry = element->document()->registry())
     92        return registry->findFor(element);
     93    return 0;
     94}
    6495
    6596#endif // ENABLE(CUSTOM_ELEMENTS)
  • trunk/Source/WebCore/bindings/v8/custom/V8CustomElementConstructorCustom.cpp

    r145932 r146851  
    3333
    3434#include "CustomElementConstructor.h"
     35#include "CustomElementHelpers.h"
    3536#include "V8Binding.h"
    36 #include "V8CustomElement.h"
    3737
    3838namespace WebCore {
     
    4949    if (!element)
    5050        return v8Undefined();
    51     return V8CustomElement::wrap(element.get(), args.Holder(), impl, args.GetIsolate());
     51    return CustomElementHelpers::wrap(element.get(), args.Holder(), impl, args.GetIsolate());
    5252}
    5353
  • trunk/Source/WebCore/dom/make_names.pl

    r146464 r146851  
    12201220
    12211221#if ENABLE(CUSTOM_ELEMENTS)
    1222 #include "V8CustomElement.h"
     1222#include "CustomElementHelpers.h"
    12231223#endif
    12241224
     
    12971297        print F <<END
    12981298#if ENABLE(CUSTOM_ELEMENTS)
    1299     if (PassRefPtr<CustomElementConstructor> constructor = V8CustomElement::constructorOf(element))
    1300         return V8CustomElement::wrap(element, creationContext, constructor, isolate);
     1299    if (PassRefPtr<CustomElementConstructor> constructor = CustomElementHelpers::constructorOf(element))
     1300        return CustomElementHelpers::wrap(element, creationContext, constructor, isolate);
    13011301#endif
    13021302END
Note: See TracChangeset for help on using the changeset viewer.