⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 197642 in webkit


Ignore:
Timestamp:
Mar 6, 2016, 12:44:49 PM (11 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

Enable DOM class create functions to take parameters in case of JSBuiltinConstructor
​https://bugs.webkit.org/show_bug.cgi?id=155022

Reviewed by Darin Adler.

Introducing JSDOMObjectInspector to check whether a given JS class is built-in (no DOM class).
If that is not the case, the JS class wraps a DOM class.
The inspector detects whether the DOM class create static method takes no parameter or some parameters.
This is used in JSDOMConstructor.h to generate correctly the createJSObject functions needed by JSBuiltinConstructor.

Updated binding generator to not generate anymore createJSObject as it is handled directly in JSDOMConstructor.h.

Covered by existing tests.

  • bindings/js/JSDOMConstructor.h:

(WebCore::JSBuiltinConstructor<JSClass>::callConstructor):
(WebCore::createJSObject):
(WebCore::JSBuiltinConstructor<JSClass>::construct):

  • bindings/js/JSDOMWrapper.h:
  • bindings/js/JSKeyValueIterator.h: Taking benefit of JSClass::DOMWrapper type declaration.
  • bindings/js/JSReadableStreamPrivateConstructors.cpp:

(WebCore::JSBuiltinReadableStreamReaderPrivateConstructor::initializeExecutable): Deleted.
(WebCore::JSBuiltinReadableStreamControllerPrivateConstructor::initializeExecutable): Deleted.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateConstructorDefinition): Deleted.

  • bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.cpp:

(WebCore::JSTestClassWithJSBuiltinConstructorConstructor::prototypeForStructure): Deleted.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r197637 r197642  
     12016-03-06  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        Enable DOM class create functions to take parameters in case of JSBuiltinConstructor
     4        https://bugs.webkit.org/show_bug.cgi?id=155022
     5
     6        Reviewed by Darin Adler.
     7
     8        Introducing JSDOMObjectInspector to check whether a given JS class is built-in (no DOM class).
     9        If that is not the case, the JS class wraps a DOM class.
     10        The inspector detects whether the DOM class create static method takes no parameter or some parameters.
     11        This is used in JSDOMConstructor.h to generate correctly the createJSObject functions needed by JSBuiltinConstructor.
     12
     13        Updated binding generator to not generate anymore createJSObject as it is handled directly in JSDOMConstructor.h.
     14
     15        Covered by existing tests.
     16
     17        * bindings/js/JSDOMConstructor.h:
     18        (WebCore::JSBuiltinConstructor<JSClass>::callConstructor):
     19        (WebCore::createJSObject):
     20        (WebCore::JSBuiltinConstructor<JSClass>::construct):
     21        * bindings/js/JSDOMWrapper.h:
     22        * bindings/js/JSKeyValueIterator.h: Taking benefit of JSClass::DOMWrapper type declaration.
     23        * bindings/js/JSReadableStreamPrivateConstructors.cpp:
     24        (WebCore::JSBuiltinReadableStreamReaderPrivateConstructor::initializeExecutable): Deleted.
     25        (WebCore::JSBuiltinReadableStreamControllerPrivateConstructor::initializeExecutable): Deleted.
     26        * bindings/scripts/CodeGeneratorJS.pm:
     27        (GenerateConstructorDefinition): Deleted.
     28        * bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.cpp:
     29        (WebCore::JSTestClassWithJSBuiltinConstructorConstructor::prototypeForStructure): Deleted.
     30
    1312016-03-06  Antti Koivisto  <antti@apple.com>
    232
  • trunk/Source/WebCore/bindings/js/JSDOMConstructor.h

    r197614 r197642  
    105105template<typename JSClass> class JSBuiltinConstructor : public DOMConstructorJSBuiltinObject {
    106106public:
    107     typedef DOMConstructorJSBuiltinObject Base;
     107    using Base = DOMConstructorJSBuiltinObject;
    108108
    109109    static JSBuiltinConstructor* create(JSC::VM&, JSC::Structure*, JSDOMGlobalObject&);
    … …  
    120120    static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&);
    121121    static JSC::EncodedJSValue JSC_HOST_CALL construct(JSC::ExecState*);
    122     JSC::JSObject* createJSObject();
     122
     123    JSC::EncodedJSValue callConstructor(JSC::ExecState&, JSC::JSObject&);
     124    JSC::EncodedJSValue callConstructor(JSC::ExecState&, JSC::JSObject*);
    123125
    124126    // Usually defined for each specialization class.
    … …  
    217219}
    218220
     221template<typename JSClass> inline JSC::EncodedJSValue JSBuiltinConstructor<JSClass>::callConstructor(JSC::ExecState& state, JSC::JSObject& object)
     222{
     223    callFunctionWithCurrentArguments(state, object, *initializeFunction());
     224    return JSC::JSValue::encode(&object);
     225}
     226
     227template<typename JSClass> inline JSC::EncodedJSValue JSBuiltinConstructor<JSClass>::callConstructor(JSC::ExecState& state, JSC::JSObject* object)
     228{
     229    if (!object)
     230        return throwConstructorDocumentUnavailableError(state, info()->className);
     231    return callConstructor(state, *object);
     232}
     233
     234template<typename JSClass> inline
     235typename std::enable_if<JSDOMObjectInspector<JSClass>::isSimpleWrapper, JSC::JSObject&>::type createJSObject(JSBuiltinConstructor<JSClass>& constructor)
     236{
     237    auto& globalObject = *constructor.globalObject();
     238    return *JSClass::create(getDOMStructure<JSClass>(globalObject.vm(), globalObject), &globalObject, JSClass::DOMWrapped::create());
     239}
     240
     241template<typename JSClass> inline
     242typename std::enable_if<JSDOMObjectInspector<JSClass>::isBuiltin, JSC::JSObject&>::type createJSObject(JSBuiltinConstructor<JSClass>& constructor)
     243{
     244    auto& globalObject = *constructor.globalObject();
     245    return *JSClass::create(getDOMStructure<JSClass>(globalObject.vm(), globalObject), &globalObject);
     246}
     247
     248template<typename JSClass> inline
     249typename std::enable_if<JSDOMObjectInspector<JSClass>::isComplexWrapper, JSC::JSObject*>::type createJSObject(JSBuiltinConstructor<JSClass>& constructor)
     250{
     251    ScriptExecutionContext* context = constructor.scriptExecutionContext();
     252    if (!context)
     253        return nullptr;
     254    auto& globalObject = *constructor.globalObject();
     255    return JSClass::create(getDOMStructure<JSClass>(globalObject.vm(), globalObject), &globalObject, JSClass::DOMWrapped::create(*context));
     256}
     257
    219258template<typename JSClass> inline JSC::EncodedJSValue JSC_HOST_CALL JSBuiltinConstructor<JSClass>::construct(JSC::ExecState* state)
    220259{
     260    ASSERT(state);
    221261    auto* castedThis = JSC::jsCast<JSBuiltinConstructor*>(state->callee());
    222     auto* object = castedThis->createJSObject();
    223     callFunctionWithCurrentArguments(*state, *object, *castedThis->initializeFunction());
    224     return JSC::JSValue::encode(object);
    225 }
    226 
    227 template<typename JSClass> inline JSC::JSObject* JSBuiltinConstructor<JSClass>::createJSObject()
    228 {
    229     return JSClass::create(getDOMStructure<JSClass>(globalObject()->vm(), *globalObject()), globalObject());
     262    return castedThis->callConstructor(*state, createJSObject(*castedThis));
    230263}
    231264
  • trunk/Source/WebCore/bindings/js/JSDOMWrapper.h

    r194496 r197642  
    3737public:
    3838    typedef JSC::JSDestructibleObject Base;
     39    static constexpr bool isDOMWrapper = false;
    3940
    4041    JSDOMGlobalObject* globalObject() const { return JSC::jsCast<JSDOMGlobalObject*>(JSC::JSNonFinalObject::globalObject()); }
    … …  
    5253public:
    5354    typedef JSDOMObject Base;
     55    typedef ImplementationClass DOMWrapped;
     56    static constexpr bool isDOMWrapper = true;
    5457
    5558    ImplementationClass& wrapped() const { return const_cast<ImplementationClass&>(m_wrapped.get()); }
    … …  
    6467};
    6568
     69template<typename JSClass, typename Enable = void>
     70struct JSDOMObjectInspector {
     71public:
     72    static constexpr bool isSimpleWrapper = false;
     73    static constexpr bool isComplexWrapper = false;
     74    static constexpr bool isBuiltin = true;
     75};
     76
     77template<typename JSClass>
     78struct JSDOMObjectInspector<JSClass, typename std::enable_if<JSClass::isDOMWrapper>::type> {
     79private:
     80    template<typename T> static constexpr auto test(int) -> decltype(T::create(), bool()) { return true; }
     81    template<typename T> static constexpr bool test(...) { return false; }
     82
     83public:
     84    static constexpr bool isSimpleWrapper = test<typename JSClass::DOMWrapped>(0);
     85    static constexpr bool isComplexWrapper = !isSimpleWrapper;
     86    static constexpr bool isBuiltin = false;
     87};
     88
    6689} // namespace WebCore
    6790
  • trunk/Source/WebCore/bindings/js/JSKeyValueIterator.h

    r197614 r197642  
    3636class JSKeyValueIteratorPrototype : public JSC::JSNonFinalObject {
    3737public:
    38     using DOMWrapped = typename std::remove_reference<decltype(std::declval<JSWrapper>().wrapped())>::type;
    3938    using Base = JSC::JSNonFinalObject;
     39    using DOMWrapped = typename JSWrapper::DOMWrapped;
    4040
    4141    static JSKeyValueIteratorPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
  • trunk/Source/WebCore/bindings/js/JSReadableStreamPrivateConstructors.cpp

    r194960 r197642  
    6464template<> const ClassInfo JSBuiltinReadableStreamControllerPrivateConstructor::s_info = { "ReadableStreamControllerPrivateConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSBuiltinReadableStreamControllerPrivateConstructor) };
    6565
    66 template<> JSObject* JSBuiltinReadableStreamReaderPrivateConstructor::createJSObject()
    67 {
    68     return JSReadableStreamReader::create(getDOMStructure<JSReadableStreamReader>(globalObject()->vm(), *globalObject()), globalObject());
    69 }
    70 
    71 template<> JSObject* JSBuiltinReadableStreamControllerPrivateConstructor::createJSObject()
    72 {
    73     return JSReadableStreamController::create(getDOMStructure<JSReadableStreamController>(globalObject()->vm(), *globalObject()), globalObject());
    74 }
    75 
    7666template<> FunctionExecutable* JSBuiltinReadableStreamReaderPrivateConstructor::initializeExecutable(JSC::VM& vm)
    7767{
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r197614 r197642  
    47894789    my $function = shift;
    47904790
    4791 
    47924791    if (IsJSBuiltinConstructor($interface)) {
    4793         if ($interface->extendedAttributes->{"JSBuiltinConstructor"}) {
    4794             # FIXME: Add support for ConstructorCallWith
    4795             push(@$outputArray, <<END);
    4796 template<> JSC::JSObject* ${className}Constructor::createJSObject()
    4797 {
    4798     return ${className}::create(getDOMStructure<${className}>(globalObject()->vm(), *globalObject()), globalObject(), ${interfaceName}::create());
    4799 }
    4800 
    4801 END
    4802         }
    48034792        return;
    48044793    }
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.cpp

    r196396 r197642  
    6363
    6464typedef JSBuiltinConstructor<JSTestClassWithJSBuiltinConstructor> JSTestClassWithJSBuiltinConstructorConstructor;
    65 
    66 template<> JSC::JSObject* JSTestClassWithJSBuiltinConstructorConstructor::createJSObject()
    67 {
    68     return JSTestClassWithJSBuiltinConstructor::create(getDOMStructure<JSTestClassWithJSBuiltinConstructor>(globalObject()->vm(), *globalObject()), globalObject(), TestClassWithJSBuiltinConstructor::create());
    69 }
    7065
    7166template<> JSValue JSTestClassWithJSBuiltinConstructorConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
Note: See TracChangeset for help on using the changeset viewer.