Update Worker::notifyFinished to not use emptySessionID
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Aug 2019 17:21:15 +0000 (17:21 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Aug 2019 17:21:15 +0000 (17:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200710

Reviewed by Alex Christensen.

No change of behavior.

Exit early if context is gone since we should not dispatch events or create worker.
Make sure to unset pending activity using a ScopeExit.

* workers/Worker.cpp:
(WebCore::Worker::notifyFinished):

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

Source/WebCore/ChangeLog
Source/WebCore/workers/Worker.cpp

index 9ec0845..ba70686 100644 (file)
@@ -1,3 +1,18 @@
+2019-08-14  Youenn Fablet  <youenn@apple.com>
+
+        Update Worker::notifyFinished to not use emptySessionID
+        https://bugs.webkit.org/show_bug.cgi?id=200710
+
+        Reviewed by Alex Christensen.
+
+        No change of behavior.
+
+        Exit early if context is gone since we should not dispatch events or create worker.
+        Make sure to unset pending activity using a ScopeExit.
+
+        * workers/Worker.cpp:
+        (WebCore::Worker::notifyFinished):
+
 2019-08-14  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][TFC] Implement TableFormattingContext::computePreferredWidthForColumns
index c1ad21f..3b36daf 100644 (file)
@@ -43,6 +43,7 @@
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/Scope.h>
 
 namespace WebCore {
 
@@ -181,20 +182,24 @@ void Worker::didReceiveResponse(unsigned long identifier, const ResourceResponse
 
 void Worker::notifyFinished()
 {
+    auto clearLoader = makeScopeExit([this] {
+        m_scriptLoader = nullptr;
+        unsetPendingActivity(*this);
+    });
+
     auto* context = scriptExecutionContext();
-    PAL::SessionID sessionID = context ? context->sessionID() : PAL::SessionID::emptySessionID();
+    if (!context)
+        return;
 
-    if (m_scriptLoader->failed() || !sessionID.isValid())
+    if (m_scriptLoader->failed()) {
         dispatchEvent(Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::Yes));
-    else {
-        bool isOnline = platformStrategies()->loaderStrategy()->isOnLine();
-        const ContentSecurityPolicyResponseHeaders& contentSecurityPolicyResponseHeaders = m_contentSecurityPolicyResponseHeaders ? m_contentSecurityPolicyResponseHeaders.value() : scriptExecutionContext()->contentSecurityPolicy()->responseHeaders();
-        m_contextProxy.startWorkerGlobalScope(m_scriptLoader->url(), m_name, scriptExecutionContext()->userAgent(m_scriptLoader->url()), isOnline, m_scriptLoader->script(), contentSecurityPolicyResponseHeaders, m_shouldBypassMainWorldContentSecurityPolicy, m_workerCreationTime, m_runtimeFlags, sessionID);
-        InspectorInstrumentation::scriptImported(*scriptExecutionContext(), m_scriptLoader->identifier(), m_scriptLoader->script());
+        return;
     }
-    m_scriptLoader = nullptr;
 
-    unsetPendingActivity(*this);
+    bool isOnline = platformStrategies()->loaderStrategy()->isOnLine();
+    const ContentSecurityPolicyResponseHeaders& contentSecurityPolicyResponseHeaders = m_contentSecurityPolicyResponseHeaders ? m_contentSecurityPolicyResponseHeaders.value() : context->contentSecurityPolicy()->responseHeaders();
+    m_contextProxy.startWorkerGlobalScope(m_scriptLoader->url(), m_name, context->userAgent(m_scriptLoader->url()), isOnline, m_scriptLoader->script(), contentSecurityPolicyResponseHeaders, m_shouldBypassMainWorldContentSecurityPolicy, m_workerCreationTime, m_runtimeFlags, context->sessionID());
+    InspectorInstrumentation::scriptImported(*context, m_scriptLoader->identifier(), m_scriptLoader->script());
 }
 
 } // namespace WebCore