Changeset 143865 in webkit


Ignore:
Timestamp:
Feb 24, 2013 5:21:42 AM (11 years ago)
Author:
morrita@google.com
Message:

[Custom Elements] Implement bare-bone document.register()
https://bugs.webkit.org/show_bug.cgi?id=100229

Reviewed by Adam Barth.

Source/WebCore:

This change implements a prefixed version of document.register(), with minimal feature support.

  • The feature is guarded by ENABLE(CUSTOM_ELEMENTS) and RuntimeEnabledFeatures::customDOMElementsEnabled().
  • This bare-bone version only recognizes "name" and "prototype" parameters. It doesn't support default value of "prototype" parameter.
  • Currently only V8 is supported. JSC binding needs its own binding implementation.

Major new classes under dom/:

The dom module gets two new classes:

  • CustomElementConstructor: A return value of document.register() which holds the custom element definition.
  • CustomElementRegistry: A collection of CustomElementConstructor objects. CustomElementRegistry instance is created per Document and is owned by the Document.

CustomElementConstructor knows the definition of each custom
element, which is registered by document.register(). The name and
other options are held by this object. CustomElementRegistry owns a set
of the registered constructors. The registry guarantees invariants
like validity and uniqueness of the element names.

A change on make_names.pl

This change tweaks make_names.pl (or generated HTMLElementFactory)
to hook the creations of unknown elements. Some of element names
which come to the fallback path can be one of registered custom
element.

[V8WrapAsFunction] extended attribute:

The document.register() API returns a constructor
function. However, the V8 binding currently doesn't support it. To
make it possible, this change introduces "V8WrapAsFunction"
extended attribute for annotating CustomElementConstructor IDL
interface.

V8WrapAsFunction wraps the annotated interface with a JavaScript
function, which calls the original object as a function, or as a
constructor depends on the context.

With this wrapper function, there are two levels of indirection
between native C++ object and author-visible JS function:

[JS Adaptor Function] <-(hidden property)-> [JS Wrapper Object] -(internal field)-> [C++ Native object]

The code generator generates the binding code which deals with
this indirection. Also, there is a set of helper functions in
V8AdaptorFunction.h/cpp which takes care of this indirection.
V8DOMWrapper.cpp/h works as a facade for these APIs and is used from
the generated code.

This redundancy comes from limitations of both V8 bindings and V8
embedding API. See bug 108138 for details.

V8HTMLCustomElement

Unlike built-in HTML elements, any custom element has no
corresponding C++ class. Instead, document.register() should allow
passing a prototype object for the elements being registered.

V8HTMLCustomElement handles this lack of native class. It behaves
like a native side proxy of non-native HTMLElement subclasses. It
connects each custom element to an appropriate native element,
which is HTMLElement at this time. This restriction will be
relaxed later. See Bug 110436 for details.

Custom DOM elements and multiple worlds

In this patch, custom element registration and instantiation is not allowed
in non-main world and document.register() API just fails there.

Reviewed by Adam Barth.

Tests: fast/dom/custom/document-register-basic.html

fast/dom/custom/document-register-reentrant-null-constructor.html
fast/dom/custom/document-register-reentrant-returning-fake.html
fast/dom/custom/document-register-reentrant-throwing-constructor.html

  • DerivedSources.make:
  • WebCore.gypi:
  • bindings/generic/RuntimeEnabledFeatures.cpp:
  • bindings/generic/RuntimeEnabledFeatures.h:

(RuntimeEnabledFeatures):
(WebCore::RuntimeEnabledFeatures::customDOMElementsEnabled):
(WebCore::RuntimeEnabledFeatures::setCustomDOMElements):

  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateHeader):

  • bindings/scripts/IDLAttributes.txt:
  • bindings/v8/CustomElementHelpers.cpp: Added.

(WebCore::CustomElementHelpers::initializeConstructorWrapper):
(WebCore::hasNoBuiltinsInPrototype):
(WebCore::CustomElementHelpers::isValidPrototypeParameter):
(WebCore::CustomElementHelpers::isFeatureAllowed):

  • bindings/v8/CustomElementHelpers.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.

(CustomElementHelpers):

  • bindings/v8/V8AdaptorFunction.cpp: Added.

(WebCore::V8AdaptorFunction::getTemplate):
(WebCore::V8AdaptorFunction::configureTemplate):
(WebCore::V8AdaptorFunction::invocationCallback):
(WebCore::V8AdaptorFunction::wrap):

  • bindings/v8/V8AdaptorFunction.h: Added.

(V8AdaptorFunction):
(WebCore::V8AdaptorFunction::unwrap):
(WebCore::V8AdaptorFunction::get):

  • bindings/v8/V8DOMConfiguration.cpp:

(WebCore::V8DOMConfiguration::configureTemplate):

  • bindings/v8/V8DOMWrapper.cpp:

(WebCore::V8DOMWrapper::toFunction):
(WebCore::V8DOMWrapper::fromFunction):

  • bindings/v8/V8DOMWrapper.h:

(V8DOMWrapper):

  • bindings/v8/V8HTMLCustomElement.cpp: Added.

(WebCore::V8HTMLCustomElement::createWrapper):

  • bindings/v8/V8HTMLCustomElement.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.

(V8HTMLCustomElement):
(WebCore::V8HTMLCustomElement::toV8):
(WebCore::HTMLCustomElement::toV8):

  • bindings/v8/V8HiddenPropertyName.h:
  • bindings/v8/custom/V8CustomElementConstructorCustom.cpp: Added.

(WebCore::V8CustomElementConstructor::callAsFunctionCallback):

  • dom/CustomElementConstructor.cpp: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.

(WebCore::CustomElementConstructor::create):
(WebCore::CustomElementConstructor::CustomElementConstructor):
(WebCore::CustomElementConstructor::~CustomElementConstructor):
(WebCore::CustomElementConstructor::createElement):

  • dom/CustomElementConstructor.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.

(CustomElementConstructor):
(WebCore::CustomElementConstructor::document):
(WebCore::CustomElementConstructor::tagName):
(WebCore::CustomElementConstructor::name):

  • dom/CustomElementConstructor.idl: Added.
  • dom/CustomElementRegistry.cpp: Added.

(WebCore::CustomElementRegistry::CustomElementRegistry):
(WebCore::CustomElementRegistry::~CustomElementRegistry):
(WebCore::CustomElementRegistry::constructorOf):
(WebCore::CustomElementRegistry::isValidName):
(WebCore::CustomElementRegistry::registerElement):
(WebCore::CustomElementRegistry::find):
(WebCore::CustomElementRegistry::createElement):
(WebCore::CustomElementRegistry::document):

  • dom/CustomElementRegistry.h: Added.

(CustomElementRegistry):

  • dom/Document.cpp:

(WebCore::Document::removedLastRef):
(WebCore::Document::registerElement):
(WebCore::Document::registry):

  • dom/Document.h:

(Document):

  • dom/make_names.pl:

(printWrapperFactoryCppFile):

  • html/HTMLDocument.idl:

Source/WebKit/chromium:

Added enableCustomDOMElements flag.

  • features.gypi:
  • public/WebRuntimeFeatures.h:

(WebRuntimeFeatures):

  • src/WebRuntimeFeatures.cpp:

(WebKit::WebRuntimeFeatures::enableCustomDOMElements):
(WebKit):
(WebKit::WebRuntimeFeatures::isCustomDOMElementsEnabled):

Tools:

Added enableCustomDOMElements flag.

  • DumpRenderTree/chromium/TestShell.cpp:

(TestShell::TestShell):

LayoutTests:

  • fast/dom/custom/document-register-basic-expected.txt: Added.
  • fast/dom/custom/document-register-basic.html: Added.
  • fast/dom/custom/document-register-reentrant-null-constructor-expected.txt: Added.
  • fast/dom/custom/document-register-reentrant-null-constructor.html: Added.
  • fast/dom/custom/document-register-reentrant-returning-fake-expected.txt: Added.
  • fast/dom/custom/document-register-reentrant-returning-fake.html: Added.
  • fast/dom/custom/document-register-reentrant-throwing-constructor-expected.txt: Added.
  • fast/dom/custom/document-register-reentrant-throwing-constructor.html: Added.
  • fast/dom/custom/resources/document-register-fuzz.js: Added.
  • platform/mac/TestExpectations:
Location:
trunk
Files:
20 added
23 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r143862 r143865  
     12013-02-24  Hajime Morrita  <morrita@google.com>
     2
     3        [Custom Elements] Implement bare-bone document.register()
     4        https://bugs.webkit.org/show_bug.cgi?id=100229
     5
     6        Reviewed by Adam Barth.
     7
     8        * fast/dom/custom/document-register-basic-expected.txt: Added.
     9        * fast/dom/custom/document-register-basic.html: Added.
     10        * fast/dom/custom/document-register-reentrant-null-constructor-expected.txt: Added.
     11        * fast/dom/custom/document-register-reentrant-null-constructor.html: Added.
     12        * fast/dom/custom/document-register-reentrant-returning-fake-expected.txt: Added.
     13        * fast/dom/custom/document-register-reentrant-returning-fake.html: Added.
     14        * fast/dom/custom/document-register-reentrant-throwing-constructor-expected.txt: Added.
     15        * fast/dom/custom/document-register-reentrant-throwing-constructor.html: Added.
     16        * fast/dom/custom/resources/document-register-fuzz.js: Added.
     17        * platform/mac/TestExpectations:
     18
    1192013-02-24  Benjamin Poulain  <benjamin@webkit.org>
    220
  • trunk/LayoutTests/platform/mac/TestExpectations

    r143849 r143865  
    11131113webkit.org/b/76439 [ Debug ] fast/dom/shadow/content-element-outside-shadow.html [ Failure ]
    11141114
     1115# ENABLE(CUSTOM_ELEMENTS) is disabled.
     1116fast/dom/custom
     1117
    11151118# CSS Variables are not yet enabled.
    11161119webkit.org/b/85580 fast/css/variables
  • trunk/Source/WebCore/ChangeLog

    r143864 r143865  
     12013-02-24  Hajime Morrita  <morrita@google.com>
     2
     3        [Custom Elements] Implement bare-bone document.register()
     4        https://bugs.webkit.org/show_bug.cgi?id=100229
     5
     6        Reviewed by Adam Barth.
     7
     8        This change implements a prefixed version of document.register(), with minimal feature support.
     9        - The feature is guarded by ENABLE(CUSTOM_ELEMENTS) and RuntimeEnabledFeatures::customDOMElementsEnabled().
     10        - This bare-bone version only recognizes "name" and "prototype" parameters. It doesn't support default value of "prototype" parameter.
     11        - Currently only V8 is supported. JSC binding needs its own binding implementation.
     12
     13        = Major new classes under dom/:
     14
     15        The dom module gets two new classes:
     16        - CustomElementConstructor: A return value of document.register()
     17          which holds the custom element definition.
     18        - CustomElementRegistry: A collection of CustomElementConstructor objects.
     19          CustomElementRegistry instance is created per Document and is owned by the Document.
     20
     21        CustomElementConstructor knows the definition of each custom
     22        element, which is registered by document.register(). The name and
     23        other options are held by this object. CustomElementRegistry owns a set
     24        of the registered constructors. The registry guarantees invariants
     25        like validity and uniqueness of the element names.
     26
     27        = A change on make_names.pl
     28
     29        This change tweaks make_names.pl (or generated HTMLElementFactory)
     30        to hook the creations of unknown elements. Some of element names
     31        which come to the fallback path can be one of registered custom
     32        element.
     33
     34        = [V8WrapAsFunction] extended attribute:
     35
     36        The document.register() API returns a constructor
     37        function. However, the V8 binding currently doesn't support it. To
     38        make it possible, this change introduces "V8WrapAsFunction"
     39        extended attribute for annotating CustomElementConstructor IDL
     40        interface.
     41
     42        V8WrapAsFunction wraps the annotated interface with a JavaScript
     43        function, which calls the original object as a function, or as a
     44        constructor depends on the context.
     45
     46        With this wrapper function, there are two levels of indirection
     47        between native C++ object and author-visible JS function:
     48
     49        [JS Adaptor Function] <-(hidden property)-> [JS Wrapper Object] -(internal field)-> [C++ Native object]
     50
     51        The code generator generates the binding code which deals with
     52        this indirection.  Also, there is a set of helper functions in
     53        V8AdaptorFunction.h/cpp which takes care of this indirection.
     54        V8DOMWrapper.cpp/h works as a facade for these APIs and is used from
     55        the generated code.
     56
     57        This redundancy comes from limitations of both V8 bindings and V8
     58        embedding API. See bug 108138 for details.
     59
     60        = V8HTMLCustomElement
     61
     62        Unlike built-in HTML elements, any custom element has no
     63        corresponding C++ class. Instead, document.register() should allow
     64        passing a prototype object for the elements being registered.
     65
     66        V8HTMLCustomElement handles this lack of native class.  It behaves
     67        like a native side proxy of non-native HTMLElement subclasses.  It
     68        connects each custom element to an appropriate native element,
     69        which is HTMLElement at this time. This restriction will be
     70        relaxed later. See Bug 110436 for details.
     71
     72        = Custom DOM elements and multiple worlds
     73
     74        In this patch, custom element registration and instantiation is not allowed
     75        in non-main world and document.register() API just fails there.
     76
     77        Reviewed by Adam Barth.
     78
     79        Tests: fast/dom/custom/document-register-basic.html
     80               fast/dom/custom/document-register-reentrant-null-constructor.html
     81               fast/dom/custom/document-register-reentrant-returning-fake.html
     82               fast/dom/custom/document-register-reentrant-throwing-constructor.html
     83
     84        * DerivedSources.make:
     85        * WebCore.gypi:
     86        * bindings/generic/RuntimeEnabledFeatures.cpp:
     87        * bindings/generic/RuntimeEnabledFeatures.h:
     88        (RuntimeEnabledFeatures):
     89        (WebCore::RuntimeEnabledFeatures::customDOMElementsEnabled):
     90        (WebCore::RuntimeEnabledFeatures::setCustomDOMElements):
     91        * bindings/scripts/CodeGeneratorV8.pm:
     92        (GenerateHeader):
     93        * bindings/scripts/IDLAttributes.txt:
     94        * bindings/v8/CustomElementHelpers.cpp: Added.
     95        (WebCore::CustomElementHelpers::initializeConstructorWrapper):
     96        (WebCore::hasNoBuiltinsInPrototype):
     97        (WebCore::CustomElementHelpers::isValidPrototypeParameter):
     98        (WebCore::CustomElementHelpers::isFeatureAllowed):
     99        * bindings/v8/CustomElementHelpers.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
     100        (CustomElementHelpers):
     101        * bindings/v8/V8AdaptorFunction.cpp: Added.
     102        (WebCore::V8AdaptorFunction::getTemplate):
     103        (WebCore::V8AdaptorFunction::configureTemplate):
     104        (WebCore::V8AdaptorFunction::invocationCallback):
     105        (WebCore::V8AdaptorFunction::wrap):
     106        * bindings/v8/V8AdaptorFunction.h: Added.
     107        (V8AdaptorFunction):
     108        (WebCore::V8AdaptorFunction::unwrap):
     109        (WebCore::V8AdaptorFunction::get):
     110        * bindings/v8/V8DOMConfiguration.cpp:
     111        (WebCore::V8DOMConfiguration::configureTemplate):
     112        * bindings/v8/V8DOMWrapper.cpp:
     113        (WebCore::V8DOMWrapper::toFunction):
     114        (WebCore::V8DOMWrapper::fromFunction):
     115        * bindings/v8/V8DOMWrapper.h:
     116        (V8DOMWrapper):
     117        * bindings/v8/V8HTMLCustomElement.cpp: Added.
     118        (WebCore::V8HTMLCustomElement::createWrapper):
     119        * bindings/v8/V8HTMLCustomElement.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
     120        (V8HTMLCustomElement):
     121        (WebCore::V8HTMLCustomElement::toV8):
     122        (WebCore::HTMLCustomElement::toV8):
     123        * bindings/v8/V8HiddenPropertyName.h:
     124        * bindings/v8/custom/V8CustomElementConstructorCustom.cpp: Added.
     125        (WebCore::V8CustomElementConstructor::callAsFunctionCallback):
     126        * dom/CustomElementConstructor.cpp: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
     127        (WebCore::CustomElementConstructor::create):
     128        (WebCore::CustomElementConstructor::CustomElementConstructor):
     129        (WebCore::CustomElementConstructor::~CustomElementConstructor):
     130        (WebCore::CustomElementConstructor::createElement):
     131        * dom/CustomElementConstructor.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
     132        (CustomElementConstructor):
     133        (WebCore::CustomElementConstructor::document):
     134        (WebCore::CustomElementConstructor::tagName):
     135        (WebCore::CustomElementConstructor::name):
     136        * dom/CustomElementConstructor.idl: Added.
     137        * dom/CustomElementRegistry.cpp: Added.
     138        (WebCore::CustomElementRegistry::CustomElementRegistry):
     139        (WebCore::CustomElementRegistry::~CustomElementRegistry):
     140        (WebCore::CustomElementRegistry::constructorOf):
     141        (WebCore::CustomElementRegistry::isValidName):
     142        (WebCore::CustomElementRegistry::registerElement):
     143        (WebCore::CustomElementRegistry::find):
     144        (WebCore::CustomElementRegistry::createElement):
     145        (WebCore::CustomElementRegistry::document):
     146        * dom/CustomElementRegistry.h: Added.
     147        (CustomElementRegistry):
     148        * dom/Document.cpp:
     149        (WebCore::Document::removedLastRef):
     150        (WebCore::Document::registerElement):
     151        (WebCore::Document::registry):
     152        * dom/Document.h:
     153        (Document):
     154        * dom/make_names.pl:
     155        (printWrapperFactoryCppFile):
     156        * html/HTMLDocument.idl:
     157
    11582013-02-24  Eugene Klyuchnikov  <eustas@chromium.org>
    2159
  • trunk/Source/WebCore/DerivedSources.make

    r143820 r143865  
    221221    $(WebCore)/dom/Comment.idl \
    222222    $(WebCore)/dom/CompositionEvent.idl \
     223    $(WebCore)/dom/CustomElementConstructor.idl \
    223224    $(WebCore)/dom/CustomEvent.idl \
    224225    $(WebCore)/dom/DOMCoreException.idl \
  • trunk/Source/WebCore/WebCore.gypi

    r143854 r143865  
    201201            'dom/Comment.idl',
    202202            'dom/CompositionEvent.idl',
     203            'dom/CustomElementConstructor.idl',
    203204            'dom/CustomEvent.idl',
    204205            'dom/DOMCoreException.idl',
     
    11921193            'bindings/v8/BindingState.cpp',
    11931194            'bindings/v8/BindingState.h',
     1195            'bindings/v8/CustomElementHelpers.cpp',
     1196            'bindings/v8/CustomElementHelpers.h',
    11941197            'bindings/v8/DOMDataStore.cpp',
    11951198            'bindings/v8/DOMDataStore.h',
     
    12601263            'bindings/v8/V8AbstractEventListener.cpp',
    12611264            'bindings/v8/V8AbstractEventListener.h',
     1265            'bindings/v8/V8AdaptorFunction.cpp',
     1266            'bindings/v8/V8AdaptorFunction.h',
    12621267            'bindings/v8/V8Binding.cpp',
    12631268            'bindings/v8/V8Binding.h',
     
    12811286            'bindings/v8/V8GCForContextDispose.cpp',
    12821287            'bindings/v8/V8GCForContextDispose.h',
     1288            'bindings/v8/V8HTMLCustomElement.cpp',
     1289            'bindings/v8/V8HTMLCustomElement.h',
    12831290            'bindings/v8/V8HiddenPropertyName.cpp',
    12841291            'bindings/v8/V8HiddenPropertyName.h',
     
    13411348            'bindings/v8/custom/V8CoordinatesCustom.cpp',
    13421349            'bindings/v8/custom/V8CryptoCustom.cpp',
     1350            'bindings/v8/custom/V8CustomElementConstructorCustom.cpp',
    13431351            'bindings/v8/custom/V8CustomEventCustom.cpp',
    13441352            'bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp',
     
    27742782            'dom/ContextFeatures.h',
    27752783            'dom/CrossThreadTask.h',
     2784            'dom/CustomElementConstructor.cpp',
     2785            'dom/CustomElementConstructor.h',
     2786            'dom/CustomElementRegistry.cpp',
     2787            'dom/CustomElementRegistry.h',
    27762788            'dom/CustomEvent.cpp',
    27772789            'dom/CustomEvent.h',
  • trunk/Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp

    r143502 r143865  
    191191#endif
    192192
     193#if ENABLE(CUSTOM_ELEMENTS)
     194bool RuntimeEnabledFeatures::isCustomDOMElementsEnabled = false;
     195#endif
     196
    193197#if ENABLE(STYLE_SCOPED)
    194198bool RuntimeEnabledFeatures::isStyleScopedEnabled = false;
  • trunk/Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h

    r143502 r143865  
    219219#endif
    220220
     221#if ENABLE(CUSTOM_ELEMENTS)
     222    static bool customDOMElementsEnabled() { return isCustomDOMElementsEnabled; }
     223    static void setCustomDOMElements(bool isEnabled) { isCustomDOMElementsEnabled = isEnabled; }
     224#endif
     225
    221226#if ENABLE(STYLE_SCOPED)
    222227    static bool styleScopedEnabled() { return isStyleScopedEnabled; }
     
    344349#endif
    345350
     351#if ENABLE(CUSTOM_ELEMENTS)
     352    static bool isCustomDOMElementsEnabled;
     353#endif
     354
    346355#if ENABLE(STYLE_SCOPED)
    347356    static bool isStyleScopedEnabled;
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r143856 r143865  
    353353    }
    354354
     355    my $fromFunctionOpening = "";
     356    my $fromFunctionClosing = "";
     357    if ($interface->extendedAttributes->{"V8WrapAsFunction"}) {
     358        $fromFunctionOpening = "V8DOMWrapper::fromFunction(";
     359        $fromFunctionClosing = ")";
     360    }
     361
    355362    push(@headerContent, <<END);
    356363    static bool HasInstance(v8::Handle<v8::Value>, v8::Isolate*);
     
    359366    static ${nativeType}* toNative(v8::Handle<v8::Object> object)
    360367    {
    361         return reinterpret_cast<${nativeType}*>(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
     368        return reinterpret_cast<${nativeType}*>(${fromFunctionOpening}object${fromFunctionClosing}->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
    362369    }
    363370    static void derefObject(void*);
     
    540547
    541548        my $createWrapperCall = $customWrap ? "${v8InterfaceName}::wrap" : "${v8InterfaceName}::createWrapper";
     549        my $returningWrapper = $interface->extendedAttributes->{"V8WrapAsFunction"} ? "V8DOMWrapper::toFunction(wrapper)" : "wrapper";
     550        my $returningCreatedWrapperOpening = $interface->extendedAttributes->{"V8WrapAsFunction"} ? "V8DOMWrapper::toFunction(" : "";
     551        my $returningCreatedWrapperClosing = $interface->extendedAttributes->{"V8WrapAsFunction"} ? ", impl->name(), isolate)" : "";
    542552
    543553        if ($customWrap) {
     
    553563    ASSERT(impl);
    554564    ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty());
    555     return $createWrapperCall(impl, creationContext, isolate);
     565    return ${returningCreatedWrapperOpening}$createWrapperCall(impl, creationContext, isolate)${returningCreatedWrapperClosing};
    556566}
    557567END
     
    566576    v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate);
    567577    if (!wrapper.IsEmpty())
    568         return wrapper;
     578        return $returningWrapper;
    569579    return wrap(impl, creationContext, isolate);
    570580}
     
    577587    v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapperFast(impl, container, wrappable);
    578588    if (!wrapper.IsEmpty())
    579         return wrapper;
     589        return $returningWrapper;
    580590    return wrap(impl, container.Holder(), container.GetIsolate());
    581591}
  • trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt

    r141034 r143865  
    130130V8SkipVTableValidation
    131131V8Unforgeable
     132V8WrapAsFunction
  • trunk/Source/WebCore/bindings/v8/CustomElementHelpers.h

    r143864 r143865  
    2929 */
    3030
    31 #ifndef V8HiddenPropertyName_h
    32 #define V8HiddenPropertyName_h
     31#ifndef CustomElementHelpers_h
     32#define CustomElementHelpers_h
    3333
    34 #include <v8.h>
     34#include "ExceptionCode.h"
     35#include "ScriptValue.h"
    3536
    3637namespace WebCore {
    3738
    38 #define V8_HIDDEN_PROPERTIES(V) \
    39     V(attributeListener) \
    40     V(callback) \
    41     V(detail) \
    42     V(document) \
    43     V(event) \
    44     V(listener) \
    45     V(scriptState) \
    46     V(sleepFunction) \
    47     V(state) \
    48     V(toStringString) \
    49     V(typedArrayHiddenCopyMethod)
     39#if ENABLE(CUSTOM_ELEMENTS)
    5040
    51 class V8HiddenPropertyName {
     41class CustomElementConstructor;
     42class ScriptState;
     43
     44class CustomElementHelpers {
    5245public:
    53     V8HiddenPropertyName() { }
    54 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name();
    55     V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY);
    56 #undef V8_DECLARE_PROPERTY
     46    static bool initializeConstructorWrapper(CustomElementConstructor*, const ScriptValue& prototype, ScriptState*);
     47    static bool isValidPrototypeParameter(const ScriptValue&, ScriptState*);
     48    static bool isFeatureAllowed(ScriptState*);
    5749
    58     static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child);
    59 
    60 private:
    61     static v8::Persistent<v8::String> createString(const char* key);
    62 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name;
    63     V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD);
    64 #undef V8_DECLARE_FIELD
     50    static bool isFeatureAllowed(v8::Handle<v8::Context>);
    6551};
    6652
    67 }
     53#endif // ENABLE(CUSTOM_ELEMENTS)
    6854
    69 #endif // V8HiddenPropertyName_h
     55} // namespace WebCore
     56
     57#endif // CustomElementHelpers_h
  • trunk/Source/WebCore/bindings/v8/V8DOMConfiguration.cpp

    r141862 r143865  
    3434namespace WebCore {
    3535
     36const int prototypeInternalFieldcount = 1;
     37
    3638void V8DOMConfiguration::batchConfigureAttributes(v8::Handle<v8::ObjectTemplate> instance, v8::Handle<v8::ObjectTemplate> prototype, const BatchedAttribute* attributes, size_t attributeCount, v8::Isolate* isolate)
    3739{
     
    6163    v8::Local<v8::ObjectTemplate> instance = functionDescriptor->InstanceTemplate();
    6264    instance->SetInternalFieldCount(fieldCount);
    63     if (!parentClass.IsEmpty())
     65    if (!parentClass.IsEmpty()) {
    6466        functionDescriptor->Inherit(parentClass);
     67        // Marks the prototype object as one of native-backed objects.
     68        // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones.
     69        // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure.
     70        v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeTemplate();
     71        prototype->SetInternalFieldCount(prototypeInternalFieldcount);
     72    }
     73
    6574    if (attributeCount)
    6675        batchConfigureAttributes(instance, functionDescriptor->PrototypeTemplate(), attributes, attributeCount, isolate);
  • trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp

    r142217 r143865  
    3232#include "V8DOMWrapper.h"
    3333
     34#include "V8AdaptorFunction.h"
    3435#include "V8Binding.h"
    3536#include "V8DOMWindow.h"
     
    138139}
    139140
     141#if ENABLE(CUSTOM_ELEMENTS)
     142
     143v8::Handle<v8::Function> V8DOMWrapper::toFunction(v8::Handle<v8::Value> object)
     144{
     145    return V8AdaptorFunction::get(v8::Handle<v8::Object>::Cast(object));
     146}
     147
     148v8::Handle<v8::Function> V8DOMWrapper::toFunction(v8::Handle<v8::Object> object, const AtomicString& name, v8::Isolate* isolate)
     149{
     150    return V8AdaptorFunction::wrap(object, name, isolate);
     151}
     152
     153v8::Handle<v8::Object> V8DOMWrapper::fromFunction(v8::Handle<v8::Object> object)
     154{
     155    if (!object->IsFunction())
     156        return object;
     157    return V8AdaptorFunction::unwrap(v8::Handle<v8::Function>::Cast(object));
     158}
     159
     160#endif // ENABLE(CUSTOM_ELEMENTS)
     161
    140162}  // namespace WebCore
  • trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h

    r142217 r143865  
    6363        static bool isDOMWrapper(v8::Handle<v8::Value>);
    6464        static bool isWrapperOfType(v8::Handle<v8::Value>, WrapperTypeInfo*);
     65
     66#if ENABLE(CUSTOM_ELEMENTS)
     67        // Used for V8WrapAsFunction, which is used only by CUSTOM_ELEMENTS
     68        static v8::Handle<v8::Function> toFunction(v8::Handle<v8::Value>);
     69        static v8::Handle<v8::Function> toFunction(v8::Handle<v8::Object>, const AtomicString& name, v8::Isolate*);
     70        static v8::Handle<v8::Object> fromFunction(v8::Handle<v8::Object>);
     71#endif // ENABLE(CUSTOM_ELEMENTS)
    6572    };
    6673
  • trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h

    r142226 r143865  
    4646    V(sleepFunction) \
    4747    V(state) \
     48    V(adaptorFunctionPeer) \
    4849    V(toStringString) \
    4950    V(typedArrayHiddenCopyMethod)
  • trunk/Source/WebCore/dom/CustomElementConstructor.cpp

    r143864 r143865  
    2929 */
    3030
    31 #ifndef V8HiddenPropertyName_h
    32 #define V8HiddenPropertyName_h
     31#include "config.h"
    3332
    34 #include <v8.h>
     33#if ENABLE(CUSTOM_ELEMENTS)
     34
     35#include "CustomElementConstructor.h"
     36
     37#include "CustomElementHelpers.h"
     38#include "Document.h"
     39#include "HTMLElement.h"
     40#include <wtf/Assertions.h>
    3541
    3642namespace WebCore {
    3743
    38 #define V8_HIDDEN_PROPERTIES(V) \
    39     V(attributeListener) \
    40     V(callback) \
    41     V(detail) \
    42     V(document) \
    43     V(event) \
    44     V(listener) \
    45     V(scriptState) \
    46     V(sleepFunction) \
    47     V(state) \
    48     V(toStringString) \
    49     V(typedArrayHiddenCopyMethod)
     44PassRefPtr<CustomElementConstructor> CustomElementConstructor::create(ScriptState* state, Document* document, const QualifiedName& tagName, const String& name, const ScriptValue& prototype)
     45{
     46    RefPtr<CustomElementConstructor> created = adoptRef(new CustomElementConstructor(document, tagName, name));
     47    if (!CustomElementHelpers::initializeConstructorWrapper(created.get(), prototype, state))
     48        return 0;
     49    return created.release();
     50}
    5051
    51 class V8HiddenPropertyName {
    52 public:
    53     V8HiddenPropertyName() { }
    54 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name();
    55     V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY);
    56 #undef V8_DECLARE_PROPERTY
     52CustomElementConstructor::CustomElementConstructor(Document* document, const QualifiedName& tagName, const String& name)
     53    : ContextDestructionObserver(document)
     54    , m_tagName(tagName)
     55    , m_name(name)
     56{
     57}
    5758
    58     static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child);
     59CustomElementConstructor::~CustomElementConstructor()
     60{
     61}
    5962
    60 private:
    61     static v8::Persistent<v8::String> createString(const char* key);
    62 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name;
    63     V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD);
    64 #undef V8_DECLARE_FIELD
    65 };
     63PassRefPtr<HTMLElement> CustomElementConstructor::createElement() const
     64{
     65    if (!document())
     66        return 0;
     67    return HTMLElement::create(m_tagName, document());
     68}
    6669
    6770}
    6871
    69 #endif // V8HiddenPropertyName_h
     72#endif // ENABLE(CUSTOM_ELEMENTS)
  • trunk/Source/WebCore/dom/CustomElementConstructor.h

    r143864 r143865  
    2929 */
    3030
    31 #ifndef V8HiddenPropertyName_h
    32 #define V8HiddenPropertyName_h
     31#ifndef CustomElementConstructor_h
     32#define CustomElementConstructor_h
    3333
    34 #include <v8.h>
     34#if ENABLE(CUSTOM_ELEMENTS)
     35
     36#include "ContextDestructionObserver.h"
     37#include "Document.h"
     38#include "QualifiedName.h"
     39#include <wtf/Forward.h>
     40#include <wtf/PassRefPtr.h>
     41#include <wtf/RefCounted.h>
     42#include <wtf/text/AtomicString.h>
    3543
    3644namespace WebCore {
    3745
    38 #define V8_HIDDEN_PROPERTIES(V) \
    39     V(attributeListener) \
    40     V(callback) \
    41     V(detail) \
    42     V(document) \
    43     V(event) \
    44     V(listener) \
    45     V(scriptState) \
    46     V(sleepFunction) \
    47     V(state) \
    48     V(toStringString) \
    49     V(typedArrayHiddenCopyMethod)
     46class Document;
     47class HTMLElement;
     48class ScriptState;
     49class ScriptValue;
    5050
    51 class V8HiddenPropertyName {
     51class CustomElementConstructor : public RefCounted<CustomElementConstructor> , public ContextDestructionObserver {
    5252public:
    53     V8HiddenPropertyName() { }
    54 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name();
    55     V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY);
    56 #undef V8_DECLARE_PROPERTY
     53    static PassRefPtr<CustomElementConstructor> create(ScriptState*, Document*, const QualifiedName&, const String&, const ScriptValue&);
    5754
    58     static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child);
     55    virtual ~CustomElementConstructor();
    5956
     57    Document* document() const { return static_cast<Document*>(m_scriptExecutionContext); }
     58    const QualifiedName& tagName() const { return m_tagName; }
     59    const AtomicString& name() const { return m_name; }
     60
     61    PassRefPtr<HTMLElement> createElement() const;
     62   
    6063private:
    61     static v8::Persistent<v8::String> createString(const char* key);
    62 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name;
    63     V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD);
    64 #undef V8_DECLARE_FIELD
     64    CustomElementConstructor(Document*, const QualifiedName&, const String&);
     65
     66    QualifiedName m_tagName;
     67    AtomicString m_name;
    6568};
    6669
    6770}
    6871
    69 #endif // V8HiddenPropertyName_h
     72#endif // ENABLE(CUSTOM_ELEMENTS)
     73
     74#endif // CustomElementConstructor_h
  • trunk/Source/WebCore/dom/Document.cpp

    r143840 r143865  
    4747#include "ContextFeatures.h"
    4848#include "CookieJar.h"
     49#include "CustomElementConstructor.h"
     50#include "CustomElementRegistry.h"
    4951#include "DOMImplementation.h"
    5052#include "DOMNamedFlowCollection.h"
     
    5254#include "DOMWindow.h"
    5355#include "DateComponents.h"
     56#include "Dictionary.h"
    5457#include "DocumentEventQueue.h"
    5558#include "DocumentFragment.h"
     
    670673    detachParser();
    671674
     675#if ENABLE(CUSTOM_ELEMENTS)
     676        m_registry.clear();
     677#endif
     678
    672679    // removeDetachedChildren() doesn't always unregister IDs,
    673680    // so tear down scope information upfront to avoid having stale references in the map.
     
    823830    return createElement(QualifiedName(nullAtom, name, nullAtom), false);
    824831}
     832
     833#if ENABLE(CUSTOM_ELEMENTS)
     834PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, ExceptionCode& ec)
     835{
     836    return registerElement(state, name, Dictionary(), ec);
     837}
     838
     839PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec)
     840{
     841    if (!m_registry)
     842        m_registry = adoptRef(new CustomElementRegistry(this));
     843    return m_registry->registerElement(state, name, options, ec);
     844}
     845
     846PassRefPtr<CustomElementRegistry> Document::registry() const
     847{
     848    return m_registry;
     849}
     850#endif // ENABLE(CUSTOM_ELEMENTS)
    825851
    826852PassRefPtr<DocumentFragment> Document::createDocumentFragment()
  • trunk/Source/WebCore/dom/Document.h

    r143840 r143865  
    7272class Comment;
    7373class ContextFeatures;
     74class CustomElementConstructor;
     75class CustomElementRegistry;
    7476class DOMImplementation;
    7577class DOMNamedFlowCollection;
     
    11431145#endif
    11441146
     1147#if ENABLE(CUSTOM_ELEMENTS)
     1148    PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, ExceptionCode&);
     1149    PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionCode&);
     1150    PassRefPtr<CustomElementRegistry> registry() const;
     1151#endif
     1152
    11451153    void adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>&, RenderObject*);
    11461154    void adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(FloatRect&, RenderObject*);
     
    15191527#endif
    15201528
     1529#if ENABLE(CUSTOM_ELEMENTS)
     1530    RefPtr<CustomElementRegistry> m_registry;
     1531#endif
     1532
    15211533    bool m_scheduledTasksAreSuspended;
    15221534   
  • trunk/Source/WebCore/dom/make_names.pl

    r143398 r143865  
    11731173    } elsif ($wrapperFactoryType eq "V8") {
    11741174        print F <<END
     1175#include "V8HTMLCustomElement.h"
    11751176#include "V8$parameters{namespace}Element.h"
    1176        
     1177
    11771178#include <v8.h>
    11781179END
     
    12731274            print F <<END
    12741275    return V8SVGElement::createWrapper(element, creationContext, isolate);
     1276END
     1277;
     1278        } elsif ($parameters{namespace} eq "HTML") {
     1279            print F <<END
     1280    return V8HTMLCustomElement::wrap(element, creationContext, isolate);
    12751281END
    12761282;
  • trunk/Source/WebCore/html/HTMLDocument.idl

    r141034 r143865  
    5454    boolean hasFocus();
    5555
     56#if defined(ENABLE_CUSTOM_ELEMENTS) && ENABLE_CUSTOM_ELEMENTS
     57    [V8EnabledAtRuntime=customDOMElements, Conditional=CUSTOM_ELEMENTS, ImplementedAs=registerElement, CallWith=ScriptState]
     58    CustomElementConstructor webkitRegister(in DOMString name, in [Optional] Dictionary options) raises(DOMException);
     59#endif
     60
    5661    // Deprecated attributes
    5762             [TreatNullAs=NullString] attribute DOMString bgColor;
  • trunk/Source/WebKit/chromium/ChangeLog

    r143846 r143865  
     12013-02-24  Hajime Morrita  <morrita@google.com>
     2
     3        [Custom Elements] Implement bare-bone document.register()
     4        https://bugs.webkit.org/show_bug.cgi?id=100229
     5
     6        Reviewed by Adam Barth.
     7
     8        Added enableCustomDOMElements flag.
     9
     10        * features.gypi:
     11        * public/WebRuntimeFeatures.h:
     12        (WebRuntimeFeatures):
     13        * src/WebRuntimeFeatures.cpp:
     14        (WebKit::WebRuntimeFeatures::enableCustomDOMElements):
     15        (WebKit):
     16        (WebKit::WebRuntimeFeatures::isCustomDOMElementsEnabled):
     17
    1182013-02-23  Mark Pilgrim  <pilgrim@chromium.org>
    219
  • trunk/Source/WebKit/chromium/features.gypi

    r143511 r143865  
    5555      'ENABLE_CSS_VARIABLES=1',
    5656      'ENABLE_CSS_STICKY_POSITION=1',
     57      'ENABLE_CUSTOM_ELEMENTS=1',
    5758      'ENABLE_CUSTOM_SCHEME_HANDLER=0',
    5859      'ENABLE_DASHBOARD_SUPPORT=0',
  • trunk/Source/WebKit/chromium/public/WebRuntimeFeatures.h

    r143502 r143865  
    126126    WEBKIT_EXPORT static bool isShadowDOMEnabled();
    127127
     128    WEBKIT_EXPORT static void enableCustomDOMElements(bool);
     129    WEBKIT_EXPORT static bool isCustomDOMElementsEnabled();
     130
    128131    WEBKIT_EXPORT static void enableStyleScoped(bool);
    129132    WEBKIT_EXPORT static bool isStyleScopedEnabled();
  • trunk/Source/WebKit/chromium/src/WebRuntimeFeatures.cpp

    r143502 r143865  
    482482}
    483483
     484void WebRuntimeFeatures::enableCustomDOMElements(bool enable)
     485{
     486#if ENABLE(CUSTOM_ELEMENTS)
     487    RuntimeEnabledFeatures::setCustomDOMElements(enable);
     488#else
     489    UNUSED_PARAM(enable);
     490#endif
     491}
     492
     493bool WebRuntimeFeatures::isCustomDOMElementsEnabled()
     494{
     495#if ENABLE(CUSTOM_ELEMENTS)
     496    return RuntimeEnabledFeatures::customDOMElementsEnabled();
     497#else
     498    return false;
     499#endif
     500}
     501
     502
    484503void WebRuntimeFeatures::enableStyleScoped(bool enable)
    485504{
  • trunk/Tools/ChangeLog

    r143852 r143865  
     12013-02-24  Hajime Morrita  <morrita@google.com>
     2
     3        [Custom Elements] Implement bare-bone document.register()
     4        https://bugs.webkit.org/show_bug.cgi?id=100229
     5
     6        Reviewed by Adam Barth.
     7
     8        Added enableCustomDOMElements flag.
     9
     10        * DumpRenderTree/chromium/TestShell.cpp:
     11        (TestShell::TestShell):
     12
    1132013-02-23  Mark Pilgrim  <pilgrim@chromium.org>
    214
  • trunk/Tools/DumpRenderTree/chromium/TestShell.cpp

    r143852 r143865  
    146146    WebRuntimeFeatures::enableGamepad(true);
    147147    WebRuntimeFeatures::enableShadowDOM(true);
     148    WebRuntimeFeatures::enableCustomDOMElements(true);
    148149    WebRuntimeFeatures::enableStyleScoped(true);
    149150    WebRuntimeFeatures::enableScriptedSpeech(true);
Note: See TracChangeset for help on using the changeset viewer.