Changeset 148648 in webkit


Ignore:
Timestamp:
Apr 17, 2013 4:53:23 PM (11 years ago)
Author:
oliver@apple.com
Message:

Automate generation of toJS function for classes that need to report extra memory usage
https://bugs.webkit.org/show_bug.cgi?id=114768

Reviewed by Geoff Garen.

Only really used by AudioBuffer for now. The other classes that need it can be
trivially refactored at a later date.

  • Modules/webaudio/AudioBuffer.idl:
  • bindings/js/JSAudioBufferCustom.cpp:
  • bindings/js/JSDOMBinding.h:

(WebCore):
(HasMemoryCost):
(NoType):
(BaseMixin):

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateImplementation):

Location:
trunk/Source/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r148645 r148648  
     12013-04-17  Oliver Hunt  <oliver@apple.com>
     2
     3        Automate generation of toJS function for classes that need to report extra memory usage
     4        https://bugs.webkit.org/show_bug.cgi?id=114768
     5
     6        Reviewed by Geoff Garen.
     7
     8        Only really used by AudioBuffer for now.  The other classes that need it can be
     9        trivially refactored at a later date.
     10
     11        * Modules/webaudio/AudioBuffer.idl:
     12        * bindings/js/JSAudioBufferCustom.cpp:
     13        * bindings/js/JSDOMBinding.h:
     14        (WebCore):
     15        (HasMemoryCost):
     16        (NoType):
     17        (BaseMixin):
     18        * bindings/scripts/CodeGeneratorJS.pm:
     19        (GenerateImplementation):
     20
    1212013-04-17  Dirk Schulze  <krit@webkit.org>
    222
  • trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl

    r148566 r148648  
    2929[
    3030    Conditional=WEB_AUDIO,
    31     CustomToJSObject,
    3231    ImplementationLacksVTable
    3332] interface AudioBuffer {
  • trunk/Source/WebCore/bindings/js/JSAudioBufferCustom.cpp

    r148579 r148648  
    3535namespace WebCore {
    3636
    37 JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, AudioBuffer* audioBuffer)
    38 {
    39     if (!audioBuffer)
    40         return jsNull();
    41 
    42     JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), audioBuffer);
    43     if (wrapper)
    44         return wrapper;
    45 
    46     wrapper = CREATE_DOM_WRAPPER(exec, globalObject, AudioBuffer, audioBuffer);
    47 
    48     exec->heap()->reportExtraMemoryCost(audioBuffer->memoryCost());
    49 
    50     return wrapper;
    51 }
    52 
    5337}
    5438
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.h

    r148257 r148648  
    524524    }
    525525
     526    template<typename T>
     527    class HasMemoryCostMemberFunction {
     528        typedef char YesType;
     529        struct NoType {
     530            char padding[8];
     531        };
     532
     533        struct BaseMixin {
     534            size_t memoryCost();
     535        };
     536
     537        struct Base : public T, public BaseMixin { };
     538
     539        template<typename U, U> struct
     540        TypeChecker { };
     541
     542        template<typename U>
     543        static NoType dummy(U*, TypeChecker<size_t (BaseMixin::*)(), &U::memoryCost>* = 0);
     544        static YesType dummy(...);
     545
     546    public:
     547        static const bool value = sizeof(dummy(static_cast<Base*>(0))) == sizeof(YesType);
     548    };
     549
    526550} // namespace WebCore
    527551
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r148593 r148648  
    27152715#endif
    27162716END
     2717push(@implContent, <<END);
     2718template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     2719template <typename T> struct ReportMemoryCost<T, true> {
     2720    static void reportMemoryCost(ExecState* exec, T* impl)
     2721    {
     2722        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     2723    }
     2724};
     2725template <typename T> struct ReportMemoryCost<T, false> {
     2726    static void reportMemoryCost(ExecState*, T*)
     2727    {
     2728    }
     2729};
     2730END
     2731
    27172732        push(@implContent, "JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, $implType* impl)\n");
    27182733        push(@implContent, "{\n");
     
    27562771    COMPILE_ASSERT(!__is_polymorphic($implType), ${implType}_is_polymorphic_but_idl_claims_not_to_be);
    27572772#endif
     2773END
     2774        push(@implContent, <<END);
     2775    ReportMemoryCost<$implType>::reportMemoryCost(exec, impl);
    27582776END
    27592777
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.cpp

    r148301 r148648  
    244244#endif
    245245#endif
     246template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     247template <typename T> struct ReportMemoryCost<T, true> {
     248    static void reportMemoryCost(ExecState* exec, T* impl)
     249    {
     250        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     251    }
     252};
     253template <typename T> struct ReportMemoryCost<T, false> {
     254    static void reportMemoryCost(ExecState*, T*)
     255    {
     256    }
     257};
    246258JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestActiveDOMObject* impl)
    247259{
     
    268280    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    269281#endif
     282    ReportMemoryCost<TestActiveDOMObject>::reportMemoryCost(exec, impl);
    270283    return createNewWrapper<JSTestActiveDOMObject>(exec, globalObject, impl);
    271284}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp

    r148301 r148648  
    228228#endif
    229229#endif
     230template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     231template <typename T> struct ReportMemoryCost<T, true> {
     232    static void reportMemoryCost(ExecState* exec, T* impl)
     233    {
     234        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     235    }
     236};
     237template <typename T> struct ReportMemoryCost<T, false> {
     238    static void reportMemoryCost(ExecState*, T*)
     239    {
     240    }
     241};
    230242JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestCustomNamedGetter* impl)
    231243{
     
    252264    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    253265#endif
     266    ReportMemoryCost<TestCustomNamedGetter>::reportMemoryCost(exec, impl);
    254267    return createNewWrapper<JSTestCustomNamedGetter>(exec, globalObject, impl);
    255268}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.cpp

    r148301 r148648  
    243243#endif
    244244#endif
     245template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     246template <typename T> struct ReportMemoryCost<T, true> {
     247    static void reportMemoryCost(ExecState* exec, T* impl)
     248    {
     249        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     250    }
     251};
     252template <typename T> struct ReportMemoryCost<T, false> {
     253    static void reportMemoryCost(ExecState*, T*)
     254    {
     255    }
     256};
    245257JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestEventConstructor* impl)
    246258{
     
    267279    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    268280#endif
     281    ReportMemoryCost<TestEventConstructor>::reportMemoryCost(exec, impl);
    269282    return createNewWrapper<JSTestEventConstructor>(exec, globalObject, impl);
    270283}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.cpp

    r148301 r148648  
    349349#endif
    350350#endif
     351template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     352template <typename T> struct ReportMemoryCost<T, true> {
     353    static void reportMemoryCost(ExecState* exec, T* impl)
     354    {
     355        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     356    }
     357};
     358template <typename T> struct ReportMemoryCost<T, false> {
     359    static void reportMemoryCost(ExecState*, T*)
     360    {
     361    }
     362};
    351363JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestEventTarget* impl)
    352364{
     
    373385    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    374386#endif
     387    ReportMemoryCost<TestEventTarget>::reportMemoryCost(exec, impl);
    375388    return createNewWrapper<JSTestEventTarget>(exec, globalObject, impl);
    376389}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestException.cpp

    r148301 r148648  
    185185#endif
    186186#endif
     187template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     188template <typename T> struct ReportMemoryCost<T, true> {
     189    static void reportMemoryCost(ExecState* exec, T* impl)
     190    {
     191        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     192    }
     193};
     194template <typename T> struct ReportMemoryCost<T, false> {
     195    static void reportMemoryCost(ExecState*, T*)
     196    {
     197    }
     198};
    187199JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestException* impl)
    188200{
     
    209221    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    210222#endif
     223    ReportMemoryCost<TestException>::reportMemoryCost(exec, impl);
    211224    return createNewWrapper<JSTestException>(exec, globalObject, impl);
    212225}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp

    r148303 r148648  
    500500}
    501501
     502template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     503template <typename T> struct ReportMemoryCost<T, true> {
     504    static void reportMemoryCost(ExecState* exec, T* impl)
     505    {
     506        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     507    }
     508};
     509template <typename T> struct ReportMemoryCost<T, false> {
     510    static void reportMemoryCost(ExecState*, T*)
     511    {
     512    }
     513};
    502514JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestInterface* impl)
    503515{
     
    512524    COMPILE_ASSERT(!__is_polymorphic(TestInterface), TestInterface_is_polymorphic_but_idl_claims_not_to_be);
    513525#endif
     526    ReportMemoryCost<TestInterface>::reportMemoryCost(exec, impl);
    514527    return createNewWrapper<JSTestInterface>(exec, globalObject, impl);
    515528}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestMediaQueryListListener.cpp

    r148301 r148648  
    206206#endif
    207207#endif
     208template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     209template <typename T> struct ReportMemoryCost<T, true> {
     210    static void reportMemoryCost(ExecState* exec, T* impl)
     211    {
     212        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     213    }
     214};
     215template <typename T> struct ReportMemoryCost<T, false> {
     216    static void reportMemoryCost(ExecState*, T*)
     217    {
     218    }
     219};
    208220JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestMediaQueryListListener* impl)
    209221{
     
    230242    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    231243#endif
     244    ReportMemoryCost<TestMediaQueryListListener>::reportMemoryCost(exec, impl);
    232245    return createNewWrapper<JSTestMediaQueryListListener>(exec, globalObject, impl);
    233246}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.cpp

    r148301 r148648  
    220220#endif
    221221#endif
     222template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     223template <typename T> struct ReportMemoryCost<T, true> {
     224    static void reportMemoryCost(ExecState* exec, T* impl)
     225    {
     226        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     227    }
     228};
     229template <typename T> struct ReportMemoryCost<T, false> {
     230    static void reportMemoryCost(ExecState*, T*)
     231    {
     232    }
     233};
    222234JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestNamedConstructor* impl)
    223235{
     
    244256    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    245257#endif
     258    ReportMemoryCost<TestNamedConstructor>::reportMemoryCost(exec, impl);
    246259    return createNewWrapper<JSTestNamedConstructor>(exec, globalObject, impl);
    247260}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r148301 r148648  
    30903090#endif
    30913091#endif
     3092template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     3093template <typename T> struct ReportMemoryCost<T, true> {
     3094    static void reportMemoryCost(ExecState* exec, T* impl)
     3095    {
     3096        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     3097    }
     3098};
     3099template <typename T> struct ReportMemoryCost<T, false> {
     3100    static void reportMemoryCost(ExecState*, T*)
     3101    {
     3102    }
     3103};
    30923104JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestObj* impl)
    30933105{
     
    31143126    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    31153127#endif
     3128    ReportMemoryCost<TestObj>::reportMemoryCost(exec, impl);
    31163129    return createNewWrapper<JSTestObj>(exec, globalObject, impl);
    31173130}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp

    r148301 r148648  
    250250#endif
    251251#endif
     252template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     253template <typename T> struct ReportMemoryCost<T, true> {
     254    static void reportMemoryCost(ExecState* exec, T* impl)
     255    {
     256        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     257    }
     258};
     259template <typename T> struct ReportMemoryCost<T, false> {
     260    static void reportMemoryCost(ExecState*, T*)
     261    {
     262    }
     263};
    252264JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestOverloadedConstructors* impl)
    253265{
     
    274286    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    275287#endif
     288    ReportMemoryCost<TestOverloadedConstructors>::reportMemoryCost(exec, impl);
    276289    return createNewWrapper<JSTestOverloadedConstructors>(exec, globalObject, impl);
    277290}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp

    r148301 r148648  
    398398#endif
    399399#endif
     400template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     401template <typename T> struct ReportMemoryCost<T, true> {
     402    static void reportMemoryCost(ExecState* exec, T* impl)
     403    {
     404        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     405    }
     406};
     407template <typename T> struct ReportMemoryCost<T, false> {
     408    static void reportMemoryCost(ExecState*, T*)
     409    {
     410    }
     411};
    400412JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestSerializedScriptValueInterface* impl)
    401413{
     
    422434    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    423435#endif
     436    ReportMemoryCost<TestSerializedScriptValueInterface>::reportMemoryCost(exec, impl);
    424437    return createNewWrapper<JSTestSerializedScriptValueInterface>(exec, globalObject, impl);
    425438}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp

    r148301 r148648  
    636636#endif
    637637#endif
     638template <typename T, bool hasReportCostFunction = HasMemoryCostMemberFunction<T>::value > struct ReportMemoryCost;
     639template <typename T> struct ReportMemoryCost<T, true> {
     640    static void reportMemoryCost(ExecState* exec, T* impl)
     641    {
     642        exec->heap()->reportExtraMemoryCost(impl->memoryCost());
     643    }
     644};
     645template <typename T> struct ReportMemoryCost<T, false> {
     646    static void reportMemoryCost(ExecState*, T*)
     647    {
     648    }
     649};
    638650JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestTypedefs* impl)
    639651{
     
    660672    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
    661673#endif
     674    ReportMemoryCost<TestTypedefs>::reportMemoryCost(exec, impl);
    662675    return createNewWrapper<JSTestTypedefs>(exec, globalObject, impl);
    663676}
Note: See TracChangeset for help on using the changeset viewer.