Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8GCController.cpp

Issue 1609343002: Move hasPendingActivity from ActiveDOMObject to ScriptWrappable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "bindings/core/v8/V8GCController.h" 31 #include "bindings/core/v8/V8GCController.h"
32 32
33 #include "bindings/core/v8/NPV8Object.h"
33 #include "bindings/core/v8/RetainedDOMInfo.h" 34 #include "bindings/core/v8/RetainedDOMInfo.h"
34 #include "bindings/core/v8/V8AbstractEventListener.h" 35 #include "bindings/core/v8/V8AbstractEventListener.h"
35 #include "bindings/core/v8/V8Binding.h" 36 #include "bindings/core/v8/V8Binding.h"
36 #include "bindings/core/v8/V8MutationObserver.h" 37 #include "bindings/core/v8/V8MutationObserver.h"
37 #include "bindings/core/v8/V8Node.h" 38 #include "bindings/core/v8/V8Node.h"
38 #include "bindings/core/v8/V8ScriptRunner.h" 39 #include "bindings/core/v8/V8ScriptRunner.h"
39 #include "bindings/core/v8/WrapperTypeInfo.h" 40 #include "bindings/core/v8/WrapperTypeInfo.h"
40 #include "core/dom/Attr.h" 41 #include "core/dom/Attr.h"
41 #include "core/dom/Document.h" 42 #include "core/dom/Document.h"
42 #include "core/dom/NodeTraversal.h" 43 #include "core/dom/NodeTraversal.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // MinorGC does not collect objects because it may be expensive to 115 // MinorGC does not collect objects because it may be expensive to
115 // update references during minorGC 116 // update references during minorGC
116 if (classId == WrapperTypeInfo::ObjectClassId) { 117 if (classId == WrapperTypeInfo::ObjectClassId) {
117 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); 118 v8::Persistent<v8::Object>::Cast(*value).MarkActive();
118 return; 119 return;
119 } 120 }
120 121
121 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); 122 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value));
122 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); 123 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper));
123 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); 124 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper);
124 ActiveDOMObject* activeDOMObject = type->toActiveDOMObject(wrapper); 125 if (type != npObjectTypeInfo() && toScriptWrappable(wrapper)->hasPending Activity())
125 if (activeDOMObject && activeDOMObject->hasPendingActivity()) {
126 v8::Persistent<v8::Object>::Cast(*value).MarkActive();
127 return; 126 return;
128 }
129 127
130 if (classId == WrapperTypeInfo::NodeClassId) { 128 if (classId == WrapperTypeInfo::NodeClassId) {
131 ASSERT(V8Node::hasInstance(wrapper, m_isolate)); 129 ASSERT(V8Node::hasInstance(wrapper, m_isolate));
132 Node* node = V8Node::toImpl(wrapper); 130 Node* node = V8Node::toImpl(wrapper);
133 if (node->hasEventListeners()) { 131 if (node->hasEventListeners()) {
134 v8::Persistent<v8::Object>::Cast(*value).MarkActive(); 132 v8::Persistent<v8::Object>::Cast(*value).MarkActive();
135 return; 133 return;
136 } 134 }
137 // FIXME: Remove the special handling for image elements. 135 // FIXME: Remove the special handling for image elements.
138 // The same special handling is in V8GCController::opaqueRootForGC() . 136 // The same special handling is in V8GCController::opaqueRootForGC() .
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return; 170 return;
173 171
174 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value)); 172 v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New(m_isolate, v8 ::Persistent<v8::Object>::Cast(*value));
175 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper)); 173 ASSERT(V8DOMWrapper::hasInternalFieldsSet(wrapper));
176 174
177 if (value->IsIndependent()) 175 if (value->IsIndependent())
178 return; 176 return;
179 177
180 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper); 178 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper);
181 179
182 ActiveDOMObject* activeDOMObject = type->toActiveDOMObject(wrapper); 180 if (type != npObjectTypeInfo() && toScriptWrappable(wrapper)->hasPending Activity()) {
183 if (activeDOMObject && activeDOMObject->hasPendingActivity()) {
184 m_isolate->SetObjectGroupId(*value, liveRootId()); 181 m_isolate->SetObjectGroupId(*value, liveRootId());
185 ++m_domObjectsWithPendingActivity; 182 ++m_domObjectsWithPendingActivity;
186 } 183 }
187 184
188 if (classId == WrapperTypeInfo::NodeClassId) { 185 if (classId == WrapperTypeInfo::NodeClassId) {
189 ASSERT(V8Node::hasInstance(wrapper, m_isolate)); 186 ASSERT(V8Node::hasInstance(wrapper, m_isolate));
190 Node* node = V8Node::toImpl(wrapper); 187 Node* node = V8Node::toImpl(wrapper);
191 if (node->hasEventListeners()) 188 if (node->hasEventListeners())
192 addReferencesForNodeWithEventListeners(m_isolate, node, v8::Pers istent<v8::Object>::Cast(*value)); 189 addReferencesForNodeWithEventListeners(m_isolate, node, v8::Pers istent<v8::Object>::Cast(*value));
193 Node* root = V8GCController::opaqueRootForGC(m_isolate, node); 190 Node* root = V8GCController::opaqueRootForGC(m_isolate, node);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 private: 449 private:
453 Visitor* m_visitor; 450 Visitor* m_visitor;
454 }; 451 };
455 452
456 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) 453 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor)
457 { 454 {
458 DOMWrapperTracer tracer(visitor); 455 DOMWrapperTracer tracer(visitor);
459 isolate->VisitHandlesWithClassIds(&tracer); 456 isolate->VisitHandlesWithClassIds(&tracer);
460 } 457 }
461 458
459 class PendingActivityVisitor : public v8::PersistentHandleVisitor {
460 public:
461 explicit PendingActivityVisitor(ExecutionContext* executionContext)
462 : m_executionContext(executionContext)
463 , m_pendingActivityFound(false)
464 {
465 }
466
467 void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uint16_t classI d) override
468 {
kinuko 2016/01/25 04:06:25 Could we count how many # of handles this class vi
haraken 2016/01/25 04:08:42 Sounds nice. Will do.
469 // If we have already found any wrapper that has a pending activity,
470 // we don't need to check other wrappers.
471 if (m_pendingActivityFound)
kinuko 2016/01/25 04:06:25 Would there be a way to exit the visitor loop once
haraken 2016/01/25 04:08:42 Yeah, in the current V8 API, we don't have a way t
472 return;
473
474 if (classId != WrapperTypeInfo::NodeClassId && classId != WrapperTypeInf o::ObjectClassId)
475 return;
476
477 const v8::Persistent<v8::Object>& wrapper = v8::Persistent<v8::Object>:: Cast(*value);
478 const WrapperTypeInfo* type = toWrapperTypeInfo(wrapper);
479 // The ExecutionContext check is heavy, so it should be done at the last .
480 if (type != npObjectTypeInfo()
481 && toScriptWrappable(wrapper)->hasPendingActivity()
482 /* && toExecutionContext(v8::Object::CreationContext(wrapper)) == m_ executionContext */
haraken 2016/01/22 17:15:44 To enable this condition, I need to implement the
483 )
484 m_pendingActivityFound = true;
485 }
486
487 bool pendingActivityFound() const { return m_pendingActivityFound; }
488
489 private:
490 RawPtrWillBePersistent<ExecutionContext> m_executionContext;
491 bool m_pendingActivityFound;
492 };
493
494 bool V8GCController::hasPendingActivity(ExecutionContext* executionContext)
495 {
496 // V8GCController::hasPendingActivity is used only when a worker checks if
497 // the worker contains any wrapper that has pending activities.
498 ASSERT(!isMainThread());
499 PendingActivityVisitor visitor(executionContext);
500 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor);
501 return visitor.pendingActivityFound();
502 }
503
462 } // namespace blink 504 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/V8GCController.h ('k') | third_party/WebKit/Source/core/dom/ActiveDOMObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698