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

Changeset 98784 in webkit


Ignore:
Timestamp:
Oct 28, 2011, 4:57:21 PM (15 years ago)
Author:
abarth@webkit.org
Message:

Factor ContextDestructionObserver out of ActiveDOMObject
https://bugs.webkit.org/show_bug.cgi?id=71153

Reviewed by Sam Weinig.

This patch paves the way to make more objects observe the destruction
of ScriptExecutioContext without needing to add ifdefs to
ScriptExecutionContext.h/cpp. (As an example, see DOMURL.)

  • dom/ActiveDOMObject.cpp:

(WebCore::ContextDestructionObserver::ContextDestructionObserver):
(WebCore::ContextDestructionObserver::~ContextDestructionObserver):
(WebCore::ContextDestructionObserver::contextDestroyed):
(WebCore::ActiveDOMObject::ActiveDOMObject):
(WebCore::ActiveDOMObject::~ActiveDOMObject):

  • dom/ActiveDOMObject.h:

(WebCore::ContextDestructionObserver::scriptExecutionContext):

  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::~ScriptExecutionContext):
(WebCore::ScriptExecutionContext::didCreateActiveDOMObject):
(WebCore::ScriptExecutionContext::willDestroyActiveDOMObject):
(WebCore::didCreateDestructionObserver):
(WebCore::willDestroyDestructionObserver):

  • dom/ScriptExecutionContext.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r98779 r98784  
     12011-10-28  Adam Barth  <abarth@webkit.org>
     2
     3        Factor ContextDestructionObserver out of ActiveDOMObject
     4        https://bugs.webkit.org/show_bug.cgi?id=71153
     5
     6        Reviewed by Sam Weinig.
     7
     8        This patch paves the way to make more objects observe the destruction
     9        of ScriptExecutioContext without needing to add ifdefs to
     10        ScriptExecutionContext.h/cpp.  (As an example, see DOMURL.)
     11
     12        * dom/ActiveDOMObject.cpp:
     13        (WebCore::ContextDestructionObserver::ContextDestructionObserver):
     14        (WebCore::ContextDestructionObserver::~ContextDestructionObserver):
     15        (WebCore::ContextDestructionObserver::contextDestroyed):
     16        (WebCore::ActiveDOMObject::ActiveDOMObject):
     17        (WebCore::ActiveDOMObject::~ActiveDOMObject):
     18        * dom/ActiveDOMObject.h:
     19        (WebCore::ContextDestructionObserver::scriptExecutionContext):
     20        * dom/ScriptExecutionContext.cpp:
     21        (WebCore::ScriptExecutionContext::~ScriptExecutionContext):
     22        (WebCore::ScriptExecutionContext::didCreateActiveDOMObject):
     23        (WebCore::ScriptExecutionContext::willDestroyActiveDOMObject):
     24        (WebCore::didCreateDestructionObserver):
     25        (WebCore::willDestroyDestructionObserver):
     26        * dom/ScriptExecutionContext.h:
     27
    1282011-10-28  Tim Horton  <timothy_horton@apple.com>
    229
  • trunk/Source/WebCore/dom/ActiveDOMObject.cpp

    r67432 r98784  
    3434namespace WebCore {
    3535
     36ContextDestructionObserver::ContextDestructionObserver(ScriptExecutionContext* scriptExecutionContext)
     37    : m_scriptExecutionContext(scriptExecutionContext)
     38{
     39    if (!m_scriptExecutionContext)
     40        return;
     41
     42    ASSERT(m_scriptExecutionContext->isContextThread());
     43    m_scriptExecutionContext->didCreateDestructionObserver(this);
     44}
     45
     46ContextDestructionObserver::~ContextDestructionObserver()
     47{
     48    if (!m_scriptExecutionContext)
     49        return;
     50
     51    ASSERT(m_scriptExecutionContext->isContextThread());
     52    m_scriptExecutionContext->willDestroyDestructionObserver(this);
     53}
     54
     55void ContextDestructionObserver::contextDestroyed()
     56{
     57    m_scriptExecutionContext = 0;
     58}
     59
    3660ActiveDOMObject::ActiveDOMObject(ScriptExecutionContext* scriptExecutionContext, void* upcastPointer)
    37     : m_scriptExecutionContext(scriptExecutionContext)
     61    : ContextDestructionObserver(scriptExecutionContext)
    3862    , m_pendingActivityCount(0)
    3963{
    40     if (m_scriptExecutionContext) {
    41         ASSERT(m_scriptExecutionContext->isContextThread());
    42         m_scriptExecutionContext->createdActiveDOMObject(this, upcastPointer);
    43     }
     64    if (!m_scriptExecutionContext)
     65        return;
     66
     67    ASSERT(m_scriptExecutionContext->isContextThread());
     68    m_scriptExecutionContext->didCreateActiveDOMObject(this, upcastPointer);
    4469}
    4570
    4671ActiveDOMObject::~ActiveDOMObject()
    4772{
    48     if (m_scriptExecutionContext) {
    49         ASSERT(m_scriptExecutionContext->isContextThread());
    50         m_scriptExecutionContext->destroyedActiveDOMObject(this);
    51     }
     73    if (!m_scriptExecutionContext)
     74        return;
     75
     76    ASSERT(m_scriptExecutionContext->isContextThread());
     77    m_scriptExecutionContext->willDestroyActiveDOMObject(this);
    5278}
    5379
     
    5581{
    5682    return m_pendingActivityCount;
    57 }
    58 
    59 void ActiveDOMObject::contextDestroyed()
    60 {
    61     m_scriptExecutionContext = 0;
    6283}
    6384
  • trunk/Source/WebCore/dom/ActiveDOMObject.h

    r67432 r98784  
    3434    class ScriptExecutionContext;
    3535
    36     class ActiveDOMObject {
     36    // FIXME: Move this class to it's own file.
     37    class ContextDestructionObserver {
     38    public:
     39        ContextDestructionObserver(ScriptExecutionContext*);
     40        virtual void contextDestroyed();
     41
     42        ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; }
     43
     44    protected:
     45        virtual ~ContextDestructionObserver();
     46
     47        ScriptExecutionContext* m_scriptExecutionContext;
     48    };
     49
     50    class ActiveDOMObject : public ContextDestructionObserver {
    3751    public:
    3852        ActiveDOMObject(ScriptExecutionContext*, void* upcastPointer);
    3953
    40         ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; }
    4154        virtual bool hasPendingActivity() const;
    42 
    43         virtual void contextDestroyed();
    4455
    4556        // canSuspend() is used by the caller if there is a choice between suspending and stopping.
     
    7788
    7889    private:
    79         ScriptExecutionContext* m_scriptExecutionContext;
    8090        unsigned m_pendingActivityCount;
    8191    };
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r98196 r98784  
    105105{
    106106    m_inDestructor = true;
    107     for (HashMap<ActiveDOMObject*, void*>::iterator iter = m_activeDOMObjects.begin(); iter != m_activeDOMObjects.end(); iter = m_activeDOMObjects.begin()) {
    108         ActiveDOMObject* object = iter->first;
    109         m_activeDOMObjects.remove(iter);
    110         ASSERT(object->scriptExecutionContext() == this);
    111         object->contextDestroyed();
     107
     108    for (HashSet<ContextDestructionObserver*>::iterator iter = m_destructionObservers.begin(); iter != m_destructionObservers.end(); iter = m_destructionObservers.begin()) {
     109        ContextDestructionObserver* observer = *iter;
     110        m_destructionObservers.remove(observer);
     111        ASSERT(observer->scriptExecutionContext() == this);
     112        observer->contextDestroyed();
    112113    }
    113114
     
    289290}
    290291
    291 void ScriptExecutionContext::createdActiveDOMObject(ActiveDOMObject* object, void* upcastPointer)
     292void ScriptExecutionContext::didCreateActiveDOMObject(ActiveDOMObject* object, void* upcastPointer)
    292293{
    293294    ASSERT(object);
     
    299300}
    300301
    301 void ScriptExecutionContext::destroyedActiveDOMObject(ActiveDOMObject* object)
     302void ScriptExecutionContext::willDestroyActiveDOMObject(ActiveDOMObject* object)
    302303{
    303304    ASSERT(object);
     
    305306        CRASH();
    306307    m_activeDOMObjects.remove(object);
     308}
     309
     310void ScriptExecutionContext::didCreateDestructionObserver(ContextDestructionObserver* observer)
     311{
     312    ASSERT(observer);
     313    ASSERT(!m_inDestructor);
     314    m_destructionObservers.add(observer);
     315}
     316
     317void ScriptExecutionContext::willDestroyDestructionObserver(ContextDestructionObserver* observer)
     318{
     319    ASSERT(observer);
     320    m_destructionObservers.remove(observer);
    307321}
    308322
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r98770 r98784  
    115115    virtual void stopActiveDOMObjects();
    116116
    117     void createdActiveDOMObject(ActiveDOMObject*, void* upcastPointer);
    118     void destroyedActiveDOMObject(ActiveDOMObject*);
     117    void didCreateActiveDOMObject(ActiveDOMObject*, void* upcastPointer);
     118    void willDestroyActiveDOMObject(ActiveDOMObject*);
     119
    119120    typedef const HashMap<ActiveDOMObject*, void*> ActiveDOMObjectsMap;
    120121    ActiveDOMObjectsMap& activeDOMObjects() const { return m_activeDOMObjects; }
     122
     123    void didCreateDestructionObserver(ContextDestructionObserver*);
     124    void willDestroyDestructionObserver(ContextDestructionObserver*);
    121125
    122126    virtual void suspendScriptedAnimationControllerCallbacks() { }
     
    200204
    201205    HashSet<MessagePort*> m_messagePorts;
    202 
     206    HashSet<ContextDestructionObserver*> m_destructionObservers;
    203207    HashMap<ActiveDOMObject*, void*> m_activeDOMObjects;
    204208    bool m_iteratingActiveDOMObjects;
Note: See TracChangeset for help on using the changeset viewer.