OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
4 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElem ent(), selectstart); | 79 DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElem ent(), selectstart); |
80 DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElem ent(), submit); | 80 DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElem ent(), submit); |
81 DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElem ent(), unload); | 81 DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElem ent(), unload); |
82 | 82 |
83 PassRefPtr<SVGElementInstance> SVGElementInstance::create(SVGUseElement* corresp ondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> origin alElement) | 83 PassRefPtr<SVGElementInstance> SVGElementInstance::create(SVGUseElement* corresp ondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> origin alElement) |
84 { | 84 { |
85 return adoptRef(new SVGElementInstance(correspondingUseElement, directUseEle ment, originalElement)); | 85 return adoptRef(new SVGElementInstance(correspondingUseElement, directUseEle ment, originalElement)); |
86 } | 86 } |
87 | 87 |
88 SVGElementInstance::SVGElementInstance(SVGUseElement* correspondingUseElement, S VGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement) | 88 SVGElementInstance::SVGElementInstance(SVGUseElement* correspondingUseElement, S VGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement) |
89 : m_parentInstance(0) | 89 : m_parentInstance(nullptr) |
90 , m_correspondingUseElement(correspondingUseElement) | 90 , m_correspondingUseElement(correspondingUseElement) |
91 , m_directUseElement(directUseElement) | 91 , m_directUseElement(directUseElement) |
92 , m_element(originalElement) | 92 , m_element(originalElement) |
93 , m_previousSibling(0) | 93 , m_previousSibling(nullptr) |
94 , m_nextSibling(0) | 94 , m_nextSibling(nullptr) |
95 , m_firstChild(0) | 95 , m_firstChild(nullptr) |
96 , m_lastChild(0) | 96 , m_lastChild(nullptr) |
97 { | 97 { |
98 ASSERT(m_correspondingUseElement); | 98 ASSERT(m_correspondingUseElement); |
99 ASSERT(m_element); | 99 ASSERT(m_element); |
100 ScriptWrappable::init(this); | 100 ScriptWrappable::init(this); |
101 | 101 |
102 #ifndef NDEBUG | 102 #ifndef NDEBUG |
103 instanceCounter.increment(); | 103 instanceCounter.increment(); |
104 #endif | 104 #endif |
105 } | 105 } |
106 | 106 |
107 SVGElementInstance::~SVGElementInstance() | 107 SVGElementInstance::~SVGElementInstance() |
108 { | 108 { |
109 // Call detach because we may be deleted directly if we are a child of a det ached instance. | |
110 detach(); | |
111 | |
112 #ifndef NDEBUG | 109 #ifndef NDEBUG |
113 instanceCounter.decrement(); | 110 instanceCounter.decrement(); |
114 #endif | 111 #endif |
115 | 112 |
113 #if !ENABLE(OILPAN) | |
114 // Call detach because we may be deleted directly if we are a child of a det ached instance. | |
115 detach(); | |
116 m_element = nullptr; | 116 m_element = nullptr; |
117 #endif | |
117 } | 118 } |
118 | 119 |
119 // It's important not to inline removedLastRef, because we don't want to inline the code to | 120 // It's important not to inline removedLastRef, because we don't want to inline the code to |
120 // delete an SVGElementInstance at each deref call site. | 121 // delete an SVGElementInstance at each deref call site. |
121 void SVGElementInstance::removedLastRef() | 122 void SVGElementInstance::removedLastRef() |
122 { | 123 { |
123 #if !ENABLE(OILPAN) | 124 #if !ENABLE(OILPAN) |
124 #if SECURITY_ASSERT_ENABLED | 125 #if SECURITY_ASSERT_ENABLED |
125 m_deletionHasBegun = true; | 126 m_deletionHasBegun = true; |
126 #endif | 127 #endif |
127 delete this; | 128 delete this; |
128 #endif | 129 #endif |
129 } | 130 } |
130 | 131 |
131 void SVGElementInstance::detach() | 132 void SVGElementInstance::detach() |
132 { | 133 { |
133 // Clear all pointers. When the node is detached from the shadow DOM it shou ld be removed but, | 134 // Clear all pointers. When the node is detached from the shadow DOM it shou ld be removed but, |
134 // due to ref counting, it may not be. So clear everything to avoid dangling pointers. | 135 // due to ref counting, it may not be. So clear everything to avoid dangling pointers. |
135 | 136 |
136 for (SVGElementInstance* node = firstChild(); node; node = node->nextSibling ()) | 137 for (SVGElementInstance* node = firstChild(); node; node = node->nextSibling ()) |
137 node->detach(); | 138 node->detach(); |
138 | 139 |
139 // Deregister as instance for passed element, if we haven't already. | 140 // Deregister as instance for passed element, if we haven't already. |
140 if (m_element->instancesForElement().contains(shadowTreeElement())) | 141 if (m_element->instancesForElement().contains(shadowTreeElement())) |
141 m_element->removeInstanceMapping(this); | 142 m_element->removeInstanceMapping(this); |
haraken
2014/05/06 15:59:42
In order to remove this, I think you need to:
- M
Mads Ager (chromium)
2014/05/07 12:13:16
I changed it to use weak processing. That will kee
| |
142 // DO NOT clear ref to m_element because JavaScriptCore uses it for garbage collection | 143 // DO NOT clear ref to m_element because JavaScriptCore uses it for garbage collection |
haraken
2014/05/06 15:59:42
This comment is obsolete :)
Mads Ager (chromium)
2014/05/07 12:13:16
Yes it is, let me remove it. :)
| |
143 | 144 |
144 m_shadowTreeElement = nullptr; | 145 m_shadowTreeElement = nullptr; |
145 | 146 |
146 m_directUseElement = 0; | 147 m_directUseElement = 0; |
147 m_correspondingUseElement = 0; | 148 m_correspondingUseElement = 0; |
148 | 149 |
150 #if !ENABLE(OILPAN) | |
haraken
2014/05/06 15:59:42
Can detach() be called in oilpan bulids? If no, yo
Mads Ager (chromium)
2014/05/07 12:13:16
Yes, it can be called via the SVGUseElement.
| |
149 removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(*t his); | 151 removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(*t his); |
152 #endif | |
150 } | 153 } |
151 | 154 |
152 void SVGElementInstance::setShadowTreeElement(SVGElement* element) | 155 void SVGElementInstance::setShadowTreeElement(SVGElement* element) |
153 { | 156 { |
154 ASSERT(element); | 157 ASSERT(element); |
155 m_shadowTreeElement = element; | 158 m_shadowTreeElement = element; |
156 // Register as instance for passed element. | 159 // Register as instance for passed element. |
157 m_element->mapInstanceToElement(this); | 160 m_element->mapInstanceToElement(this); |
158 | 161 |
159 } | 162 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 } | 217 } |
215 | 218 |
216 EventTargetData& SVGElementInstance::ensureEventTargetData() | 219 EventTargetData& SVGElementInstance::ensureEventTargetData() |
217 { | 220 { |
218 // EventTarget would use these methods if we were actually using its add/rem oveEventListener logic. | 221 // EventTarget would use these methods if we were actually using its add/rem oveEventListener logic. |
219 // As we're forwarding those calls to the correspondingElement(), no one sho uld ever call this function. | 222 // As we're forwarding those calls to the correspondingElement(), no one sho uld ever call this function. |
220 ASSERT_NOT_REACHED(); | 223 ASSERT_NOT_REACHED(); |
221 return *eventTargetData(); | 224 return *eventTargetData(); |
222 } | 225 } |
223 | 226 |
227 void SVGElementInstance::trace(Visitor* visitor) | |
228 { | |
229 visitor->trace(m_parentInstance); | |
230 visitor->trace(m_element); | |
231 visitor->trace(m_shadowTreeElement); | |
232 visitor->trace(m_previousSibling); | |
233 visitor->trace(m_nextSibling); | |
234 visitor->trace(m_firstChild); | |
235 visitor->trace(m_lastChild); | |
224 } | 236 } |
237 | |
238 } | |
OLD | NEW |