Title: [204529] trunk
Revision
204529
Author
ander...@apple.com
Date
2016-08-16 15:32:50 -0700 (Tue, 16 Aug 2016)

Log Message

Add WTF::ScopeExit
https://bugs.webkit.org/show_bug.cgi?id=160908

Reviewed by Geoffrey Garen.

Source/WTF:

WTF::ScopeExit and WTF::makeScopeExit let you define an object that will invoke a function when the
object goes out of scope. This is going to be used to avoid spagetti-code and gotos in a future patch.

The class is modeled after the LWG paper "P0052 - Generic Scope Guard and RAII Wrapper for the Standard Library".

* WTF.xcodeproj/project.pbxproj:
* wtf/Scope.h: Added.
(WTF::makeScopeExit):

Tools:

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/Scope.cpp: Added.
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (204528 => 204529)


--- trunk/Source/WTF/ChangeLog	2016-08-16 22:26:40 UTC (rev 204528)
+++ trunk/Source/WTF/ChangeLog	2016-08-16 22:32:50 UTC (rev 204529)
@@ -1,3 +1,19 @@
+2016-08-16  Anders Carlsson  <ander...@apple.com>
+
+        Add WTF::ScopeExit
+        https://bugs.webkit.org/show_bug.cgi?id=160908
+
+        Reviewed by Geoffrey Garen.
+
+        WTF::ScopeExit and WTF::makeScopeExit let you define an object that will invoke a function when the
+        object goes out of scope. This is going to be used to avoid spagetti-code and gotos in a future patch.
+
+        The class is modeled after the LWG paper "P0052 - Generic Scope Guard and RAII Wrapper for the Standard Library".
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/Scope.h: Added.
+        (WTF::makeScopeExit):
+
 2016-08-15  Anders Carlsson  <ander...@apple.com>
 
         Add an address-of operator to RetainPtr

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (204528 => 204529)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2016-08-16 22:26:40 UTC (rev 204528)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2016-08-16 22:32:50 UTC (rev 204529)
@@ -81,6 +81,7 @@
 		1A1D8B9C173186CE00141DA4 /* FunctionDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1D8B9B173186CE00141DA4 /* FunctionDispatcher.h */; };
 		1A1D8B9E1731879800141DA4 /* FunctionDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */; };
 		1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A233C7C17DAA6E300A93ACF /* MallocPtr.h */; };
+		1A3524AB1D63A2FF0031729B /* Scope.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A3524AA1D63A2FF0031729B /* Scope.h */; };
 		1A428B8C1C8F89DD0051E9EB /* AppKitCompatibilityDeclarations.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A428B8B1C8F89DD0051E9EB /* AppKitCompatibilityDeclarations.h */; };
 		1A4656191C7FC68E00F5920F /* OptionSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4656181C7FC68E00F5920F /* OptionSet.h */; };
 		1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6BB768162F300500DD16DB /* StreamBuffer.h */; };
@@ -416,6 +417,7 @@
 		1A1D8B9B173186CE00141DA4 /* FunctionDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionDispatcher.h; sourceTree = "<group>"; };
 		1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FunctionDispatcher.cpp; sourceTree = "<group>"; };
 		1A233C7C17DAA6E300A93ACF /* MallocPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MallocPtr.h; sourceTree = "<group>"; };
+		1A3524AA1D63A2FF0031729B /* Scope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Scope.h; sourceTree = "<group>"; };
 		1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeverDestroyed.h; sourceTree = "<group>"; };
 		1A428B8B1C8F89DD0051E9EB /* AppKitCompatibilityDeclarations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppKitCompatibilityDeclarations.h; sourceTree = "<group>"; };
 		1A4656181C7FC68E00F5920F /* OptionSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OptionSet.h; sourceTree = "<group>"; };
@@ -788,10 +790,10 @@
 		A5BA15F11824339F00A82E69 /* mac */ = {
 			isa = PBXGroup;
 			children = (
-				1C181C951D30800A00F5FA16 /* TextBreakIteratorInternalICUMac.mm */,
 				A5BA15F41824348000A82E69 /* StringImplMac.mm */,
 				A5BA15F2182433A900A82E69 /* StringMac.mm */,
 				93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */,
+				1C181C951D30800A00F5FA16 /* TextBreakIteratorInternalICUMac.mm */,
 			);
 			name = mac;
 			sourceTree = "<group>";
@@ -810,7 +812,6 @@
 		A876DBD6151816E500DADB95 /* wtf */ = {
 			isa = PBXGroup;
 			children = (
-				5C7C88D31D0A3A0A009D2F6D /* UniqueRef.h */,
 				2CDED0F018115C3F004DBA70 /* cf */,
 				E4A0AD3B1A96251900536DF6 /* cocoa */,
 				A8A47281151A825A004123FF /* dtoa */,
@@ -984,6 +985,7 @@
 				1469419416EAAFF80024E146 /* SchedulePair.h */,
 				1469419816EAB0410024E146 /* SchedulePairCF.cpp */,
 				1469419516EAAFF80024E146 /* SchedulePairMac.mm */,
+				1A3524AA1D63A2FF0031729B /* Scope.h */,
 				0FEC84B01BDACD390080FF74 /* ScopedLambda.h */,
 				A8A47306151A825B004123FF /* SegmentedVector.h */,
 				A8A47307151A825B004123FF /* SentinelLinkedList.h */,
@@ -1025,6 +1027,7 @@
 				149EF16216BBFE0D000A4331 /* TriState.h */,
 				83FBA93119DF459700F30ADB /* TypeCasts.h */,
 				A8A4735C151A825B004123FF /* UnionFind.h */,
+				5C7C88D31D0A3A0A009D2F6D /* UniqueRef.h */,
 				A8A4736F151A825B004123FF /* ValueCheck.h */,
 				7CD0D5A71D55322A000CC9E1 /* Variant.h */,
 				A8A47370151A825B004123FF /* Vector.h */,
@@ -1083,8 +1086,8 @@
 		A8A4731B151A825B004123FF /* text */ = {
 			isa = PBXGroup;
 			children = (
+				A5BA15F61824359E00A82E69 /* cf */,
 				1C181C881D307AB800F5FA16 /* icu */,
-				A5BA15F61824359E00A82E69 /* cf */,
 				A5BA15F11824339F00A82E69 /* mac */,
 				A8A4731C151A825B004123FF /* ASCIIFastPath.h */,
 				A8A4731D151A825B004123FF /* AtomicString.cpp */,
@@ -1101,6 +1104,7 @@
 				A8A47322151A825B004123FF /* CString.h */,
 				26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */,
 				93AC91A718942FC400244939 /* LChar.h */,
+				1C181C811D30797C00F5FA16 /* LineBreakIteratorPoolICU.h */,
 				A8A47323151A825B004123FF /* StringBuffer.h */,
 				A8A47324151A825B004123FF /* StringBuilder.cpp */,
 				A8A47325151A825B004123FF /* StringBuilder.h */,
@@ -1116,14 +1120,13 @@
 				70ECA60B1B02426800449739 /* SymbolImpl.h */,
 				70A993FC1AD7151300FA615B /* SymbolRegistry.cpp */,
 				70A993FD1AD7151300FA615B /* SymbolRegistry.h */,
+				1C181C7D1D3078DA00F5FA16 /* TextBreakIterator.cpp */,
+				1C181C7E1D3078DA00F5FA16 /* TextBreakIterator.h */,
+				1C181C821D3079AC00F5FA16 /* TextBreakIteratorInternalICU.h */,
 				A8A4732C151A825B004123FF /* TextPosition.h */,
 				70ECA60C1B02426800449739 /* UniquedStringImpl.h */,
 				A8A4732D151A825B004123FF /* WTFString.cpp */,
 				A8A4732E151A825B004123FF /* WTFString.h */,
-				1C181C7D1D3078DA00F5FA16 /* TextBreakIterator.cpp */,
-				1C181C7E1D3078DA00F5FA16 /* TextBreakIterator.h */,
-				1C181C811D30797C00F5FA16 /* LineBreakIteratorPoolICU.h */,
-				1C181C821D3079AC00F5FA16 /* TextBreakIteratorInternalICU.h */,
 			);
 			path = text;
 			sourceTree = "<group>";
@@ -1171,9 +1174,9 @@
 			isa = PBXGroup;
 			children = (
 				DE5A09FB1BA36992003D4424 /* CommonCryptoSPI.h */,
+				93DDE9311CDC052D00FD3491 /* dyldSPI.h */,
 				A5098AFF1C169E0700087797 /* SandboxSPI.h */,
 				CE73E02419DCB7AB00580D5C /* XPCSPI.h */,
-				93DDE9311CDC052D00FD3491 /* dyldSPI.h */,
 			);
 			path = darwin;
 			sourceTree = "<group>";
@@ -1218,10 +1221,9 @@
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				1A428B8C1C8F89DD0051E9EB /* AppKitCompatibilityDeclarations.h in Headers */,
 				A8A47385151A825B004123FF /* ASCIICType.h in Headers */,
-				5C7C88D41D0A3A0A009D2F6D /* UniqueRef.h in Headers */,
 				A8A47434151A825B004123FF /* ASCIIFastPath.h in Headers */,
-				539EB0631D55284200C82EF7 /* LEBDecoder.h in Headers */,
 				A8A47387151A825B004123FF /* Assertions.h in Headers */,
 				A8A47388151A825B004123FF /* Atomics.h in Headers */,
 				A8A47436151A825B004123FF /* AtomicString.h in Headers */,
@@ -1229,8 +1231,8 @@
 				A8A47438151A825B004123FF /* AtomicStringImpl.h in Headers */,
 				9BD8F40B176C2B470002D865 /* AtomicStringTable.h in Headers */,
 				1469419C16EAB10A0024E146 /* AutodrainedPool.h in Headers */,
+				DCEE22051CEB9869000C2396 /* BackwardsGraph.h in Headers */,
 				0FB14E19180FA218009B6B4D /* Bag.h in Headers */,
-				DCEE22001CEA7551000C2396 /* BlockObjCExceptions.h in Headers */,
 				0FB14E1B1810E1DC009B6B4D /* BagToHashMap.h in Headers */,
 				8134013915B092FD001FF0B8 /* Base64.h in Headers */,
 				A8A473A9151A825B004123FF /* bignum-dtoa.h in Headers */,
@@ -1238,9 +1240,8 @@
 				A8A47452151A825B004123FF /* BinarySemaphore.h in Headers */,
 				A8A4738A151A825B004123FF /* Bitmap.h in Headers */,
 				A8A4738C151A825B004123FF /* BitVector.h in Headers */,
-				515F79561CFD3A6900CCED93 /* CrossThreadQueue.h in Headers */,
+				DCEE22001CEA7551000C2396 /* BlockObjCExceptions.h in Headers */,
 				1A944F471C3D8814005BD28C /* BlockPtr.h in Headers */,
-				93DDE9321CDC052D00FD3491 /* dyldSPI.h in Headers */,
 				A8A4738E151A825B004123FF /* BlockStack.h in Headers */,
 				A8A4738F151A825B004123FF /* BloomFilter.h in Headers */,
 				0F93274B1C17F4B700CF6564 /* Box.h in Headers */,
@@ -1248,20 +1249,21 @@
 				A8A47391151A825B004123FF /* BumpPointerAllocator.h in Headers */,
 				EB95E1F0161A72410089A2F5 /* ByteOrder.h in Headers */,
 				A8A473AD151A825B004123FF /* cached-powers.h in Headers */,
-				DCEE22051CEB9869000C2396 /* BackwardsGraph.h in Headers */,
+				DCEE21FB1CEA7538000C2396 /* CFBundleSPI.h in Headers */,
 				A8A4745E151A825B004123FF /* CharacterNames.h in Headers */,
 				A8A47394151A825B004123FF /* CheckedArithmetic.h in Headers */,
 				A8A47395151A825B004123FF /* CheckedBoolean.h in Headers */,
 				A8A4745F151A825B004123FF /* Collator.h in Headers */,
 				0FC4EDE61696149600F65041 /* CommaPrinter.h in Headers */,
-				79EC70611C99F9BC003A3AE2 /* SmallPtrSet.h in Headers */,
 				DE5A09FC1BA36992003D4424 /* CommonCryptoSPI.h in Headers */,
 				0F8F2B91172E00FC007DBDA5 /* CompilationThread.h in Headers */,
 				A8A47398151A825B004123FF /* Compiler.h in Headers */,
-				1A428B8C1C8F89DD0051E9EB /* AppKitCompatibilityDeclarations.h in Headers */,
 				0FDB698E1B7C643A000C1078 /* Condition.h in Headers */,
 				A8A4748C151A8264004123FF /* config.h in Headers */,
 				0F8F2B9C172F2596007DBDA5 /* ConversionMode.h in Headers */,
+				515F794F1CFC9F4A00CCED93 /* CrossThreadCopier.h in Headers */,
+				515F79561CFD3A6900CCED93 /* CrossThreadQueue.h in Headers */,
+				515F79501CFC9F4A00CCED93 /* CrossThreadTask.h in Headers */,
 				A8A4739B151A825B004123FF /* CryptographicallyRandomNumber.h in Headers */,
 				E15556F618A0CC18006F48FB /* CryptographicUtilities.h in Headers */,
 				A8A4743A151A825B004123FF /* CString.h in Headers */,
@@ -1278,6 +1280,7 @@
 				A8A473B2151A825B004123FF /* double.h in Headers */,
 				A8A473A7151A825B004123FF /* DoublyLinkedList.h in Headers */,
 				A8A473BB151A825B004123FF /* dtoa.h in Headers */,
+				93DDE9321CDC052D00FD3491 /* dyldSPI.h in Headers */,
 				A8A473C1151A825B004123FF /* ExportMacros.h in Headers */,
 				A8A473B4151A825B004123FF /* fast-dtoa.h in Headers */,
 				0FD81AC5154FB22E00983E72 /* FastBitVector.h in Headers */,
@@ -1287,6 +1290,7 @@
 				A8A473B6151A825B004123FF /* fixed-dtoa.h in Headers */,
 				0F2B66A717B6B4FD00A7AE3F /* FlipBytes.h in Headers */,
 				A8A473C8151A825B004123FF /* Forward.h in Headers */,
+				83F2BADF1CF9524E003E99C3 /* Function.h in Headers */,
 				1A1D8B9C173186CE00141DA4 /* FunctionDispatcher.h in Headers */,
 				A8A473CA151A825B004123FF /* GetPtr.h in Headers */,
 				0FEC84AF1BD825310080FF74 /* GraphNodeWorklist.h in Headers */,
@@ -1293,7 +1297,6 @@
 				2C05385415BC819000F21B96 /* GregorianDateTime.h in Headers */,
 				A8A473D3151A825B004123FF /* HashCountedSet.h in Headers */,
 				A8A4742D151A825B004123FF /* Hasher.h in Headers */,
-				1C181C901D307AB800F5FA16 /* UTextProvider.h in Headers */,
 				A8A473D4151A825B004123FF /* HashFunctions.h in Headers */,
 				A8A473D5151A825B004123FF /* HashIterators.h in Headers */,
 				A8A473D6151A825B004123FF /* HashMap.h in Headers */,
@@ -1301,7 +1304,7 @@
 				A8A473D9151A825B004123FF /* HashTable.h in Headers */,
 				A8A473DA151A825B004123FF /* HashTraits.h in Headers */,
 				A8A473DB151A825B004123FF /* HexNumber.h in Headers */,
-				83F2BADF1CF9524E003E99C3 /* Function.h in Headers */,
+				FE8925B01D00DAEC0046907E /* Indenter.h in Headers */,
 				2684D4361C000D400081D663 /* IndexSparseSet.h in Headers */,
 				A8A473DC151A825B004123FF /* InlineASM.h in Headers */,
 				A70DA0841799F04D00529A9B /* Insertion.h in Headers */,
@@ -1309,18 +1312,17 @@
 				7CDD7FF8186D291E007433CD /* IteratorAdaptors.h in Headers */,
 				7CDD7FFA186D2A54007433CD /* IteratorRange.h in Headers */,
 				93AC91A818942FC400244939 /* LChar.h in Headers */,
+				539EB0631D55284200C82EF7 /* LEBDecoder.h in Headers */,
 				A70DA0851799F04D00529A9B /* ListDump.h in Headers */,
-				1C181C941D307AB800F5FA16 /* UTextProviderUTF16.h in Headers */,
 				A8A473E1151A825B004123FF /* ListHashSet.h in Headers */,
 				0FE1646B1B6FFC9600400E7C /* Lock.h in Headers */,
 				A8A473E3151A825B004123FF /* Locker.h in Headers */,
+				513E170B1CD7D5BF00E3650B /* LoggingAccumulator.h in Headers */,
 				A8A473E6151A825B004123FF /* MainThread.h in Headers */,
-				515F794F1CFC9F4A00CCED93 /* CrossThreadCopier.h in Headers */,
 				1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */,
 				A8A473E8151A825B004123FF /* MathExtras.h in Headers */,
 				A8A473EA151A825B004123FF /* MD5.h in Headers */,
 				CD5497AD15857D0300B5BC30 /* MediaTime.h in Headers */,
-				1C181C801D3078DA00F5FA16 /* TextBreakIterator.h in Headers */,
 				A8A473EB151A825B004123FF /* MessageQueue.h in Headers */,
 				A8A473ED151A825B004123FF /* MetaAllocator.h in Headers */,
 				A8A473EE151A825B004123FF /* MetaAllocatorHandle.h in Headers */,
@@ -1347,6 +1349,7 @@
 				0F824A691B7443A0002E345D /* ParkingLot.h in Headers */,
 				A8A4740C151A825B004123FF /* PassRefPtr.h in Headers */,
 				A876DBD8151816E500DADB95 /* Platform.h in Headers */,
+				DCEE22021CEA7551000C2396 /* PlatformUserPreferredLanguages.h in Headers */,
 				0FF860951BCCBD740045127F /* PointerComparison.h in Headers */,
 				0F9D3363165DBA73005AD387 /* PrintStream.h in Headers */,
 				0FC4488316FE9FE100844BE9 /* ProcessID.h in Headers */,
@@ -1354,7 +1357,6 @@
 				A8A47415151A825B004123FF /* RandomNumber.h in Headers */,
 				A8A47416151A825B004123FF /* RandomNumberSeed.h in Headers */,
 				0F725CAC1C50461600AD943A /* RangeSet.h in Headers */,
-				513E170B1CD7D5BF00E3650B /* LoggingAccumulator.h in Headers */,
 				0F87105A16643F190090B0AD /* RawPointer.h in Headers */,
 				A8A47417151A825B004123FF /* RedBlackTree.h in Headers */,
 				26299B6E17A9E5B800ADEBE5 /* Ref.h in Headers */,
@@ -1364,12 +1366,12 @@
 				86F46F611A2840EE00CCBF22 /* RefCounter.h in Headers */,
 				A8A4741C151A825B004123FF /* RefPtr.h in Headers */,
 				A8A4741E151A825B004123FF /* RetainPtr.h in Headers */,
-				515F79501CFC9F4A00CCED93 /* CrossThreadTask.h in Headers */,
 				2CDED0F418115C85004DBA70 /* RunLoop.h in Headers */,
 				1469419216EAAF6D0024E146 /* RunLoopTimer.h in Headers */,
 				A5098B001C169E0700087797 /* SandboxSPI.h in Headers */,
 				14F3B0F715E45E4600210069 /* SaturatedArithmetic.h in Headers */,
 				1469419616EAAFF80024E146 /* SchedulePair.h in Headers */,
+				1A3524AB1D63A2FF0031729B /* Scope.h in Headers */,
 				0FEC84B11BDACD390080FF74 /* ScopedLambda.h in Headers */,
 				A5098B021C16A4F900087797 /* SecuritySPI.h in Headers */,
 				A8A4741F151A825B004123FF /* SegmentedVector.h in Headers */,
@@ -1379,11 +1381,10 @@
 				A8A47423151A825B004123FF /* SimpleStats.h in Headers */,
 				A8A47424151A825B004123FF /* SinglyLinkedList.h in Headers */,
 				A748745317A0BDAE00FA04CB /* SixCharacterHash.h in Headers */,
+				79EC70611C99F9BC003A3AE2 /* SmallPtrSet.h in Headers */,
 				A8A47426151A825B004123FF /* Spectrum.h in Headers */,
 				A8A47428151A825B004123FF /* StackBounds.h in Headers */,
-				1C181C921D307AB800F5FA16 /* UTextProviderLatin1.h in Headers */,
 				FEDACD3E1630F83F00C69634 /* StackStats.h in Headers */,
-				7CD0D5A91D5534A7000CC9E1 /* Variant.h in Headers */,
 				A8A47429151A825B004123FF /* StaticConstructors.h in Headers */,
 				A8A4742A151A825B004123FF /* StdLibExtras.h in Headers */,
 				C4F8A93719C65EB400B2B15D /* Stopwatch.h in Headers */,
@@ -1396,7 +1397,6 @@
 				A8A4743F151A825B004123FF /* StringHash.h in Headers */,
 				A748745417A0BDAE00FA04CB /* StringHashDumpContext.h in Headers */,
 				A8A47441151A825B004123FF /* StringImpl.h in Headers */,
-				DCEE21FB1CEA7538000C2396 /* CFBundleSPI.h in Headers */,
 				A8A47442151A825B004123FF /* StringOperators.h in Headers */,
 				0FDDBFA81666DFA300C55FEF /* StringPrintStream.h in Headers */,
 				1A6EB1E0187D0BD30030126F /* StringView.h in Headers */,
@@ -1405,6 +1405,7 @@
 				70A993FF1AD7151300FA615B /* SymbolRegistry.h in Headers */,
 				0FB317C41C488001007E395A /* SystemTracing.h in Headers */,
 				A8A47433151A825B004123FF /* TemporaryChange.h in Headers */,
+				1C181C801D3078DA00F5FA16 /* TextBreakIterator.h in Headers */,
 				A8A47444151A825B004123FF /* TextPosition.h in Headers */,
 				A8A47447151A825B004123FF /* ThreadFunctionInvocation.h in Headers */,
 				A8A47449151A825B004123FF /* ThreadIdentifierDataPthreads.h in Headers */,
@@ -1414,16 +1415,19 @@
 				A8A47455151A825B004123FF /* ThreadSpecific.h in Headers */,
 				553071CA1C40427200384898 /* TinyLRUCache.h in Headers */,
 				0FED67B61B22D4D80066CE15 /* TinyPtrSet.h in Headers */,
-				DCEE22021CEA7551000C2396 /* PlatformUserPreferredLanguages.h in Headers */,
 				149EF16316BBFE0D000A4331 /* TriState.h in Headers */,
 				83FBA93219DF459700F30ADB /* TypeCasts.h in Headers */,
 				1AFDE648195201C300C48FFA /* TypeCastsCF.h in Headers */,
-				FE8925B01D00DAEC0046907E /* Indenter.h in Headers */,
 				A8A4746D151A825B004123FF /* UnionFind.h in Headers */,
 				70ECA60F1B02426800449739 /* UniquedStringImpl.h in Headers */,
+				5C7C88D41D0A3A0A009D2F6D /* UniqueRef.h in Headers */,
+				1C181C901D307AB800F5FA16 /* UTextProvider.h in Headers */,
+				1C181C921D307AB800F5FA16 /* UTextProviderLatin1.h in Headers */,
+				1C181C941D307AB800F5FA16 /* UTextProviderUTF16.h in Headers */,
 				A8A4746A151A825B004123FF /* UTF8.h in Headers */,
 				A8A473B9151A825B004123FF /* utils.h in Headers */,
 				A8A4747D151A825B004123FF /* ValueCheck.h in Headers */,
+				7CD0D5A91D5534A7000CC9E1 /* Variant.h in Headers */,
 				A8A4747E151A825B004123FF /* Vector.h in Headers */,
 				A8A4747F151A825B004123FF /* VectorTraits.h in Headers */,
 				A8A47480151A825B004123FF /* VMTags.h in Headers */,
@@ -1546,14 +1550,15 @@
 				A8A473AA151A825B004123FF /* bignum.cc in Sources */,
 				A8A47451151A825B004123FF /* BinarySemaphore.cpp in Sources */,
 				A8A4738B151A825B004123FF /* BitVector.cpp in Sources */,
+				DCEE22011CEA7551000C2396 /* BlockObjCExceptions.mm in Sources */,
 				A8A473AC151A825B004123FF /* cached-powers.cc in Sources */,
 				A8A47460151A825B004123FF /* CollatorDefault.cpp in Sources */,
 				A8A47463151A825B004123FF /* CollatorICU.cpp in Sources */,
 				0F8F2B92172E0103007DBDA5 /* CompilationThread.cpp in Sources */,
+				515F794E1CFC9F4A00CCED93 /* CrossThreadCopier.cpp in Sources */,
 				A8A4739A151A825B004123FF /* CryptographicallyRandomNumber.cpp in Sources */,
 				E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */,
 				A8A47439151A825B004123FF /* CString.cpp in Sources */,
-				1C181C961D30800A00F5FA16 /* TextBreakIteratorInternalICUMac.mm in Sources */,
 				A8A4739C151A825B004123FF /* CurrentTime.cpp in Sources */,
 				A8A4739E151A825B004123FF /* DataLog.cpp in Sources */,
 				A8A473A0151A825B004123FF /* DateMath.cpp in Sources */,
@@ -1565,9 +1570,7 @@
 				A8A473B3151A825B004123FF /* fast-dtoa.cc in Sources */,
 				0F885E0F1845AEA900F1E3FA /* FastBitVector.cpp in Sources */,
 				A8A473C3151A825B004123FF /* FastMalloc.cpp in Sources */,
-				DCEE22011CEA7551000C2396 /* BlockObjCExceptions.mm in Sources */,
 				0F9D3360165DBA73005AD387 /* FilePrintStream.cpp in Sources */,
-				1C181C8F1D307AB800F5FA16 /* UTextProvider.cpp in Sources */,
 				A8A473B5151A825B004123FF /* fixed-dtoa.cc in Sources */,
 				1A1D8B9E1731879800141DA4 /* FunctionDispatcher.cpp in Sources */,
 				2CCD892A15C0390200285083 /* GregorianDateTime.cpp in Sources */,
@@ -1582,9 +1585,9 @@
 				A8A473F7151A825B004123FF /* OSAllocatorPosix.cpp in Sources */,
 				A8A473F9151A825B004123FF /* OSRandomSource.cpp in Sources */,
 				A8A47402151A825B004123FF /* PageBlock.cpp in Sources */,
-				1C181C931D307AB800F5FA16 /* UTextProviderUTF16.cpp in Sources */,
 				0FFF19DC1BB334EB00886D91 /* ParallelHelperPool.cpp in Sources */,
 				0F824A681B7443A0002E345D /* ParkingLot.cpp in Sources */,
+				DCEE22031CEA7551000C2396 /* PlatformUserPreferredLanguagesMac.mm in Sources */,
 				0F9D3362165DBA73005AD387 /* PrintStream.cpp in Sources */,
 				143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */,
 				A8A47414151A825B004123FF /* RandomNumber.cpp in Sources */,
@@ -1598,7 +1601,6 @@
 				A748745217A0BDAE00FA04CB /* SixCharacterHash.cpp in Sources */,
 				A8A47425151A825B004123FF /* SizeLimits.cpp in Sources */,
 				A8A47427151A825B004123FF /* StackBounds.cpp in Sources */,
-				515F794E1CFC9F4A00CCED93 /* CrossThreadCopier.cpp in Sources */,
 				FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */,
 				A8A4743C151A825B004123FF /* StringBuilder.cpp in Sources */,
 				A5BA15FB182435A600A82E69 /* StringCF.cpp in Sources */,
@@ -1612,16 +1614,18 @@
 				93934BD518A1F16900D0D6A1 /* StringViewCF.cpp in Sources */,
 				93934BD318A1E8C300D0D6A1 /* StringViewObjC.mm in Sources */,
 				A8A473B7151A825B004123FF /* strtod.cc in Sources */,
+				70A993FE1AD7151300FA615B /* SymbolRegistry.cpp in Sources */,
 				1C181C7F1D3078DA00F5FA16 /* TextBreakIterator.cpp in Sources */,
-				1C181C911D307AB800F5FA16 /* UTextProviderLatin1.cpp in Sources */,
-				70A993FE1AD7151300FA615B /* SymbolRegistry.cpp in Sources */,
+				1C181C961D30800A00F5FA16 /* TextBreakIteratorInternalICUMac.mm in Sources */,
 				A8A47448151A825B004123FF /* ThreadIdentifierDataPthreads.cpp in Sources */,
 				A8A4744A151A825B004123FF /* Threading.cpp in Sources */,
 				A8A4744E151A825B004123FF /* ThreadingPthreads.cpp in Sources */,
+				1C181C8F1D307AB800F5FA16 /* UTextProvider.cpp in Sources */,
+				1C181C911D307AB800F5FA16 /* UTextProviderLatin1.cpp in Sources */,
+				1C181C931D307AB800F5FA16 /* UTextProviderUTF16.cpp in Sources */,
 				A8A47469151A825B004123FF /* UTF8.cpp in Sources */,
 				1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */,
 				0FE4479C1B7AAA03009498EB /* WordLock.cpp in Sources */,
-				DCEE22031CEA7551000C2396 /* PlatformUserPreferredLanguagesMac.mm in Sources */,
 				E4A0AD391A96245500536DF6 /* WorkQueue.cpp in Sources */,
 				E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */,
 				A8A47445151A825B004123FF /* WTFString.cpp in Sources */,

Added: trunk/Source/WTF/wtf/Scope.h (0 => 204529)


--- trunk/Source/WTF/wtf/Scope.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/Scope.h	2016-08-16 22:32:50 UTC (rev 204529)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#pragma once
+
+#include <type_traits>
+#include <wtf/StdLibExtras.h>
+
+// Based on http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0052r2.pdf
+
+namespace WTF {
+
+template<typename ExitFunction>
+class ScopeExit final {
+public:
+    template<typename ExitFunctionParameter>
+    explicit ScopeExit(ExitFunctionParameter&& exitFunction)
+        : m_exitFunction(std::forward<ExitFunction>(m_exitFunction))
+    {
+    }
+
+    ScopeExit(ScopeExit&& other)
+        : m_exitFunction(WTFMove(other.m_exitFunction))
+        , m_executeOnDestruction(std::exchange(other.m_executeOnDestruction, false))
+    {
+    }
+
+    ~ScopeExit()
+    {
+        if (m_executeOnDestruction)
+            m_exitFunction();
+    }
+
+    void release()
+    {
+        m_executeOnDestruction = false;
+    }
+
+    ScopeExit(const ScopeExit&) = delete;
+    ScopeExit& operator=(const ScopeExit&) = delete;
+    ScopeExit& operator=(ScopeExit&&) = delete;
+
+private:
+    ExitFunction m_exitFunction;
+    bool m_executeOnDestruction { true };
+};
+
+template<typename ExitFunction>
+ScopeExit<ExitFunction> makeScopeExit(ExitFunction&& exitFunction)
+{
+    return ScopeExit<ExitFunction>(std::forward<ExitFunction>(exitFunction));
+}
+
+}
+
+using WTF::ScopeExit;
+using WTF::makeScopeExit;

Modified: trunk/Tools/ChangeLog (204528 => 204529)


--- trunk/Tools/ChangeLog	2016-08-16 22:26:40 UTC (rev 204528)
+++ trunk/Tools/ChangeLog	2016-08-16 22:32:50 UTC (rev 204529)
@@ -1,3 +1,15 @@
+2016-08-16  Anders Carlsson  <ander...@apple.com>
+
+        Add WTF::ScopeExit
+        https://bugs.webkit.org/show_bug.cgi?id=160908
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/Scope.cpp: Added.
+        (TestWebKitAPI::TEST):
+
 2016-08-16  Aakash Jain  <aakash_j...@apple.com>
 
         EWS logs file are rotated too quickly

Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (204528 => 204529)


--- trunk/Tools/TestWebKitAPI/CMakeLists.txt	2016-08-16 22:26:40 UTC (rev 204528)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt	2016-08-16 22:32:50 UTC (rev 204529)
@@ -68,6 +68,7 @@
     ${TESTWEBKITAPI_DIR}/Tests/WTF/RefPtr.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/SHA1.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/SaturatedArithmeticOperations.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WTF/Scope.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/ScopedLambda.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringBuilder.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringHasher.cpp

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (204528 => 204529)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-08-16 22:26:40 UTC (rev 204528)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-08-16 22:32:50 UTC (rev 204529)
@@ -27,6 +27,7 @@
 		0F139E791A42457000F590F5 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
 		0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */; };
 		1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
+		1A3524AE1D63A4FB0031729B /* Scope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3524AC1D63A4FB0031729B /* Scope.cpp */; };
 		1A4F81CF1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A4F81CD1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm */; };
 		1A50AA201A2A51FC00F4C345 /* close-from-within-create-page.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A50AA1F1A2A4EA500F4C345 /* close-from-within-create-page.html */; };
 		1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93D3D19B17B1A7B000C7C415 /* all-content-in-one-iframe.html */; };
@@ -656,6 +657,7 @@
 		1A02C84B125D4A5E00E3F4BD /* find.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = find.html; sourceTree = "<group>"; };
 		1A02C84E125D4A8400E3F4BD /* Find.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Find.cpp; sourceTree = "<group>"; };
 		1A3524A91D627BD40031729B /* DeletedAddressOfOperator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeletedAddressOfOperator.h; sourceTree = "<group>"; };
+		1A3524AC1D63A4FB0031729B /* Scope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Scope.cpp; sourceTree = "<group>"; };
 		1A4F81C81BDFFD18004E672E /* RemoteObjectRegistry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteObjectRegistry.mm; sourceTree = "<group>"; };
 		1A4F81CD1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteObjectRegistryPlugIn.mm; sourceTree = "<group>"; };
 		1A4F81D01BDFFDCF004E672E /* RemoteObjectRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteObjectRegistry.h; sourceTree = "<group>"; };
@@ -1633,6 +1635,7 @@
 				93A427A8180D9B0700CD24D7 /* RefPtr.cpp */,
 				E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */,
 				14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */,
+				1A3524AC1D63A4FB0031729B /* Scope.cpp */,
 				DC69AA621CF77C6500C6272F /* ScopedLambda.cpp */,
 				CD5393C91757BAC400C07123 /* SHA1.cpp */,
 				81B50192140F232300D9EB58 /* StringBuilder.cpp */,
@@ -2093,6 +2096,7 @@
 				7C83DE9C1D0A590C00FEBCF3 /* BloomFilter.cpp in Sources */,
 				7C83DEA01D0A590C00FEBCF3 /* CheckedArithmeticOperations.cpp in Sources */,
 				7C83DEC31D0A590C00FEBCF3 /* Condition.cpp in Sources */,
+				1A3524AE1D63A4FB0031729B /* Scope.cpp in Sources */,
 				7C83DEA61D0A590C00FEBCF3 /* Counters.cpp in Sources */,
 				7C83DEA91D0A590C00FEBCF3 /* CString.cpp in Sources */,
 				7C83DEAD1D0A590C00FEBCF3 /* Deque.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WTF/Scope.cpp (0 => 204529)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/Scope.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Scope.cpp	2016-08-16 22:32:50 UTC (rev 204529)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "config.h"
+#include <wtf/Scope.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF_Scope, ScopeExit)
+{
+    bool isCalled = false;
+    {
+        auto scopeExit = makeScopeExit([&] {
+            EXPECT_FALSE(isCalled);
+            isCalled = true;
+        });
+        EXPECT_FALSE(isCalled);
+    }
+    EXPECT_TRUE(isCalled);
+
+    isCalled = false;
+    {
+        auto scopeExit = makeScopeExit([&] {
+            isCalled = true;
+        });
+        scopeExit.release();
+    }
+    EXPECT_FALSE(isCalled);
+}
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to