Changeset 250843 in webkit
- Timestamp:
- Oct 8, 2019 11:39:04 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r250839 r250843 1 2019-10-08 Chris Dumez <cdumez@apple.com> 2 3 Make sure ActiveDOMObject properly deals with detached documents 4 https://bugs.webkit.org/show_bug.cgi?id=202596 5 6 Reviewed by Geoffrey Garen. 7 8 For detached document, the script execution context is their context document. 9 The ActiveDOMObject constructor taking a Document& would make sure to get the 10 document's contextDocument. However, if the ActiveDOMObject constructor taking 11 a ScriptExecutionContext* is called, it would assume this is the right script 12 execution context, which is unsafe. In this patch, all ActiveDOMObject 13 constructors now check for detached documents and make sure to use their 14 context document when necessary. 15 16 * dom/ActiveDOMObject.cpp: 17 (WebCore::suitableScriptExecutionContext): 18 (WebCore::ActiveDOMObject::ActiveDOMObject): 19 * dom/ActiveDOMObject.h: 20 * dom/Document.h: 21 1 22 2019-10-08 Ross Kirsling <ross.kirsling@sony.com> 2 23 -
trunk/Source/WebCore/dom/ActiveDOMObject.cpp
r241130 r250843 33 33 namespace WebCore { 34 34 35 ActiveDOMObject::ActiveDOMObject(ScriptExecutionContext* scriptExecutionContext) 36 : ContextDestructionObserver(scriptExecutionContext) 37 , m_pendingActivityCount(0) 38 #if !ASSERT_DISABLED 39 , m_suspendIfNeededWasCalled(false) 40 #endif 35 static inline ScriptExecutionContext* suitableScriptExecutionContext(ScriptExecutionContext* scriptExecutionContext) 41 36 { 42 ASSERT(!is<Document>(m_scriptExecutionContext) || &downcast<Document>(m_scriptExecutionContext)->contextDocument() == downcast<Document>(m_scriptExecutionContext)); 43 if (!m_scriptExecutionContext) 37 // For detached documents, make sure we observe their context document instead. 38 return is<Document>(scriptExecutionContext) ? &downcast<Document>(*scriptExecutionContext).contextDocument() : scriptExecutionContext; 39 } 40 41 inline ActiveDOMObject::ActiveDOMObject(ScriptExecutionContext* context, CheckedScriptExecutionContextType) 42 : ContextDestructionObserver(context) 43 { 44 ASSERT(!is<Document>(context) || &downcast<Document>(context)->contextDocument() == downcast<Document>(context)); 45 if (!context) 44 46 return; 45 47 46 ASSERT(m_scriptExecutionContext->isContextThread()); 47 m_scriptExecutionContext->didCreateActiveDOMObject(*this); 48 ASSERT(context->isContextThread()); 49 context->didCreateActiveDOMObject(*this); 50 } 51 52 ActiveDOMObject::ActiveDOMObject(ScriptExecutionContext* scriptExecutionContext) 53 : ActiveDOMObject(suitableScriptExecutionContext(scriptExecutionContext), CheckedScriptExecutionContext) 54 { 55 } 56 57 ActiveDOMObject::ActiveDOMObject(Document* document) 58 : ActiveDOMObject(document ? &document->contextDocument() : nullptr, CheckedScriptExecutionContext) 59 { 60 } 61 62 ActiveDOMObject::ActiveDOMObject(Document& document) 63 : ActiveDOMObject(&document.contextDocument(), CheckedScriptExecutionContext) 64 { 48 65 } 49 66 … … 92 109 } 93 110 94 bool ActiveDOMObject::canSuspendForDocumentSuspension() const95 {96 return false;97 }98 99 111 void ActiveDOMObject::suspend(ReasonForSuspension) 100 112 { -
trunk/Source/WebCore/dom/ActiveDOMObject.h
r250662 r250843 117 117 protected: 118 118 explicit ActiveDOMObject(ScriptExecutionContext*); 119 explicit ActiveDOMObject(Document*) = delete;120 explicit ActiveDOMObject(Document&); // Implemented in Document.h119 explicit ActiveDOMObject(Document*); 120 explicit ActiveDOMObject(Document&); 121 121 virtual ~ActiveDOMObject(); 122 122 123 123 private: 124 unsigned m_pendingActivityCount; 124 enum CheckedScriptExecutionContextType { CheckedScriptExecutionContext }; 125 ActiveDOMObject(ScriptExecutionContext*, CheckedScriptExecutionContextType); 126 127 unsigned m_pendingActivityCount { 0 }; 125 128 #if !ASSERT_DISABLED 126 bool m_suspendIfNeededWasCalled ;129 bool m_suspendIfNeededWasCalled { false }; 127 130 Ref<Thread> m_creationThread { Thread::current() }; 128 131 #endif -
trunk/Source/WebCore/dom/Document.h
r250816 r250843 2105 2105 } 2106 2106 2107 inline ActiveDOMObject::ActiveDOMObject(Document& document)2108 : ActiveDOMObject(static_cast<ScriptExecutionContext*>(&document.contextDocument()))2109 {2110 }2111 2112 2107 } // namespace WebCore 2113 2108
Note: See TracChangeset
for help on using the changeset viewer.