haikuwebkit/Source/WTF/wtf/WeakPtr.h

329 lines
11 KiB
C
Raw Permalink Normal View History

Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
/*
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
* Copyright (C) 2013 Google, Inc. All rights reserved.
* Copyright (C) 2015-2020 Apple Inc. All rights reserved.
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
Use pragma once in WTF https://bugs.webkit.org/show_bug.cgi?id=190527 Reviewed by Chris Dumez. Source/WTF: We also need to consistently include wtf headers from within wtf so we can build wtf without symbol redefinition errors from including the copy in Source and the copy in the build directory. * wtf/ASCIICType.h: * wtf/Assertions.cpp: * wtf/Assertions.h: * wtf/Atomics.h: * wtf/AutomaticThread.cpp: * wtf/AutomaticThread.h: * wtf/BackwardsGraph.h: * wtf/Bag.h: * wtf/BagToHashMap.h: * wtf/BitVector.cpp: * wtf/BitVector.h: * wtf/Bitmap.h: * wtf/BloomFilter.h: * wtf/Box.h: * wtf/BubbleSort.h: * wtf/BumpPointerAllocator.h: * wtf/ByteOrder.h: * wtf/CPUTime.cpp: * wtf/CallbackAggregator.h: * wtf/CheckedArithmetic.h: * wtf/CheckedBoolean.h: * wtf/ClockType.cpp: * wtf/ClockType.h: * wtf/CommaPrinter.h: * wtf/CompilationThread.cpp: * wtf/CompilationThread.h: * wtf/Compiler.h: * wtf/ConcurrentPtrHashSet.cpp: * wtf/ConcurrentVector.h: * wtf/Condition.h: * wtf/CountingLock.cpp: * wtf/CrossThreadTaskHandler.cpp: * wtf/CryptographicUtilities.cpp: * wtf/CryptographicUtilities.h: * wtf/CryptographicallyRandomNumber.cpp: * wtf/CryptographicallyRandomNumber.h: * wtf/CurrentTime.cpp: * wtf/DataLog.cpp: * wtf/DataLog.h: * wtf/DateMath.cpp: * wtf/DateMath.h: * wtf/DecimalNumber.cpp: * wtf/DecimalNumber.h: * wtf/Deque.h: * wtf/DisallowCType.h: * wtf/Dominators.h: * wtf/DoublyLinkedList.h: * wtf/FastBitVector.cpp: * wtf/FastMalloc.cpp: * wtf/FastMalloc.h: * wtf/FeatureDefines.h: * wtf/FilePrintStream.cpp: * wtf/FilePrintStream.h: * wtf/FlipBytes.h: * wtf/FunctionDispatcher.cpp: * wtf/FunctionDispatcher.h: * wtf/GetPtr.h: * wtf/Gigacage.cpp: * wtf/GlobalVersion.cpp: * wtf/GraphNodeWorklist.h: * wtf/GregorianDateTime.cpp: * wtf/GregorianDateTime.h: * wtf/HashFunctions.h: * wtf/HashMap.h: * wtf/HashMethod.h: * wtf/HashSet.h: * wtf/HashTable.cpp: * wtf/HashTraits.h: * wtf/Indenter.h: * wtf/IndexSparseSet.h: * wtf/InlineASM.h: * wtf/Insertion.h: * wtf/IteratorAdaptors.h: * wtf/IteratorRange.h: * wtf/JSONValues.cpp: * wtf/JSValueMalloc.cpp: * wtf/LEBDecoder.h: * wtf/Language.cpp: * wtf/ListDump.h: * wtf/Lock.cpp: * wtf/Lock.h: * wtf/LockAlgorithm.h: * wtf/LockedPrintStream.cpp: * wtf/Locker.h: * wtf/MD5.cpp: * wtf/MD5.h: * wtf/MainThread.cpp: * wtf/MainThread.h: * wtf/MallocPtr.h: * wtf/MathExtras.h: * wtf/MediaTime.cpp: * wtf/MediaTime.h: * wtf/MemoryPressureHandler.cpp: * wtf/MessageQueue.h: * wtf/MetaAllocator.cpp: * wtf/MetaAllocator.h: * wtf/MetaAllocatorHandle.h: * wtf/MonotonicTime.cpp: * wtf/MonotonicTime.h: * wtf/NakedPtr.h: * wtf/NoLock.h: * wtf/NoTailCalls.h: * wtf/Noncopyable.h: * wtf/NumberOfCores.cpp: * wtf/NumberOfCores.h: * wtf/OSAllocator.h: * wtf/OSAllocatorPosix.cpp: * wtf/OSRandomSource.cpp: * wtf/OSRandomSource.h: * wtf/ObjcRuntimeExtras.h: * wtf/OrderMaker.h: * wtf/PackedIntVector.h: * wtf/PageAllocation.h: * wtf/PageBlock.cpp: * wtf/PageBlock.h: * wtf/PageReservation.h: * wtf/ParallelHelperPool.cpp: * wtf/ParallelHelperPool.h: * wtf/ParallelJobs.h: * wtf/ParallelJobsLibdispatch.h: * wtf/ParallelVectorIterator.h: * wtf/ParkingLot.cpp: * wtf/ParkingLot.h: * wtf/Platform.h: * wtf/PointerComparison.h: * wtf/Poisoned.cpp: * wtf/PrintStream.cpp: * wtf/PrintStream.h: * wtf/ProcessID.h: * wtf/ProcessPrivilege.cpp: * wtf/RAMSize.cpp: * wtf/RAMSize.h: * wtf/RandomDevice.cpp: * wtf/RandomNumber.cpp: * wtf/RandomNumber.h: * wtf/RandomNumberSeed.h: * wtf/RangeSet.h: * wtf/RawPointer.h: * wtf/ReadWriteLock.cpp: * wtf/RedBlackTree.h: * wtf/Ref.h: * wtf/RefCountedArray.h: * wtf/RefCountedLeakCounter.cpp: * wtf/RefCountedLeakCounter.h: * wtf/RefCounter.h: * wtf/RefPtr.h: * wtf/RetainPtr.h: * wtf/RunLoop.cpp: * wtf/RunLoop.h: * wtf/RunLoopTimer.h: * wtf/RunLoopTimerCF.cpp: * wtf/SHA1.cpp: * wtf/SHA1.h: * wtf/SaturatedArithmetic.h: (saturatedSubtraction): * wtf/SchedulePair.h: * wtf/SchedulePairCF.cpp: * wtf/SchedulePairMac.mm: * wtf/ScopedLambda.h: * wtf/Seconds.cpp: * wtf/Seconds.h: * wtf/SegmentedVector.h: * wtf/SentinelLinkedList.h: * wtf/SharedTask.h: * wtf/SimpleStats.h: * wtf/SingleRootGraph.h: * wtf/SinglyLinkedList.h: * wtf/SixCharacterHash.cpp: * wtf/SixCharacterHash.h: * wtf/SmallPtrSet.h: * wtf/Spectrum.h: * wtf/StackBounds.cpp: * wtf/StackBounds.h: * wtf/StackStats.cpp: * wtf/StackStats.h: * wtf/StackTrace.cpp: * wtf/StdLibExtras.h: * wtf/StreamBuffer.h: * wtf/StringHashDumpContext.h: * wtf/StringPrintStream.cpp: * wtf/StringPrintStream.h: * wtf/ThreadGroup.cpp: * wtf/ThreadMessage.cpp: * wtf/ThreadSpecific.h: * wtf/Threading.cpp: * wtf/Threading.h: * wtf/ThreadingPrimitives.h: * wtf/ThreadingPthreads.cpp: * wtf/TimeWithDynamicClockType.cpp: * wtf/TimeWithDynamicClockType.h: * wtf/TimingScope.cpp: * wtf/TinyLRUCache.h: * wtf/TinyPtrSet.h: * wtf/TriState.h: * wtf/TypeCasts.h: * wtf/UUID.cpp: * wtf/UnionFind.h: * wtf/VMTags.h: * wtf/ValueCheck.h: * wtf/Vector.h: * wtf/VectorTraits.h: * wtf/WallTime.cpp: * wtf/WallTime.h: * wtf/WeakPtr.h: * wtf/WeakRandom.h: * wtf/WordLock.cpp: * wtf/WordLock.h: * wtf/WorkQueue.cpp: * wtf/WorkQueue.h: * wtf/WorkerPool.cpp: * wtf/cf/LanguageCF.cpp: * wtf/cf/RunLoopCF.cpp: * wtf/cocoa/Entitlements.mm: * wtf/cocoa/MachSendRight.cpp: * wtf/cocoa/MainThreadCocoa.mm: * wtf/cocoa/MemoryFootprintCocoa.cpp: * wtf/cocoa/WorkQueueCocoa.cpp: * wtf/dtoa.cpp: * wtf/dtoa.h: * wtf/ios/WebCoreThread.cpp: * wtf/ios/WebCoreThread.h: * wtf/mac/AppKitCompatibilityDeclarations.h: * wtf/mac/DeprecatedSymbolsUsedBySafari.mm: * wtf/mbmalloc.cpp: * wtf/persistence/PersistentCoders.cpp: * wtf/persistence/PersistentDecoder.cpp: * wtf/persistence/PersistentEncoder.cpp: * wtf/spi/cf/CFBundleSPI.h: * wtf/spi/darwin/CommonCryptoSPI.h: * wtf/text/ASCIIFastPath.h: * wtf/text/ASCIILiteral.cpp: * wtf/text/AtomicString.cpp: * wtf/text/AtomicString.h: * wtf/text/AtomicStringHash.h: * wtf/text/AtomicStringImpl.cpp: * wtf/text/AtomicStringImpl.h: * wtf/text/AtomicStringTable.cpp: * wtf/text/AtomicStringTable.h: * wtf/text/Base64.cpp: * wtf/text/CString.cpp: * wtf/text/CString.h: * wtf/text/ConversionMode.h: * wtf/text/ExternalStringImpl.cpp: * wtf/text/IntegerToStringConversion.h: * wtf/text/LChar.h: * wtf/text/LineEnding.cpp: * wtf/text/StringBuffer.h: * wtf/text/StringBuilder.cpp: * wtf/text/StringBuilder.h: * wtf/text/StringBuilderJSON.cpp: * wtf/text/StringCommon.h: * wtf/text/StringConcatenate.h: * wtf/text/StringHash.h: * wtf/text/StringImpl.cpp: * wtf/text/StringImpl.h: * wtf/text/StringOperators.h: * wtf/text/StringView.cpp: * wtf/text/StringView.h: * wtf/text/SymbolImpl.cpp: * wtf/text/SymbolRegistry.cpp: * wtf/text/SymbolRegistry.h: * wtf/text/TextBreakIterator.cpp: * wtf/text/TextBreakIterator.h: * wtf/text/TextBreakIteratorInternalICU.h: * wtf/text/TextPosition.h: * wtf/text/TextStream.cpp: * wtf/text/UniquedStringImpl.h: * wtf/text/WTFString.cpp: * wtf/text/WTFString.h: * wtf/text/cocoa/StringCocoa.mm: * wtf/text/cocoa/StringViewCocoa.mm: * wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp: * wtf/text/icu/UTextProvider.cpp: * wtf/text/icu/UTextProvider.h: * wtf/text/icu/UTextProviderLatin1.cpp: * wtf/text/icu/UTextProviderLatin1.h: * wtf/text/icu/UTextProviderUTF16.cpp: * wtf/text/icu/UTextProviderUTF16.h: * wtf/threads/BinarySemaphore.cpp: * wtf/threads/BinarySemaphore.h: * wtf/threads/Signals.cpp: * wtf/unicode/CharacterNames.h: * wtf/unicode/Collator.h: * wtf/unicode/CollatorDefault.cpp: * wtf/unicode/UTF8.cpp: * wtf/unicode/UTF8.h: Tools: Put WorkQueue in namespace DRT so it does not conflict with WTF::WorkQueue. * DumpRenderTree/TestRunner.cpp: (TestRunner::queueLoadHTMLString): (TestRunner::queueLoadAlternateHTMLString): (TestRunner::queueBackNavigation): (TestRunner::queueForwardNavigation): (TestRunner::queueLoadingScript): (TestRunner::queueNonLoadingScript): (TestRunner::queueReload): * DumpRenderTree/WorkQueue.cpp: (WorkQueue::singleton): Deleted. (WorkQueue::WorkQueue): Deleted. (WorkQueue::queue): Deleted. (WorkQueue::dequeue): Deleted. (WorkQueue::count): Deleted. (WorkQueue::clear): Deleted. (WorkQueue::processWork): Deleted. * DumpRenderTree/WorkQueue.h: (WorkQueue::setFrozen): Deleted. * DumpRenderTree/WorkQueueItem.h: * DumpRenderTree/mac/DumpRenderTree.mm: (runTest): * DumpRenderTree/mac/FrameLoadDelegate.mm: (-[FrameLoadDelegate processWork:]): (-[FrameLoadDelegate webView:locationChangeDone:forDataSource:]): * DumpRenderTree/mac/TestRunnerMac.mm: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): * DumpRenderTree/win/DumpRenderTree.cpp: (runTest): * DumpRenderTree/win/FrameLoadDelegate.cpp: (FrameLoadDelegate::processWork): (FrameLoadDelegate::locationChangeDone): * DumpRenderTree/win/TestRunnerWin.cpp: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): Canonical link: https://commits.webkit.org/205473@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-10-15 14:24:49 +00:00
#pragma once
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
Use WeakHashMap and WeakPtr with Node in more places https://bugs.webkit.org/show_bug.cgi?id=227192 <rdar://problem/79828322> Reviewed by Geoffrey Garen. Source/WebCore: Deploy WeakHashMap and WeakPtr with Node/Element in more places. * dom/Document.cpp: (WebCore::Document::elementForAccessKey): (WebCore::Document::buildAccessKeyCache): (WebCore::Document::registerForVisibilityStateChangedCallbacks): (WebCore::Document::unregisterForVisibilityStateChangedCallbacks): (WebCore::Document::visibilityStateChanged): * dom/Document.h: * dom/VisibilityChangeClient.h: * html/FormController.cpp: (WebCore::FormKeyGenerator::formKey): (WebCore::FormKeyGenerator::willDeleteForm): * html/HTMLAnchorElement.cpp: (WebCore::rootEditableElementMap): (WebCore::HTMLAnchorElement::rootEditableElementForSelectionOnMouseDown const): (WebCore::HTMLAnchorElement::clearRootEditableElementForSelectionOnMouseDown): (WebCore::HTMLAnchorElement::setRootEditableElementForSelectionOnMouseDown): * inspector/agents/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::bind): (WebCore::InspectorDOMAgent::unbind): (WebCore::InspectorDOMAgent::nodeForId): (WebCore::InspectorDOMAgent::pushNodePathToFrontend): (WebCore::InspectorDOMAgent::boundNodeId): (WebCore::InspectorDOMAgent::willDestroyDOMNode): (WebCore::InspectorDOMAgent::mediaMetricsTimerFired): * inspector/agents/InspectorDOMAgent.h: * inspector/agents/InspectorLayerTreeAgent.cpp: (WebCore::InspectorLayerTreeAgent::bindPseudoElement): (WebCore::InspectorLayerTreeAgent::unbindPseudoElement): * inspector/agents/InspectorLayerTreeAgent.h: * style/StyleSharingResolver.h: Source/WTF: * wtf/WeakHashMap.h: (WTF::WeakHashMap::WeakHashMapIteratorBase::makePeek): Fixed type mismatch errors. (WTF::WeakHashMap::ensure): Made this function return AddResult like HashMap::ensure. (WTF::WeakHashMap::take): Added. (WTF::WeakHashMap::removeIf): Fixed the bug that the callback was called with the iterator of m_impl and not WeakHashMapIterator. * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl<Counter>>>::isReleasedWeakValue): Moved to WeakPtr.h * wtf/WeakPtr.h: (WTF::HashTraits<Ref<WeakPtrImpl<Counter>>>::isReleasedWeakValue): Moved from WeakHashSet.h Canonical link: https://commits.webkit.org/239295@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279439 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-30 22:51:21 +00:00
#include <wtf/HashTraits.h>
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
#include <wtf/Threading.h>
namespace WTF {
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename, typename> class WeakHashSet;
template<typename, typename> class WeakPtrFactory;
WeakPtr breaks vtables when upcasting to base classes https://bugs.webkit.org/show_bug.cgi?id=188799 Reviewed by Youenn Fablet. Source/WebCore: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): * Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs. Removed redundant WeakPtrFactory. * css/CSSFontFace.cpp: (WebCore::CSSFontFace::existingWrapper): * css/CSSFontFace.h: Moved functions out of line to avoid #include explosion for .get(). * dom/ContainerNode.h: * dom/Document.h: * dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all subclasses except for DocumentFragment were already so, and we have code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::fullscreenRenderer const): * dom/FullscreenManager.h: (WebCore::FullscreenManager::fullscreenRenderer const): Deleted. * html/FormAssociatedElement.cpp: (WebCore::FormAssociatedElement::form const): * html/FormAssociatedElement.h: (WebCore::FormAssociatedElement::form const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * html/HTMLMediaElement.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): Removed redundant .get(). * page/DOMWindowProperty.cpp: (WebCore::DOMWindowProperty::window const): * page/DOMWindowProperty.h: (WebCore::DOMWindowProperty::window const): Deleted. * page/FrameViewLayoutContext.cpp: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): * page/FrameViewLayoutContext.h: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted. * page/UndoItem.cpp: (WebCore::UndoItem::undoManager const): * page/UndoItem.h: (WebCore::UndoItem::undoManager const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/ScrollView.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * platform/Widget.cpp: (WebCore::Widget::parent const): * platform/Widget.h: (WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/encryptedmedia/CDMInstanceSession.h: Made CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: CanMakeWeakPtr is inherited now. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted. (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted. * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::CMTimebaseEffectiveRateChangedCallback): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): (WebCore::SourceBufferPrivateAVFObjC::setCDMSession): (WebCore::SourceBufferPrivateAVFObjC::flushVideo): (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): (WebCore::SourceBufferPrivateAVFObjC::setVideoLayer): (WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage. * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::multiColumnFlowSlowCase const): * rendering/RenderBlockFlow.h: (WebCore::RenderBlockFlow::multiColumnFlow const): * rendering/RenderMultiColumnFlow.cpp: (WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const): * rendering/RenderMultiColumnFlow.h: * rendering/RenderTable.cpp: (WebCore::RenderTable::header const): (WebCore::RenderTable::footer const): (WebCore::RenderTable::firstBody const): (WebCore::RenderTable::topSection const): * rendering/RenderTable.h: (WebCore::RenderTable::header const): Deleted. (WebCore::RenderTable::footer const): Deleted. (WebCore::RenderTable::firstBody const): Deleted. (WebCore::RenderTable::topSection const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WebKit: * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::networkSession): * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::suspendedPage const): * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * UIProcess/Authentication/cocoa/SecKeyProxyStore.h: (WebKit::SecKeyProxyStore::get const): (WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted CanMakeWeakPtr. * UIProcess/WebAuthentication/AuthenticatorManager.h: * UIProcess/WebProcessProxy.cpp: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. (WebKit::WebProcessProxy::processPool const): * UIProcess/WebProcessProxy.h: (WebKit::WebProcessProxy::processPool const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WTF: This patch switches from reinterpret_cast to static_cast when loading from WeakReference storage. We know which type to cast *to* because it's specified by the type of the calling WeakPtr. We know which type to cast *from* because it's specified by a typedef in CanMakeWeakPtr. (Our convention is that we store a pointer to the class that derives from CanMakeWeakPtr. We cast from that pointer to derived pointers when we get(). This means that #include of the derived type header is now required in order to get() the pointer.) * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition is now eagerly required because WeakReference is not a template anymore. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computesEmpty const): (WTF::WeakHashSet::hasNullReferences const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted. Updated for new WeakReference get() API. * wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template specialization because WeakReference is not a class template anymore. (Or maybe we could have kept it working with a dummy template argument? Felt weird, so I switched.) (WTF::WeakReference::create): (WTF::WeakReference::~WeakReference): (WTF::WeakReference::get const): (WTF::WeakReference::operator bool const): (WTF::WeakReference::WeakReference): WeakReference is just a void* now. It's the caller's responsibility, when creating and getting, to use a consistent storage type. We ensure a canonical storage type using a typedef inside CanMakeWeakPtr. (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get const): (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): Adopted new WeakReference API. (WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast. (WTF::weak_reference_cast): This isn't required for correctness, but it's nice to show a complier error at WeakPtr construction sites when you know that the types won't work. Otherwise, you get compiler errors at dereference sites, which are slightly more mysterious ways of saying that you constructed your WeakPtr incorrectly. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::weak_reference_upcast): Deleted. (WTF::weak_reference_downcast): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead of template specialization for observing weak references. (TestWebKitAPI::Int::Int): (TestWebKitAPI::Int::operator int const): (TestWebKitAPI::Int::operator== const): Use a class for integer tests because WeakPtr doesn't naturally support pointing to non-class objects now. (TestWebKitAPI::Base::foo): (TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable deduction of the weak pointer type. (TestWebKitAPI::TEST): Updated to use Int. (TestWebKitAPI::Base::weakPtrFactory const): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted. Canonical link: https://commits.webkit.org/212376@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-29 21:15:54 +00:00
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
struct EmptyCounter {
static void increment() { }
static void decrement() { }
};
WeakPtr functions crash when created with default constructor https://bugs.webkit.org/show_bug.cgi?id=140479 Reviewed by Andreas Kling. Source/WTF: This patch rearranges how WeakPtr works, and has the following ideas behind it: 1. WeakPtr should use Ref internally. This solves the crash by always having a valid WeakReference. 2. Clients should not be able to construct WeakReferences directly. Instead, only WeakPtrFactory (and WeakPtr's default constructor) should be able to construct them. They are considered an implementation detail of WeakPtr. 3. Except for the default constructor, clients should not be able to construct WeakPtrs directly. Instead, the WeakPtrFactory must construct them. This guarantees that the WeakPtrs all reference the same WeakReference. 4. Clients can construct a WeakPtr using its default constructor, and then use the assignment operator to make it non-null. (Or they could use WeakPtrFactory to make it non-null at creation-time.) 5. No one was using WeakReference::bindTo(), and it doesn't seem useful, so I removed it. Tests: WTF_WeakPtr API tests * wtf/Ref.h: (WTF::Ref::Ref): Added extra ASSERT()s, and explicitly deleted copy constructors with a comment. (WTF::Ref::operator=): Added extra ASSERT()s, and explicitly deleted copy assignment operators with a comment. * wtf/WeakPtr.h: (WTF::WeakReference::clear): Used nullptr. (WTF::WeakReference::create): Moved to private: (WTF::WeakPtr::WeakPtr): For the default constructor, initialized the Ref with a new WeakReference. For the other constructor, moved it to private:. Also added copy constructors and copy assignment operators (since Ref doesn't have them but RefPtr does). These constructors/operators are relied upon in various places throughout WebCore. (WTF::WeakPtr::operator bool): Made non-explicit. (WTF::WeakReference::createUnbound): Deleted. (WTF::WeakReference::bindTo): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: Add WeakPtr API tests. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Added. * TestWebKitAPI/Tests/WTF/Ref.cpp: Update to not use copy constructor. Canonical link: https://commits.webkit.org/158549@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@178615 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-01-17 00:39:57 +00:00
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
enum class EnableWeakPtrThreadingAssertions : bool { No, Yes };
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename Counter = EmptyCounter> class WeakPtrImpl : public ThreadSafeRefCounted<WeakPtrImpl<Counter>> {
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
WTF_MAKE_NONCOPYABLE(WeakPtrImpl);
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
WTF_MAKE_FAST_ALLOCATED;
public:
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
template<typename T> static Ref<WeakPtrImpl> create(T* ptr)
{
return adoptRef(*new WeakPtrImpl(ptr));
}
WeakPtr breaks vtables when upcasting to base classes https://bugs.webkit.org/show_bug.cgi?id=188799 Reviewed by Youenn Fablet. Source/WebCore: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): * Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs. Removed redundant WeakPtrFactory. * css/CSSFontFace.cpp: (WebCore::CSSFontFace::existingWrapper): * css/CSSFontFace.h: Moved functions out of line to avoid #include explosion for .get(). * dom/ContainerNode.h: * dom/Document.h: * dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all subclasses except for DocumentFragment were already so, and we have code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::fullscreenRenderer const): * dom/FullscreenManager.h: (WebCore::FullscreenManager::fullscreenRenderer const): Deleted. * html/FormAssociatedElement.cpp: (WebCore::FormAssociatedElement::form const): * html/FormAssociatedElement.h: (WebCore::FormAssociatedElement::form const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * html/HTMLMediaElement.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): Removed redundant .get(). * page/DOMWindowProperty.cpp: (WebCore::DOMWindowProperty::window const): * page/DOMWindowProperty.h: (WebCore::DOMWindowProperty::window const): Deleted. * page/FrameViewLayoutContext.cpp: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): * page/FrameViewLayoutContext.h: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted. * page/UndoItem.cpp: (WebCore::UndoItem::undoManager const): * page/UndoItem.h: (WebCore::UndoItem::undoManager const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/ScrollView.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * platform/Widget.cpp: (WebCore::Widget::parent const): * platform/Widget.h: (WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/encryptedmedia/CDMInstanceSession.h: Made CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: CanMakeWeakPtr is inherited now. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted. (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted. * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::CMTimebaseEffectiveRateChangedCallback): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): (WebCore::SourceBufferPrivateAVFObjC::setCDMSession): (WebCore::SourceBufferPrivateAVFObjC::flushVideo): (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): (WebCore::SourceBufferPrivateAVFObjC::setVideoLayer): (WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage. * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::multiColumnFlowSlowCase const): * rendering/RenderBlockFlow.h: (WebCore::RenderBlockFlow::multiColumnFlow const): * rendering/RenderMultiColumnFlow.cpp: (WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const): * rendering/RenderMultiColumnFlow.h: * rendering/RenderTable.cpp: (WebCore::RenderTable::header const): (WebCore::RenderTable::footer const): (WebCore::RenderTable::firstBody const): (WebCore::RenderTable::topSection const): * rendering/RenderTable.h: (WebCore::RenderTable::header const): Deleted. (WebCore::RenderTable::footer const): Deleted. (WebCore::RenderTable::firstBody const): Deleted. (WebCore::RenderTable::topSection const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WebKit: * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::networkSession): * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::suspendedPage const): * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * UIProcess/Authentication/cocoa/SecKeyProxyStore.h: (WebKit::SecKeyProxyStore::get const): (WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted CanMakeWeakPtr. * UIProcess/WebAuthentication/AuthenticatorManager.h: * UIProcess/WebProcessProxy.cpp: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. (WebKit::WebProcessProxy::processPool const): * UIProcess/WebProcessProxy.h: (WebKit::WebProcessProxy::processPool const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WTF: This patch switches from reinterpret_cast to static_cast when loading from WeakReference storage. We know which type to cast *to* because it's specified by the type of the calling WeakPtr. We know which type to cast *from* because it's specified by a typedef in CanMakeWeakPtr. (Our convention is that we store a pointer to the class that derives from CanMakeWeakPtr. We cast from that pointer to derived pointers when we get(). This means that #include of the derived type header is now required in order to get() the pointer.) * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition is now eagerly required because WeakReference is not a template anymore. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computesEmpty const): (WTF::WeakHashSet::hasNullReferences const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted. Updated for new WeakReference get() API. * wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template specialization because WeakReference is not a class template anymore. (Or maybe we could have kept it working with a dummy template argument? Felt weird, so I switched.) (WTF::WeakReference::create): (WTF::WeakReference::~WeakReference): (WTF::WeakReference::get const): (WTF::WeakReference::operator bool const): (WTF::WeakReference::WeakReference): WeakReference is just a void* now. It's the caller's responsibility, when creating and getting, to use a consistent storage type. We ensure a canonical storage type using a typedef inside CanMakeWeakPtr. (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get const): (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): Adopted new WeakReference API. (WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast. (WTF::weak_reference_cast): This isn't required for correctness, but it's nice to show a complier error at WeakPtr construction sites when you know that the types won't work. Otherwise, you get compiler errors at dereference sites, which are slightly more mysterious ways of saying that you constructed your WeakPtr incorrectly. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::weak_reference_upcast): Deleted. (WTF::weak_reference_downcast): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead of template specialization for observing weak references. (TestWebKitAPI::Int::Int): (TestWebKitAPI::Int::operator int const): (TestWebKitAPI::Int::operator== const): Use a class for integer tests because WeakPtr doesn't naturally support pointing to non-class objects now. (TestWebKitAPI::Base::foo): (TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable deduction of the weak pointer type. (TestWebKitAPI::TEST): Updated to use Int. (TestWebKitAPI::Base::weakPtrFactory const): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted. Canonical link: https://commits.webkit.org/212376@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-29 21:15:54 +00:00
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
~WeakPtrImpl()
WeakPtr breaks vtables when upcasting to base classes https://bugs.webkit.org/show_bug.cgi?id=188799 Reviewed by Youenn Fablet. Source/WebCore: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): * Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs. Removed redundant WeakPtrFactory. * css/CSSFontFace.cpp: (WebCore::CSSFontFace::existingWrapper): * css/CSSFontFace.h: Moved functions out of line to avoid #include explosion for .get(). * dom/ContainerNode.h: * dom/Document.h: * dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all subclasses except for DocumentFragment were already so, and we have code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::fullscreenRenderer const): * dom/FullscreenManager.h: (WebCore::FullscreenManager::fullscreenRenderer const): Deleted. * html/FormAssociatedElement.cpp: (WebCore::FormAssociatedElement::form const): * html/FormAssociatedElement.h: (WebCore::FormAssociatedElement::form const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * html/HTMLMediaElement.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): Removed redundant .get(). * page/DOMWindowProperty.cpp: (WebCore::DOMWindowProperty::window const): * page/DOMWindowProperty.h: (WebCore::DOMWindowProperty::window const): Deleted. * page/FrameViewLayoutContext.cpp: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): * page/FrameViewLayoutContext.h: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted. * page/UndoItem.cpp: (WebCore::UndoItem::undoManager const): * page/UndoItem.h: (WebCore::UndoItem::undoManager const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/ScrollView.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * platform/Widget.cpp: (WebCore::Widget::parent const): * platform/Widget.h: (WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/encryptedmedia/CDMInstanceSession.h: Made CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: CanMakeWeakPtr is inherited now. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted. (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted. * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::CMTimebaseEffectiveRateChangedCallback): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): (WebCore::SourceBufferPrivateAVFObjC::setCDMSession): (WebCore::SourceBufferPrivateAVFObjC::flushVideo): (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): (WebCore::SourceBufferPrivateAVFObjC::setVideoLayer): (WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage. * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::multiColumnFlowSlowCase const): * rendering/RenderBlockFlow.h: (WebCore::RenderBlockFlow::multiColumnFlow const): * rendering/RenderMultiColumnFlow.cpp: (WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const): * rendering/RenderMultiColumnFlow.h: * rendering/RenderTable.cpp: (WebCore::RenderTable::header const): (WebCore::RenderTable::footer const): (WebCore::RenderTable::firstBody const): (WebCore::RenderTable::topSection const): * rendering/RenderTable.h: (WebCore::RenderTable::header const): Deleted. (WebCore::RenderTable::footer const): Deleted. (WebCore::RenderTable::firstBody const): Deleted. (WebCore::RenderTable::topSection const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WebKit: * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::networkSession): * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::suspendedPage const): * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * UIProcess/Authentication/cocoa/SecKeyProxyStore.h: (WebKit::SecKeyProxyStore::get const): (WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted CanMakeWeakPtr. * UIProcess/WebAuthentication/AuthenticatorManager.h: * UIProcess/WebProcessProxy.cpp: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. (WebKit::WebProcessProxy::processPool const): * UIProcess/WebProcessProxy.h: (WebKit::WebProcessProxy::processPool const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WTF: This patch switches from reinterpret_cast to static_cast when loading from WeakReference storage. We know which type to cast *to* because it's specified by the type of the calling WeakPtr. We know which type to cast *from* because it's specified by a typedef in CanMakeWeakPtr. (Our convention is that we store a pointer to the class that derives from CanMakeWeakPtr. We cast from that pointer to derived pointers when we get(). This means that #include of the derived type header is now required in order to get() the pointer.) * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition is now eagerly required because WeakReference is not a template anymore. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computesEmpty const): (WTF::WeakHashSet::hasNullReferences const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted. Updated for new WeakReference get() API. * wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template specialization because WeakReference is not a class template anymore. (Or maybe we could have kept it working with a dummy template argument? Felt weird, so I switched.) (WTF::WeakReference::create): (WTF::WeakReference::~WeakReference): (WTF::WeakReference::get const): (WTF::WeakReference::operator bool const): (WTF::WeakReference::WeakReference): WeakReference is just a void* now. It's the caller's responsibility, when creating and getting, to use a consistent storage type. We ensure a canonical storage type using a typedef inside CanMakeWeakPtr. (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get const): (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): Adopted new WeakReference API. (WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast. (WTF::weak_reference_cast): This isn't required for correctness, but it's nice to show a complier error at WeakPtr construction sites when you know that the types won't work. Otherwise, you get compiler errors at dereference sites, which are slightly more mysterious ways of saying that you constructed your WeakPtr incorrectly. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::weak_reference_upcast): Deleted. (WTF::weak_reference_downcast): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead of template specialization for observing weak references. (TestWebKitAPI::Int::Int): (TestWebKitAPI::Int::operator int const): (TestWebKitAPI::Int::operator== const): Use a class for integer tests because WeakPtr doesn't naturally support pointing to non-class objects now. (TestWebKitAPI::Base::foo): (TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable deduction of the weak pointer type. (TestWebKitAPI::TEST): Updated to use Int. (TestWebKitAPI::Base::weakPtrFactory const): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted. Canonical link: https://commits.webkit.org/212376@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-29 21:15:54 +00:00
{
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
Counter::decrement();
WeakPtr breaks vtables when upcasting to base classes https://bugs.webkit.org/show_bug.cgi?id=188799 Reviewed by Youenn Fablet. Source/WebCore: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): * Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs. Removed redundant WeakPtrFactory. * css/CSSFontFace.cpp: (WebCore::CSSFontFace::existingWrapper): * css/CSSFontFace.h: Moved functions out of line to avoid #include explosion for .get(). * dom/ContainerNode.h: * dom/Document.h: * dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all subclasses except for DocumentFragment were already so, and we have code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::fullscreenRenderer const): * dom/FullscreenManager.h: (WebCore::FullscreenManager::fullscreenRenderer const): Deleted. * html/FormAssociatedElement.cpp: (WebCore::FormAssociatedElement::form const): * html/FormAssociatedElement.h: (WebCore::FormAssociatedElement::form const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * html/HTMLMediaElement.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): Removed redundant .get(). * page/DOMWindowProperty.cpp: (WebCore::DOMWindowProperty::window const): * page/DOMWindowProperty.h: (WebCore::DOMWindowProperty::window const): Deleted. * page/FrameViewLayoutContext.cpp: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): * page/FrameViewLayoutContext.h: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted. * page/UndoItem.cpp: (WebCore::UndoItem::undoManager const): * page/UndoItem.h: (WebCore::UndoItem::undoManager const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/ScrollView.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * platform/Widget.cpp: (WebCore::Widget::parent const): * platform/Widget.h: (WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/encryptedmedia/CDMInstanceSession.h: Made CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: CanMakeWeakPtr is inherited now. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted. (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted. * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::CMTimebaseEffectiveRateChangedCallback): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): (WebCore::SourceBufferPrivateAVFObjC::setCDMSession): (WebCore::SourceBufferPrivateAVFObjC::flushVideo): (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): (WebCore::SourceBufferPrivateAVFObjC::setVideoLayer): (WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage. * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::multiColumnFlowSlowCase const): * rendering/RenderBlockFlow.h: (WebCore::RenderBlockFlow::multiColumnFlow const): * rendering/RenderMultiColumnFlow.cpp: (WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const): * rendering/RenderMultiColumnFlow.h: * rendering/RenderTable.cpp: (WebCore::RenderTable::header const): (WebCore::RenderTable::footer const): (WebCore::RenderTable::firstBody const): (WebCore::RenderTable::topSection const): * rendering/RenderTable.h: (WebCore::RenderTable::header const): Deleted. (WebCore::RenderTable::footer const): Deleted. (WebCore::RenderTable::firstBody const): Deleted. (WebCore::RenderTable::topSection const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WebKit: * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::networkSession): * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::suspendedPage const): * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * UIProcess/Authentication/cocoa/SecKeyProxyStore.h: (WebKit::SecKeyProxyStore::get const): (WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted CanMakeWeakPtr. * UIProcess/WebAuthentication/AuthenticatorManager.h: * UIProcess/WebProcessProxy.cpp: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. (WebKit::WebProcessProxy::processPool const): * UIProcess/WebProcessProxy.h: (WebKit::WebProcessProxy::processPool const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WTF: This patch switches from reinterpret_cast to static_cast when loading from WeakReference storage. We know which type to cast *to* because it's specified by the type of the calling WeakPtr. We know which type to cast *from* because it's specified by a typedef in CanMakeWeakPtr. (Our convention is that we store a pointer to the class that derives from CanMakeWeakPtr. We cast from that pointer to derived pointers when we get(). This means that #include of the derived type header is now required in order to get() the pointer.) * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition is now eagerly required because WeakReference is not a template anymore. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computesEmpty const): (WTF::WeakHashSet::hasNullReferences const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted. Updated for new WeakReference get() API. * wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template specialization because WeakReference is not a class template anymore. (Or maybe we could have kept it working with a dummy template argument? Felt weird, so I switched.) (WTF::WeakReference::create): (WTF::WeakReference::~WeakReference): (WTF::WeakReference::get const): (WTF::WeakReference::operator bool const): (WTF::WeakReference::WeakReference): WeakReference is just a void* now. It's the caller's responsibility, when creating and getting, to use a consistent storage type. We ensure a canonical storage type using a typedef inside CanMakeWeakPtr. (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get const): (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): Adopted new WeakReference API. (WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast. (WTF::weak_reference_cast): This isn't required for correctness, but it's nice to show a complier error at WeakPtr construction sites when you know that the types won't work. Otherwise, you get compiler errors at dereference sites, which are slightly more mysterious ways of saying that you constructed your WeakPtr incorrectly. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::weak_reference_upcast): Deleted. (WTF::weak_reference_downcast): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead of template specialization for observing weak references. (TestWebKitAPI::Int::Int): (TestWebKitAPI::Int::operator int const): (TestWebKitAPI::Int::operator== const): Use a class for integer tests because WeakPtr doesn't naturally support pointing to non-class objects now. (TestWebKitAPI::Base::foo): (TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable deduction of the weak pointer type. (TestWebKitAPI::TEST): Updated to use Int. (TestWebKitAPI::Base::weakPtrFactory const): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted. Canonical link: https://commits.webkit.org/212376@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-29 21:15:54 +00:00
}
Add WeakHashSet https://bugs.webkit.org/show_bug.cgi?id=195152 Reviewed by Antti Koivisto. Source/WTF: Added WeakHashSet which is a HashSet of WeakPtr. When the object pointed by WeakPtr is deleted, WeakHashSet treats the key to be no longer in the set. That is, WeakHashSet::contains returns false and const_iterator skips such a WeakPtr in the set. We decided not to make HashSet<WeahPtr<T>> work because it involves weird semantics such as making find(X) delete the table entry as remove(find(X)) would be a no-op otherwise as find(X) would return necessarily need to return HashSet<WeakPtr<T>>::end(). Furthermore, we cannot determine the true size of this set in O(1) because the objected pointed by some of WeakPtr in the set may have already been deleted. This has implications that we can't have size(), isEmpty(), random(), etc... as O(1) operation. WeakHashSet is implemented as HashSet<WeakReference<T>>. HashTable::rehash has been updated to delete WeakReference<T>'s whose m_ptr has become null, and HashTable::expand first deletes any such entry before deciding an actual expansion is needed. This is accomplished via newly added hash trait, hasIsReleasedWeakValueFunction, and HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue which returns true for when WeakReference<T> pointed by Ref<WeakReference<T>> has null m_ptr, not to be confused with Ref<WeakReference<T>> itself pointing to a null WeakReference<T>. * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/Forward.h: * wtf/HashSet.h: (WTF::HashSet<T, U, V>::checkConsistency const): Added. * wtf/HashTable.h: (WTF::HashTable::isReleasedWeakBucket): Added. (WTF::HashTable::expand): Delete WeakReference<T> with null m_ptr first. This updates m_keyCount and may make mustRehashInPlace() return true. (WTF::HashTable::deleteReleasedWeakBuckets): Added. (WTF::HashTable::rehash): Delete WeakReference<T> with null m_ptr. Also refactored the code a bit to avoid keep repeating oldTable[i]. * wtf/HashTraits.h: (WTF::HashTraits<T>::isHashTraitsReleasedWeakValue): Added. (WTF::RefHashTraits<T>): Extracted from HashTraits<Ref<P>> to share code with HashTraits<Ref<WeakReference<T>>>. (WTF::HashTraitsReleasedWeakValueChecker<Traits, hasIsReleasedWeakValueFunction>): Added. (WTF::isHashTraitsReleasedWeakValue<Traits, hasIsReleasedWeakValueFunction>): Added. * wtf/WeakHashSet.h: Added. (WTF::WeakHashSet): Added. (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator* const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator-> const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator++): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::WeakHashSetConstIterator::operator== const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator!= const): (WTF::WeakHashSet::WeakHashSet): (WTF::WeakHashSet::begin const): (WTF::WeakHashSet::end const): (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::capacity const): (WTF::WeakHashSet::computeSize const): Deletes any WeakReference<T> with null m_ptr first. (WTF::WeakHashSet::checkConsistency const): (WTF::HashTraits<Ref<WeakReference<T>>>): Added. This hash traits triggers the new code in HashTable's expand and rehash methods to delete WeakReference<T> with null m_ptr. (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): * wtf/WeakPtr.h: (WTF::WeakReference::~WeakReference): Added so that we can keep track the number of live WeakReference in API tests by template specializations. Tools: Added tests for WeakHashSet. * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::Base::Base): Moved. (TestWebKitAPI::Derived::foo): Moved. (WTF::WeakReference<TestWebKitAPI::Base>): Added to track the number of live WeakReference. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): (TestWebKitAPI::computeSizeOfWeakHashSet): Added. Canonical link: https://commits.webkit.org/209643@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242387 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-04 21:52:32 +00:00
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
template<typename T> typename T::WeakValueType* get()
{
return static_cast<typename T::WeakValueType*>(m_ptr);
}
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
explicit operator bool() const { return m_ptr; }
WeakPtrFactory should populate m_ref lazily. https://bugs.webkit.org/show_bug.cgi?id=177375 Reviewed by Geoffrey Garen. Source/WebCore: * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::CDM): * Modules/encryptedmedia/CDM.h: (WebCore::CDM::createWeakPtr): * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::MediaKeys): (WebCore::MediaKeys::createSession): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: (WebCore::MediaDevices::createWeakPtr): * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::MediaStreamTrack): * Modules/mediastream/MediaStreamTrack.h: (WebCore::MediaStreamTrack::createWeakPtr): * accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::AccessibilityRenderObject): * accessibility/AccessibilityRenderObject.h: (WebCore::AccessibilityRenderObject::createWeakPtr): * animation/WebAnimation.cpp: (WebCore::WebAnimation::WebAnimation): * animation/WebAnimation.h: * css/FontFace.cpp: (WebCore::FontFace::FontFace): (WebCore::FontFace::createWeakPtr): (WebCore::FontFace::createWeakPtr const): Deleted. * css/FontFace.h: * css/StyleSheetContents.h: * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::DataTransferItemList): (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/Document.cpp: (WebCore::Document::postTask): * dom/Document.h: (WebCore::Document::createWeakPtr): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::createWeakPtr): * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: (WebCore::HTMLResourcePreloader::HTMLResourcePreloader): (WebCore::HTMLResourcePreloader::createWeakPtr): * loader/LinkLoader.cpp: (WebCore::LinkLoader::LinkLoader): * loader/LinkLoader.h: (WebCore::LinkLoader::createWeakPtr): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * page/DOMWindow.h: * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::TaskDispatcher): (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::GenericTaskQueue): (WebCore::GenericTaskQueue::enqueueTask): * platform/ScrollableArea.h: (WebCore::ScrollableArea::createWeakPtr): * platform/Scrollbar.cpp: (WebCore::Scrollbar::Scrollbar): * platform/Scrollbar.h: (WebCore::Scrollbar::createWeakPtr): * platform/Widget.h: (WebCore::Widget::createWeakPtr): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::FontCascade): * platform/graphics/FontCascade.h: (WebCore::FontCascade::createWeakPtr const): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: (WebCore::MediaPlayerPrivateAVFoundation::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: (WebCore::CDMSessionAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: (WebCore::CDMSessionAVStreamSession::CDMSessionAVStreamSession): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::sizeWillChangeAtTime): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::append): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::TextureCacheCV): (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac): (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/ios/RemoteCommandListenerIOS.h: (WebCore::RemoteCommandListenerIOS::createWeakPtr): * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: (WebCore::RemoteCommandListenerMac::createWeakPtr): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::MediaStreamPrivate): * platform/mediastream/MediaStreamPrivate.h: (WebCore::MediaStreamPrivate::createWeakPtr): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::RealtimeMediaSource): * platform/mediastream/RealtimeMediaSource.h: * platform/mock/MockMediaEndpoint.cpp: (WebCore::MockMediaEndpoint::MockMediaEndpoint): (WebCore::MockMediaEndpoint::generateDtlsInfo): * rendering/RenderMultiColumnSpannerPlaceholder.cpp: (WebCore::RenderMultiColumnSpannerPlaceholder::RenderMultiColumnSpannerPlaceholder): * rendering/RenderMultiColumnSpannerPlaceholder.h: * rendering/RenderView.cpp: (WebCore::RenderView::RenderView): * rendering/RenderView.h: * rendering/RenderWidget.cpp: (WebCore::RenderWidget::RenderWidget): * rendering/RenderWidget.h: (WebCore::RenderWidget::createWeakPtr): * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::RootInlineBox): * rendering/RootInlineBox.h: (WebCore::RootInlineBox::createWeakPtr): * svg/SVGPathElement.cpp: (WebCore::SVGPathElement::SVGPathElement): * svg/SVGPathElement.h: * svg/properties/SVGMatrixTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::MockCDMFactory): (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::MockCDM): (WebCore::MockCDM::createInstance): (WebCore::m_weakPtrFactory): Deleted. Source/WebCore/PAL: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy): (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::createWeakPtr): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::WebViewImpl): * UIProcess/Launcher/ProcessLauncher.cpp: (WebKit::ProcessLauncher::ProcessLauncher): * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: (WebKit::ProcessAssertion::createWeakPtr): * UIProcess/WebPageProxy.cpp: (WebKit::m_configurationPreferenceValues): (WebKit::m_weakPtrFactory): Deleted. * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::createWeakPtr const): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: (WebKit::RemoteLayerTreeDrawingArea::createWeakPtr): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea): Source/WebKitLegacy/mac: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::WebEditorClient): (WebEditorClient::requestCandidatesForSelection): Source/WTF: This helps us with the overhead of initializing WeakPtrFactory for objects that rarely end up creating the weak reference. -This is in preparation for introducing WeakPtr to RenderObject. All credit to Geoffrey Garen. * wtf/WeakPtr.h: (WTF::WeakReference::get const): (WTF::WeakReference::clear): (WTF::WeakReference::WeakReference): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-23 04:38:45 +00:00
void clear() { m_ptr = nullptr; }
Use WeakPtrs to communicate between the HTMLDocumentParser and the BackgroundHTMLParser https://bugs.webkit.org/show_bug.cgi?id=107190 Reviewed by Eric Seidel. Source/WebCore: This patch replaces the parser map with WeakPtr. We now use WeakPtrs to communicate from the main thread to the background thread. (We were already using WeakPtrs to communicate from the background thread to the main thread.) This change lets us remove a bunch of boilerplate code. * html/parser/BackgroundHTMLParser.cpp: (WebCore::BackgroundHTMLParser::BackgroundHTMLParser): (WebCore::BackgroundHTMLParser::stop): (WebCore): * html/parser/BackgroundHTMLParser.h: (WebCore::BackgroundHTMLParser::create): (BackgroundHTMLParser): * html/parser/HTMLDocumentParser.cpp: (WebCore::HTMLDocumentParser::didFailSpeculation): (WebCore::HTMLDocumentParser::startBackgroundParser): (WebCore::HTMLDocumentParser::stopBackgroundParser): (WebCore::HTMLDocumentParser::append): (WebCore::HTMLDocumentParser::finish): * html/parser/HTMLDocumentParser.h: (WebCore): (HTMLDocumentParser): Source/WTF: Add the ability to create an unbound weak reference. This facility lets you start sending messages to a WeakPtr on another thread before the object backing the WeakPtr has actually been created. * wtf/WeakPtr.h: (WTF::WeakReference::createUnbound): (WTF::WeakReference::bindTo): (WeakReference): (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WeakPtr): (WTF::WeakPtrFactory::WeakPtrFactory): (WeakPtrFactory): (WTF::WeakPtrFactory::revokeAll): Canonical link: https://commits.webkit.org/127546@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142305 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-02-08 19:30:54 +00:00
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#if ASSERT_ENABLED
bool wasConstructedOnMainThread() const { return m_wasConstructedOnMainThread; }
#endif
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
private:
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
template<typename T> explicit WeakPtrImpl(T* ptr)
: m_ptr(static_cast<typename T::WeakValueType*>(ptr))
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#if ASSERT_ENABLED
, m_wasConstructedOnMainThread(isMainThread())
#endif
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
{
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
Counter::increment();
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
}
WeakPtr breaks vtables when upcasting to base classes https://bugs.webkit.org/show_bug.cgi?id=188799 Reviewed by Youenn Fablet. Source/WebCore: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): * Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs. Removed redundant WeakPtrFactory. * css/CSSFontFace.cpp: (WebCore::CSSFontFace::existingWrapper): * css/CSSFontFace.h: Moved functions out of line to avoid #include explosion for .get(). * dom/ContainerNode.h: * dom/Document.h: * dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all subclasses except for DocumentFragment were already so, and we have code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::fullscreenRenderer const): * dom/FullscreenManager.h: (WebCore::FullscreenManager::fullscreenRenderer const): Deleted. * html/FormAssociatedElement.cpp: (WebCore::FormAssociatedElement::form const): * html/FormAssociatedElement.h: (WebCore::FormAssociatedElement::form const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * html/HTMLMediaElement.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): Removed redundant .get(). * page/DOMWindowProperty.cpp: (WebCore::DOMWindowProperty::window const): * page/DOMWindowProperty.h: (WebCore::DOMWindowProperty::window const): Deleted. * page/FrameViewLayoutContext.cpp: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): * page/FrameViewLayoutContext.h: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted. * page/UndoItem.cpp: (WebCore::UndoItem::undoManager const): * page/UndoItem.h: (WebCore::UndoItem::undoManager const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/ScrollView.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * platform/Widget.cpp: (WebCore::Widget::parent const): * platform/Widget.h: (WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/encryptedmedia/CDMInstanceSession.h: Made CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: CanMakeWeakPtr is inherited now. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted. (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted. * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::CMTimebaseEffectiveRateChangedCallback): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): (WebCore::SourceBufferPrivateAVFObjC::setCDMSession): (WebCore::SourceBufferPrivateAVFObjC::flushVideo): (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): (WebCore::SourceBufferPrivateAVFObjC::setVideoLayer): (WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage. * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::multiColumnFlowSlowCase const): * rendering/RenderBlockFlow.h: (WebCore::RenderBlockFlow::multiColumnFlow const): * rendering/RenderMultiColumnFlow.cpp: (WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const): * rendering/RenderMultiColumnFlow.h: * rendering/RenderTable.cpp: (WebCore::RenderTable::header const): (WebCore::RenderTable::footer const): (WebCore::RenderTable::firstBody const): (WebCore::RenderTable::topSection const): * rendering/RenderTable.h: (WebCore::RenderTable::header const): Deleted. (WebCore::RenderTable::footer const): Deleted. (WebCore::RenderTable::firstBody const): Deleted. (WebCore::RenderTable::topSection const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WebKit: * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::networkSession): * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::suspendedPage const): * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * UIProcess/Authentication/cocoa/SecKeyProxyStore.h: (WebKit::SecKeyProxyStore::get const): (WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted CanMakeWeakPtr. * UIProcess/WebAuthentication/AuthenticatorManager.h: * UIProcess/WebProcessProxy.cpp: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. (WebKit::WebProcessProxy::processPool const): * UIProcess/WebProcessProxy.h: (WebKit::WebProcessProxy::processPool const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WTF: This patch switches from reinterpret_cast to static_cast when loading from WeakReference storage. We know which type to cast *to* because it's specified by the type of the calling WeakPtr. We know which type to cast *from* because it's specified by a typedef in CanMakeWeakPtr. (Our convention is that we store a pointer to the class that derives from CanMakeWeakPtr. We cast from that pointer to derived pointers when we get(). This means that #include of the derived type header is now required in order to get() the pointer.) * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition is now eagerly required because WeakReference is not a template anymore. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computesEmpty const): (WTF::WeakHashSet::hasNullReferences const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted. Updated for new WeakReference get() API. * wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template specialization because WeakReference is not a class template anymore. (Or maybe we could have kept it working with a dummy template argument? Felt weird, so I switched.) (WTF::WeakReference::create): (WTF::WeakReference::~WeakReference): (WTF::WeakReference::get const): (WTF::WeakReference::operator bool const): (WTF::WeakReference::WeakReference): WeakReference is just a void* now. It's the caller's responsibility, when creating and getting, to use a consistent storage type. We ensure a canonical storage type using a typedef inside CanMakeWeakPtr. (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get const): (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): Adopted new WeakReference API. (WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast. (WTF::weak_reference_cast): This isn't required for correctness, but it's nice to show a complier error at WeakPtr construction sites when you know that the types won't work. Otherwise, you get compiler errors at dereference sites, which are slightly more mysterious ways of saying that you constructed your WeakPtr incorrectly. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::weak_reference_upcast): Deleted. (WTF::weak_reference_downcast): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead of template specialization for observing weak references. (TestWebKitAPI::Int::Int): (TestWebKitAPI::Int::operator int const): (TestWebKitAPI::Int::operator== const): Use a class for integer tests because WeakPtr doesn't naturally support pointing to non-class objects now. (TestWebKitAPI::Base::foo): (TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable deduction of the weak pointer type. (TestWebKitAPI::TEST): Updated to use Int. (TestWebKitAPI::Base::weakPtrFactory const): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted. Canonical link: https://commits.webkit.org/212376@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-29 21:15:54 +00:00
void* m_ptr;
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#if ASSERT_ENABLED
bool m_wasConstructedOnMainThread;
#endif
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
};
Use WeakHashMap and WeakPtr with Node in more places https://bugs.webkit.org/show_bug.cgi?id=227192 <rdar://problem/79828322> Reviewed by Geoffrey Garen. Source/WebCore: Deploy WeakHashMap and WeakPtr with Node/Element in more places. * dom/Document.cpp: (WebCore::Document::elementForAccessKey): (WebCore::Document::buildAccessKeyCache): (WebCore::Document::registerForVisibilityStateChangedCallbacks): (WebCore::Document::unregisterForVisibilityStateChangedCallbacks): (WebCore::Document::visibilityStateChanged): * dom/Document.h: * dom/VisibilityChangeClient.h: * html/FormController.cpp: (WebCore::FormKeyGenerator::formKey): (WebCore::FormKeyGenerator::willDeleteForm): * html/HTMLAnchorElement.cpp: (WebCore::rootEditableElementMap): (WebCore::HTMLAnchorElement::rootEditableElementForSelectionOnMouseDown const): (WebCore::HTMLAnchorElement::clearRootEditableElementForSelectionOnMouseDown): (WebCore::HTMLAnchorElement::setRootEditableElementForSelectionOnMouseDown): * inspector/agents/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::bind): (WebCore::InspectorDOMAgent::unbind): (WebCore::InspectorDOMAgent::nodeForId): (WebCore::InspectorDOMAgent::pushNodePathToFrontend): (WebCore::InspectorDOMAgent::boundNodeId): (WebCore::InspectorDOMAgent::willDestroyDOMNode): (WebCore::InspectorDOMAgent::mediaMetricsTimerFired): * inspector/agents/InspectorDOMAgent.h: * inspector/agents/InspectorLayerTreeAgent.cpp: (WebCore::InspectorLayerTreeAgent::bindPseudoElement): (WebCore::InspectorLayerTreeAgent::unbindPseudoElement): * inspector/agents/InspectorLayerTreeAgent.h: * style/StyleSharingResolver.h: Source/WTF: * wtf/WeakHashMap.h: (WTF::WeakHashMap::WeakHashMapIteratorBase::makePeek): Fixed type mismatch errors. (WTF::WeakHashMap::ensure): Made this function return AddResult like HashMap::ensure. (WTF::WeakHashMap::take): Added. (WTF::WeakHashMap::removeIf): Fixed the bug that the callback was called with the iterator of m_impl and not WeakHashMapIterator. * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl<Counter>>>::isReleasedWeakValue): Moved to WeakPtr.h * wtf/WeakPtr.h: (WTF::HashTraits<Ref<WeakPtrImpl<Counter>>>::isReleasedWeakValue): Moved from WeakHashSet.h Canonical link: https://commits.webkit.org/239295@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279439 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-30 22:51:21 +00:00
template<typename Counter> struct HashTraits<Ref<WeakPtrImpl<Counter>>> : RefHashTraits<WeakPtrImpl<Counter>> {
static constexpr bool hasIsReleasedWeakValueFunction = true;
static bool isReleasedWeakValue(const Ref<WeakPtrImpl<Counter>>& value)
{
return !value.isHashTableDeletedValue() && !value.isHashTableEmptyValue() && !value.get();
}
};
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename Counter> class WeakPtr {
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
WTF_MAKE_FAST_ALLOCATED;
public:
WeakPtr() { }
WeakPtr(std::nullptr_t) { }
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename U> WeakPtr(const WeakPtr<U, Counter>&);
template<typename U> WeakPtr(WeakPtr<U, Counter>&&);
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
T* get() const
{
// FIXME: Our GC threads currently need to get opaque pointers from WeakPtrs and have to be special-cased.
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
ASSERT(!m_impl || !m_shouldEnableAssertions || Thread::mayBeGCThread() || m_impl->wasConstructedOnMainThread() == isMainThread());
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
return m_impl ? static_cast<T*>(m_impl->template get<T>()) : nullptr;
}
Improve some media code https://bugs.webkit.org/show_bug.cgi?id=208322 Reviewed by Anders Carlsson. Source/WebCore: - TextTrack objects now take Document instead of ScriptExecutionContext. - Made more TextTrack functions private and protected. - Made TextTrack parsing functions use return values rather than out arguments. - Use references rather than pointers and Ref rather than RefPtr for non-null things. - Made MediaControlsHost use a WeakPtr instead of a raw pointer. * Modules/mediacontrols/MediaControlsHost.cpp: (WebCore::alwaysOnKeyword): Made private to this file instead of exposed in header. (WebCore::manualKeyword): Ditto. (WebCore::MediaControlsHost::create): Take a reference instead of a pointer to the media element. (WebCore::MediaControlsHost::MediaControlsHost): Ditto, and make a weak pointer. (WebCore::MediaControlsHost::sortedTrackListForMenu): Added null check. (WebCore::MediaControlsHost::displayNameForTrack): Ditto. (WebCore::MediaControlsHost::captionMenuOffItem): Ditto. (WebCore::MediaControlsHost::captionMenuAutomaticItem): Ditto. (WebCore::MediaControlsHost::captionDisplayMode const): Ditto. (WebCore::MediaControlsHost::setSelectedTextTrack): Ditto. (WebCore::MediaControlsHost::textTrackContainer): Ditto. (WebCore::MediaControlsHost::allowsInlineMediaPlayback const): Ditto. (WebCore::MediaControlsHost::supportsFullscreen const): Ditto. (WebCore::MediaControlsHost::isVideoLayerInline const): Ditto. (WebCore::MediaControlsHost::isInMediaDocument const): Ditto. (WebCore::MediaControlsHost::setPreparedToReturnVideoLayerToInline): Ditto. (WebCore::MediaControlsHost::userGestureRequired const): Ditto. (WebCore::MediaControlsHost::shouldForceControlsDisplay const): Ditto. (WebCore::MediaControlsHost::externalDeviceDisplayName const): Ditto. (WebCore::MediaControlsHost::externalDeviceType const): Ditto. (WebCore::MediaControlsHost::controlsDependOnPageScaleFactor const): Ditto. (WebCore::MediaControlsHost::setControlsDependOnPageScaleFactor): Ditto. (WebCore::MediaControlsHost::generateUUID): Made a static member. (WebCore::MediaControlsHost::shadowRootCSSText): Ditto. (WebCore::MediaControlsHost::base64StringForIconNameAndType): Ditto. (WebCore::MediaControlsHost::formattedStringForDuration): Ditto. (WebCore::MediaControlsHost::compactMode const): Tweaked logic a bit. * Modules/mediacontrols/MediaControlsHost.h: Made various member functions into static member functions, used references instead of pointers for things that are never null, used WeakPtr for m_mediaElement. * Modules/mediasource/SourceBuffer.cpp: (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment): Document instead of ScriptExecutionContext. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerDidAddTextTrack): Document instead of ScriptExecutionContext. (WebCore::HTMLMediaElement::updateCaptionContainer): Pass reference to MediaControlsHost::create. (WebCore::HTMLMediaElement::setSelectedTextTrack): Update since special items are now references rather than pointers. (WebCore::HTMLMediaElement::updateTextTrackDisplay): Pass reference. (WebCore::HTMLMediaElement::didAddUserAgentShadowRoot): Ditto. * html/HTMLTrackElement.cpp: (WebCore::HTMLTrackElement::parseAttribute): Removed setIsDefault function since the track can simply read the attribute out of the element instead. * html/shadow/MediaControlElements.cpp: (WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Update since special items are now referencse rather than pointers. * html/track/DataCue.cpp: (WebCore::DataCue::DataCue): Document instead of ScriptExecutionContext. (WebCore::DataCue::create): Moved these functions out of the header. * html/track/DataCue.h: Updated for the above. * html/track/DataCue.idl: Ditto. * html/track/InbandDataTextTrack.cpp: (WebCore::InbandDataTextTrack::InbandDataTextTrack): Document instead of ScriptExecutionContext. (WebCore::InbandDataTextTrack::create): Ditto. (WebCore::InbandDataTextTrack::addDataCue): Ditto. Also use reference instead of pointer when calling hasCue. * html/track/InbandDataTextTrack.h: Updated for the above. * html/track/InbandGenericTextTrack.cpp: (WebCore::InbandGenericTextTrack::InbandGenericTextTrack): Document instead of ScriptExecutionContext. (WebCore::InbandGenericTextTrack::create): Ditto. (WebCore::InbandGenericTextTrack::addGenericCue): Ditto. Also use reference instead of pointer when calling hasCue. (WebCore::InbandGenericTextTrack::parser): Ditto. (WebCore::InbandGenericTextTrack::newCuesParsed): Ditto. Also use return value from takeCues instead of out arguenmt from getNewCues. Also use reference instead of pointer when calling hasCue. (WebCore::InbandGenericTextTrack::newRegionsParsed): Ditto. * html/track/InbandGenericTextTrack.h: Update for above. * html/track/InbandTextTrack.cpp: (WebCore::InbandTextTrack::create): Document instead of ScriptExecutionContext. (WebCore::InbandTextTrack::InbandTextTrack): Ditto. * html/track/InbandTextTrack.h: Update for above. * html/track/InbandWebVTTTextTrack.cpp: (WebCore::InbandWebVTTTextTrack::InbandWebVTTTextTrack): Document instead of ScriptExecutionContext. (WebCore::InbandWebVTTTextTrack::create): Ditto. (WebCore::InbandWebVTTTextTrack::parser): Ditto. (WebCore::InbandWebVTTTextTrack::newCuesParsed): Ditto. Also use return value from takeCues instead of out arguenmt from getNewCues. Also use reference instead of pointer when calling hasCue. (WebCore::InbandWebVTTTextTrack::newRegionsParsed): Ditto. * html/track/InbandWebVTTTextTrack.h: Update for above. * html/track/LoadableTextTrack.cpp: (WebCore::LoadableTextTrack::create): Moved here from header. (WebCore::LoadableTextTrack::loadTimerFired): Document instead of ScriptExecutionContext. (WebCore::LoadableTextTrack::newRegionsAvailable): Use return value from getNewRegions instead of out argument. (WebCore::LoadableTextTrack::isDefault const): New implementation that does not rely on a data member; checks attribute on video element. * html/track/LoadableTextTrack.h: Updated for above changes. * html/track/TextTrack.cpp: (WebCore::TextTrack::captionMenuOffItem): Return a reference rather than a pointer. (WebCore::TextTrack::captionMenuAutomaticItem): Ditto. (WebCore::TextTrack::create): Document rather than ScriptExecutionContext. (WebCore::TextTrack::document const): Added. For use by derived classes. (WebCore::TextTrack::addRegion): Ref rather than RefPtr. (WebCore::TextTrack::removeRegion): Reference rather than pointer. (WebCore::TextTrack::cueWillChange): Ditto. (WebCore::TextTrack::cueDidChange): Ditto. (WebCore::TextTrack::hasCue): Ditto. * html/track/TextTrack.h: Removed declarations of non-existent disabledKeyword, hiddenKeyword, and showingKeyword functions. Made setKind, client, and hasCue protected. Made overrides of eventTargetInterface, scriptExecutionContext, and logClassName private. Removed setIsDefault. Updated for changes above. * html/track/TextTrack.idl: Did what FIXME suggested, making the region parameters non-nullable. Passing null silently did nothing before. There is some small risk of website incompatibility if someone accidentally relied on this WebKit-specific behavior. * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::create): Document instead of ScriptExecutionContext. (WebCore::TextTrackCue::TextTrackCue): Ditto. (WebCore::TextTrackCue::willChange): Pass reference. (WebCore::TextTrackCue::didChange): Ditto. * html/track/TextTrackCue.h: Update for above changes. * html/track/TextTrackCue.idl: Ditto. * html/track/TextTrackCueGeneric.cpp: (WebCore::TextTrackCueGeneric::TextTrackCueGeneric): Update since the base class now takes an rvalue reference to the string. (WebCore::TextTrackCueGeneric::isOrderedBefore const): Use auto. (WebCore::TextTrackCueGeneric::isPositionedAbove const): Ditto. * html/track/VTTCue.cpp: (WebCore::VTTCue::create): Document instead of ScriptExecutionContext. Also take String with an rvalue reference. (WebCore::VTTCue::VTTCue): Ditto. * html/track/VTTCue.h: Update for above changes. * html/track/VTTCue.idl: Ditto. * html/track/WebVTTParser.cpp: (WebCore::WebVTTParser::WebVTTParser): Document instead of ScriptExecutionContext. References instead of pointers. Initialize m_state in class definition. (WebCore::WebVTTParser::takeCues): Renamed from getNewCues and changed to use a return value instead of an out argument. (WebCore::WebVTTParser::takeRegions): Ditto. (WebCore::WebVTTParser::takeStyleSheets): Ditto. (WebCore::WebVTTParser::parseCueData): Remove null check of m_client. (WebCore::WebVTTParser::parse): Ditto. (WebCore::WebVTTParser::collectWebVTTBlock): Ditto. (WebCore::WebVTTParser::checkAndCreateRegion): Pass document. (WebCore::WebVTTParser::checkAndStoreRegion): Use Vector::removeFirstMatching instead of Vector::removeFirst. (WebCore::WebVTTParser::createNewCue): Remove null check of m_client. * html/track/WebVTTParser.h: Update for above changes. * loader/TextTrackLoader.cpp: (WebCore::TextTrackLoader::TextTrackLoader): Document instead of ScriptExecutionContext. References instead of pointers. Initialize data members in in class definition. (WebCore::TextTrackLoader::processNewCueData): Pass references. (WebCore::TextTrackLoader::corsPolicyPreventedLoad): Use m_document. (WebCore::TextTrackLoader::load): Ditto. (WebCore::TextTrackLoader::getNewCues): Use takeCues. (WebCore::TextTrackLoader::getNewRegions): Changed to return a vector instead of using an out argument. Use takeRegions. (WebCore::TextTrackLoader::getNewStyleSheets): Ditto. * loader/TextTrackLoader.h: Updated for the above. * page/CaptionUserPreferences.cpp: (WebCore::trackDisplayName): Updated since these are references. (WebCore::CaptionUserPreferences::mediaSelectionOptionForTrack const): Ditto. (WebCore::CaptionUserPreferences::sortedTrackListForMenu): Ditto. * page/CaptionUserPreferencesMediaAF.cpp: (WebCore::trackDisplayName): Ditto. (WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu): Ditto. * platform/cocoa/PlaybackSessionModelMediaElement.mm: (WebCore::PlaybackSessionModelMediaElement::selectLegibleMediaOption): Ditto. (WebCore::PlaybackSessionModelMediaElement::legibleMediaSelectedIndex const): Updated to use references rather than pointers. Refactored the logic to use Optional and nested if statements to make the algorithm clearer. Source/WTF: * wtf/WeakPtr.h: (WTF::WeakPtr::operator! const): Added. Canonical link: https://commits.webkit.org/221612@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257997 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-06 16:08:33 +00:00
bool operator!() const { return !m_impl || !*m_impl; }
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
explicit operator bool() const { return m_impl && *m_impl; }
WeakPtr functions crash when created with default constructor https://bugs.webkit.org/show_bug.cgi?id=140479 Reviewed by Andreas Kling. Source/WTF: This patch rearranges how WeakPtr works, and has the following ideas behind it: 1. WeakPtr should use Ref internally. This solves the crash by always having a valid WeakReference. 2. Clients should not be able to construct WeakReferences directly. Instead, only WeakPtrFactory (and WeakPtr's default constructor) should be able to construct them. They are considered an implementation detail of WeakPtr. 3. Except for the default constructor, clients should not be able to construct WeakPtrs directly. Instead, the WeakPtrFactory must construct them. This guarantees that the WeakPtrs all reference the same WeakReference. 4. Clients can construct a WeakPtr using its default constructor, and then use the assignment operator to make it non-null. (Or they could use WeakPtrFactory to make it non-null at creation-time.) 5. No one was using WeakReference::bindTo(), and it doesn't seem useful, so I removed it. Tests: WTF_WeakPtr API tests * wtf/Ref.h: (WTF::Ref::Ref): Added extra ASSERT()s, and explicitly deleted copy constructors with a comment. (WTF::Ref::operator=): Added extra ASSERT()s, and explicitly deleted copy assignment operators with a comment. * wtf/WeakPtr.h: (WTF::WeakReference::clear): Used nullptr. (WTF::WeakReference::create): Moved to private: (WTF::WeakPtr::WeakPtr): For the default constructor, initialized the Ref with a new WeakReference. For the other constructor, moved it to private:. Also added copy constructors and copy assignment operators (since Ref doesn't have them but RefPtr does). These constructors/operators are relied upon in various places throughout WebCore. (WTF::WeakPtr::operator bool): Made non-explicit. (WTF::WeakReference::createUnbound): Deleted. (WTF::WeakReference::bindTo): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: Add WeakPtr API tests. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Added. * TestWebKitAPI/Tests/WTF/Ref.cpp: Update to not use copy constructor. Canonical link: https://commits.webkit.org/158549@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@178615 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-01-17 00:39:57 +00:00
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
WeakPtr& operator=(std::nullptr_t) { m_impl = nullptr; return *this; }
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename U> WeakPtr& operator=(const WeakPtr<U, Counter>&);
template<typename U> WeakPtr& operator=(WeakPtr<U, Counter>&&);
T* operator->() const
{
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
ASSERT(!m_impl || !m_shouldEnableAssertions || m_impl->wasConstructedOnMainThread() == isMainThread());
return get();
}
T& operator*() const
{
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
ASSERT(!m_impl || !m_shouldEnableAssertions || m_impl->wasConstructedOnMainThread() == isMainThread());
return *get();
}
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
void clear() { m_impl = nullptr; }
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
private:
Add WeakHashMap https://bugs.webkit.org/show_bug.cgi?id=226872 Reviewed by Geoffrey Garen. Source/WTF: Added WeakHashMap which deletes entries during rehashing and amortized over time (based on the number of read & write accesses done on a given WeakHashMap instance). * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakHashMap.h: Added. (WTF::WeakHashMap): Added. (WTF::WeakHashMap::PeekKeyValuePairTraits): Added. (WTF::WeakHashMap::PeekType): Added. (WTF::WeakHashMap::PeekPtrType): Added. Unlike a regular HashMap, we need to fake the iterator pointer value with this struct since key-value pair doesn't exist in HashTable itself as it stores Ref<WeakRefImpl> instead. (WTF::WeakHashMap::WeakHashMapIteratorBase): Added. Has a bunch of helper functions so that WeakHashMapIterator and WeakHashMapConstIterator can share the code. (WTF::WeakHashMap::WeakHashMapIterator): Added. (WTF::WeakHashMap::WeakHashMapConstIterator): Added. (WTF::WeakHashMap::AddResult): Added. (WTF::WeakHashMap::begin): Added. (WTF::WeakHashMap::end): Added. (WTF::WeakHashMap::add): Added. (WTF::WeakHashMap::set): Added. (WTF::WeakHashMap::find): Added. (WTF::WeakHashMap::contains): Added. (WTF::WeakHashMap::get): Added. (WTF::WeakHashMap::remove): Added. (WTF::WeakHashMap::removeIf): Added. (WTF::WeakHashMap::clear): Added. (WTF::WeakHashMap::capacity): Added. (WTF::WeakHashMap::isEmptyIgnoringNullReferences): Added. This is akin to WeakHashSet::computesEmpty. Per prior discussion, we intend to rename WeakHashSet's version to this name as well for clarity. Note that this function will clear the hash table completely if the map is semantically empty but HashTable contains null references as keys. (WTF::WeakHashMap::hasNullReferences): Added. Triggers amortized cleanup based on the number of iterations performed. If there are no null references, it resets m_operationCountSinceLastCleanup. (WTF::WeakHashMap::computeSize): Added. (WTF::WeakHashMap::removeNullReferences): Added. Since WeakHashMap doesn't eagerly delete the value when the key goes away, this function should be called when values held onto by WeakRefImpl with the nullptr back pointer should be deleted en masse. (WTF::WeakHashMap::checkConsistency): Added. (WTF::WeakHashMap::makeKeyImpl): Added. (WTF::WeakHashMap::keyImplIfExists): Added. * wtf/WeakPtr.h: Tools: Added unit tests for WeakHashMap. * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::computeSizeOfWeakHashSet): Deleted the unused variant. (WTF_WeakPtr.WeakHashSetExpansion): Deleted the superflous for loop. (TestWebKitAPI::computeSizeOfWeakHashMap): Added. (TestWebKitAPI::ValueObject): Added. (TestWebKitAPI::ValueObject::create): (TestWebKitAPI::ValueObject::~ValueObject): (TestWebKitAPI::ValueObject::ValueObject): (WTF_WeakPtr.WeakHashMapBasic): Added. (WTF_WeakPtr.WeakHashMapConstObjects): Added. (WTF_WeakPtr.WeakHashMapExpansion): Added. (WTF_WeakPtr.WeakHashMapRemoveNullReferences): Added. (TestWebKitAPI::collectKeyValuePairsUsingIterators): Added. (WTF_WeakPtr.WeakHashMapIterators): Added. (WTF_WeakPtr.WeakHashMapAmortizedCleanup): Added. Canonical link: https://commits.webkit.org/238760@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278803 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-12 01:42:09 +00:00
template<typename, typename, typename> friend class WeakHashMap;
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename, typename> friend class WeakHashSet;
template<typename, typename> friend class WeakPtr;
template<typename, typename> friend class WeakPtrFactory;
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
explicit WeakPtr(Ref<WeakPtrImpl<Counter>>&& ref, EnableWeakPtrThreadingAssertions shouldEnableAssertions)
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
: m_impl(WTFMove(ref))
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
#if ASSERT_ENABLED
, m_shouldEnableAssertions(shouldEnableAssertions == EnableWeakPtrThreadingAssertions::Yes)
#endif
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
{
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
UNUSED_PARAM(shouldEnableAssertions);
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
RefPtr<WeakPtrImpl<Counter>> m_impl;
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
#if ASSERT_ENABLED
bool m_shouldEnableAssertions { true };
#endif
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
};
// Note: you probably want to inherit from CanMakeWeakPtr rather than use this directly.
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename Counter = EmptyCounter> class WeakPtrFactory {
WTF_MAKE_NONCOPYABLE(WeakPtrFactory);
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
WTF_MAKE_FAST_ALLOCATED;
public:
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
using CounterType = Counter;
WeakPtrFactory()
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#if ASSERT_ENABLED
: m_wasConstructedOnMainThread(isMainThread())
#endif
{
}
WeakPtrFactory should populate m_ref lazily. https://bugs.webkit.org/show_bug.cgi?id=177375 Reviewed by Geoffrey Garen. Source/WebCore: * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::CDM): * Modules/encryptedmedia/CDM.h: (WebCore::CDM::createWeakPtr): * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::MediaKeys): (WebCore::MediaKeys::createSession): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: (WebCore::MediaDevices::createWeakPtr): * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::MediaStreamTrack): * Modules/mediastream/MediaStreamTrack.h: (WebCore::MediaStreamTrack::createWeakPtr): * accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::AccessibilityRenderObject): * accessibility/AccessibilityRenderObject.h: (WebCore::AccessibilityRenderObject::createWeakPtr): * animation/WebAnimation.cpp: (WebCore::WebAnimation::WebAnimation): * animation/WebAnimation.h: * css/FontFace.cpp: (WebCore::FontFace::FontFace): (WebCore::FontFace::createWeakPtr): (WebCore::FontFace::createWeakPtr const): Deleted. * css/FontFace.h: * css/StyleSheetContents.h: * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::DataTransferItemList): (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/Document.cpp: (WebCore::Document::postTask): * dom/Document.h: (WebCore::Document::createWeakPtr): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::createWeakPtr): * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: (WebCore::HTMLResourcePreloader::HTMLResourcePreloader): (WebCore::HTMLResourcePreloader::createWeakPtr): * loader/LinkLoader.cpp: (WebCore::LinkLoader::LinkLoader): * loader/LinkLoader.h: (WebCore::LinkLoader::createWeakPtr): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * page/DOMWindow.h: * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::TaskDispatcher): (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::GenericTaskQueue): (WebCore::GenericTaskQueue::enqueueTask): * platform/ScrollableArea.h: (WebCore::ScrollableArea::createWeakPtr): * platform/Scrollbar.cpp: (WebCore::Scrollbar::Scrollbar): * platform/Scrollbar.h: (WebCore::Scrollbar::createWeakPtr): * platform/Widget.h: (WebCore::Widget::createWeakPtr): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::FontCascade): * platform/graphics/FontCascade.h: (WebCore::FontCascade::createWeakPtr const): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: (WebCore::MediaPlayerPrivateAVFoundation::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: (WebCore::CDMSessionAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: (WebCore::CDMSessionAVStreamSession::CDMSessionAVStreamSession): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::sizeWillChangeAtTime): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::append): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::TextureCacheCV): (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac): (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/ios/RemoteCommandListenerIOS.h: (WebCore::RemoteCommandListenerIOS::createWeakPtr): * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: (WebCore::RemoteCommandListenerMac::createWeakPtr): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::MediaStreamPrivate): * platform/mediastream/MediaStreamPrivate.h: (WebCore::MediaStreamPrivate::createWeakPtr): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::RealtimeMediaSource): * platform/mediastream/RealtimeMediaSource.h: * platform/mock/MockMediaEndpoint.cpp: (WebCore::MockMediaEndpoint::MockMediaEndpoint): (WebCore::MockMediaEndpoint::generateDtlsInfo): * rendering/RenderMultiColumnSpannerPlaceholder.cpp: (WebCore::RenderMultiColumnSpannerPlaceholder::RenderMultiColumnSpannerPlaceholder): * rendering/RenderMultiColumnSpannerPlaceholder.h: * rendering/RenderView.cpp: (WebCore::RenderView::RenderView): * rendering/RenderView.h: * rendering/RenderWidget.cpp: (WebCore::RenderWidget::RenderWidget): * rendering/RenderWidget.h: (WebCore::RenderWidget::createWeakPtr): * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::RootInlineBox): * rendering/RootInlineBox.h: (WebCore::RootInlineBox::createWeakPtr): * svg/SVGPathElement.cpp: (WebCore::SVGPathElement::SVGPathElement): * svg/SVGPathElement.h: * svg/properties/SVGMatrixTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::MockCDMFactory): (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::MockCDM): (WebCore::MockCDM::createInstance): (WebCore::m_weakPtrFactory): Deleted. Source/WebCore/PAL: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy): (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::createWeakPtr): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::WebViewImpl): * UIProcess/Launcher/ProcessLauncher.cpp: (WebKit::ProcessLauncher::ProcessLauncher): * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: (WebKit::ProcessAssertion::createWeakPtr): * UIProcess/WebPageProxy.cpp: (WebKit::m_configurationPreferenceValues): (WebKit::m_weakPtrFactory): Deleted. * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::createWeakPtr const): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: (WebKit::RemoteLayerTreeDrawingArea::createWeakPtr): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea): Source/WebKitLegacy/mac: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::WebEditorClient): (WebEditorClient::requestCandidatesForSelection): Source/WTF: This helps us with the overhead of initializing WeakPtrFactory for objects that rarely end up creating the weak reference. -This is in preparation for introducing WeakPtr to RenderObject. All credit to Geoffrey Garen. * wtf/WeakPtr.h: (WTF::WeakReference::get const): (WTF::WeakReference::clear): (WTF::WeakReference::WeakReference): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-23 04:38:45 +00:00
~WeakPtrFactory()
{
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
if (!m_impl)
WeakPtrFactory should populate m_ref lazily. https://bugs.webkit.org/show_bug.cgi?id=177375 Reviewed by Geoffrey Garen. Source/WebCore: * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::CDM): * Modules/encryptedmedia/CDM.h: (WebCore::CDM::createWeakPtr): * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::MediaKeys): (WebCore::MediaKeys::createSession): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: (WebCore::MediaDevices::createWeakPtr): * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::MediaStreamTrack): * Modules/mediastream/MediaStreamTrack.h: (WebCore::MediaStreamTrack::createWeakPtr): * accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::AccessibilityRenderObject): * accessibility/AccessibilityRenderObject.h: (WebCore::AccessibilityRenderObject::createWeakPtr): * animation/WebAnimation.cpp: (WebCore::WebAnimation::WebAnimation): * animation/WebAnimation.h: * css/FontFace.cpp: (WebCore::FontFace::FontFace): (WebCore::FontFace::createWeakPtr): (WebCore::FontFace::createWeakPtr const): Deleted. * css/FontFace.h: * css/StyleSheetContents.h: * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::DataTransferItemList): (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/Document.cpp: (WebCore::Document::postTask): * dom/Document.h: (WebCore::Document::createWeakPtr): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::createWeakPtr): * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: (WebCore::HTMLResourcePreloader::HTMLResourcePreloader): (WebCore::HTMLResourcePreloader::createWeakPtr): * loader/LinkLoader.cpp: (WebCore::LinkLoader::LinkLoader): * loader/LinkLoader.h: (WebCore::LinkLoader::createWeakPtr): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * page/DOMWindow.h: * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::TaskDispatcher): (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::GenericTaskQueue): (WebCore::GenericTaskQueue::enqueueTask): * platform/ScrollableArea.h: (WebCore::ScrollableArea::createWeakPtr): * platform/Scrollbar.cpp: (WebCore::Scrollbar::Scrollbar): * platform/Scrollbar.h: (WebCore::Scrollbar::createWeakPtr): * platform/Widget.h: (WebCore::Widget::createWeakPtr): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::FontCascade): * platform/graphics/FontCascade.h: (WebCore::FontCascade::createWeakPtr const): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: (WebCore::MediaPlayerPrivateAVFoundation::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: (WebCore::CDMSessionAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: (WebCore::CDMSessionAVStreamSession::CDMSessionAVStreamSession): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::sizeWillChangeAtTime): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::append): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::TextureCacheCV): (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac): (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/ios/RemoteCommandListenerIOS.h: (WebCore::RemoteCommandListenerIOS::createWeakPtr): * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: (WebCore::RemoteCommandListenerMac::createWeakPtr): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::MediaStreamPrivate): * platform/mediastream/MediaStreamPrivate.h: (WebCore::MediaStreamPrivate::createWeakPtr): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::RealtimeMediaSource): * platform/mediastream/RealtimeMediaSource.h: * platform/mock/MockMediaEndpoint.cpp: (WebCore::MockMediaEndpoint::MockMediaEndpoint): (WebCore::MockMediaEndpoint::generateDtlsInfo): * rendering/RenderMultiColumnSpannerPlaceholder.cpp: (WebCore::RenderMultiColumnSpannerPlaceholder::RenderMultiColumnSpannerPlaceholder): * rendering/RenderMultiColumnSpannerPlaceholder.h: * rendering/RenderView.cpp: (WebCore::RenderView::RenderView): * rendering/RenderView.h: * rendering/RenderWidget.cpp: (WebCore::RenderWidget::RenderWidget): * rendering/RenderWidget.h: (WebCore::RenderWidget::createWeakPtr): * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::RootInlineBox): * rendering/RootInlineBox.h: (WebCore::RootInlineBox::createWeakPtr): * svg/SVGPathElement.cpp: (WebCore::SVGPathElement::SVGPathElement): * svg/SVGPathElement.h: * svg/properties/SVGMatrixTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::MockCDMFactory): (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::MockCDM): (WebCore::MockCDM::createInstance): (WebCore::m_weakPtrFactory): Deleted. Source/WebCore/PAL: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy): (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::createWeakPtr): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::WebViewImpl): * UIProcess/Launcher/ProcessLauncher.cpp: (WebKit::ProcessLauncher::ProcessLauncher): * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: (WebKit::ProcessAssertion::createWeakPtr): * UIProcess/WebPageProxy.cpp: (WebKit::m_configurationPreferenceValues): (WebKit::m_weakPtrFactory): Deleted. * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::createWeakPtr const): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: (WebKit::RemoteLayerTreeDrawingArea::createWeakPtr): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea): Source/WebKitLegacy/mac: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::WebEditorClient): (WebEditorClient::requestCandidatesForSelection): Source/WTF: This helps us with the overhead of initializing WeakPtrFactory for objects that rarely end up creating the weak reference. -This is in preparation for introducing WeakPtr to RenderObject. All credit to Geoffrey Garen. * wtf/WeakPtr.h: (WTF::WeakReference::get const): (WTF::WeakReference::clear): (WTF::WeakReference::WeakReference): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-23 04:38:45 +00:00
return;
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
m_impl->clear();
WeakPtrFactory should populate m_ref lazily. https://bugs.webkit.org/show_bug.cgi?id=177375 Reviewed by Geoffrey Garen. Source/WebCore: * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::CDM): * Modules/encryptedmedia/CDM.h: (WebCore::CDM::createWeakPtr): * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::MediaKeys): (WebCore::MediaKeys::createSession): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: (WebCore::MediaDevices::createWeakPtr): * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::MediaStreamTrack): * Modules/mediastream/MediaStreamTrack.h: (WebCore::MediaStreamTrack::createWeakPtr): * accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::AccessibilityRenderObject): * accessibility/AccessibilityRenderObject.h: (WebCore::AccessibilityRenderObject::createWeakPtr): * animation/WebAnimation.cpp: (WebCore::WebAnimation::WebAnimation): * animation/WebAnimation.h: * css/FontFace.cpp: (WebCore::FontFace::FontFace): (WebCore::FontFace::createWeakPtr): (WebCore::FontFace::createWeakPtr const): Deleted. * css/FontFace.h: * css/StyleSheetContents.h: * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::DataTransferItemList): (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/Document.cpp: (WebCore::Document::postTask): * dom/Document.h: (WebCore::Document::createWeakPtr): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::createWeakPtr): * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: (WebCore::HTMLResourcePreloader::HTMLResourcePreloader): (WebCore::HTMLResourcePreloader::createWeakPtr): * loader/LinkLoader.cpp: (WebCore::LinkLoader::LinkLoader): * loader/LinkLoader.h: (WebCore::LinkLoader::createWeakPtr): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * page/DOMWindow.h: * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::TaskDispatcher): (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::GenericTaskQueue): (WebCore::GenericTaskQueue::enqueueTask): * platform/ScrollableArea.h: (WebCore::ScrollableArea::createWeakPtr): * platform/Scrollbar.cpp: (WebCore::Scrollbar::Scrollbar): * platform/Scrollbar.h: (WebCore::Scrollbar::createWeakPtr): * platform/Widget.h: (WebCore::Widget::createWeakPtr): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::FontCascade): * platform/graphics/FontCascade.h: (WebCore::FontCascade::createWeakPtr const): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: (WebCore::MediaPlayerPrivateAVFoundation::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: (WebCore::CDMSessionAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: (WebCore::CDMSessionAVStreamSession::CDMSessionAVStreamSession): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::sizeWillChangeAtTime): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::append): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::TextureCacheCV): (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac): (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/ios/RemoteCommandListenerIOS.h: (WebCore::RemoteCommandListenerIOS::createWeakPtr): * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: (WebCore::RemoteCommandListenerMac::createWeakPtr): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::MediaStreamPrivate): * platform/mediastream/MediaStreamPrivate.h: (WebCore::MediaStreamPrivate::createWeakPtr): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::RealtimeMediaSource): * platform/mediastream/RealtimeMediaSource.h: * platform/mock/MockMediaEndpoint.cpp: (WebCore::MockMediaEndpoint::MockMediaEndpoint): (WebCore::MockMediaEndpoint::generateDtlsInfo): * rendering/RenderMultiColumnSpannerPlaceholder.cpp: (WebCore::RenderMultiColumnSpannerPlaceholder::RenderMultiColumnSpannerPlaceholder): * rendering/RenderMultiColumnSpannerPlaceholder.h: * rendering/RenderView.cpp: (WebCore::RenderView::RenderView): * rendering/RenderView.h: * rendering/RenderWidget.cpp: (WebCore::RenderWidget::RenderWidget): * rendering/RenderWidget.h: (WebCore::RenderWidget::createWeakPtr): * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::RootInlineBox): * rendering/RootInlineBox.h: (WebCore::RootInlineBox::createWeakPtr): * svg/SVGPathElement.cpp: (WebCore::SVGPathElement::SVGPathElement): * svg/SVGPathElement.h: * svg/properties/SVGMatrixTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::MockCDMFactory): (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::MockCDM): (WebCore::MockCDM::createInstance): (WebCore::m_weakPtrFactory): Deleted. Source/WebCore/PAL: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy): (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::createWeakPtr): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::WebViewImpl): * UIProcess/Launcher/ProcessLauncher.cpp: (WebKit::ProcessLauncher::ProcessLauncher): * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: (WebKit::ProcessAssertion::createWeakPtr): * UIProcess/WebPageProxy.cpp: (WebKit::m_configurationPreferenceValues): (WebKit::m_weakPtrFactory): Deleted. * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::createWeakPtr const): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: (WebKit::RemoteLayerTreeDrawingArea::createWeakPtr): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea): Source/WebKitLegacy/mac: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::WebEditorClient): (WebEditorClient::requestCandidatesForSelection): Source/WTF: This helps us with the overhead of initializing WeakPtrFactory for objects that rarely end up creating the weak reference. -This is in preparation for introducing WeakPtr to RenderObject. All credit to Geoffrey Garen. * wtf/WeakPtr.h: (WTF::WeakReference::get const): (WTF::WeakReference::clear): (WTF::WeakReference::WeakReference): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-23 04:38:45 +00:00
}
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
void initializeIfNeeded(const T& object) const
WeakPtrFactory should populate m_ref lazily. https://bugs.webkit.org/show_bug.cgi?id=177375 Reviewed by Geoffrey Garen. Source/WebCore: * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::CDM): * Modules/encryptedmedia/CDM.h: (WebCore::CDM::createWeakPtr): * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::MediaKeys): (WebCore::MediaKeys::createSession): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: (WebCore::MediaDevices::createWeakPtr): * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::MediaStreamTrack): * Modules/mediastream/MediaStreamTrack.h: (WebCore::MediaStreamTrack::createWeakPtr): * accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::AccessibilityRenderObject): * accessibility/AccessibilityRenderObject.h: (WebCore::AccessibilityRenderObject::createWeakPtr): * animation/WebAnimation.cpp: (WebCore::WebAnimation::WebAnimation): * animation/WebAnimation.h: * css/FontFace.cpp: (WebCore::FontFace::FontFace): (WebCore::FontFace::createWeakPtr): (WebCore::FontFace::createWeakPtr const): Deleted. * css/FontFace.h: * css/StyleSheetContents.h: * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::DataTransferItemList): (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/Document.cpp: (WebCore::Document::postTask): * dom/Document.h: (WebCore::Document::createWeakPtr): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::createWeakPtr): * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: (WebCore::HTMLResourcePreloader::HTMLResourcePreloader): (WebCore::HTMLResourcePreloader::createWeakPtr): * loader/LinkLoader.cpp: (WebCore::LinkLoader::LinkLoader): * loader/LinkLoader.h: (WebCore::LinkLoader::createWeakPtr): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * page/DOMWindow.h: * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::TaskDispatcher): (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::GenericTaskQueue): (WebCore::GenericTaskQueue::enqueueTask): * platform/ScrollableArea.h: (WebCore::ScrollableArea::createWeakPtr): * platform/Scrollbar.cpp: (WebCore::Scrollbar::Scrollbar): * platform/Scrollbar.h: (WebCore::Scrollbar::createWeakPtr): * platform/Widget.h: (WebCore::Widget::createWeakPtr): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::FontCascade): * platform/graphics/FontCascade.h: (WebCore::FontCascade::createWeakPtr const): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: (WebCore::MediaPlayerPrivateAVFoundation::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: (WebCore::CDMSessionAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: (WebCore::CDMSessionAVStreamSession::CDMSessionAVStreamSession): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::sizeWillChangeAtTime): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::append): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::TextureCacheCV): (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac): (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/ios/RemoteCommandListenerIOS.h: (WebCore::RemoteCommandListenerIOS::createWeakPtr): * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: (WebCore::RemoteCommandListenerMac::createWeakPtr): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::MediaStreamPrivate): * platform/mediastream/MediaStreamPrivate.h: (WebCore::MediaStreamPrivate::createWeakPtr): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::RealtimeMediaSource): * platform/mediastream/RealtimeMediaSource.h: * platform/mock/MockMediaEndpoint.cpp: (WebCore::MockMediaEndpoint::MockMediaEndpoint): (WebCore::MockMediaEndpoint::generateDtlsInfo): * rendering/RenderMultiColumnSpannerPlaceholder.cpp: (WebCore::RenderMultiColumnSpannerPlaceholder::RenderMultiColumnSpannerPlaceholder): * rendering/RenderMultiColumnSpannerPlaceholder.h: * rendering/RenderView.cpp: (WebCore::RenderView::RenderView): * rendering/RenderView.h: * rendering/RenderWidget.cpp: (WebCore::RenderWidget::RenderWidget): * rendering/RenderWidget.h: (WebCore::RenderWidget::createWeakPtr): * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::RootInlineBox): * rendering/RootInlineBox.h: (WebCore::RootInlineBox::createWeakPtr): * svg/SVGPathElement.cpp: (WebCore::SVGPathElement::SVGPathElement): * svg/SVGPathElement.h: * svg/properties/SVGMatrixTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::MockCDMFactory): (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::MockCDM): (WebCore::MockCDM::createInstance): (WebCore::m_weakPtrFactory): Deleted. Source/WebCore/PAL: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy): (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::createWeakPtr): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::WebViewImpl): * UIProcess/Launcher/ProcessLauncher.cpp: (WebKit::ProcessLauncher::ProcessLauncher): * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: (WebKit::ProcessAssertion::createWeakPtr): * UIProcess/WebPageProxy.cpp: (WebKit::m_configurationPreferenceValues): (WebKit::m_weakPtrFactory): Deleted. * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::createWeakPtr const): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: (WebKit::RemoteLayerTreeDrawingArea::createWeakPtr): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea): Source/WebKitLegacy/mac: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::WebEditorClient): (WebEditorClient::requestCandidatesForSelection): Source/WTF: This helps us with the overhead of initializing WeakPtrFactory for objects that rarely end up creating the weak reference. -This is in preparation for introducing WeakPtr to RenderObject. All credit to Geoffrey Garen. * wtf/WeakPtr.h: (WTF::WeakReference::get const): (WTF::WeakReference::clear): (WTF::WeakReference::WeakReference): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-23 04:38:45 +00:00
{
if (m_impl)
return;
ASSERT(m_wasConstructedOnMainThread == isMainThread());
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
m_impl = WeakPtrImpl<Counter>::create(const_cast<T*>(&object));
WeakPtrFactory should populate m_ref lazily. https://bugs.webkit.org/show_bug.cgi?id=177375 Reviewed by Geoffrey Garen. Source/WebCore: * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::CDM): * Modules/encryptedmedia/CDM.h: (WebCore::CDM::createWeakPtr): * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::MediaKeys): (WebCore::MediaKeys::createSession): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: (WebCore::MediaDevices::createWeakPtr): * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::MediaStreamTrack): * Modules/mediastream/MediaStreamTrack.h: (WebCore::MediaStreamTrack::createWeakPtr): * accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::AccessibilityRenderObject): * accessibility/AccessibilityRenderObject.h: (WebCore::AccessibilityRenderObject::createWeakPtr): * animation/WebAnimation.cpp: (WebCore::WebAnimation::WebAnimation): * animation/WebAnimation.h: * css/FontFace.cpp: (WebCore::FontFace::FontFace): (WebCore::FontFace::createWeakPtr): (WebCore::FontFace::createWeakPtr const): Deleted. * css/FontFace.h: * css/StyleSheetContents.h: * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::DataTransferItemList): (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/Document.cpp: (WebCore::Document::postTask): * dom/Document.h: (WebCore::Document::createWeakPtr): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::createWeakPtr): * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: (WebCore::HTMLResourcePreloader::HTMLResourcePreloader): (WebCore::HTMLResourcePreloader::createWeakPtr): * loader/LinkLoader.cpp: (WebCore::LinkLoader::LinkLoader): * loader/LinkLoader.h: (WebCore::LinkLoader::createWeakPtr): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * page/DOMWindow.h: * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::TaskDispatcher): (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::GenericTaskQueue): (WebCore::GenericTaskQueue::enqueueTask): * platform/ScrollableArea.h: (WebCore::ScrollableArea::createWeakPtr): * platform/Scrollbar.cpp: (WebCore::Scrollbar::Scrollbar): * platform/Scrollbar.h: (WebCore::Scrollbar::createWeakPtr): * platform/Widget.h: (WebCore::Widget::createWeakPtr): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::FontCascade): * platform/graphics/FontCascade.h: (WebCore::FontCascade::createWeakPtr const): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: (WebCore::MediaPlayerPrivateAVFoundation::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: (WebCore::CDMSessionAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: (WebCore::CDMSessionAVStreamSession::CDMSessionAVStreamSession): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::sizeWillChangeAtTime): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::append): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::TextureCacheCV): (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac): (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/ios/RemoteCommandListenerIOS.h: (WebCore::RemoteCommandListenerIOS::createWeakPtr): * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: (WebCore::RemoteCommandListenerMac::createWeakPtr): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::MediaStreamPrivate): * platform/mediastream/MediaStreamPrivate.h: (WebCore::MediaStreamPrivate::createWeakPtr): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::RealtimeMediaSource): * platform/mediastream/RealtimeMediaSource.h: * platform/mock/MockMediaEndpoint.cpp: (WebCore::MockMediaEndpoint::MockMediaEndpoint): (WebCore::MockMediaEndpoint::generateDtlsInfo): * rendering/RenderMultiColumnSpannerPlaceholder.cpp: (WebCore::RenderMultiColumnSpannerPlaceholder::RenderMultiColumnSpannerPlaceholder): * rendering/RenderMultiColumnSpannerPlaceholder.h: * rendering/RenderView.cpp: (WebCore::RenderView::RenderView): * rendering/RenderView.h: * rendering/RenderWidget.cpp: (WebCore::RenderWidget::RenderWidget): * rendering/RenderWidget.h: (WebCore::RenderWidget::createWeakPtr): * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::RootInlineBox): * rendering/RootInlineBox.h: (WebCore::RootInlineBox::createWeakPtr): * svg/SVGPathElement.cpp: (WebCore::SVGPathElement::SVGPathElement): * svg/SVGPathElement.h: * svg/properties/SVGMatrixTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::MockCDMFactory): (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::MockCDM): (WebCore::MockCDM::createInstance): (WebCore::m_weakPtrFactory): Deleted. Source/WebCore/PAL: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy): (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::createWeakPtr): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::WebViewImpl): * UIProcess/Launcher/ProcessLauncher.cpp: (WebKit::ProcessLauncher::ProcessLauncher): * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: (WebKit::ProcessAssertion::createWeakPtr): * UIProcess/WebPageProxy.cpp: (WebKit::m_configurationPreferenceValues): (WebKit::m_weakPtrFactory): Deleted. * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::createWeakPtr const): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: (WebKit::RemoteLayerTreeDrawingArea::createWeakPtr): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea): Source/WebKitLegacy/mac: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::WebEditorClient): (WebEditorClient::requestCandidatesForSelection): Source/WTF: This helps us with the overhead of initializing WeakPtrFactory for objects that rarely end up creating the weak reference. -This is in preparation for introducing WeakPtr to RenderObject. All credit to Geoffrey Garen. * wtf/WeakPtr.h: (WTF::WeakReference::get const): (WTF::WeakReference::clear): (WTF::WeakReference::WeakReference): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-23 04:38:45 +00:00
}
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
template<typename U> WeakPtr<U, Counter> createWeakPtr(U& object, EnableWeakPtrThreadingAssertions enableWeakPtrThreadingAssertions = EnableWeakPtrThreadingAssertions::Yes) const
{
initializeIfNeeded(object);
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
ASSERT(&object == m_impl->template get<T>());
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
return WeakPtr<U, Counter>(makeRef(*m_impl), enableWeakPtrThreadingAssertions);
}
BackgroundHTMLParser::sendTokensToMainThread should use bind https://bugs.webkit.org/show_bug.cgi?id=107637 Reviewed by Eric Seidel. Source/WebCore: This patch replaces our hand-written implementation of bind for didReceiveTokensFromBackgroundParser with bind from Functional.h. To use the generic version of bind, we need to switch to using WeakPtr to hold a reference to the main thread parser in the BackgroundHTMLParser. * html/parser/BackgroundHTMLParser.cpp: (WebCore::BackgroundHTMLParser::BackgroundHTMLParser): (WebCore::BackgroundHTMLParser::sendTokensToMainThread): (WebCore::BackgroundHTMLParser::createPartial): * html/parser/BackgroundHTMLParser.h: (WebCore::BackgroundHTMLParser::create): (BackgroundHTMLParser): (ParserMap): * html/parser/HTMLDocumentParser.cpp: (WebCore::HTMLDocumentParser::HTMLDocumentParser): (WebCore::HTMLDocumentParser::startBackgroundParser): (WebCore::HTMLDocumentParser::stopBackgroundParser): * html/parser/HTMLDocumentParser.h: (HTMLDocumentParser): Source/WTF: * wtf/Functional.h: - I had to re-work the approach to validating WeakPtr |this| arguments a bit. Previously you couldn't pass a WeakPtr as a non-|this| argument to a function because we would try to unwrap it into a raw pointer. * wtf/WeakPtr.h: (WTF::WeakPtrFactory::revokeAll): (WeakPtrFactory): - Let clients revoke all outstanding WeakPtrs without needing to destroy the WeakPtrFactory. * wtf/chromium/MainThreadChromium.cpp: (WTF::callFunctionObject): (WTF::callOnMainThread): - Implement callOnMainThread for Function objects. The non-Chromium implementation of MainThread.cpp already implements this feature. Canonical link: https://commits.webkit.org/125924@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@140589 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-23 22:15:54 +00:00
void revokeAll()
{
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
if (!m_impl)
WeakPtrFactory should populate m_ref lazily. https://bugs.webkit.org/show_bug.cgi?id=177375 Reviewed by Geoffrey Garen. Source/WebCore: * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::CDM): * Modules/encryptedmedia/CDM.h: (WebCore::CDM::createWeakPtr): * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::MediaKeys): (WebCore::MediaKeys::createSession): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: (WebCore::MediaDevices::createWeakPtr): * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::MediaStreamTrack): * Modules/mediastream/MediaStreamTrack.h: (WebCore::MediaStreamTrack::createWeakPtr): * accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::AccessibilityRenderObject): * accessibility/AccessibilityRenderObject.h: (WebCore::AccessibilityRenderObject::createWeakPtr): * animation/WebAnimation.cpp: (WebCore::WebAnimation::WebAnimation): * animation/WebAnimation.h: * css/FontFace.cpp: (WebCore::FontFace::FontFace): (WebCore::FontFace::createWeakPtr): (WebCore::FontFace::createWeakPtr const): Deleted. * css/FontFace.h: * css/StyleSheetContents.h: * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::DataTransferItemList): (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/Document.cpp: (WebCore::Document::postTask): * dom/Document.h: (WebCore::Document::createWeakPtr): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): * html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::createWeakPtr): * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: (WebCore::HTMLResourcePreloader::HTMLResourcePreloader): (WebCore::HTMLResourcePreloader::createWeakPtr): * loader/LinkLoader.cpp: (WebCore::LinkLoader::LinkLoader): * loader/LinkLoader.h: (WebCore::LinkLoader::createWeakPtr): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * page/DOMWindow.h: * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::TaskDispatcher): (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::GenericTaskQueue): (WebCore::GenericTaskQueue::enqueueTask): * platform/ScrollableArea.h: (WebCore::ScrollableArea::createWeakPtr): * platform/Scrollbar.cpp: (WebCore::Scrollbar::Scrollbar): * platform/Scrollbar.h: (WebCore::Scrollbar::createWeakPtr): * platform/Widget.h: (WebCore::Widget::createWeakPtr): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::FontCascade): * platform/graphics/FontCascade.h: (WebCore::FontCascade::createWeakPtr const): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: (WebCore::MediaPlayerPrivateAVFoundation::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: (WebCore::CDMSessionAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: (WebCore::CDMSessionAVStreamSession::CDMSessionAVStreamSession): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::sizeWillChangeAtTime): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::append): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::TextureCacheCV): (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac): (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/ios/RemoteCommandListenerIOS.h: (WebCore::RemoteCommandListenerIOS::createWeakPtr): * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: (WebCore::RemoteCommandListenerMac::createWeakPtr): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::MediaStreamPrivate): * platform/mediastream/MediaStreamPrivate.h: (WebCore::MediaStreamPrivate::createWeakPtr): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::RealtimeMediaSource): * platform/mediastream/RealtimeMediaSource.h: * platform/mock/MockMediaEndpoint.cpp: (WebCore::MockMediaEndpoint::MockMediaEndpoint): (WebCore::MockMediaEndpoint::generateDtlsInfo): * rendering/RenderMultiColumnSpannerPlaceholder.cpp: (WebCore::RenderMultiColumnSpannerPlaceholder::RenderMultiColumnSpannerPlaceholder): * rendering/RenderMultiColumnSpannerPlaceholder.h: * rendering/RenderView.cpp: (WebCore::RenderView::RenderView): * rendering/RenderView.h: * rendering/RenderWidget.cpp: (WebCore::RenderWidget::RenderWidget): * rendering/RenderWidget.h: (WebCore::RenderWidget::createWeakPtr): * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::RootInlineBox): * rendering/RootInlineBox.h: (WebCore::RootInlineBox::createWeakPtr): * svg/SVGPathElement.cpp: (WebCore::SVGPathElement::SVGPathElement): * svg/SVGPathElement.h: * svg/properties/SVGMatrixTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::MockCDMFactory): (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::MockCDM): (WebCore::MockCDM::createInstance): (WebCore::m_weakPtrFactory): Deleted. Source/WebCore/PAL: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy): (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/WebViewImpl.h: (WebKit::WebViewImpl::createWeakPtr): * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::WebViewImpl): * UIProcess/Launcher/ProcessLauncher.cpp: (WebKit::ProcessLauncher::ProcessLauncher): * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: (WebKit::ProcessAssertion::createWeakPtr): * UIProcess/WebPageProxy.cpp: (WebKit::m_configurationPreferenceValues): (WebKit::m_weakPtrFactory): Deleted. * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::createWeakPtr const): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: (WebKit::RemoteLayerTreeDrawingArea::createWeakPtr): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea): Source/WebKitLegacy/mac: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::WebEditorClient): (WebEditorClient::requestCandidatesForSelection): Source/WTF: This helps us with the overhead of initializing WeakPtrFactory for objects that rarely end up creating the weak reference. -This is in preparation for introducing WeakPtr to RenderObject. All credit to Geoffrey Garen. * wtf/WeakPtr.h: (WTF::WeakReference::get const): (WTF::WeakReference::clear): (WTF::WeakReference::WeakReference): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::WeakPtrFactory): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/193718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-23 04:38:45 +00:00
return;
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
m_impl->clear();
m_impl = nullptr;
BackgroundHTMLParser::sendTokensToMainThread should use bind https://bugs.webkit.org/show_bug.cgi?id=107637 Reviewed by Eric Seidel. Source/WebCore: This patch replaces our hand-written implementation of bind for didReceiveTokensFromBackgroundParser with bind from Functional.h. To use the generic version of bind, we need to switch to using WeakPtr to hold a reference to the main thread parser in the BackgroundHTMLParser. * html/parser/BackgroundHTMLParser.cpp: (WebCore::BackgroundHTMLParser::BackgroundHTMLParser): (WebCore::BackgroundHTMLParser::sendTokensToMainThread): (WebCore::BackgroundHTMLParser::createPartial): * html/parser/BackgroundHTMLParser.h: (WebCore::BackgroundHTMLParser::create): (BackgroundHTMLParser): (ParserMap): * html/parser/HTMLDocumentParser.cpp: (WebCore::HTMLDocumentParser::HTMLDocumentParser): (WebCore::HTMLDocumentParser::startBackgroundParser): (WebCore::HTMLDocumentParser::stopBackgroundParser): * html/parser/HTMLDocumentParser.h: (HTMLDocumentParser): Source/WTF: * wtf/Functional.h: - I had to re-work the approach to validating WeakPtr |this| arguments a bit. Previously you couldn't pass a WeakPtr as a non-|this| argument to a function because we would try to unwrap it into a raw pointer. * wtf/WeakPtr.h: (WTF::WeakPtrFactory::revokeAll): (WeakPtrFactory): - Let clients revoke all outstanding WeakPtrs without needing to destroy the WeakPtrFactory. * wtf/chromium/MainThreadChromium.cpp: (WTF::callFunctionObject): (WTF::callOnMainThread): - Implement callOnMainThread for Function objects. The non-Chromium implementation of MainThread.cpp already implements this feature. Canonical link: https://commits.webkit.org/125924@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@140589 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-23 22:15:54 +00:00
}
Drop legacy MainThreadTaskQueue & EventLoopTaskQueue classes https://bugs.webkit.org/show_bug.cgi?id=226734 Reviewed by Ryosuke Niwa. Source/WebCore: Drop legacy MainThreadTaskQueue & EventLoopTaskQueue classes. Code that was using MainThreadTaskQueue is now calling callOnMainThread() directly. Call that was using EventLoopTaskQueue is now using the HTML event loop directly. If said code needed to cancel tasks or check if a previously scheduled task is still pending, it now relies on WTF::CancellableTask / WTF::TaskCancellationGroup to do so. * Headers.cmake: * Modules/encryptedmedia/MediaKeySystemAccess.cpp: * WebCore.xcodeproj/project.pbxproj: * animation/DocumentTimelinesController.cpp: (WebCore::DocumentTimelinesController::cacheCurrentTime): (WebCore::DocumentTimelinesController::maybeClearCachedCurrentTime): * animation/DocumentTimelinesController.h: * dom/ActiveDOMObject.h: * dom/Document.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::HTMLMediaElement): (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::scheduleNextSourceChild): (WebCore::HTMLMediaElement::scheduleCheckPlaybackTargetCompatability): (WebCore::HTMLMediaElement::seekWithTolerance): (WebCore::HTMLMediaElement::setVolume): (WebCore::HTMLMediaElement::scheduleConfigureTextTracks): (WebCore::HTMLMediaElement::scheduleMediaEngineWasUpdated): (WebCore::HTMLMediaElement::scheduleUpdatePlayState): (WebCore::HTMLMediaElement::cancelPendingTasks): (WebCore::HTMLMediaElement::clearMediaPlayer): (WebCore::HTMLMediaElement::closeTaskQueues): (WebCore::HTMLMediaElement::suspend): (WebCore::HTMLMediaElement::resume): (WebCore::HTMLMediaElement::virtualHasPendingActivity const): (WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): (WebCore::HTMLMediaElement::mediaPlayerBufferedTimeRangesChanged): (WebCore::HTMLMediaElement::scheduleUpdateMediaState): (WebCore::HTMLMediaElement::playbackControlsManagerBehaviorRestrictionsTimerFired): * html/HTMLMediaElement.h: * platform/GenericTaskQueue.h: Removed. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (-[WebCoreAVFMovieObserver metadataLoaded]): (-[WebCoreAVFMovieObserver didEnd:]): (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): (-[WebCoreAVFMovieObserver legibleOutput:didOutputAttributedStrings:nativeSampleBuffers:forItemTime:]): (-[WebCoreAVFMovieObserver outputSequenceWasFlushed:]): (-[WebCoreAVFMovieObserver metadataOutput:didOutputTimedMetadataGroups:fromPlayerItemTrack:]): (-[WebCoreAVFMovieObserver metadataCollector:didCollectDateRangeMetadataGroups:indexesOfNewGroups:indexesOfModifiedGroups:]): (-[WebCoreAVFLoaderDelegate resourceLoader:shouldWaitForLoadingOfRequestedResource:]): (-[WebCoreAVFLoaderDelegate resourceLoader:didCancelLoadingRequest:]): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::~SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::didParseInitializationData): (WebCore::SourceBufferPrivateAVFObjC::abort): * platform/mediastream/ios/AVAudioSessionCaptureDeviceManager.h: Source/WTF: We recently introduced the WTF::CancellableTask in order to be able to cancel a pending task in the event loop, and/or check if the task is still pending. It worked great as a replacement for EventLoopDeferrableTask. However, it was insufficient as a replacement for task queues (such as MainThreadTaskQueue & EventLoopTaskQueue) since there was no convenient way to cancel a group of tasks. To address this, I am introducing WTF::TaskCancellationGroup. Whenever one needs to create a CancellableTask, it now needs to provide a TaskCancellationGroup. Several CancellableTask objects can share the same TaskCancellationGroup. Code now now schedule one or more CancellableTasks on the event loop and hold on to a TaskCancellationGroup. If they need to cancel those tasks, they can simply call cancel() on the TaskCancellationGroup. They can also check if previously scheduled tasks are still pending via TaskCancellationGroup::hasPendingTask(). * wtf/CancellableTask.h: (WTF::TaskCancellationGroup::TaskCancellationGroup): (WTF::TaskCancellationGroup::cancel): (WTF::TaskCancellationGroup::hasPendingTask const): (WTF::TaskCancellationGroup::Impl::cancel): (WTF::TaskCancellationGroup::Impl::hasPendingTask const): (WTF::TaskCancellationGroup::Handle::isCancelled const): (WTF::TaskCancellationGroup::Handle::Handle): (WTF::TaskCancellationGroup::createHandle): (WTF::CancellableTask::CancellableTask): (WTF::CancellableTask::operator()): * wtf/WeakPtr.h: (WTF::WeakPtrFactory::weakPtrCount const): Canonical link: https://commits.webkit.org/238574@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278580 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-08 00:29:50 +00:00
unsigned weakPtrCount() const { return m_impl ? m_impl->refCount() - 1 : 0; }
Reduce the overhead of DocumentFragment in innerHTML & outerHTML https://bugs.webkit.org/show_bug.cgi?id=221535 <rdar://problem/73861015> Reviewed by Geoffrey Garen. Source/WebCore: This patch reduces the overhead of using DocumentFragment in innerHTMl and outerHTML setters by 1. Cache DocumentFragment used for innerHTML and outerHTML. 2. Adding a fast path to removeAllChildrenWithScriptAssertion when removing child nodes from (1) immediately before appending it to the new parent. This is safe for now since no DOM nodes or API store information about its root node or parent node when it's DocumentFragment, and and there are no node flags to be updated or invalidated since we're removing already-disconnected nodes to which no script ever had access up until this point. We release-assert these conditions before going into the fast path. No new tests since there should be no observable behavior change. * dom/ContainerNode.cpp: (WebCore::ContainerNode::removeAllChildrenWithScriptAssertion): Added a fast path. See above. * dom/Document.cpp: (WebCore::Document::commonTeardown): Clear m_documentFragmentForInnerOuterHTML as it would keep the ownewr document (this Document) alive otherwise. (WebCore::Document::documentFragmentForInnerOuterHTML): Added. Lazily create a DocumentFragment used to parse the fragment for innerHTML and outerHTML setters. Remove any child nodes left in the document fragment in the case the last call to replaceChildrenWithFragment took a fast path for a single text node, which case we don't remove any child nodes from DocumentFragment. * dom/Document.h: * dom/DocumentFragment.h: (WebCore::DocumentFragment::setIsDocumentFragmentForInnerOuterHTML): Added. * dom/Node.h: (WebCore::Node::isDocumentFragmentForInnerOuterHTML const): Added. * editing/markup.cpp: (WebCore::createFragmentForMarkup): Extracted from createFragmentForInnerOuterHTML to share code between createFragmentForInnerOuterHTML and createContextualFragment. (WebCore::createFragmentForInnerOuterHTML): Reuse the fragment in createFragmentForMarkup. (WebCore::createContextualFragment): Don't reuse the fragment in createFragmentForMarkup as this function is used by Range::createContextualFragment which exposes the document fragment to arbitrary author scripts. (WebCore::hasOneChild): Deleted since we now have Node::hasOneChild. (WebCore::hasOneTextChild): Use Node::hasOneChild. (WebCore::replaceChildrenWithFragment): Added assertions to make sure we don't have any child nodes left after replacing the children. Source/WTF: Added a helper function for writing assertions. * wtf/WeakPtr.h: (WTF::WeakPtrFactory::isInitialized const): Added. Canonical link: https://commits.webkit.org/233948@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272703 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-11 03:18:46 +00:00
#if ASSERT_ENABLED
bool isInitialized() const { return m_impl; }
#endif
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
private:
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename, typename> friend class WeakHashSet;
Add WeakHashMap https://bugs.webkit.org/show_bug.cgi?id=226872 Reviewed by Geoffrey Garen. Source/WTF: Added WeakHashMap which deletes entries during rehashing and amortized over time (based on the number of read & write accesses done on a given WeakHashMap instance). * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakHashMap.h: Added. (WTF::WeakHashMap): Added. (WTF::WeakHashMap::PeekKeyValuePairTraits): Added. (WTF::WeakHashMap::PeekType): Added. (WTF::WeakHashMap::PeekPtrType): Added. Unlike a regular HashMap, we need to fake the iterator pointer value with this struct since key-value pair doesn't exist in HashTable itself as it stores Ref<WeakRefImpl> instead. (WTF::WeakHashMap::WeakHashMapIteratorBase): Added. Has a bunch of helper functions so that WeakHashMapIterator and WeakHashMapConstIterator can share the code. (WTF::WeakHashMap::WeakHashMapIterator): Added. (WTF::WeakHashMap::WeakHashMapConstIterator): Added. (WTF::WeakHashMap::AddResult): Added. (WTF::WeakHashMap::begin): Added. (WTF::WeakHashMap::end): Added. (WTF::WeakHashMap::add): Added. (WTF::WeakHashMap::set): Added. (WTF::WeakHashMap::find): Added. (WTF::WeakHashMap::contains): Added. (WTF::WeakHashMap::get): Added. (WTF::WeakHashMap::remove): Added. (WTF::WeakHashMap::removeIf): Added. (WTF::WeakHashMap::clear): Added. (WTF::WeakHashMap::capacity): Added. (WTF::WeakHashMap::isEmptyIgnoringNullReferences): Added. This is akin to WeakHashSet::computesEmpty. Per prior discussion, we intend to rename WeakHashSet's version to this name as well for clarity. Note that this function will clear the hash table completely if the map is semantically empty but HashTable contains null references as keys. (WTF::WeakHashMap::hasNullReferences): Added. Triggers amortized cleanup based on the number of iterations performed. If there are no null references, it resets m_operationCountSinceLastCleanup. (WTF::WeakHashMap::computeSize): Added. (WTF::WeakHashMap::removeNullReferences): Added. Since WeakHashMap doesn't eagerly delete the value when the key goes away, this function should be called when values held onto by WeakRefImpl with the nullptr back pointer should be deleted en masse. (WTF::WeakHashMap::checkConsistency): Added. (WTF::WeakHashMap::makeKeyImpl): Added. (WTF::WeakHashMap::keyImplIfExists): Added. * wtf/WeakPtr.h: Tools: Added unit tests for WeakHashMap. * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::computeSizeOfWeakHashSet): Deleted the unused variant. (WTF_WeakPtr.WeakHashSetExpansion): Deleted the superflous for loop. (TestWebKitAPI::computeSizeOfWeakHashMap): Added. (TestWebKitAPI::ValueObject): Added. (TestWebKitAPI::ValueObject::create): (TestWebKitAPI::ValueObject::~ValueObject): (TestWebKitAPI::ValueObject::ValueObject): (WTF_WeakPtr.WeakHashMapBasic): Added. (WTF_WeakPtr.WeakHashMapConstObjects): Added. (WTF_WeakPtr.WeakHashMapExpansion): Added. (WTF_WeakPtr.WeakHashMapRemoveNullReferences): Added. (TestWebKitAPI::collectKeyValuePairsUsingIterators): Added. (WTF_WeakPtr.WeakHashMapIterators): Added. (WTF_WeakPtr.WeakHashMapAmortizedCleanup): Added. Canonical link: https://commits.webkit.org/238760@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278803 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-12 01:42:09 +00:00
template<typename, typename, typename> friend class WeakHashMap;
Add WeakHashSet https://bugs.webkit.org/show_bug.cgi?id=195152 Reviewed by Antti Koivisto. Source/WTF: Added WeakHashSet which is a HashSet of WeakPtr. When the object pointed by WeakPtr is deleted, WeakHashSet treats the key to be no longer in the set. That is, WeakHashSet::contains returns false and const_iterator skips such a WeakPtr in the set. We decided not to make HashSet<WeahPtr<T>> work because it involves weird semantics such as making find(X) delete the table entry as remove(find(X)) would be a no-op otherwise as find(X) would return necessarily need to return HashSet<WeakPtr<T>>::end(). Furthermore, we cannot determine the true size of this set in O(1) because the objected pointed by some of WeakPtr in the set may have already been deleted. This has implications that we can't have size(), isEmpty(), random(), etc... as O(1) operation. WeakHashSet is implemented as HashSet<WeakReference<T>>. HashTable::rehash has been updated to delete WeakReference<T>'s whose m_ptr has become null, and HashTable::expand first deletes any such entry before deciding an actual expansion is needed. This is accomplished via newly added hash trait, hasIsReleasedWeakValueFunction, and HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue which returns true for when WeakReference<T> pointed by Ref<WeakReference<T>> has null m_ptr, not to be confused with Ref<WeakReference<T>> itself pointing to a null WeakReference<T>. * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/Forward.h: * wtf/HashSet.h: (WTF::HashSet<T, U, V>::checkConsistency const): Added. * wtf/HashTable.h: (WTF::HashTable::isReleasedWeakBucket): Added. (WTF::HashTable::expand): Delete WeakReference<T> with null m_ptr first. This updates m_keyCount and may make mustRehashInPlace() return true. (WTF::HashTable::deleteReleasedWeakBuckets): Added. (WTF::HashTable::rehash): Delete WeakReference<T> with null m_ptr. Also refactored the code a bit to avoid keep repeating oldTable[i]. * wtf/HashTraits.h: (WTF::HashTraits<T>::isHashTraitsReleasedWeakValue): Added. (WTF::RefHashTraits<T>): Extracted from HashTraits<Ref<P>> to share code with HashTraits<Ref<WeakReference<T>>>. (WTF::HashTraitsReleasedWeakValueChecker<Traits, hasIsReleasedWeakValueFunction>): Added. (WTF::isHashTraitsReleasedWeakValue<Traits, hasIsReleasedWeakValueFunction>): Added. * wtf/WeakHashSet.h: Added. (WTF::WeakHashSet): Added. (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator* const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator-> const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator++): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::WeakHashSetConstIterator::operator== const): (WTF::WeakHashSet::WeakHashSetConstIterator::operator!= const): (WTF::WeakHashSet::WeakHashSet): (WTF::WeakHashSet::begin const): (WTF::WeakHashSet::end const): (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::capacity const): (WTF::WeakHashSet::computeSize const): Deletes any WeakReference<T> with null m_ptr first. (WTF::WeakHashSet::checkConsistency const): (WTF::HashTraits<Ref<WeakReference<T>>>): Added. This hash traits triggers the new code in HashTable's expand and rehash methods to delete WeakReference<T> with null m_ptr. (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): * wtf/WeakPtr.h: (WTF::WeakReference::~WeakReference): Added so that we can keep track the number of live WeakReference in API tests by template specializations. Tools: Added tests for WeakHashSet. * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: (TestWebKitAPI::Base::Base): Moved. (TestWebKitAPI::Derived::foo): Moved. (WTF::WeakReference<TestWebKitAPI::Base>): Added to track the number of live WeakReference. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): (TestWebKitAPI::computeSizeOfWeakHashSet): Added. Canonical link: https://commits.webkit.org/209643@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242387 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-04 21:52:32 +00:00
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
mutable RefPtr<WeakPtrImpl<Counter>> m_impl;
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
#if ASSERT_ENABLED
bool m_wasConstructedOnMainThread;
#endif
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
};
// We use lazy initialization of the WeakPtrFactory by default to avoid unnecessary initialization. Eager
// initialization is however useful if you plan to call makeWeakPtr() from other threads.
enum class WeakPtrFactoryInitialization { Lazy, Eager };
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, WeakPtrFactoryInitialization initializationMode = WeakPtrFactoryInitialization::Lazy, typename Counter = EmptyCounter> class CanMakeWeakPtr {
Add base class to get WeakPtrFactory member and avoid some boilerplate code https://bugs.webkit.org/show_bug.cgi?id=186407 Reviewed by Brent Fulgham. Source/JavaScriptCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wasm/WasmInstance.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::registerInstance): Source/WebCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * Modules/credentialmanagement/CredentialsMessenger.h: * Modules/credentialmanagement/NavigatorCredentials.cpp: (WebCore::NavigatorCredentials::credentials): * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::doSupportedConfigurationStep): (WebCore::CDM::getConsentStatus): * Modules/encryptedmedia/CDM.h: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeySession.h: * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::createSession): * Modules/encryptedmedia/MediaKeys.h: * Modules/gamepad/GamepadManager.cpp: (WebCore::GamepadManager::platformGamepadDisconnected): (WebCore::GamepadManager::makeGamepadVisible): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::applyConstraints): * Modules/mediastream/MediaStreamTrack.h: * Modules/webauthn/cocoa/LocalAuthenticator.h: * Modules/webauthn/cocoa/LocalAuthenticator.mm: (WebCore::LocalAuthenticator::makeCredential): * accessibility/AccessibilityRenderObject.h: * accessibility/AccessibilitySVGRoot.cpp: (WebCore::AccessibilitySVGRoot::setParent): * crypto/SubtleCrypto.cpp: (WebCore::SubtleCrypto::encrypt): (WebCore::SubtleCrypto::decrypt): (WebCore::SubtleCrypto::sign): (WebCore::SubtleCrypto::verify): (WebCore::SubtleCrypto::digest): (WebCore::SubtleCrypto::generateKey): (WebCore::SubtleCrypto::deriveKey): (WebCore::SubtleCrypto::deriveBits): (WebCore::SubtleCrypto::importKey): (WebCore::SubtleCrypto::exportKey): (WebCore::SubtleCrypto::wrapKey): (WebCore::SubtleCrypto::unwrapKey): * crypto/SubtleCrypto.h: * css/CSSFontFace.cpp: (WebCore::CSSFontFace::CSSFontFace): (WebCore::CSSFontFace::wrapper): (WebCore::CSSFontFace::setWrapper): * css/DeprecatedCSSOMValue.h: * css/FontFace.cpp: * css/FontFace.h: * css/MediaQueryEvaluator.cpp: (WebCore::MediaQueryEvaluator::MediaQueryEvaluator): * css/StyleSheetContents.h: * css/parser/CSSDeferredParser.cpp: (WebCore::CSSDeferredParser::CSSDeferredParser): * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/DataTransferItemList.h: * dom/Document.cpp: (WebCore::Document::postTask): (WebCore::Document::hasStorageAccess): (WebCore::Document::requestStorageAccess): * dom/Document.h: (WebCore::Document::setContextDocument): * dom/MessagePort.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::setPictureElement): * html/HTMLInputElement.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): * html/HTMLMediaElement.h: * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: * layout/layouttree/LayoutBox.h: (WebCore::Layout::Box::style const): * loader/FormState.h: * loader/LinkLoader.cpp: (WebCore::LinkLoader::preconnectIfNeeded): * loader/LinkLoader.h: * loader/LinkPreloadResourceClients.cpp: (WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.h: * page/EventHandler.cpp: (WebCore::widgetForElement): (WebCore::EventHandler::updateLastScrollbarUnderMouse): * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::enqueueTask): (WebCore::GenericTaskQueue::cancelAllTasks): * platform/ScrollView.h: * platform/ScrollableArea.h: * platform/Scrollbar.h: * platform/Widget.cpp: (WebCore::Widget::setParent): * platform/Widget.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::decodeAudioForBusCreation): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/audio/mac/AudioHardwareListenerMac.h: * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::CDMInstanceClearKey::requestLicense): (WebCore::CDMInstanceClearKey::updateLicense): (WebCore::CDMInstanceClearKey::loadSession): (WebCore::CDMInstanceClearKey::closeSession): (WebCore::CDMInstanceClearKey::removeSessionData): * platform/encryptedmedia/clearkey/CDMClearKey.h: * platform/graphics/FontCascade.h: * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification): (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability): (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): (WebCore::MediaPlayerPrivateAVFoundationObjC::seekToTime): (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession): (WebCore::MediaPlayerPrivateAVFoundationObjC::setShouldPlayToPlaybackTarget): (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::requestNotificationWhenReadyForVideoData): (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask): * platform/graphics/cv/TextureCacheCV.h: * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVideo): (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfAudio): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage): (WebCore::MediaPlayerPrivateGStreamerBase::initializationDataEncountered): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::connectDemuxerSrcPadToAppsink): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/graphics/mac/DisplayRefreshMonitorMac.h: * platform/graphics/texmap/TextureMapperLayer.cpp: (WebCore::TextureMapperLayer::setMaskLayer): (WebCore::TextureMapperLayer::setReplicaLayer): * platform/graphics/texmap/TextureMapperLayer.h: * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::endCreatedMediaSource): (WebCore::MediaPlayerPrivateMediaFoundation::endGetEvent): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::processInputNotify): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h: * platform/ios/RemoteCommandListenerIOS.h: * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: * platform/mac/RemoteCommandListenerMac.mm: (WebCore::RemoteCommandListenerMac::RemoteCommandListenerMac): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::scheduleDeferredTask): * platform/mediastream/MediaStreamPrivate.h: * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::scheduleDeferredTask): * platform/mediastream/RealtimeMediaSource.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm: (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): * platform/vr/VRPlatformDisplay.h: * platform/vr/openvr/VRPlatformManagerOpenVR.cpp: (WebCore::VRPlatformManagerOpenVR::getVRDisplays): * rendering/FloatingObjects.h: (WebCore::FloatingObject::setOriginatingLine): * rendering/RenderObject.h: * rendering/RootInlineBox.cpp: * rendering/RootInlineBox.h: * svg/SVGPathElement.h: * svg/SVGPathSegWithContext.h: (WebCore::SVGPathSegWithContext::SVGPathSegWithContext): (WebCore::SVGPathSegWithContext::setContextAndRole): * svg/SVGTransformList.h: * svg/properties/SVGAnimatedListPropertyTearOff.h: (WebCore::SVGAnimatedListPropertyTearOff::baseVal): (WebCore::SVGAnimatedListPropertyTearOff::animVal): * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h: * svg/properties/SVGAnimatedPropertyTearOff.h: * svg/properties/SVGAnimatedTransformListPropertyTearOff.h: * svg/properties/SVGListProperty.h: (WebCore::SVGListProperty::initializeValuesAndWrappers): (WebCore::SVGListProperty::getItemValuesAndWrappers): (WebCore::SVGListProperty::insertItemBeforeValuesAndWrappers): (WebCore::SVGListProperty::replaceItemValuesAndWrappers): (WebCore::SVGListProperty::appendItemValuesAndWrappers): * svg/properties/SVGMatrixTearOff.h: * svg/properties/SVGPropertyTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::createInstance): * testing/MockCDMFactory.h: * workers/service/ExtendableEvent.h: * workers/service/FetchEvent.cpp: (WebCore::FetchEvent::respondWith): * workers/service/server/SWServer.h: * xml/DOMParser.cpp: (WebCore::DOMParser::DOMParser): Source/WebCore/PAL: 186407_CanMakeWeakPtr * pal/system/mac/SystemSleepListenerMac.h: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace): * NetworkProcess/PreconnectTask.h: * NetworkProcess/cache/CacheStorageEngine.h: * Shared/Authentication/AuthenticationManager.h: * UIProcess/API/APIAttachment.cpp: (API::Attachment::Attachment): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.h: * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/ViewGestureController.cpp: (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage): * UIProcess/Cocoa/WebViewImpl.h: * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::updateWindowAndViewFrames): (WebKit::WebViewImpl::setTopContentInset): (WebKit::WebViewImpl::viewDidMoveToWindow): (WebKit::WebViewImpl::prepareForMoveToWindow): (WebKit::WebViewImpl::validateUserInterfaceItem): (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded): (WebKit::WebViewImpl::interpretKeyEvent): (WebKit::WebViewImpl::firstRectForCharacterRange): (WebKit::WebViewImpl::performKeyEquivalent): (WebKit::WebViewImpl::keyUp): (WebKit::WebViewImpl::keyDown): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.cpp: (WebKit::WebCredentialsMessengerProxy::makeCredential): (WebKit::WebCredentialsMessengerProxy::getAssertion): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.h: * UIProcess/Downloads/DownloadProxy.cpp: (WebKit::DownloadProxy::setOriginatingPage): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: * UIProcess/WebPageProxy.h: * UIProcess/WebsiteData/WebsiteDataStore.h: * UIProcess/gtk/WaylandCompositor.cpp: (WebKit::WaylandCompositor::Surface::attachBuffer): * UIProcess/gtk/WaylandCompositor.h: * UIProcess/ios/ProcessAssertionIOS.mm: (WebKit::ProcessAssertion::ProcessAssertion): * UIProcess/mac/DisplayLink.cpp: (WebKit::DisplayLink::displayLinkCallback): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDisplayRefreshMonitor.mm: (WebKit::RemoteLayerTreeDisplayRefreshMonitor::RemoteLayerTreeDisplayRefreshMonitor): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: Source/WebKitLegacy/mac: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * WebCoreSupport/WebEditorClient.h: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::requestCandidatesForSelection): Source/WTF: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wtf/WeakPtr.h: (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Canonical link: https://commits.webkit.org/201784@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:56:04 +00:00
public:
using WeakValueType = T;
WeakPtr breaks vtables when upcasting to base classes https://bugs.webkit.org/show_bug.cgi?id=188799 Reviewed by Youenn Fablet. Source/WebCore: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::MediaKeySession): * Modules/encryptedmedia/MediaKeySession.h: Adopted modern WeakPtr APIs. Removed redundant WeakPtrFactory. * css/CSSFontFace.cpp: (WebCore::CSSFontFace::existingWrapper): * css/CSSFontFace.h: Moved functions out of line to avoid #include explosion for .get(). * dom/ContainerNode.h: * dom/Document.h: * dom/Element.h: Moved CanMakeWeakPtr to ContainerNode because all subclasses except for DocumentFragment were already so, and we have code that uses WeakPtr<ContainerNode>, which, now that WeakPtr is type-safe, is awkward to do when ContainerNode isn't CanMakeWeakPtr. * dom/FullscreenManager.cpp: (WebCore::FullscreenManager::fullscreenRenderer const): * dom/FullscreenManager.h: (WebCore::FullscreenManager::fullscreenRenderer const): Deleted. * html/FormAssociatedElement.cpp: (WebCore::FormAssociatedElement::form const): * html/FormAssociatedElement.h: (WebCore::FormAssociatedElement::form const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * html/HTMLMediaElement.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::requestResource): Removed redundant .get(). * page/DOMWindowProperty.cpp: (WebCore::DOMWindowProperty::window const): * page/DOMWindowProperty.h: (WebCore::DOMWindowProperty::window const): Deleted. * page/FrameViewLayoutContext.cpp: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): * page/FrameViewLayoutContext.h: (WebCore::FrameViewLayoutContext::subtreeLayoutRoot const): Deleted. * page/UndoItem.cpp: (WebCore::UndoItem::undoManager const): * page/UndoItem.h: (WebCore::UndoItem::undoManager const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/ScrollView.h: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. * platform/Widget.cpp: (WebCore::Widget::parent const): * platform/Widget.h: (WebCore::Widget::parent const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * platform/encryptedmedia/CDMInstanceSession.h: Made CDMInstanceSessionClient CanMakeWeakPtr because we use WeakPtr<CDMInstanceSessionClient>. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: CanMakeWeakPtr is inherited now. * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): (WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): Deleted. (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): Deleted. * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::CMTimebaseEffectiveRateChangedCallback): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::durationChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::cdmSession const): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): (WebCore::SourceBufferPrivateAVFObjC::setCDMSession): (WebCore::SourceBufferPrivateAVFObjC::flushVideo): (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): (WebCore::SourceBufferPrivateAVFObjC::setVideoLayer): (WebCore::SourceBufferPrivateAVFObjC::setDecompressionSession): Modernized WeakPtr API usage. * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::multiColumnFlowSlowCase const): * rendering/RenderBlockFlow.h: (WebCore::RenderBlockFlow::multiColumnFlow const): * rendering/RenderMultiColumnFlow.cpp: (WebCore::RenderMultiColumnFlow::findColumnSpannerPlaceholder const): * rendering/RenderMultiColumnFlow.h: * rendering/RenderTable.cpp: (WebCore::RenderTable::header const): (WebCore::RenderTable::footer const): (WebCore::RenderTable::firstBody const): (WebCore::RenderTable::topSection const): * rendering/RenderTable.h: (WebCore::RenderTable::header const): Deleted. (WebCore::RenderTable::footer const): Deleted. (WebCore::RenderTable::firstBody const): Deleted. (WebCore::RenderTable::topSection const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WebKit: * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: (WebKit::WebResourceLoadStatisticsStore::networkSession): * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::suspendedPage const): * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::suspendedPage const): Deleted. Moved functions out of line to avoid #include explosion for .get(). * UIProcess/Authentication/cocoa/SecKeyProxyStore.h: (WebKit::SecKeyProxyStore::get const): (WebKit::SecKeyProxyStore::weakPtrFactory const): Deleted. Adopted CanMakeWeakPtr. * UIProcess/WebAuthentication/AuthenticatorManager.h: * UIProcess/WebProcessProxy.cpp: It takes an extra using declaration to disambiguate multiple CanMakeWeakPtr base classes now. (WebKit::WebProcessProxy::processPool const): * UIProcess/WebProcessProxy.h: (WebKit::WebProcessProxy::processPool const): Deleted. Moved functions out of line to avoid #include explosion for .get(). Source/WTF: This patch switches from reinterpret_cast to static_cast when loading from WeakReference storage. We know which type to cast *to* because it's specified by the type of the calling WeakPtr. We know which type to cast *from* because it's specified by a typedef in CanMakeWeakPtr. (Our convention is that we store a pointer to the class that derives from CanMakeWeakPtr. We cast from that pointer to derived pointers when we get(). This means that #include of the derived type header is now required in order to get() the pointer.) * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Definition is now eagerly required because WeakReference is not a template anymore. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computesEmpty const): (WTF::WeakHashSet::hasNullReferences const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference<T>>>::isReleasedWeakValue): Deleted. Updated for new WeakReference get() API. * wtf/WeakPtr.h: Use a macro for TestAPI support. We can't use template specialization because WeakReference is not a class template anymore. (Or maybe we could have kept it working with a dummy template argument? Felt weird, so I switched.) (WTF::WeakReference::create): (WTF::WeakReference::~WeakReference): (WTF::WeakReference::get const): (WTF::WeakReference::operator bool const): (WTF::WeakReference::WeakReference): WeakReference is just a void* now. It's the caller's responsibility, when creating and getting, to use a consistent storage type. We ensure a canonical storage type using a typedef inside CanMakeWeakPtr. (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get const): (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): Adopted new WeakReference API. (WTF::WeakPtrFactory::createWeakPtr const): No need for reinterpret_cast. (WTF::weak_reference_cast): This isn't required for correctness, but it's nice to show a complier error at WeakPtr construction sites when you know that the types won't work. Otherwise, you get compiler errors at dereference sites, which are slightly more mysterious ways of saying that you constructed your WeakPtr incorrectly. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::weak_reference_upcast): Deleted. (WTF::weak_reference_downcast): Deleted. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Adopt the new macro API instead of template specialization for observing weak references. (TestWebKitAPI::Int::Int): (TestWebKitAPI::Int::operator int const): (TestWebKitAPI::Int::operator== const): Use a class for integer tests because WeakPtr doesn't naturally support pointing to non-class objects now. (TestWebKitAPI::Base::foo): (TestWebKitAPI::Derived::foo): Inherit from CanMakeWeakPtr to enable deduction of the weak pointer type. (TestWebKitAPI::TEST): Updated to use Int. (TestWebKitAPI::Base::weakPtrFactory const): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::WeakReference): Deleted. (WTF::WeakReference<TestWebKitAPI::Base>::~WeakReference): Deleted. Canonical link: https://commits.webkit.org/212376@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-29 21:15:54 +00:00
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
const WeakPtrFactory<T, Counter>& weakPtrFactory() const { return m_weakPtrFactory; }
WeakPtrFactory<T, Counter>& weakPtrFactory() { return m_weakPtrFactory; }
Add base class to get WeakPtrFactory member and avoid some boilerplate code https://bugs.webkit.org/show_bug.cgi?id=186407 Reviewed by Brent Fulgham. Source/JavaScriptCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wasm/WasmInstance.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::registerInstance): Source/WebCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * Modules/credentialmanagement/CredentialsMessenger.h: * Modules/credentialmanagement/NavigatorCredentials.cpp: (WebCore::NavigatorCredentials::credentials): * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::doSupportedConfigurationStep): (WebCore::CDM::getConsentStatus): * Modules/encryptedmedia/CDM.h: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeySession.h: * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::createSession): * Modules/encryptedmedia/MediaKeys.h: * Modules/gamepad/GamepadManager.cpp: (WebCore::GamepadManager::platformGamepadDisconnected): (WebCore::GamepadManager::makeGamepadVisible): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::applyConstraints): * Modules/mediastream/MediaStreamTrack.h: * Modules/webauthn/cocoa/LocalAuthenticator.h: * Modules/webauthn/cocoa/LocalAuthenticator.mm: (WebCore::LocalAuthenticator::makeCredential): * accessibility/AccessibilityRenderObject.h: * accessibility/AccessibilitySVGRoot.cpp: (WebCore::AccessibilitySVGRoot::setParent): * crypto/SubtleCrypto.cpp: (WebCore::SubtleCrypto::encrypt): (WebCore::SubtleCrypto::decrypt): (WebCore::SubtleCrypto::sign): (WebCore::SubtleCrypto::verify): (WebCore::SubtleCrypto::digest): (WebCore::SubtleCrypto::generateKey): (WebCore::SubtleCrypto::deriveKey): (WebCore::SubtleCrypto::deriveBits): (WebCore::SubtleCrypto::importKey): (WebCore::SubtleCrypto::exportKey): (WebCore::SubtleCrypto::wrapKey): (WebCore::SubtleCrypto::unwrapKey): * crypto/SubtleCrypto.h: * css/CSSFontFace.cpp: (WebCore::CSSFontFace::CSSFontFace): (WebCore::CSSFontFace::wrapper): (WebCore::CSSFontFace::setWrapper): * css/DeprecatedCSSOMValue.h: * css/FontFace.cpp: * css/FontFace.h: * css/MediaQueryEvaluator.cpp: (WebCore::MediaQueryEvaluator::MediaQueryEvaluator): * css/StyleSheetContents.h: * css/parser/CSSDeferredParser.cpp: (WebCore::CSSDeferredParser::CSSDeferredParser): * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/DataTransferItemList.h: * dom/Document.cpp: (WebCore::Document::postTask): (WebCore::Document::hasStorageAccess): (WebCore::Document::requestStorageAccess): * dom/Document.h: (WebCore::Document::setContextDocument): * dom/MessagePort.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::setPictureElement): * html/HTMLInputElement.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): * html/HTMLMediaElement.h: * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: * layout/layouttree/LayoutBox.h: (WebCore::Layout::Box::style const): * loader/FormState.h: * loader/LinkLoader.cpp: (WebCore::LinkLoader::preconnectIfNeeded): * loader/LinkLoader.h: * loader/LinkPreloadResourceClients.cpp: (WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.h: * page/EventHandler.cpp: (WebCore::widgetForElement): (WebCore::EventHandler::updateLastScrollbarUnderMouse): * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::enqueueTask): (WebCore::GenericTaskQueue::cancelAllTasks): * platform/ScrollView.h: * platform/ScrollableArea.h: * platform/Scrollbar.h: * platform/Widget.cpp: (WebCore::Widget::setParent): * platform/Widget.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::decodeAudioForBusCreation): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/audio/mac/AudioHardwareListenerMac.h: * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::CDMInstanceClearKey::requestLicense): (WebCore::CDMInstanceClearKey::updateLicense): (WebCore::CDMInstanceClearKey::loadSession): (WebCore::CDMInstanceClearKey::closeSession): (WebCore::CDMInstanceClearKey::removeSessionData): * platform/encryptedmedia/clearkey/CDMClearKey.h: * platform/graphics/FontCascade.h: * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification): (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability): (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): (WebCore::MediaPlayerPrivateAVFoundationObjC::seekToTime): (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession): (WebCore::MediaPlayerPrivateAVFoundationObjC::setShouldPlayToPlaybackTarget): (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::requestNotificationWhenReadyForVideoData): (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask): * platform/graphics/cv/TextureCacheCV.h: * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVideo): (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfAudio): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage): (WebCore::MediaPlayerPrivateGStreamerBase::initializationDataEncountered): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::connectDemuxerSrcPadToAppsink): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/graphics/mac/DisplayRefreshMonitorMac.h: * platform/graphics/texmap/TextureMapperLayer.cpp: (WebCore::TextureMapperLayer::setMaskLayer): (WebCore::TextureMapperLayer::setReplicaLayer): * platform/graphics/texmap/TextureMapperLayer.h: * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::endCreatedMediaSource): (WebCore::MediaPlayerPrivateMediaFoundation::endGetEvent): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::processInputNotify): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h: * platform/ios/RemoteCommandListenerIOS.h: * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: * platform/mac/RemoteCommandListenerMac.mm: (WebCore::RemoteCommandListenerMac::RemoteCommandListenerMac): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::scheduleDeferredTask): * platform/mediastream/MediaStreamPrivate.h: * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::scheduleDeferredTask): * platform/mediastream/RealtimeMediaSource.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm: (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): * platform/vr/VRPlatformDisplay.h: * platform/vr/openvr/VRPlatformManagerOpenVR.cpp: (WebCore::VRPlatformManagerOpenVR::getVRDisplays): * rendering/FloatingObjects.h: (WebCore::FloatingObject::setOriginatingLine): * rendering/RenderObject.h: * rendering/RootInlineBox.cpp: * rendering/RootInlineBox.h: * svg/SVGPathElement.h: * svg/SVGPathSegWithContext.h: (WebCore::SVGPathSegWithContext::SVGPathSegWithContext): (WebCore::SVGPathSegWithContext::setContextAndRole): * svg/SVGTransformList.h: * svg/properties/SVGAnimatedListPropertyTearOff.h: (WebCore::SVGAnimatedListPropertyTearOff::baseVal): (WebCore::SVGAnimatedListPropertyTearOff::animVal): * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h: * svg/properties/SVGAnimatedPropertyTearOff.h: * svg/properties/SVGAnimatedTransformListPropertyTearOff.h: * svg/properties/SVGListProperty.h: (WebCore::SVGListProperty::initializeValuesAndWrappers): (WebCore::SVGListProperty::getItemValuesAndWrappers): (WebCore::SVGListProperty::insertItemBeforeValuesAndWrappers): (WebCore::SVGListProperty::replaceItemValuesAndWrappers): (WebCore::SVGListProperty::appendItemValuesAndWrappers): * svg/properties/SVGMatrixTearOff.h: * svg/properties/SVGPropertyTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::createInstance): * testing/MockCDMFactory.h: * workers/service/ExtendableEvent.h: * workers/service/FetchEvent.cpp: (WebCore::FetchEvent::respondWith): * workers/service/server/SWServer.h: * xml/DOMParser.cpp: (WebCore::DOMParser::DOMParser): Source/WebCore/PAL: 186407_CanMakeWeakPtr * pal/system/mac/SystemSleepListenerMac.h: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace): * NetworkProcess/PreconnectTask.h: * NetworkProcess/cache/CacheStorageEngine.h: * Shared/Authentication/AuthenticationManager.h: * UIProcess/API/APIAttachment.cpp: (API::Attachment::Attachment): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.h: * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/ViewGestureController.cpp: (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage): * UIProcess/Cocoa/WebViewImpl.h: * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::updateWindowAndViewFrames): (WebKit::WebViewImpl::setTopContentInset): (WebKit::WebViewImpl::viewDidMoveToWindow): (WebKit::WebViewImpl::prepareForMoveToWindow): (WebKit::WebViewImpl::validateUserInterfaceItem): (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded): (WebKit::WebViewImpl::interpretKeyEvent): (WebKit::WebViewImpl::firstRectForCharacterRange): (WebKit::WebViewImpl::performKeyEquivalent): (WebKit::WebViewImpl::keyUp): (WebKit::WebViewImpl::keyDown): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.cpp: (WebKit::WebCredentialsMessengerProxy::makeCredential): (WebKit::WebCredentialsMessengerProxy::getAssertion): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.h: * UIProcess/Downloads/DownloadProxy.cpp: (WebKit::DownloadProxy::setOriginatingPage): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: * UIProcess/WebPageProxy.h: * UIProcess/WebsiteData/WebsiteDataStore.h: * UIProcess/gtk/WaylandCompositor.cpp: (WebKit::WaylandCompositor::Surface::attachBuffer): * UIProcess/gtk/WaylandCompositor.h: * UIProcess/ios/ProcessAssertionIOS.mm: (WebKit::ProcessAssertion::ProcessAssertion): * UIProcess/mac/DisplayLink.cpp: (WebKit::DisplayLink::displayLinkCallback): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDisplayRefreshMonitor.mm: (WebKit::RemoteLayerTreeDisplayRefreshMonitor::RemoteLayerTreeDisplayRefreshMonitor): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: Source/WebKitLegacy/mac: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * WebCoreSupport/WebEditorClient.h: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::requestCandidatesForSelection): Source/WTF: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wtf/WeakPtr.h: (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Canonical link: https://commits.webkit.org/201784@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:56:04 +00:00
protected:
CanMakeWeakPtr()
{
if (initializationMode == WeakPtrFactoryInitialization::Eager)
Support AbortSignal in addEventListenerOptions to unsubscribe from events https://bugs.webkit.org/show_bug.cgi?id=218753 <rdar://problem/71258012> Reviewed by Darin Adler. LayoutTests/imported/w3c: Import test coverage from WPT. * web-platform-tests/dom/events/AddEventListenerOptions-signal.any-expected.txt: Added. * web-platform-tests/dom/events/AddEventListenerOptions-signal.any.html: Added. * web-platform-tests/dom/events/AddEventListenerOptions-signal.any.js: Added. * web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker-expected.txt: Added. * web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker.html: Added. * web-platform-tests/dom/events/w3c-import.log: Source/WebCore: Support AbortSignal in addEventListenerOptions to unsubscribe from events: - https://github.com/whatwg/dom/issues/911 - https://github.com/whatwg/dom/pull/919 Blink already added support for this. Tests: imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-signal.any.html imported/w3c/web-platform-tests/dom/events/AddEventListenerOptions-signal.any.worker.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Headers.cmake: * Modules/async-clipboard/Clipboard.h: * Modules/encryptedmedia/MediaKeySession.h: * Modules/indexeddb/IDBRequest.h: * Modules/mediastream/MediaDevices.h: * Modules/mediastream/RTCPeerConnection.h: * Modules/paymentrequest/PaymentRequest.h: * Modules/speech/SpeechRecognition.h: * Modules/webaudio/BaseAudioContext.h: * Modules/webgpu/WebGPUDevice.h: * Modules/webxr/WebXRSystem.h: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * animation/WebAnimation.h: * css/MediaQueryList.cpp: (WebCore::MediaQueryList::addListener): (WebCore::MediaQueryList::removeListener): * css/MediaQueryList.h: * dom/AbortSignal.h: * dom/AddEventListenerOptions.h: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h. (WebCore::AddEventListenerOptions::AddEventListenerOptions): * dom/AddEventListenerOptions.idl: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h. * dom/EventListener.h: * dom/EventListenerMap.cpp: * dom/EventListenerOptions.h: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h. (WebCore::EventListenerOptions::EventListenerOptions): * dom/EventListenerOptions.idl: Copied from Source/WebCore/loader/appcache/DOMApplicationCache.h. * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::removeEventListenerForBindings): (WebCore::EventTarget::removeEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/EventTarget.h: (WebCore::EventTarget::removeEventListener): * dom/EventTarget.idl: * dom/MessagePort.cpp: (WebCore::MessagePort::MessagePort): (WebCore::MessagePort::removeEventListener): * dom/MessagePort.h: * dom/Node.cpp: (WebCore::tryAddEventListener): (WebCore::tryRemoveEventListener): (WebCore::Node::removeEventListener): * dom/Node.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::removeEventListener): * html/HTMLMediaElement.h: * html/ImageDocument.cpp: * html/track/TextTrackCue.h: * inspector/agents/InspectorDOMAgent.cpp: * loader/appcache/DOMApplicationCache.h: * page/DOMWindow.cpp: (WebCore::DOMWindow::removeEventListener): * page/DOMWindow.h: * platform/cocoa/PlaybackSessionModelMediaElement.mm: * platform/cocoa/VideoFullscreenModelVideoElement.mm: * svg/SVGElement.cpp: (WebCore::SVGElement::removeEventListener): * svg/SVGElement.h: * svg/SVGTRefElement.cpp: * svg/animation/SVGSMILElement.cpp: * testing/Internals.cpp: * workers/service/ServiceWorkerContainer.h: Source/WebKit: Minor build fixes. * WebProcess/Plugins/PDF/PDFPluginAnnotation.mm: Source/WebKitLegacy/mac: Minor build fixes. * DOM/DOMNode.mm: Source/WTF: Add initializeWeakPtrFactory() protection function to CanMakeWeakPtr so that a subclass can eagerly initialize the WeakPtrFactory even if it does not subclass WeakPtrFactory<T, WeakPtrFactoryInitialization::Eager>. MessagePort used to subclass WeakPtrFactory<T, WeakPtrFactoryInitialization::Eager> for thread-safety reason but it now subclasses WeakPtrFactory<T, WeakPtrFactoryInitialization::Lazy> via EventTarget. * wtf/WeakPtr.h: (WTF::CanMakeWeakPtr::initializeWeakPtrFactory): Canonical link: https://commits.webkit.org/233312@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271806 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-25 20:06:25 +00:00
initializeWeakPtrFactory();
}
void initializeWeakPtrFactory()
{
m_weakPtrFactory.initializeIfNeeded(static_cast<T&>(*this));
}
Add base class to get WeakPtrFactory member and avoid some boilerplate code https://bugs.webkit.org/show_bug.cgi?id=186407 Reviewed by Brent Fulgham. Source/JavaScriptCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wasm/WasmInstance.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::registerInstance): Source/WebCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * Modules/credentialmanagement/CredentialsMessenger.h: * Modules/credentialmanagement/NavigatorCredentials.cpp: (WebCore::NavigatorCredentials::credentials): * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::doSupportedConfigurationStep): (WebCore::CDM::getConsentStatus): * Modules/encryptedmedia/CDM.h: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeySession.h: * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::createSession): * Modules/encryptedmedia/MediaKeys.h: * Modules/gamepad/GamepadManager.cpp: (WebCore::GamepadManager::platformGamepadDisconnected): (WebCore::GamepadManager::makeGamepadVisible): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::applyConstraints): * Modules/mediastream/MediaStreamTrack.h: * Modules/webauthn/cocoa/LocalAuthenticator.h: * Modules/webauthn/cocoa/LocalAuthenticator.mm: (WebCore::LocalAuthenticator::makeCredential): * accessibility/AccessibilityRenderObject.h: * accessibility/AccessibilitySVGRoot.cpp: (WebCore::AccessibilitySVGRoot::setParent): * crypto/SubtleCrypto.cpp: (WebCore::SubtleCrypto::encrypt): (WebCore::SubtleCrypto::decrypt): (WebCore::SubtleCrypto::sign): (WebCore::SubtleCrypto::verify): (WebCore::SubtleCrypto::digest): (WebCore::SubtleCrypto::generateKey): (WebCore::SubtleCrypto::deriveKey): (WebCore::SubtleCrypto::deriveBits): (WebCore::SubtleCrypto::importKey): (WebCore::SubtleCrypto::exportKey): (WebCore::SubtleCrypto::wrapKey): (WebCore::SubtleCrypto::unwrapKey): * crypto/SubtleCrypto.h: * css/CSSFontFace.cpp: (WebCore::CSSFontFace::CSSFontFace): (WebCore::CSSFontFace::wrapper): (WebCore::CSSFontFace::setWrapper): * css/DeprecatedCSSOMValue.h: * css/FontFace.cpp: * css/FontFace.h: * css/MediaQueryEvaluator.cpp: (WebCore::MediaQueryEvaluator::MediaQueryEvaluator): * css/StyleSheetContents.h: * css/parser/CSSDeferredParser.cpp: (WebCore::CSSDeferredParser::CSSDeferredParser): * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/DataTransferItemList.h: * dom/Document.cpp: (WebCore::Document::postTask): (WebCore::Document::hasStorageAccess): (WebCore::Document::requestStorageAccess): * dom/Document.h: (WebCore::Document::setContextDocument): * dom/MessagePort.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::setPictureElement): * html/HTMLInputElement.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): * html/HTMLMediaElement.h: * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: * layout/layouttree/LayoutBox.h: (WebCore::Layout::Box::style const): * loader/FormState.h: * loader/LinkLoader.cpp: (WebCore::LinkLoader::preconnectIfNeeded): * loader/LinkLoader.h: * loader/LinkPreloadResourceClients.cpp: (WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.h: * page/EventHandler.cpp: (WebCore::widgetForElement): (WebCore::EventHandler::updateLastScrollbarUnderMouse): * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::enqueueTask): (WebCore::GenericTaskQueue::cancelAllTasks): * platform/ScrollView.h: * platform/ScrollableArea.h: * platform/Scrollbar.h: * platform/Widget.cpp: (WebCore::Widget::setParent): * platform/Widget.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::decodeAudioForBusCreation): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/audio/mac/AudioHardwareListenerMac.h: * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::CDMInstanceClearKey::requestLicense): (WebCore::CDMInstanceClearKey::updateLicense): (WebCore::CDMInstanceClearKey::loadSession): (WebCore::CDMInstanceClearKey::closeSession): (WebCore::CDMInstanceClearKey::removeSessionData): * platform/encryptedmedia/clearkey/CDMClearKey.h: * platform/graphics/FontCascade.h: * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification): (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability): (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): (WebCore::MediaPlayerPrivateAVFoundationObjC::seekToTime): (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession): (WebCore::MediaPlayerPrivateAVFoundationObjC::setShouldPlayToPlaybackTarget): (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::requestNotificationWhenReadyForVideoData): (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask): * platform/graphics/cv/TextureCacheCV.h: * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVideo): (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfAudio): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage): (WebCore::MediaPlayerPrivateGStreamerBase::initializationDataEncountered): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::connectDemuxerSrcPadToAppsink): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/graphics/mac/DisplayRefreshMonitorMac.h: * platform/graphics/texmap/TextureMapperLayer.cpp: (WebCore::TextureMapperLayer::setMaskLayer): (WebCore::TextureMapperLayer::setReplicaLayer): * platform/graphics/texmap/TextureMapperLayer.h: * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::endCreatedMediaSource): (WebCore::MediaPlayerPrivateMediaFoundation::endGetEvent): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::processInputNotify): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h: * platform/ios/RemoteCommandListenerIOS.h: * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: * platform/mac/RemoteCommandListenerMac.mm: (WebCore::RemoteCommandListenerMac::RemoteCommandListenerMac): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::scheduleDeferredTask): * platform/mediastream/MediaStreamPrivate.h: * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::scheduleDeferredTask): * platform/mediastream/RealtimeMediaSource.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm: (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): * platform/vr/VRPlatformDisplay.h: * platform/vr/openvr/VRPlatformManagerOpenVR.cpp: (WebCore::VRPlatformManagerOpenVR::getVRDisplays): * rendering/FloatingObjects.h: (WebCore::FloatingObject::setOriginatingLine): * rendering/RenderObject.h: * rendering/RootInlineBox.cpp: * rendering/RootInlineBox.h: * svg/SVGPathElement.h: * svg/SVGPathSegWithContext.h: (WebCore::SVGPathSegWithContext::SVGPathSegWithContext): (WebCore::SVGPathSegWithContext::setContextAndRole): * svg/SVGTransformList.h: * svg/properties/SVGAnimatedListPropertyTearOff.h: (WebCore::SVGAnimatedListPropertyTearOff::baseVal): (WebCore::SVGAnimatedListPropertyTearOff::animVal): * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h: * svg/properties/SVGAnimatedPropertyTearOff.h: * svg/properties/SVGAnimatedTransformListPropertyTearOff.h: * svg/properties/SVGListProperty.h: (WebCore::SVGListProperty::initializeValuesAndWrappers): (WebCore::SVGListProperty::getItemValuesAndWrappers): (WebCore::SVGListProperty::insertItemBeforeValuesAndWrappers): (WebCore::SVGListProperty::replaceItemValuesAndWrappers): (WebCore::SVGListProperty::appendItemValuesAndWrappers): * svg/properties/SVGMatrixTearOff.h: * svg/properties/SVGPropertyTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::createInstance): * testing/MockCDMFactory.h: * workers/service/ExtendableEvent.h: * workers/service/FetchEvent.cpp: (WebCore::FetchEvent::respondWith): * workers/service/server/SWServer.h: * xml/DOMParser.cpp: (WebCore::DOMParser::DOMParser): Source/WebCore/PAL: 186407_CanMakeWeakPtr * pal/system/mac/SystemSleepListenerMac.h: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace): * NetworkProcess/PreconnectTask.h: * NetworkProcess/cache/CacheStorageEngine.h: * Shared/Authentication/AuthenticationManager.h: * UIProcess/API/APIAttachment.cpp: (API::Attachment::Attachment): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.h: * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/ViewGestureController.cpp: (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage): * UIProcess/Cocoa/WebViewImpl.h: * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::updateWindowAndViewFrames): (WebKit::WebViewImpl::setTopContentInset): (WebKit::WebViewImpl::viewDidMoveToWindow): (WebKit::WebViewImpl::prepareForMoveToWindow): (WebKit::WebViewImpl::validateUserInterfaceItem): (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded): (WebKit::WebViewImpl::interpretKeyEvent): (WebKit::WebViewImpl::firstRectForCharacterRange): (WebKit::WebViewImpl::performKeyEquivalent): (WebKit::WebViewImpl::keyUp): (WebKit::WebViewImpl::keyDown): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.cpp: (WebKit::WebCredentialsMessengerProxy::makeCredential): (WebKit::WebCredentialsMessengerProxy::getAssertion): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.h: * UIProcess/Downloads/DownloadProxy.cpp: (WebKit::DownloadProxy::setOriginatingPage): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: * UIProcess/WebPageProxy.h: * UIProcess/WebsiteData/WebsiteDataStore.h: * UIProcess/gtk/WaylandCompositor.cpp: (WebKit::WaylandCompositor::Surface::attachBuffer): * UIProcess/gtk/WaylandCompositor.h: * UIProcess/ios/ProcessAssertionIOS.mm: (WebKit::ProcessAssertion::ProcessAssertion): * UIProcess/mac/DisplayLink.cpp: (WebKit::DisplayLink::displayLinkCallback): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDisplayRefreshMonitor.mm: (WebKit::RemoteLayerTreeDisplayRefreshMonitor::RemoteLayerTreeDisplayRefreshMonitor): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: Source/WebKitLegacy/mac: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * WebCoreSupport/WebEditorClient.h: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::requestCandidatesForSelection): Source/WTF: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wtf/WeakPtr.h: (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Canonical link: https://commits.webkit.org/201784@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:56:04 +00:00
private:
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
WeakPtrFactory<T, Counter> m_weakPtrFactory;
Add base class to get WeakPtrFactory member and avoid some boilerplate code https://bugs.webkit.org/show_bug.cgi?id=186407 Reviewed by Brent Fulgham. Source/JavaScriptCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wasm/WasmInstance.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::registerInstance): Source/WebCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * Modules/credentialmanagement/CredentialsMessenger.h: * Modules/credentialmanagement/NavigatorCredentials.cpp: (WebCore::NavigatorCredentials::credentials): * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::doSupportedConfigurationStep): (WebCore::CDM::getConsentStatus): * Modules/encryptedmedia/CDM.h: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeySession.h: * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::createSession): * Modules/encryptedmedia/MediaKeys.h: * Modules/gamepad/GamepadManager.cpp: (WebCore::GamepadManager::platformGamepadDisconnected): (WebCore::GamepadManager::makeGamepadVisible): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::applyConstraints): * Modules/mediastream/MediaStreamTrack.h: * Modules/webauthn/cocoa/LocalAuthenticator.h: * Modules/webauthn/cocoa/LocalAuthenticator.mm: (WebCore::LocalAuthenticator::makeCredential): * accessibility/AccessibilityRenderObject.h: * accessibility/AccessibilitySVGRoot.cpp: (WebCore::AccessibilitySVGRoot::setParent): * crypto/SubtleCrypto.cpp: (WebCore::SubtleCrypto::encrypt): (WebCore::SubtleCrypto::decrypt): (WebCore::SubtleCrypto::sign): (WebCore::SubtleCrypto::verify): (WebCore::SubtleCrypto::digest): (WebCore::SubtleCrypto::generateKey): (WebCore::SubtleCrypto::deriveKey): (WebCore::SubtleCrypto::deriveBits): (WebCore::SubtleCrypto::importKey): (WebCore::SubtleCrypto::exportKey): (WebCore::SubtleCrypto::wrapKey): (WebCore::SubtleCrypto::unwrapKey): * crypto/SubtleCrypto.h: * css/CSSFontFace.cpp: (WebCore::CSSFontFace::CSSFontFace): (WebCore::CSSFontFace::wrapper): (WebCore::CSSFontFace::setWrapper): * css/DeprecatedCSSOMValue.h: * css/FontFace.cpp: * css/FontFace.h: * css/MediaQueryEvaluator.cpp: (WebCore::MediaQueryEvaluator::MediaQueryEvaluator): * css/StyleSheetContents.h: * css/parser/CSSDeferredParser.cpp: (WebCore::CSSDeferredParser::CSSDeferredParser): * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/DataTransferItemList.h: * dom/Document.cpp: (WebCore::Document::postTask): (WebCore::Document::hasStorageAccess): (WebCore::Document::requestStorageAccess): * dom/Document.h: (WebCore::Document::setContextDocument): * dom/MessagePort.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::setPictureElement): * html/HTMLInputElement.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): * html/HTMLMediaElement.h: * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: * layout/layouttree/LayoutBox.h: (WebCore::Layout::Box::style const): * loader/FormState.h: * loader/LinkLoader.cpp: (WebCore::LinkLoader::preconnectIfNeeded): * loader/LinkLoader.h: * loader/LinkPreloadResourceClients.cpp: (WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.h: * page/EventHandler.cpp: (WebCore::widgetForElement): (WebCore::EventHandler::updateLastScrollbarUnderMouse): * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::enqueueTask): (WebCore::GenericTaskQueue::cancelAllTasks): * platform/ScrollView.h: * platform/ScrollableArea.h: * platform/Scrollbar.h: * platform/Widget.cpp: (WebCore::Widget::setParent): * platform/Widget.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::decodeAudioForBusCreation): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/audio/mac/AudioHardwareListenerMac.h: * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::CDMInstanceClearKey::requestLicense): (WebCore::CDMInstanceClearKey::updateLicense): (WebCore::CDMInstanceClearKey::loadSession): (WebCore::CDMInstanceClearKey::closeSession): (WebCore::CDMInstanceClearKey::removeSessionData): * platform/encryptedmedia/clearkey/CDMClearKey.h: * platform/graphics/FontCascade.h: * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification): (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability): (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): (WebCore::MediaPlayerPrivateAVFoundationObjC::seekToTime): (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession): (WebCore::MediaPlayerPrivateAVFoundationObjC::setShouldPlayToPlaybackTarget): (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::requestNotificationWhenReadyForVideoData): (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask): * platform/graphics/cv/TextureCacheCV.h: * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVideo): (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfAudio): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage): (WebCore::MediaPlayerPrivateGStreamerBase::initializationDataEncountered): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::connectDemuxerSrcPadToAppsink): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/graphics/mac/DisplayRefreshMonitorMac.h: * platform/graphics/texmap/TextureMapperLayer.cpp: (WebCore::TextureMapperLayer::setMaskLayer): (WebCore::TextureMapperLayer::setReplicaLayer): * platform/graphics/texmap/TextureMapperLayer.h: * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::endCreatedMediaSource): (WebCore::MediaPlayerPrivateMediaFoundation::endGetEvent): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::processInputNotify): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h: * platform/ios/RemoteCommandListenerIOS.h: * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: * platform/mac/RemoteCommandListenerMac.mm: (WebCore::RemoteCommandListenerMac::RemoteCommandListenerMac): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::scheduleDeferredTask): * platform/mediastream/MediaStreamPrivate.h: * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::scheduleDeferredTask): * platform/mediastream/RealtimeMediaSource.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm: (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): * platform/vr/VRPlatformDisplay.h: * platform/vr/openvr/VRPlatformManagerOpenVR.cpp: (WebCore::VRPlatformManagerOpenVR::getVRDisplays): * rendering/FloatingObjects.h: (WebCore::FloatingObject::setOriginatingLine): * rendering/RenderObject.h: * rendering/RootInlineBox.cpp: * rendering/RootInlineBox.h: * svg/SVGPathElement.h: * svg/SVGPathSegWithContext.h: (WebCore::SVGPathSegWithContext::SVGPathSegWithContext): (WebCore::SVGPathSegWithContext::setContextAndRole): * svg/SVGTransformList.h: * svg/properties/SVGAnimatedListPropertyTearOff.h: (WebCore::SVGAnimatedListPropertyTearOff::baseVal): (WebCore::SVGAnimatedListPropertyTearOff::animVal): * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h: * svg/properties/SVGAnimatedPropertyTearOff.h: * svg/properties/SVGAnimatedTransformListPropertyTearOff.h: * svg/properties/SVGListProperty.h: (WebCore::SVGListProperty::initializeValuesAndWrappers): (WebCore::SVGListProperty::getItemValuesAndWrappers): (WebCore::SVGListProperty::insertItemBeforeValuesAndWrappers): (WebCore::SVGListProperty::replaceItemValuesAndWrappers): (WebCore::SVGListProperty::appendItemValuesAndWrappers): * svg/properties/SVGMatrixTearOff.h: * svg/properties/SVGPropertyTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::createInstance): * testing/MockCDMFactory.h: * workers/service/ExtendableEvent.h: * workers/service/FetchEvent.cpp: (WebCore::FetchEvent::respondWith): * workers/service/server/SWServer.h: * xml/DOMParser.cpp: (WebCore::DOMParser::DOMParser): Source/WebCore/PAL: 186407_CanMakeWeakPtr * pal/system/mac/SystemSleepListenerMac.h: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace): * NetworkProcess/PreconnectTask.h: * NetworkProcess/cache/CacheStorageEngine.h: * Shared/Authentication/AuthenticationManager.h: * UIProcess/API/APIAttachment.cpp: (API::Attachment::Attachment): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.h: * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/ViewGestureController.cpp: (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage): * UIProcess/Cocoa/WebViewImpl.h: * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::updateWindowAndViewFrames): (WebKit::WebViewImpl::setTopContentInset): (WebKit::WebViewImpl::viewDidMoveToWindow): (WebKit::WebViewImpl::prepareForMoveToWindow): (WebKit::WebViewImpl::validateUserInterfaceItem): (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded): (WebKit::WebViewImpl::interpretKeyEvent): (WebKit::WebViewImpl::firstRectForCharacterRange): (WebKit::WebViewImpl::performKeyEquivalent): (WebKit::WebViewImpl::keyUp): (WebKit::WebViewImpl::keyDown): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.cpp: (WebKit::WebCredentialsMessengerProxy::makeCredential): (WebKit::WebCredentialsMessengerProxy::getAssertion): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.h: * UIProcess/Downloads/DownloadProxy.cpp: (WebKit::DownloadProxy::setOriginatingPage): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: * UIProcess/WebPageProxy.h: * UIProcess/WebsiteData/WebsiteDataStore.h: * UIProcess/gtk/WaylandCompositor.cpp: (WebKit::WaylandCompositor::Surface::attachBuffer): * UIProcess/gtk/WaylandCompositor.h: * UIProcess/ios/ProcessAssertionIOS.mm: (WebKit::ProcessAssertion::ProcessAssertion): * UIProcess/mac/DisplayLink.cpp: (WebKit::DisplayLink::displayLinkCallback): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDisplayRefreshMonitor.mm: (WebKit::RemoteLayerTreeDisplayRefreshMonitor::RemoteLayerTreeDisplayRefreshMonitor): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: Source/WebKitLegacy/mac: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * WebCoreSupport/WebEditorClient.h: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::requestCandidatesForSelection): Source/WTF: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wtf/WeakPtr.h: (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Canonical link: https://commits.webkit.org/201784@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:56:04 +00:00
};
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename U, typename Counter> inline WeakPtrImpl<Counter>* weak_ptr_impl_cast(WeakPtrImpl<Counter>* impl)
{
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
static_assert(std::is_same_v<typename T::WeakValueType, typename U::WeakValueType>, "Invalid weak pointer cast");
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
return impl;
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>::WeakPtr(const WeakPtr<U, Counter>& o)
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
: m_impl(weak_ptr_impl_cast<T, U>(o.m_impl.get()))
{
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>::WeakPtr(WeakPtr<U, Counter>&& o)
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
: m_impl(adoptRef(weak_ptr_impl_cast<T, U>(o.m_impl.leakRef())))
{
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>& WeakPtr<T, Counter>::operator=(const WeakPtr<U, Counter>& o)
{
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
m_impl = weak_ptr_impl_cast<T, U>(o.m_impl.get());
return *this;
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename Counter> template<typename U> inline WeakPtr<T, Counter>& WeakPtr<T, Counter>::operator=(WeakPtr<U, Counter>&& o)
{
Some WeakPtr cleanup https://bugs.webkit.org/show_bug.cgi?id=198390 Reviewed by Chris Dumez. Source/WebCore: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::storageQuotaManagerGetter): Dereference the weak pointer directly instead of using a weak pointer to guard a raw pointer. It's safer and more idiomatic to use weak pointers directly. * Modules/indexeddb/shared/InProcessIDBServer.h: Use our base clase weakPtrFactory() definition instead of writing our own. Declare WeakValueType so we can dereference the weak pointer we create (above). Source/WTF: * wtf/WeakHashSet.h: (WTF::HashTraits<Ref<WeakPtrImpl>>::isReleasedWeakValue): (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Updated for rename to WeakPtrImpl. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Updated for new get() interface. Also, switched to iterator operator* to help clarify the double dereference here. (WTF::WeakHashSet::add): (WTF::WeakHashSet::remove): (WTF::WeakHashSet::contains const): (WTF::WeakHashSet::computeSize const): (WTF::HashTraits<Ref<WeakReference>>::isReleasedWeakValue): Deleted. Updated for rename to WeakPtrImpl. * wtf/WeakPtr.h: (WTF::WeakPtrImpl::create): (WTF::WeakPtrImpl::~WeakPtrImpl): Renamed WeakReference to WeakPtrImpl. Now we don't need a comment explaining that this class is the backing implementation of WeakPtr. (WTF::WeakPtrImpl::get): Return the pointer type we stored, rather than the pointer type requested by our client. It's a little too surprising for a field to store one pointer type and load another. (WTF::WeakPtrImpl::WeakPtrImpl): Fixed a theoretical type safety bug. Make sure to store T::WeakValueType* instead of T*, since they might not be the same pointer value. (In practice, T and T::WeakValueType* are always the same type in this constructor because WeakPtrFactory makes them so, but it's best not to depend on implementation details across classes.) (WTF::WeakPtr::get const): Updated for new get() interface. (WTF::WeakPtr::operator bool const): (WTF::WeakPtr::operator=): (WTF::WeakPtr::clear): (WTF::WeakPtr::WeakPtr): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::~WeakPtrFactory): Updated for WeakPtrImpl rename. (WTF::WeakPtrFactory::createWeakPtr const): ASSERT that the passed-in pointer is equal to the stored pointer. As a space optimization, we require our client to remind us what we point to each time a weak pointer is created -- but nothing guarantees that our client will do this correctly. (WTF::WeakPtrFactory::revokeAll): Updated for WeakPtrImpl rename. (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Use idiomatic accessor naming. (WTF::weak_ptr_impl_cast): Fixed a theoretical type safety bug. Previously, if Base and Derived both inherited CanMakeWeakPtr, and you casted WeakPtr<Base> to WeakPtr<Derived> (or vice versa), and casting Base <-> Derived required pointer fixup, the previous compile-time check would accept the cast, even though the stored pointer would be wrong. (WTF::WeakPtr<T>::WeakPtr): (WTF::=): (WTF::makeWeakPtr): (WTF::WeakReference::create): Deleted. (WTF::WeakReference::~WeakReference): Deleted. (WTF::WeakReference::get const): Deleted. (WTF::WeakReference::operator bool const): Deleted. (WTF::WeakReference::clear): Deleted. (WTF::WeakReference::WeakReference): Deleted. (WTF::weak_reference_cast): Deleted. Updated for rename to WeakPtrImpl. Don't export WeakPtrImpl because it's an implmenetation detail and it shouldn't be easy to use outside WTF. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Updated for rename. Canonical link: https://commits.webkit.org/212447@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-31 17:11:58 +00:00
m_impl = adoptRef(weak_ptr_impl_cast<T, U>(o.m_impl.leakRef()));
return *this;
}
template<typename T, typename = std::enable_if_t<!IsSmartPtr<T>::value>> inline auto makeWeakPtr(T& object, EnableWeakPtrThreadingAssertions enableWeakPtrThreadingAssertions = EnableWeakPtrThreadingAssertions::Yes)
{
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
return object.weakPtrFactory().template createWeakPtr<T>(object, enableWeakPtrThreadingAssertions);
}
template<typename T, typename = std::enable_if_t<!IsSmartPtr<T>::value>> inline auto makeWeakPtr(T* ptr, EnableWeakPtrThreadingAssertions enableWeakPtrThreadingAssertions = EnableWeakPtrThreadingAssertions::Yes) -> decltype(makeWeakPtr(*ptr))
{
if (!ptr)
return { };
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
return makeWeakPtr(*ptr, enableWeakPtrThreadingAssertions);
}
template<typename T, typename = std::enable_if_t<!IsSmartPtr<T>::value>> inline auto makeWeakPtr(const Ref<T>& object, EnableWeakPtrThreadingAssertions enableWeakPtrThreadingAssertions = EnableWeakPtrThreadingAssertions::Yes)
{
return makeWeakPtr(object.get(), enableWeakPtrThreadingAssertions);
}
template<typename T, typename = std::enable_if_t<!IsSmartPtr<T>::value>> inline auto makeWeakPtr(const RefPtr<T>& object, EnableWeakPtrThreadingAssertions enableWeakPtrThreadingAssertions = EnableWeakPtrThreadingAssertions::Yes)
{
return makeWeakPtr(object.get(), enableWeakPtrThreadingAssertions);
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename U, typename Counter> inline bool operator==(const WeakPtr<T, Counter>& a, const WeakPtr<U, Counter>& b)
{
return a.get() == b.get();
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename U, typename Counter> inline bool operator==(const WeakPtr<T, Counter>& a, U* b)
{
return a.get() == b;
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename U, typename Counter> inline bool operator==(T* a, const WeakPtr<U, Counter>& b)
{
return a == b.get();
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename U, typename Counter> inline bool operator!=(const WeakPtr<T, Counter>& a, const WeakPtr<U, Counter>& b)
{
return a.get() != b.get();
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename U, typename Counter> inline bool operator!=(const WeakPtr<T, Counter>& a, U* b)
{
return a.get() != b;
}
Add iterator checking to ListHashSet https://bugs.webkit.org/show_bug.cgi?id=211669 Reviewed by Anders Carlsson. Source/WebCore: * page/ios/ContentChangeObserver.h: Added an include of Element.h, needed to call makeWeakPtr in an inline function. This is due to a change in the way makeWeakPtr now checks the type of the argument. It's possible we could refine it further to relax this requirement, but it seems OK to include Element.h here. Source/WTF: HashSet and HashMap have iterator checking in debug builds. Add similar checking to ListHashSet, controlled by the same macro, CHECK_HASHTABLE_ITERATORS. Use WeakPtr to make the implementation simple. * wtf/Forward.h: Update to add a second parameter to WeakPtr. Also rearranged and tweaked the file a bug. * wtf/ListHashSet.h: Make ListHashSet and ListHashSetNode derive from CanMakeWeakPtr. Add m_weakSet and m_weakPosition members to ListHashSetConstIterator, and assert their values at the appropriate times so we will get a breakpoint or crash. * wtf/WeakHashSet.h: Updated to add a Counter argument for testing. * wtf/WeakPtr.h: Removed the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL macros, which didn't really work because using them violated the C++ one-definition rule. Replaced with a Counter argument, which defaults to EmptyCounter, which is inlines that do nothing. This required some updates to the classes and functions to make them work with a second argument. Tools: * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Removed use of the DID_CREATE_WEAK_PTR_IMPL and WILL_DESTROY_WEAK_PTR_IMPL, which didn't work consistently because of the one-definition rule. Instead, this file parameterizes the WeakPtr family of class templates with a counter class. To avoid having to rewrite test code, used alias templates to insert these class template into the TestWebKitAPI namespace, hiding the class templates from the WTF namespace. Canonical link: https://commits.webkit.org/224909@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-18 17:16:16 +00:00
template<typename T, typename U, typename Counter> inline bool operator!=(T* a, const WeakPtr<U, Counter>& b)
{
return a != b.get();
}
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
} // namespace WTF
Add base class to get WeakPtrFactory member and avoid some boilerplate code https://bugs.webkit.org/show_bug.cgi?id=186407 Reviewed by Brent Fulgham. Source/JavaScriptCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wasm/WasmInstance.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::registerInstance): Source/WebCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * Modules/credentialmanagement/CredentialsMessenger.h: * Modules/credentialmanagement/NavigatorCredentials.cpp: (WebCore::NavigatorCredentials::credentials): * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::doSupportedConfigurationStep): (WebCore::CDM::getConsentStatus): * Modules/encryptedmedia/CDM.h: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeySession.h: * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::createSession): * Modules/encryptedmedia/MediaKeys.h: * Modules/gamepad/GamepadManager.cpp: (WebCore::GamepadManager::platformGamepadDisconnected): (WebCore::GamepadManager::makeGamepadVisible): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::applyConstraints): * Modules/mediastream/MediaStreamTrack.h: * Modules/webauthn/cocoa/LocalAuthenticator.h: * Modules/webauthn/cocoa/LocalAuthenticator.mm: (WebCore::LocalAuthenticator::makeCredential): * accessibility/AccessibilityRenderObject.h: * accessibility/AccessibilitySVGRoot.cpp: (WebCore::AccessibilitySVGRoot::setParent): * crypto/SubtleCrypto.cpp: (WebCore::SubtleCrypto::encrypt): (WebCore::SubtleCrypto::decrypt): (WebCore::SubtleCrypto::sign): (WebCore::SubtleCrypto::verify): (WebCore::SubtleCrypto::digest): (WebCore::SubtleCrypto::generateKey): (WebCore::SubtleCrypto::deriveKey): (WebCore::SubtleCrypto::deriveBits): (WebCore::SubtleCrypto::importKey): (WebCore::SubtleCrypto::exportKey): (WebCore::SubtleCrypto::wrapKey): (WebCore::SubtleCrypto::unwrapKey): * crypto/SubtleCrypto.h: * css/CSSFontFace.cpp: (WebCore::CSSFontFace::CSSFontFace): (WebCore::CSSFontFace::wrapper): (WebCore::CSSFontFace::setWrapper): * css/DeprecatedCSSOMValue.h: * css/FontFace.cpp: * css/FontFace.h: * css/MediaQueryEvaluator.cpp: (WebCore::MediaQueryEvaluator::MediaQueryEvaluator): * css/StyleSheetContents.h: * css/parser/CSSDeferredParser.cpp: (WebCore::CSSDeferredParser::CSSDeferredParser): * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/DataTransferItemList.h: * dom/Document.cpp: (WebCore::Document::postTask): (WebCore::Document::hasStorageAccess): (WebCore::Document::requestStorageAccess): * dom/Document.h: (WebCore::Document::setContextDocument): * dom/MessagePort.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::setPictureElement): * html/HTMLInputElement.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): * html/HTMLMediaElement.h: * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: * layout/layouttree/LayoutBox.h: (WebCore::Layout::Box::style const): * loader/FormState.h: * loader/LinkLoader.cpp: (WebCore::LinkLoader::preconnectIfNeeded): * loader/LinkLoader.h: * loader/LinkPreloadResourceClients.cpp: (WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.h: * page/EventHandler.cpp: (WebCore::widgetForElement): (WebCore::EventHandler::updateLastScrollbarUnderMouse): * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::enqueueTask): (WebCore::GenericTaskQueue::cancelAllTasks): * platform/ScrollView.h: * platform/ScrollableArea.h: * platform/Scrollbar.h: * platform/Widget.cpp: (WebCore::Widget::setParent): * platform/Widget.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::decodeAudioForBusCreation): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/audio/mac/AudioHardwareListenerMac.h: * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::CDMInstanceClearKey::requestLicense): (WebCore::CDMInstanceClearKey::updateLicense): (WebCore::CDMInstanceClearKey::loadSession): (WebCore::CDMInstanceClearKey::closeSession): (WebCore::CDMInstanceClearKey::removeSessionData): * platform/encryptedmedia/clearkey/CDMClearKey.h: * platform/graphics/FontCascade.h: * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification): (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability): (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): (WebCore::MediaPlayerPrivateAVFoundationObjC::seekToTime): (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession): (WebCore::MediaPlayerPrivateAVFoundationObjC::setShouldPlayToPlaybackTarget): (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::requestNotificationWhenReadyForVideoData): (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask): * platform/graphics/cv/TextureCacheCV.h: * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVideo): (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfAudio): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage): (WebCore::MediaPlayerPrivateGStreamerBase::initializationDataEncountered): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::connectDemuxerSrcPadToAppsink): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/graphics/mac/DisplayRefreshMonitorMac.h: * platform/graphics/texmap/TextureMapperLayer.cpp: (WebCore::TextureMapperLayer::setMaskLayer): (WebCore::TextureMapperLayer::setReplicaLayer): * platform/graphics/texmap/TextureMapperLayer.h: * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::endCreatedMediaSource): (WebCore::MediaPlayerPrivateMediaFoundation::endGetEvent): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::processInputNotify): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h: * platform/ios/RemoteCommandListenerIOS.h: * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: * platform/mac/RemoteCommandListenerMac.mm: (WebCore::RemoteCommandListenerMac::RemoteCommandListenerMac): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::scheduleDeferredTask): * platform/mediastream/MediaStreamPrivate.h: * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::scheduleDeferredTask): * platform/mediastream/RealtimeMediaSource.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm: (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): * platform/vr/VRPlatformDisplay.h: * platform/vr/openvr/VRPlatformManagerOpenVR.cpp: (WebCore::VRPlatformManagerOpenVR::getVRDisplays): * rendering/FloatingObjects.h: (WebCore::FloatingObject::setOriginatingLine): * rendering/RenderObject.h: * rendering/RootInlineBox.cpp: * rendering/RootInlineBox.h: * svg/SVGPathElement.h: * svg/SVGPathSegWithContext.h: (WebCore::SVGPathSegWithContext::SVGPathSegWithContext): (WebCore::SVGPathSegWithContext::setContextAndRole): * svg/SVGTransformList.h: * svg/properties/SVGAnimatedListPropertyTearOff.h: (WebCore::SVGAnimatedListPropertyTearOff::baseVal): (WebCore::SVGAnimatedListPropertyTearOff::animVal): * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h: * svg/properties/SVGAnimatedPropertyTearOff.h: * svg/properties/SVGAnimatedTransformListPropertyTearOff.h: * svg/properties/SVGListProperty.h: (WebCore::SVGListProperty::initializeValuesAndWrappers): (WebCore::SVGListProperty::getItemValuesAndWrappers): (WebCore::SVGListProperty::insertItemBeforeValuesAndWrappers): (WebCore::SVGListProperty::replaceItemValuesAndWrappers): (WebCore::SVGListProperty::appendItemValuesAndWrappers): * svg/properties/SVGMatrixTearOff.h: * svg/properties/SVGPropertyTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::createInstance): * testing/MockCDMFactory.h: * workers/service/ExtendableEvent.h: * workers/service/FetchEvent.cpp: (WebCore::FetchEvent::respondWith): * workers/service/server/SWServer.h: * xml/DOMParser.cpp: (WebCore::DOMParser::DOMParser): Source/WebCore/PAL: 186407_CanMakeWeakPtr * pal/system/mac/SystemSleepListenerMac.h: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace): * NetworkProcess/PreconnectTask.h: * NetworkProcess/cache/CacheStorageEngine.h: * Shared/Authentication/AuthenticationManager.h: * UIProcess/API/APIAttachment.cpp: (API::Attachment::Attachment): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.h: * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/ViewGestureController.cpp: (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage): * UIProcess/Cocoa/WebViewImpl.h: * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::updateWindowAndViewFrames): (WebKit::WebViewImpl::setTopContentInset): (WebKit::WebViewImpl::viewDidMoveToWindow): (WebKit::WebViewImpl::prepareForMoveToWindow): (WebKit::WebViewImpl::validateUserInterfaceItem): (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded): (WebKit::WebViewImpl::interpretKeyEvent): (WebKit::WebViewImpl::firstRectForCharacterRange): (WebKit::WebViewImpl::performKeyEquivalent): (WebKit::WebViewImpl::keyUp): (WebKit::WebViewImpl::keyDown): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.cpp: (WebKit::WebCredentialsMessengerProxy::makeCredential): (WebKit::WebCredentialsMessengerProxy::getAssertion): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.h: * UIProcess/Downloads/DownloadProxy.cpp: (WebKit::DownloadProxy::setOriginatingPage): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: * UIProcess/WebPageProxy.h: * UIProcess/WebsiteData/WebsiteDataStore.h: * UIProcess/gtk/WaylandCompositor.cpp: (WebKit::WaylandCompositor::Surface::attachBuffer): * UIProcess/gtk/WaylandCompositor.h: * UIProcess/ios/ProcessAssertionIOS.mm: (WebKit::ProcessAssertion::ProcessAssertion): * UIProcess/mac/DisplayLink.cpp: (WebKit::DisplayLink::displayLinkCallback): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDisplayRefreshMonitor.mm: (WebKit::RemoteLayerTreeDisplayRefreshMonitor::RemoteLayerTreeDisplayRefreshMonitor): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: Source/WebKitLegacy/mac: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * WebCoreSupport/WebEditorClient.h: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::requestCandidatesForSelection): Source/WTF: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wtf/WeakPtr.h: (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Canonical link: https://commits.webkit.org/201784@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:56:04 +00:00
using WTF::CanMakeWeakPtr;
OfflineAudioContext objects are leaking https://bugs.webkit.org/show_bug.cgi?id=224279 Reviewed by Darin Adler. Source/WebCore: OfflineAudioContext objects were always leaking due to 2 reference cycles: 1. BaseAudioContext -> m_listener (AudioListener) -> m_positionX (AudioParam) -> m_context (BaseAudioContext) 2. BaseAudioContext -> m_destinationNode (AudioDestinationNode) -> m_context (BaseAudioContext) For reference cycle 1, I made AudioSummingJunction (base class of AudioParam) hold a weak pointer to the AudioContext instead of a Ref<>. I don't think there is a good reason for an AudioSummingJunction (AudioParam or AudioNodeInput) to keep its AudioContext alive. AudioNodes already keep their AudioContext alive. AudioNodeInputs and AudioParams are associated to AudioNodes. For reference cycle 2, I made AudioDestinationNode not hold a strong pointer to its context but instead a weak pointer. Since keeping an AudioDestinationNode alive should keep its AudioContext alive, I made it so that ref'ing the AudioDestinationNode refs its BaseAudioContext. Also, BaseAudioContext::m_destinationNode is now a UniqueRef<> instead of a RefPtr<> to avoid a cycle. Tests: webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html webaudio/OfflineAudioContext/offlineaudiocontext-leak.html * Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::baseLatency): (WebCore::AudioContext::getOutputTimestamp): (WebCore::AudioContext::close): (WebCore::AudioContext::destination): (WebCore::AudioContext::destination const): (WebCore::AudioContext::suspendRendering): (WebCore::AudioContext::resumeRendering): (WebCore::AudioContext::startRendering): (WebCore::AudioContext::lazyInitialize): (WebCore::AudioContext::mediaState const): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::suspendPlayback): (WebCore::AudioContext::pageMutedStateDidChange): * Modules/webaudio/AudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/AudioDestinationNode.cpp: (WebCore::AudioDestinationNode::ref): (WebCore::AudioDestinationNode::deref): * Modules/webaudio/AudioDestinationNode.h: Have AudioDestinationNode override AudioNode's ref() / deref() to forward the refcounting to its BaseAudioContext, instead of using the AudioNode's internal refCount. * Modules/webaudio/AudioListener.cpp: (WebCore::AudioListener::updateValuesIfNeeded): (WebCore::AudioListener::setPosition): (WebCore::AudioListener::setOrientation): Add some null-checks for AudioParam::context() now that AudioParam holds a WeakPtr to its context. * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::toWeakOrStrongContext): (WebCore::AudioNode::AudioNode): (WebCore::AudioNode::connect): (WebCore::AudioNode::sampleRate const): (WebCore::AudioNode::markNodeForDeletionIfNecessary): (WebCore::AudioNode::contextForBindings): (WebCore::AudioNode::context): (WebCore::AudioNode::context const): * Modules/webaudio/AudioNode.h: - Hold the BaseAudioContext as a WeakPtr instead of a Ref<> if the AudioNode is an AudioDestinationNode. This avoids a reference cycle since the BaseAudioContext owns the AudioDestinationNode. Even though we are using a WeakPtr, it is safe to assume that the context is not null because ref'ing an AudioDestinationNode refs its BaseAudioContext. - Make sure markNodeForDeletionIfNecessary() has no effect for AudioDestinationNode since BaseAudioContext now owns the AudioDestinationNode when we take care of destroying its destination node when destroyed. * Modules/webaudio/AudioNodeInput.cpp: (WebCore::AudioNodeInput::connect): (WebCore::AudioNodeInput::disconnect): (WebCore::AudioNodeInput::outputEnabledStateChanged): (WebCore::AudioNodeInput::updateInternalBus): (WebCore::AudioNodeInput::bus): (WebCore::AudioNodeInput::internalSummingBus): (WebCore::AudioNodeInput::sumAllConnections): (WebCore::AudioNodeInput::pull): Add assertions that the context is not null. There were already assertions that we are the graph owner, which means we are holding the BaseAudioContext's lock, which means that the audio context is alive. * Modules/webaudio/AudioParam.cpp: (WebCore::AudioParam::value): (WebCore::AudioParam::setValueForBindings): (WebCore::AudioParam::smooth): (WebCore::AudioParam::hasSampleAccurateValues const): (WebCore::AudioParam::calculateSampleAccurateValues): (WebCore::AudioParam::calculateFinalValues): (WebCore::AudioParam::calculateTimelineValues): (WebCore::AudioParam::connect): (WebCore::AudioParam::disconnect): Add null-checks for the AudioContext now that the AudioParam is only holding a WeakPtr to its BaseAudioContext (to avoid a reference cycle). * Modules/webaudio/AudioSummingJunction.cpp: (WebCore::AudioSummingJunction::AudioSummingJunction): (WebCore::AudioSummingJunction::~AudioSummingJunction): (WebCore::AudioSummingJunction::markRenderingStateAsDirty): (WebCore::AudioSummingJunction::addOutput): (WebCore::AudioSummingJunction::removeOutput): (WebCore::AudioSummingJunction::updateRenderingState): (WebCore::AudioSummingJunction::outputEnabledStateChanged): * Modules/webaudio/AudioSummingJunction.h: (WebCore::AudioSummingJunction::context): (WebCore::AudioSummingJunction::context const): - Hold a WeakPtr to the BaseAudioContext to avoid a reference cycle. - Deal with the fact that the audio context may be null now that we're holding a WeakPtr to it (except when holding the graph lock) * Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::BaseAudioContext): (WebCore::BaseAudioContext::~BaseAudioContext): (WebCore::BaseAudioContext::numberOfInstances): (WebCore::BaseAudioContext::lazyInitialize): (WebCore::BaseAudioContext::clear): (WebCore::BaseAudioContext::uninitialize): (WebCore::BaseAudioContext::stop): (WebCore::BaseAudioContext::sampleRate const): (WebCore::BaseAudioContext::decodeAudioData): (WebCore::BaseAudioContext::markForDeletion): (WebCore::BaseAudioContext::deleteMarkedNodes): (WebCore::BaseAudioContext::setPendingActivity): (WebCore::BaseAudioContext::workletIsReady): * Modules/webaudio/BaseAudioContext.h: (WebCore::BaseAudioContext::destination): (WebCore::BaseAudioContext::destination const): (WebCore::BaseAudioContext::currentSampleFrame const): (WebCore::BaseAudioContext::currentTime const): - Switch m_destinationNode from RefPtr<> to UniqueRef<> since the AudioContext is now the owner of the destinationNode and since refing the destination node actually refs its BaseAudioContext. - Drop some null checks now that m_destinationNode can no longer be null. - Rename makePendingActivity() to setPendingActivity() to avoid a naming conflict with ActiveDOMObject::makePendingActivity(). * Modules/webaudio/DefaultAudioDestinationNode.h: * Modules/webaudio/OfflineAudioDestinationNode.h: - Drop create() factory functions and make the constructor public now that the BaseAudioContext owns its destination node via a UniqueRef<>. - Make some member functions public as they are virtual and they now called on the subclass instead of the base class (and these functions are public in the base class). * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): (WebCore::OfflineAudioContext::resumeOfflineRendering): * Modules/webaudio/OfflineAudioContext.h: - Drop some null checks now that m_destinationNode can no longer be null. - Capture an ActiveDOMObject::PendingActivity when doing async work that ends up resolving a Promise, so that we keep both the object and its wrapper alive for the duration of the async work. * Modules/webaudio/WebKitAudioContext.cpp: (WebCore::WebKitAudioContext::close): Drop null checks for the destination node now that it can never be null. * dom/ShadowRoot.cpp: * rendering/FloatingObjects.cpp: * rendering/RootInlineBox.cpp: Update classes used of size restrictions since the size of a WeakPtr is not longer the same as the size of a pointer when debug assertions are enabled. As long as they are the same size in release builds, there is no memory use concern. * testing/Internals.cpp: (WebCore::Internals::numberOfBaseAudioContexts const): * testing/Internals.h: * testing/Internals.idl: Add testing function to check how many BaseAudioContexts are alive, so that we can write layout tests and check for leaks. Source/WTF: Add flag that can be passed when constructing a WeakPtr to disable threading assertions. This is useful for cases where we know it is safe due to locking but we'd like to use a WeakPtr instead of a raw pointer because it is safer. * wtf/WeakPtr.h: (WTF::WeakPtr::get const): (WTF::WeakPtr::operator-> const): (WTF::WeakPtr::operator* const): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::=): (WTF::makeWeakPtr): LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-after-rendering.html: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak-expected.txt: Added. * webaudio/OfflineAudioContext/offlineaudiocontext-leak.html: Added. Canonical link: https://commits.webkit.org/236304@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 18:41:23 +00:00
using WTF::EnableWeakPtrThreadingAssertions;
Generalize DocumentWeakReference into WTF::WeakPtr https://bugs.webkit.org/show_bug.cgi?id=106854 Reviewed by Darin Adler. Source/WebCore: This patch replaces DocumentWeakReference with WeakPtr. There should be no change in behavior. * dom/Document.cpp: (WebCore): (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::PerformTaskContext::PerformTaskContext): (PerformTaskContext): (WebCore::Document::didReceiveTask): (WebCore::Document::postTask): (WebCore::Document::reportMemoryUsage): * dom/Document.h: (WebCore): (Document): Source/WTF: This patch adds a simple WeakPtr object to WTF. To use WeakPtr, objects must hold a WeakPtrFactory member variable, which clears the WeakPtrs when the object is destructed. The underlying storage is a ThreadSafeRefCounted "WeakReference" object, which is shared by all the WeakPtrs. WeakPtr is a generalization of DocumentWeakReference, which is used to check whether the Document object is alive when tasks arive on the main thread from worker threads. We plan to use a similar pattern in the threaded HTML parser, but we want to send tasks to objects other than Document. * GNUmakefile.list.am: * WTF.gypi: * WTF.pro: * WTF.vcproj/WTF.vcproj: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/WeakPtr.h: Added. (WeakReference): - The ThreadSafeRefCounted object shared by all the WeakPtr instances. This patch uses ThreadSafeRefCounted so that we can use WeakPtrs to cancel cross-thread messages. (WTF::WeakReference::create): (WTF::WeakReference::get): (WTF::WeakReference::clear): - When the object is destroyed, WeakPtrFactory calls this function to clear all the WeakPtrs. (WTF::WeakReference::WeakReference): (WTF::WeakPtr::WeakPtr): (WTF::WeakPtr::get): - We might want to add implicit conversions and Boolean operators in the future, but I've kept this class simple for now. (WTF::WeakPtrFactory::WeakPtrFactory): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::createWeakPtr): Canonical link: https://commits.webkit.org/125163@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-01-15 21:35:08 +00:00
using WTF::WeakPtr;
using WTF::WeakPtrFactory;
using WTF::WeakPtrFactoryInitialization;
using WTF::makeWeakPtr;