Remove scopeguard from platform
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2017 14:06:26 +0000 (14:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2017 14:06:26 +0000 (14:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178681

Patch by Christopher Reid <chris.reid@sony.com> on 2017-10-26
Reviewed by Brady Eidson.

Source/WebCore:

Replacing platform/ScopeGuard with WTF::ScopeExit.
No new tests, no change in behavior.

* Modules/indexeddb/IDBRequest.cpp:
* Modules/indexeddb/IDBRequest.h:
* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
* WebCore.xcodeproj/project.pbxproj:
* platform/FileSystem.cpp:
* platform/ScopeGuard.h: Removed.
* platform/network/BlobRegistryImpl.cpp:
* workers/service/ServiceWorkerContainer.cpp:

Source/WebKit:

* Shared/mac/ChildProcessMac.mm:

Tools:

* TestWebKitAPI/Tests/WebCore/FileMonitor.cpp:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224018 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WTF/wtf/Scope.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBRequest.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/FileSystem.cpp
Source/WebCore/platform/ScopeGuard.h [deleted file]
Source/WebCore/platform/network/BlobRegistryImpl.cpp
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/mac/ChildProcessMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/FileMonitor.cpp

index 97131d4..7bd7637 100644 (file)
@@ -37,7 +37,7 @@ class ScopeExit final {
 public:
     template<typename ExitFunctionParameter>
     explicit ScopeExit(ExitFunctionParameter&& exitFunction)
-        : m_exitFunction(std::forward<ExitFunction>(exitFunction))
+        : m_exitFunction(WTFMove(exitFunction))
     {
     }
 
index 0bc532b..1864bf4 100644 (file)
@@ -1,3 +1,22 @@
+2017-10-26  Christopher Reid  <chris.reid@sony.com>
+
+        Remove scopeguard from platform
+        https://bugs.webkit.org/show_bug.cgi?id=178681
+
+        Reviewed by Brady Eidson.
+
+        Replacing platform/ScopeGuard with WTF::ScopeExit.
+        No new tests, no change in behavior.
+
+        * Modules/indexeddb/IDBRequest.cpp:
+        * Modules/indexeddb/IDBRequest.h:
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/FileSystem.cpp:
+        * platform/ScopeGuard.h: Removed.
+        * platform/network/BlobRegistryImpl.cpp:
+        * workers/service/ServiceWorkerContainer.cpp:
+
 2017-10-26  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         REGRESSION(r222090): [HarfBuzz] Arabic shaping is broken except for first word in line
index 05d28e3..8e68f76 100644 (file)
 #include "JSDOMConvertNumbers.h"
 #include "JSDOMConvertSequences.h"
 #include "Logging.h"
-#include "ScopeGuard.h"
 #include "ScriptExecutionContext.h"
 #include "ThreadSafeDataBuffer.h"
 #include <heap/StrongInlines.h>
+#include <wtf/Scope.h>
 #include <wtf/Variant.h>
 
 
@@ -177,7 +177,7 @@ void IDBRequest::setSource(IDBCursor& cursor)
     ASSERT(!m_cursorRequestNotifier);
 
     m_source = Source { &cursor };
-    m_cursorRequestNotifier = std::make_unique<ScopeGuard>([this]() {
+    m_cursorRequestNotifier = std::make_unique<WTF::ScopeExit<WTF::Function<void()>>>([this]() {
         ASSERT(WTF::holds_alternative<RefPtr<IDBCursor>>(m_source.value()));
         WTF::get<RefPtr<IDBCursor>>(m_source.value())->decrementOutstandingRequestCount();
     });
@@ -487,7 +487,7 @@ void IDBRequest::willIterateCursor(IDBCursor& cursor)
     m_domError = nullptr;
     m_idbError = IDBError { };
 
-    m_cursorRequestNotifier = std::make_unique<ScopeGuard>([this]() {
+    m_cursorRequestNotifier = std::make_unique<WTF::ScopeExit<WTF::Function<void()>>>([this]() {
         m_pendingCursor->decrementOutstandingRequestCount();
     });
 }
index c2ae36f..b1f7b4a 100644 (file)
@@ -34,6 +34,8 @@
 #include "IDBResourceIdentifier.h"
 #include "IndexedDB.h"
 #include <heap/Strong.h>
+#include <wtf/Function.h>
+#include <wtf/Scope.h>
 
 namespace WebCore {
 
@@ -47,7 +49,6 @@ class IDBObjectStore;
 class IDBResultData;
 class IDBTransaction;
 class IDBValue;
-class ScopeGuard;
 class ThreadSafeDataBuffer;
 
 namespace IDBClient {
@@ -170,7 +171,7 @@ private:
 
     RefPtr<IDBCursor> m_pendingCursor;
 
-    std::unique_ptr<ScopeGuard> m_cursorRequestNotifier;
+    std::unique_ptr<WTF::ScopeExit<WTF::Function<void()>>> m_cursorRequestNotifier;
 
     Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
 };
index af825ef..81cdc97 100644 (file)
@@ -40,7 +40,6 @@
 #include "IDBTransactionInfo.h"
 #include "IDBValue.h"
 #include "Logging.h"
-#include "ScopeGuard.h"
 #include "SerializedScriptValue.h"
 #include "UniqueIDBDatabaseConnection.h"
 #include <heap/HeapInlines.h>
@@ -49,6 +48,7 @@
 #include <runtime/StructureInlines.h>
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/Scope.h>
 
 
 namespace WebCore {
@@ -984,9 +984,12 @@ void UniqueIDBDatabase::performPutOrAdd(uint64_t callbackIdentifier, const IDBRe
     }
 
     bool usedKeyIsGenerated = false;
-    ScopeGuard generatedKeyResetter;
+    uint64_t keyNumber;
+    auto generatedKeyResetter = WTF::makeScopeExit([this, transactionIdentifier, objectStoreIdentifier, &keyNumber, &usedKeyIsGenerated]() {
+        if (usedKeyIsGenerated)
+            m_backingStore->revertGeneratedKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber);
+    });
     if (objectStoreInfo->autoIncrement() && !keyData.isValid()) {
-        uint64_t keyNumber;
         error = m_backingStore->generateKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber);
         if (!error.isNull()) {
             postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, error, usedKey));
@@ -995,9 +998,6 @@ void UniqueIDBDatabase::performPutOrAdd(uint64_t callbackIdentifier, const IDBRe
         
         usedKey.setNumberValue(keyNumber);
         usedKeyIsGenerated = true;
-        generatedKeyResetter.enable([this, transactionIdentifier, objectStoreIdentifier, keyNumber]() {
-            m_backingStore->revertGeneratedKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber);
-        });
     } else
         usedKey = keyData;
 
@@ -1065,7 +1065,7 @@ void UniqueIDBDatabase::performPutOrAdd(uint64_t callbackIdentifier, const IDBRe
     if (overwriteMode != IndexedDB::ObjectStoreOverwriteMode::OverwriteForCursor && objectStoreInfo->autoIncrement() && keyData.type() == IndexedDB::KeyType::Number)
         error = m_backingStore->maybeUpdateKeyGeneratorNumber(transactionIdentifier, objectStoreIdentifier, keyData.number());
 
-    generatedKeyResetter.disable();
+    generatedKeyResetter.release();
     postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, error, usedKey));
 }
 
index b1d1bc7..95f4c34 100644 (file)
                51327D6011A33A2B004F9D65 /* SinkDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 51327D5E11A33A2B004F9D65 /* SinkDocument.h */; };
                513F14540AB634C400094DDF /* IconLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 513F14520AB634C400094DDF /* IconLoader.h */; };
                51405C89190B014400754F94 /* SelectionRectGatherer.h in Headers */ = {isa = PBXBuildFile; fileRef = 51405C87190B014400754F94 /* SelectionRectGatherer.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               514129901C601ACC0059E714 /* ScopeGuard.h in Headers */ = {isa = PBXBuildFile; fileRef = 5141298F1C601A890059E714 /* ScopeGuard.h */; settings = {ATTRIBUTES = (Private, ); }; };
                514129991C6976900059E714 /* IDBRequestCompletionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 514129971C6976150059E714 /* IDBRequestCompletionEvent.h */; };
                5143B2631DDD15200014FAC6 /* LinkIcon.h in Headers */ = {isa = PBXBuildFile; fileRef = 5143B2621DDD14900014FAC6 /* LinkIcon.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5145B10A1BC48E2E00E86219 /* IDBResourceIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 5145B1081BC4890B00E86219 /* IDBResourceIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51405C86190B014400754F94 /* SelectionRectGatherer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionRectGatherer.cpp; sourceTree = "<group>"; };
                51405C87190B014400754F94 /* SelectionRectGatherer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionRectGatherer.h; sourceTree = "<group>"; };
                5141298D1C5FD7E90059E714 /* JSIDBCursorWithValueCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBCursorWithValueCustom.cpp; sourceTree = "<group>"; };
-               5141298F1C601A890059E714 /* ScopeGuard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopeGuard.h; sourceTree = "<group>"; };
                514129961C6976150059E714 /* IDBRequestCompletionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBRequestCompletionEvent.cpp; sourceTree = "<group>"; };
                514129971C6976150059E714 /* IDBRequestCompletionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBRequestCompletionEvent.h; sourceTree = "<group>"; };
                5141299A1C6C166D0059E714 /* JSIDBIndexCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBIndexCustom.cpp; sourceTree = "<group>"; };
                                293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */,
                                5162C7F211F77EFA00612EFE /* SchemeRegistry.cpp */,
                                5162C7F311F77EFB00612EFE /* SchemeRegistry.h */,
-                               5141298F1C601A890059E714 /* ScopeGuard.h */,
                                BC8AE34C12EA096A00EB3AE6 /* ScrollableArea.cpp */,
                                BC8AE34D12EA096A00EB3AE6 /* ScrollableArea.h */,
                                CA3BF67B10D99BAE00E6CE53 /* ScrollAnimator.cpp */,
                                5DFE8F570D16477C0076E937 /* ScheduledAction.h in Headers */,
                                5162C7F511F77EFB00612EFE /* SchemeRegistry.h in Headers */,
                                9BD0BF9312A42BF50072FD43 /* ScopedEventQueue.h in Headers */,
-                               514129901C601ACC0059E714 /* ScopeGuard.h in Headers */,
                                BCEC01BE0C274DAC009F4EC9 /* Screen.h in Headers */,
                                A84D82C111D3474800972990 /* ScriptableDocumentParser.h in Headers */,
                                41F1D21F0EF35C2A00DA8753 /* ScriptCachedFrameData.h in Headers */,
index a13d6bc..49de347 100644 (file)
@@ -28,8 +28,8 @@
 #include "FileSystem.h"
 
 #include "FileMetadata.h"
-#include "ScopeGuard.h"
 #include <wtf/HexNumber.h>
+#include <wtf/Scope.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringBuilder.h>
 
@@ -213,7 +213,7 @@ bool appendFileContentsToFileHandle(const String& path, PlatformFileHandle& targ
     static int bufferSize = 1 << 19;
     Vector<char> buffer(bufferSize);
 
-    ScopeGuard fileCloser([source]() {
+    auto fileCloser = WTF::makeScopeExit([source]() {
         PlatformFileHandle handle = source;
         closeFile(handle);
     });
diff --git a/Source/WebCore/platform/ScopeGuard.h b/Source/WebCore/platform/ScopeGuard.h
deleted file mode 100644 (file)
index d4cb3b9..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.
- */
-#ifndef ScopeGuard_h
-#define ScopeGuard_h
-
-#include <wtf/Function.h>
-
-namespace WebCore {
-
-class ScopeGuard {
-public:
-    ScopeGuard()
-    {
-    }
-
-    ScopeGuard(WTF::Function<void()>&& function)
-        : m_function(WTFMove(function))
-    {
-    }
-
-    ~ScopeGuard()
-    {
-        if (m_function)
-            m_function();
-    }
-
-    void enable(WTF::Function<void()>&& function)
-    {
-        m_function = WTFMove(function);
-    }
-
-    void disable()
-    {
-        m_function = nullptr;
-    }
-
-private:
-    WTF::Function<void()> m_function;
-};
-
-} // namespace WebCore
-
-#endif // ScopeGuard_h
index 5b274c2..0f01974 100644 (file)
@@ -41,9 +41,9 @@
 #include "ResourceHandle.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
-#include "ScopeGuard.h"
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/Scope.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/WorkQueue.h>
 
@@ -286,7 +286,7 @@ void BlobRegistryImpl::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs
                 PlatformFileHandle file;
                 String tempFilePath = openTemporaryFile(ASCIILiteral("Blob"), file);
 
-                ScopeGuard fileCloser([file]() mutable {
+                auto fileCloser = WTF::makeScopeExit([file]() mutable {
                     closeFile(file);
                 });
                 
index 713ce03..8b1e875 100644 (file)
@@ -35,7 +35,6 @@
 #include "Logging.h"
 #include "NavigatorBase.h"
 #include "ResourceError.h"
-#include "ScopeGuard.h"
 #include "ScriptExecutionContext.h"
 #include "SecurityOrigin.h"
 #include "ServiceWorker.h"
@@ -44,6 +43,7 @@
 #include "ServiceWorkerProvider.h"
 #include "URL.h"
 #include <wtf/RunLoop.h>
+#include <wtf/Scope.h>
 
 namespace WebCore {
 
@@ -202,7 +202,7 @@ void ServiceWorkerContainer::jobFailedWithException(ServiceWorkerJob& job, const
 
 void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job, ServiceWorkerRegistrationData&& data)
 {
-    ScopeGuard guard([this, &job] {
+    auto guard = WTF::makeScopeExit([this, &job] {
         jobDidFinish(job);
     });
 
@@ -221,7 +221,7 @@ void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job,
 
 void ServiceWorkerContainer::jobResolvedWithUnregistrationResult(ServiceWorkerJob& job, bool unregistrationResult)
 {
-    ScopeGuard guard([this, &job] {
+    auto guard = WTF::makeScopeExit([this, &job] {
         jobDidFinish(job);
     });
 
index 3423339..cd4a039 100644 (file)
@@ -1,3 +1,12 @@
+2017-10-26  Christopher Reid  <chris.reid@sony.com>
+
+        Remove scopeguard from platform
+        https://bugs.webkit.org/show_bug.cgi?id=178681
+
+        Reviewed by Brady Eidson.
+
+        * Shared/mac/ChildProcessMac.mm:
+
 2017-10-25  Per Arne Vollan  <pvollan@apple.com>
 
         Network process crash under WebKit::AuthenticationManager::rejectProtectionSpaceAndContinueForSingleChallenge.
index 956445c..54ae658 100644 (file)
@@ -33,7 +33,6 @@
 #import "QuarantineSPI.h"
 #import "SandboxInitializationParameters.h"
 #import <WebCore/FileSystem.h>
-#import <WebCore/ScopeGuard.h>
 #import <WebCore/SystemVersion.h>
 #import <mach/mach.h>
 #import <mach/task.h>
@@ -41,6 +40,7 @@
 #import <pwd.h>
 #import <stdlib.h>
 #import <sysexits.h>
+#import <wtf/Scope.h>
 #import <wtf/spi/darwin/SandboxSPI.h>
 
 #if USE(APPLE_INTERNAL_SDK)
@@ -84,7 +84,7 @@ static OSStatus enableSandboxStyleFileQuarantine()
 {
     int error;
     qtn_proc_t quarantineProperties = qtn_proc_alloc();
-    ScopeGuard quarantinePropertiesDeleter([quarantineProperties]() {
+    auto quarantinePropertiesDeleter = makeScopeExit([quarantineProperties]() {
         qtn_proc_free(quarantineProperties);
     });
 
index 0b9c0c8..b46cf7c 100644 (file)
@@ -1,3 +1,12 @@
+2017-10-26  Christopher Reid  <chris.reid@sony.com>
+
+        Remove scopeguard from platform
+        https://bugs.webkit.org/show_bug.cgi?id=178681
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/FileMonitor.cpp:
+
 2017-09-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         WebDriver: Add support to import and run W3C tests
index bfcd299..fbcc623 100644 (file)
@@ -30,9 +30,9 @@
 #include "WTFStringUtilities.h"
 #include <WebCore/FileMonitor.h>
 #include <WebCore/FileSystem.h>
-#include <WebCore/ScopeGuard.h>
 #include <wtf/MainThread.h>
 #include <wtf/RunLoop.h>
+#include <wtf/Scope.h>
 #include <wtf/StringExtras.h>
 #include <wtf/WorkQueue.h>
 #include <wtf/text/StringBuffer.h>
@@ -120,7 +120,7 @@ static String readContentsOfFile(const String& path)
 
     StringBuffer<LChar> buffer(bufferSize);
 
-    ScopeGuard fileCloser([source]() {
+    auto fileCloser = WTF::makeScopeExit([source]() {
         PlatformFileHandle handle = source;
         closeFile(handle);
     });