Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "core/dom/MutationObserverRegistration.h" | 33 #include "core/dom/MutationObserverRegistration.h" |
| 34 | 34 |
| 35 #include "core/dom/Node.h" | 35 #include "core/dom/Node.h" |
| 36 #include "core/dom/QualifiedName.h" | 36 #include "core/dom/QualifiedName.h" |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 PassOwnPtr<MutationObserverRegistration> MutationObserverRegistration::create(Mu tationObserver& observer, Node& registrationNode, MutationObserverOptions option s, const HashSet<AtomicString>& attributeFilter) | 40 PassOwnPtrWillBeRawPtr<MutationObserverRegistration> MutationObserverRegistratio n::create(MutationObserver& observer, Node& registrationNode, MutationObserverOp tions options, const HashSet<AtomicString>& attributeFilter) |
| 41 { | 41 { |
| 42 return adoptPtr(new MutationObserverRegistration(observer, registrationNode, options, attributeFilter)); | 42 return adoptPtrWillBeNoop(new MutationObserverRegistration(observer, registr ationNode, options, attributeFilter)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs erver, Node& registrationNode, MutationObserverOptions options, const HashSet<At omicString>& attributeFilter) | 45 MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs erver, Node& registrationNode, MutationObserverOptions options, const HashSet<At omicString>& attributeFilter) |
| 46 : m_observer(observer) | 46 : m_observer(observer) |
| 47 , m_registrationNode(registrationNode) | 47 , m_registrationNode(registrationNode) |
| 48 , m_options(options) | 48 , m_options(options) |
| 49 , m_attributeFilter(attributeFilter) | 49 , m_attributeFilter(attributeFilter) |
| 50 { | 50 { |
| 51 m_observer->observationStarted(this); | 51 m_observer->observationStarted(this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 MutationObserverRegistration::~MutationObserverRegistration() | 54 MutationObserverRegistration::~MutationObserverRegistration() |
| 55 { | 55 { |
| 56 #if ENABLE(OILPAN) | |
| 57 // The observer is heap allocated, and cannot be accessed. | |
| 58 // | |
| 59 // So should an observer still have this object in its | |
| 60 // list of registrations, and that observer lives beyond | |
| 61 // the current sweep, this dead registration object might | |
|
Erik Corry
2014/04/16 08:02:52
This doesn't make any sense to me. The pointer fr
| |
| 62 // be attempted accessed. Hence, insist that all | |
| 63 // MutationObserverRegistration objects are explicitly | |
| 64 // dispose()d before being let go of. | |
| 65 ASSERT(!m_observer); | |
| 66 #endif | |
| 67 dispose(); | |
|
haraken
2014/04/17 05:37:12
Can you restructure the code so that dispose() is
sof
2014/04/17 12:41:55
Certainly; have a look now.
| |
| 68 } | |
| 69 | |
| 70 void MutationObserverRegistration::dispose() | |
| 71 { | |
| 56 clearTransientRegistrations(); | 72 clearTransientRegistrations(); |
|
Erik Corry
2014/04/16 08:20:48
I think if the transientRegistrations were a weak
sof
2014/04/16 15:29:47
This seems very relevant to what I'm faced with (n
haraken
2014/04/17 05:37:12
Just help me understand: At the point where V8's G
sof
2014/04/17 12:41:55
Consider what happens when a Node is destructed an
haraken
2014/04/17 13:20:54
Hmm, I think you're talking about the following si
sof
2014/04/17 13:47:31
There's a level of indirection, the persistent is
haraken
2014/04/17 14:01:37
Hmm, this is a hard problem.
It seems that the re
sof
2014/04/17 15:54:37
Yes, it just so happens that the MutationObserver
Erik Corry
2014/04/22 12:46:54
Sorry, when I wrote transientRegistrations I reall
| |
| 57 m_observer->observationEnded(this); | 73 if (m_observer) { |
| 74 m_observer->observationEnded(this); | |
| 75 m_observer.clear(); | |
| 76 } | |
| 58 } | 77 } |
| 59 | 78 |
| 60 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter) | 79 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter) |
| 61 { | 80 { |
| 62 clearTransientRegistrations(); | 81 clearTransientRegistrations(); |
| 63 m_options = options; | 82 m_options = options; |
| 64 m_attributeFilter = attributeFilter; | 83 m_attributeFilter = attributeFilter; |
| 65 } | 84 } |
| 66 | 85 |
| 67 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node) | 86 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 82 } | 101 } |
| 83 | 102 |
| 84 void MutationObserverRegistration::clearTransientRegistrations() | 103 void MutationObserverRegistration::clearTransientRegistrations() |
| 85 { | 104 { |
| 86 if (!m_transientRegistrationNodes) { | 105 if (!m_transientRegistrationNodes) { |
| 87 ASSERT(!m_registrationNodeKeepAlive); | 106 ASSERT(!m_registrationNodeKeepAlive); |
| 88 return; | 107 return; |
| 89 } | 108 } |
| 90 | 109 |
| 91 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) | 110 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) |
| 92 (*iter)->unregisterTransientMutationObserver(this); | 111 (*iter)->unregisterTransientMutationObserver(this); |
|
Erik Corry
2014/04/16 08:20:48
If I understand this right, this MutationObserverR
sof
2014/04/16 15:29:47
I think that's correct and is safe.
However, the
haraken
2014/04/17 05:37:12
Agreed with sof@. It's nicer if we could move more
| |
| 93 | 112 |
| 94 m_transientRegistrationNodes.clear(); | 113 m_transientRegistrationNodes.clear(); |
| 95 | 114 |
| 96 ASSERT(m_registrationNodeKeepAlive); | 115 ASSERT(m_registrationNodeKeepAlive); |
| 97 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. | 116 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. |
| 98 } | 117 } |
| 99 | 118 |
| 100 void MutationObserverRegistration::unregister() | 119 void MutationObserverRegistration::unregister() |
| 101 { | 120 { |
| 102 m_registrationNode.unregisterMutationObserver(this); | 121 m_registrationNode.unregisterMutationObserver(this); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 123 | 142 |
| 124 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const | 143 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const |
| 125 { | 144 { |
| 126 nodes.add(&m_registrationNode); | 145 nodes.add(&m_registrationNode); |
| 127 if (!m_transientRegistrationNodes) | 146 if (!m_transientRegistrationNodes) |
| 128 return; | 147 return; |
| 129 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) | 148 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) |
| 130 nodes.add(iter->get()); | 149 nodes.add(iter->get()); |
| 131 } | 150 } |
| 132 | 151 |
| 152 void MutationObserverRegistration::trace(Visitor* visitor) | |
| 153 { | |
| 154 visitor->trace(m_observer); | |
| 155 } | |
| 156 | |
| 133 } // namespace WebCore | 157 } // namespace WebCore |
| OLD | NEW |