Changeset 275465 in webkit


Ignore:
Timestamp:
Apr 5, 2021 6:05:24 PM (3 years ago)
Author:
Chris Dumez
Message:

Make sure service workers use a ScriptSourceCode backed by file-mapped memory when possible
https://bugs.webkit.org/show_bug.cgi?id=224088

Reviewed by Yusuke Suzuki.

Source/WebCore:

To run a worker, we were constructing a ScriptSourceCode from the source String and calling
JSC::evaluate. ScriptSourceCode would construct a JSC::StringSourceProvider, which would
keep the source String alive for the lifetime of the provider. This is problematic since
those worker scripts may be big and keeping heap-allocated version of them in memory is
expensive.

To address the issue, this patch introduces a new JSC::SourceProvider subclass named
ScriptBufferSourceProvider, which uses a ScriptBuffer internally. ScriptBuffer has the
benefit of being able to hold file-mapped data. We only convert the ScriptBuffer to
a String whenever necessary (When the script contains non-ascii characters and JSC
requests a StringView to the script). If we do end up converting the ScriptBuffer to
a String, this String will get cleared on memory pressure. This is similar to what
CachedScriptSourceProvider / CachedScript do on the main thread.

In the warm case, where the service worker script is coming from disk, we create
the ScriptBufferSourceProvider right away from a file-mapped ScriptBuffer, thus
greatly reducing dirty memory use. In the cold case, we initially construct the
ScriptBufferSourceProvider using a ScriptBuffer that is not file-mapped. However,
once the script is saved to disk (via SWScriptStorage), we replace the
ScriptBufferSourceProvider's ScriptBuffer with the new file-mapped version in
order to reduce dirty memory use in this case too.

  • WebCore.xcodeproj/project.pbxproj:

Add ScriptBufferSourceProvider.h to the project.

  • bindings/js/ScriptBufferSourceProvider.h: Added.
  • Add new ScriptBufferSourceProvider, which is a JSC::SourceProvider subclass that

uses a ScriptBuffer as backing instead of a String. This allows us to use file-mapped
memory whenever possible, thus reducing dirty memory use. This provider provides
similar functionality to CachedScriptSourceProvider / CachedScript but works with
a ScriptBuffer and can be used off the main thread.

  • We only transform the SharedBuffer into a String when strictly necessary, meaning that the ScriptBuffer contains non-ascii characters and JSC is asking for a StringView to the script.
  • The class supports clearing the String copy of the script (done on memory pressure) and replacing the ScriptBuffer (with a new file-mapped version).
  • bindings/js/ScriptSourceCode.h:

(WebCore::ScriptSourceCode::ScriptSourceCode):
(WebCore::ScriptSourceCode::m_code):
(WebCore::ScriptSourceCode::provider):
Add new constructors taking a ScriptBuffer instead of a String for the source code.
We then use the new ScriptBufferSourceProvider internally instead of the
StringSourceProvider.

  • workers/DedicatedWorkerThread.cpp:

(WebCore::DedicatedWorkerThread::DedicatedWorkerThread):

  • workers/DedicatedWorkerThread.h:

Use ScriptBuffer instead of String.

  • workers/ScriptBuffer.cpp:

(WebCore::ScriptBuffer::empty):
(WebCore::ScriptBuffer::append):
(WebCore::operator!=):

  • workers/ScriptBuffer.h:

(WebCore::ScriptBuffer::isEmpty const):
Add some functionality to SCriptBuffer to make it more convenient to use.

  • workers/Worker.cpp:

(WebCore::Worker::notifyFinished):
Convert ScriptBuffer to a String since this is what WebInspector expects.

  • workers/WorkerGlobalScope.cpp:

(WebCore::WorkerGlobalScope::importScripts):

  • When importing a new script, we now construct a ScriptSourceCode from a

ScriptBuffer instead of a String.

  • We also store a weak pointer to the ScriptBufferSourceProvider used by the ScriptSourceCode on the WorkerGlobalScope. This is so that we can ask those ScriptBufferSourceProvider objects to clear their cached String representation of the script source on memory pressure. It is also needed so we can replace the ScriptBufferSourceProvider's ScriptBuffer with a file-mapped version when one becomes available.

(WebCore::WorkerGlobalScope::releaseMemory):
In addition to deleting JS code and doing garbage collection, we now also ask the
ScriptBufferSourceProvider objects to clear their cached String representation of the script
source.

(WebCore::WorkerGlobalScope::deleteJSCodeAndGC):
Moved the logic to delete JS code and doing GC from releaseMemory() to a new function, now
that releaseMemory() needs to do more things.

(WebCore::WorkerGlobalScope::setMainScriptSourceProvider):
(WebCore::WorkerGlobalScope::addImportedScriptSourceProvider):
Functions used to store the CachedScriptSourceProvider objects for the scripts used by the
worker on the WorkerGlobalScope. We keep weak pointers to those.

(WebCore::WorkerGlobalScope::clearDecodedScriptData):
Function used to ask the ScriptBufferSourceProvider objects to clear their cached String
representation of the script source on memory pressure.

(WebCore::WorkerGlobalScope::updateSourceProviderBuffers):
Function used to ask the ScriptBufferSourceProvider objects to replace their ScriptBuffers
with file-backed versions.

  • workers/WorkerGlobalScope.h:
  • workers/WorkerGlobalScopeProxy.h:
  • workers/WorkerMessagingProxy.cpp:

(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):

  • workers/WorkerMessagingProxy.h:

Use ScriptBuffer instead of String.

  • workers/WorkerScriptLoader.cpp:

(WebCore::WorkerScriptLoader::WorkerScriptLoader):
(WebCore::WorkerScriptLoader::loadSynchronously):
(WebCore::WorkerScriptLoader::didReceiveData):

  • workers/WorkerScriptLoader.h:

(WebCore::WorkerScriptLoader::script):
Use ScriptBuffer instead of String to hold the script source. We eventually need a ScriptBuffer
since this is what the Worker now needs to launch. Also, in the service worker case, we may
get a ScriptBuffer right away from the scriptResourceMap, without going to the network at all.

  • workers/WorkerThread.cpp:

(WebCore::WorkerThreadStartupData::WorkerThreadStartupData):
(WebCore::WorkerThread::WorkerThread):
Use ScriptBuffer instead of String.

(WebCore::WorkerThread::evaluateScriptIfNecessary):

  • When evaluating the main worker script, we now construct a ScriptSourceCode from a

ScriptBuffer instead of a String.

  • We also store a weak pointer to the ScriptBufferSourceProvider used by the ScriptSourceCode on the WorkerGlobalScope. This is so that we can ask those ScriptBufferSourceProvider objects to clear their cached String representation of the script source on memory pressure. It is also needed so we can replace the ScriptBufferSourceProvider's ScriptBuffer with a file-mapped version when one becomes available.
  • workers/WorkerThread.h:
  • workers/service/ServiceWorkerContainer.cpp:

(WebCore::ServiceWorkerContainer::jobFinishedLoadingScript):

  • workers/service/ServiceWorkerContainer.h:
  • workers/service/ServiceWorkerFetchResult.h:
  • workers/service/ServiceWorkerGlobalScope.cpp:

(WebCore::ServiceWorkerGlobalScope::didSaveScriptsToDisk):

  • workers/service/ServiceWorkerJobClient.h:
  • workers/service/context/ServiceWorkerThread.cpp:

(WebCore::ServiceWorkerThread::ServiceWorkerThread):

  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::updateWorker):

  • workers/service/server/SWServer.h:
  • workers/service/server/SWServerJobQueue.cpp:

(WebCore::SWServerJobQueue::scriptFetchFinished):
Use ScriptBuffer instead of String.

Source/WebKit:

  • NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp:

(WebKit::ServiceWorkerSoftUpdateLoader::didFinishLoading):

Location:
trunk/Source
Files:
1 added
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r275463 r275465  
     12021-04-05  Chris Dumez  <cdumez@apple.com>
     2
     3        Make sure service workers use a ScriptSourceCode backed by file-mapped memory when possible
     4        https://bugs.webkit.org/show_bug.cgi?id=224088
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        To run a worker, we were constructing a ScriptSourceCode from the source String and calling
     9        JSC::evaluate. ScriptSourceCode would construct a JSC::StringSourceProvider, which would
     10        keep the source String alive for the lifetime of the provider. This is problematic since
     11        those worker scripts may be big and keeping heap-allocated version of them in memory is
     12        expensive.
     13
     14        To address the issue, this patch introduces a new JSC::SourceProvider subclass named
     15        ScriptBufferSourceProvider, which uses a ScriptBuffer internally. ScriptBuffer has the
     16        benefit of being able to hold file-mapped data. We only convert the ScriptBuffer to
     17        a String whenever necessary (When the script contains non-ascii characters and JSC
     18        requests a StringView to the script). If we do end up converting the ScriptBuffer to
     19        a String, this String will get cleared on memory pressure. This is similar to what
     20        CachedScriptSourceProvider / CachedScript do on the main thread.
     21
     22        In the warm case, where the service worker script is coming from disk, we create
     23        the ScriptBufferSourceProvider right away from a file-mapped ScriptBuffer, thus
     24        greatly reducing dirty memory use. In the cold case, we initially construct the
     25        ScriptBufferSourceProvider using a ScriptBuffer that is not file-mapped. However,
     26        once the script is saved to disk (via SWScriptStorage), we replace the
     27        ScriptBufferSourceProvider's ScriptBuffer with the new file-mapped version in
     28        order to reduce dirty memory use in this case too.
     29
     30        * WebCore.xcodeproj/project.pbxproj:
     31        Add ScriptBufferSourceProvider.h to the project.
     32
     33        * bindings/js/ScriptBufferSourceProvider.h: Added.
     34        - Add new ScriptBufferSourceProvider, which is a JSC::SourceProvider subclass that
     35        uses a ScriptBuffer as backing instead of a String. This allows us to use file-mapped
     36        memory whenever possible, thus reducing dirty memory use. This provider provides
     37        similar functionality to CachedScriptSourceProvider / CachedScript but works with
     38        a ScriptBuffer and can be used off the main thread.
     39        - We only transform the SharedBuffer into a String when strictly necessary, meaning
     40          that the ScriptBuffer contains non-ascii characters and JSC is asking for a StringView
     41          to the script.
     42        - The class supports clearing the String copy of the script (done on memory pressure)
     43          and replacing the ScriptBuffer (with a new file-mapped version).
     44
     45        * bindings/js/ScriptSourceCode.h:
     46        (WebCore::ScriptSourceCode::ScriptSourceCode):
     47        (WebCore::ScriptSourceCode::m_code):
     48        (WebCore::ScriptSourceCode::provider):
     49        Add new constructors taking a ScriptBuffer instead of a String for the source code.
     50        We then use the new ScriptBufferSourceProvider internally instead of the
     51        StringSourceProvider.
     52
     53        * workers/DedicatedWorkerThread.cpp:
     54        (WebCore::DedicatedWorkerThread::DedicatedWorkerThread):
     55        * workers/DedicatedWorkerThread.h:
     56        Use ScriptBuffer instead of String.
     57
     58        * workers/ScriptBuffer.cpp:
     59        (WebCore::ScriptBuffer::empty):
     60        (WebCore::ScriptBuffer::append):
     61        (WebCore::operator!=):
     62        * workers/ScriptBuffer.h:
     63        (WebCore::ScriptBuffer::isEmpty const):
     64        Add some functionality to SCriptBuffer to make it more convenient to use.
     65
     66        * workers/Worker.cpp:
     67        (WebCore::Worker::notifyFinished):
     68        Convert ScriptBuffer to a String since this is what WebInspector expects.
     69
     70        * workers/WorkerGlobalScope.cpp:
     71        (WebCore::WorkerGlobalScope::importScripts):
     72        - When importing a new script, we now construct a ScriptSourceCode from a
     73        ScriptBuffer instead of a String.
     74        - We also store a weak pointer to the ScriptBufferSourceProvider used by the ScriptSourceCode
     75          on the WorkerGlobalScope. This is so that we can ask those ScriptBufferSourceProvider objects
     76          to clear their cached String representation of the script source on memory pressure. It is
     77          also needed so we can replace the ScriptBufferSourceProvider's ScriptBuffer with a file-mapped
     78          version when one becomes available.
     79
     80        (WebCore::WorkerGlobalScope::releaseMemory):
     81        In addition to deleting JS code and doing garbage collection, we now also ask the
     82        ScriptBufferSourceProvider objects to clear their cached String representation of the script
     83        source.
     84
     85        (WebCore::WorkerGlobalScope::deleteJSCodeAndGC):
     86        Moved the logic to delete JS code and doing GC from releaseMemory() to a new function, now
     87        that releaseMemory() needs to do more things.
     88
     89        (WebCore::WorkerGlobalScope::setMainScriptSourceProvider):
     90        (WebCore::WorkerGlobalScope::addImportedScriptSourceProvider):
     91        Functions used to store the CachedScriptSourceProvider objects for the scripts used by the
     92        worker on the WorkerGlobalScope. We keep weak pointers to those.
     93
     94        (WebCore::WorkerGlobalScope::clearDecodedScriptData):
     95        Function used to ask the ScriptBufferSourceProvider objects to clear their cached String
     96        representation of the script source on memory pressure.
     97
     98        (WebCore::WorkerGlobalScope::updateSourceProviderBuffers):
     99        Function used to ask the ScriptBufferSourceProvider objects to replace their ScriptBuffers
     100        with file-backed versions.
     101
     102        * workers/WorkerGlobalScope.h:
     103        * workers/WorkerGlobalScopeProxy.h:
     104        * workers/WorkerMessagingProxy.cpp:
     105        (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
     106        * workers/WorkerMessagingProxy.h:
     107        Use ScriptBuffer instead of String.
     108
     109        * workers/WorkerScriptLoader.cpp:
     110        (WebCore::WorkerScriptLoader::WorkerScriptLoader):
     111        (WebCore::WorkerScriptLoader::loadSynchronously):
     112        (WebCore::WorkerScriptLoader::didReceiveData):
     113        * workers/WorkerScriptLoader.h:
     114        (WebCore::WorkerScriptLoader::script):
     115        Use ScriptBuffer instead of String to hold the script source. We eventually need a ScriptBuffer
     116        since this is what the Worker now needs to launch. Also, in the service worker case, we may
     117        get a ScriptBuffer right away from the scriptResourceMap, without going to the network at all.
     118
     119        * workers/WorkerThread.cpp:
     120        (WebCore::WorkerThreadStartupData::WorkerThreadStartupData):
     121        (WebCore::WorkerThread::WorkerThread):
     122        Use ScriptBuffer instead of String.
     123
     124        (WebCore::WorkerThread::evaluateScriptIfNecessary):
     125        - When evaluating the main worker script, we now construct a ScriptSourceCode from a
     126        ScriptBuffer instead of a String.
     127        - We also store a weak pointer to the ScriptBufferSourceProvider used by the ScriptSourceCode
     128          on the WorkerGlobalScope. This is so that we can ask those ScriptBufferSourceProvider objects
     129          to clear their cached String representation of the script source on memory pressure. It is
     130          also needed so we can replace the ScriptBufferSourceProvider's ScriptBuffer with a file-mapped
     131          version when one becomes available.
     132
     133        * workers/WorkerThread.h:
     134        * workers/service/ServiceWorkerContainer.cpp:
     135        (WebCore::ServiceWorkerContainer::jobFinishedLoadingScript):
     136        * workers/service/ServiceWorkerContainer.h:
     137        * workers/service/ServiceWorkerFetchResult.h:
     138        * workers/service/ServiceWorkerGlobalScope.cpp:
     139        (WebCore::ServiceWorkerGlobalScope::didSaveScriptsToDisk):
     140        * workers/service/ServiceWorkerJobClient.h:
     141        * workers/service/context/ServiceWorkerThread.cpp:
     142        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
     143        * workers/service/server/SWServer.cpp:
     144        (WebCore::SWServer::updateWorker):
     145        * workers/service/server/SWServer.h:
     146        * workers/service/server/SWServerJobQueue.cpp:
     147        (WebCore::SWServerJobQueue::scriptFetchFinished):
     148        Use ScriptBuffer instead of String.
     149
    11502021-04-05  Fujii Hironori  <Hironori.Fujii@sony.com>
    2151
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r275459 r275465  
    12891289                46B63F6C1C6E8D19002E914B /* JSEventTargetCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B63F6B1C6E8CDF002E914B /* JSEventTargetCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12901290                46B650DD2296262700FD8AA4 /* PageIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B650DB2296262700FD8AA4 /* PageIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1291                46B8593C261672270019EDC6 /* ScriptBufferSourceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B8593A2616720C0019EDC6 /* ScriptBufferSourceProvider.h */; };
    12911292                46B95195207D633400A7D2DD /* AbstractDOMWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B9518A207D632800A7D2DD /* AbstractDOMWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12921293                46B95196207D633A00A7D2DD /* AbstractFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B9518F207D632B00A7D2DD /* AbstractFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    82858286                46B63F6B1C6E8CDF002E914B /* JSEventTargetCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEventTargetCustom.h; sourceTree = "<group>"; };
    82868287                46B650DB2296262700FD8AA4 /* PageIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageIdentifier.h; sourceTree = "<group>"; };
     8288                46B8593A2616720C0019EDC6 /* ScriptBufferSourceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScriptBufferSourceProvider.h; sourceTree = "<group>"; };
    82878289                46B9518A207D632800A7D2DD /* AbstractDOMWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractDOMWindow.h; sourceTree = "<group>"; };
    82888290                46B9518C207D632900A7D2DD /* RemoteFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteFrame.cpp; sourceTree = "<group>"; };
     
    2728927291                                418C395F1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.h */,
    2729027292                                51BA946F23AC305000444846 /* RunJavaScriptParameters.h */,
     27293                                46B8593A2616720C0019EDC6 /* ScriptBufferSourceProvider.h */,
    2729127294                                41F1D21E0EF35C2A00DA8753 /* ScriptCachedFrameData.cpp */,
    2729227295                                41F1D21D0EF35C2A00DA8753 /* ScriptCachedFrameData.h */,
     
    3480934812                                A84D82C111D3474800972990 /* ScriptableDocumentParser.h in Headers */,
    3481034813                                462E4C502616A811003A2C67 /* ScriptBuffer.h in Headers */,
     34814                                46B8593C261672270019EDC6 /* ScriptBufferSourceProvider.h in Headers */,
    3481134815                                41F1D21F0EF35C2A00DA8753 /* ScriptCachedFrameData.h in Headers */,
    3481234816                                93B70D7009EB0C7C009D8468 /* ScriptController.h in Headers */,
  • trunk/Source/WebCore/bindings/js/ScriptSourceCode.h

    r273203 r275465  
    3535#include "CachedScriptFetcher.h"
    3636#include "CachedScriptSourceProvider.h"
     37#include "ScriptBufferSourceProvider.h"
    3738#include <JavaScriptCore/SourceCode.h>
    3839#include <JavaScriptCore/SourceProvider.h>
     
    4748    ScriptSourceCode(const String& source, URL&& url = URL(), const TextPosition& startPosition = TextPosition(), JSC::SourceProviderSourceType sourceType = JSC::SourceProviderSourceType::Program)
    4849        : m_provider(JSC::StringSourceProvider::create(source, JSC::SourceOrigin { url }, url.string(), startPosition, sourceType))
     50        , m_code(m_provider.copyRef(), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt())
     51    {
     52    }
     53
     54    ScriptSourceCode(const ScriptBuffer& source, URL&& url = URL(), const TextPosition& startPosition = TextPosition(), JSC::SourceProviderSourceType sourceType = JSC::SourceProviderSourceType::Program)
     55        : m_provider(ScriptBufferSourceProvider::create(source, JSC::SourceOrigin { url }, url.string(), startPosition, sourceType))
    4956        , m_code(m_provider.copyRef(), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt())
    5057    {
     
    6471    }
    6572
     73    ScriptSourceCode(const ScriptBuffer& source, URL&& url, const TextPosition& startPosition, JSC::SourceProviderSourceType sourceType, Ref<JSC::ScriptFetcher>&& scriptFetcher)
     74        : m_provider(ScriptBufferSourceProvider::create(source, JSC::SourceOrigin { url, WTFMove(scriptFetcher) }, url.string(), startPosition, sourceType))
     75        , m_code(m_provider.copyRef(), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt())
     76    {
     77    }
     78
    6679    bool isEmpty() const { return m_code.length() == 0; }
    6780
    6881    const JSC::SourceCode& jsSourceCode() const { return m_code; }
    6982
     83    JSC::SourceProvider& provider() { return m_provider.get(); }
    7084    StringView source() const { return m_provider->source(); }
    7185
  • trunk/Source/WebCore/workers/DedicatedWorkerThread.cpp

    r268897 r275465  
    3939namespace WebCore {
    4040
    41 DedicatedWorkerThread::DedicatedWorkerThread(const WorkerParameters& params, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerDebuggerProxy& workerDebuggerProxy, WorkerObjectProxy& workerObjectProxy, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, JSC::RuntimeFlags runtimeFlags)
     41DedicatedWorkerThread::DedicatedWorkerThread(const WorkerParameters& params, const ScriptBuffer& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerDebuggerProxy& workerDebuggerProxy, WorkerObjectProxy& workerObjectProxy, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, JSC::RuntimeFlags runtimeFlags)
    4242    : WorkerThread(params, sourceCode, workerLoaderProxy, workerDebuggerProxy, workerObjectProxy, startMode, topOrigin, connectionProxy, socketProvider, runtimeFlags)
    4343    , m_workerObjectProxy(workerObjectProxy)
  • trunk/Source/WebCore/workers/DedicatedWorkerThread.h

    r256012 r275465  
    3737
    3838class ContentSecurityPolicyResponseHeaders;
     39class ScriptBuffer;
    3940class WorkerObjectProxy;
    4041
     
    5556
    5657private:
    57     DedicatedWorkerThread(const WorkerParameters&, const String& sourceCode, WorkerLoaderProxy&, WorkerDebuggerProxy&, WorkerObjectProxy&, WorkerThreadStartMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, JSC::RuntimeFlags);
     58    DedicatedWorkerThread(const WorkerParameters&, const ScriptBuffer& sourceCode, WorkerLoaderProxy&, WorkerDebuggerProxy&, WorkerObjectProxy&, WorkerThreadStartMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, JSC::RuntimeFlags);
    5859
    5960    WorkerObjectProxy& m_workerObjectProxy;
  • trunk/Source/WebCore/workers/ScriptBuffer.cpp

    r275443 r275465  
    4242}
    4343
     44ScriptBuffer ScriptBuffer::empty()
     45{
     46    return ScriptBuffer { SharedBuffer::create() };
     47}
     48
     49
    4450String ScriptBuffer::toString() const
    4551{
     
    5864}
    5965
     66void ScriptBuffer::append(const String& string)
     67{
     68    if (!m_buffer)
     69        m_buffer = SharedBuffer::create();
     70    auto utf8 = string.utf8();
     71    m_buffer->append(utf8.data(), utf8.length());
     72}
     73
    6074bool operator==(const ScriptBuffer& a, const ScriptBuffer& b)
    6175{
     
    6781}
    6882
     83bool operator!=(const ScriptBuffer& a, const ScriptBuffer& b)
     84{
     85    return !(a == b);
     86}
     87
    6988} // namespace WebCore
  • trunk/Source/WebCore/workers/ScriptBuffer.h

    r275443 r275465  
    4444    }
    4545
    46     explicit ScriptBuffer(const String&);
     46    static ScriptBuffer empty();
     47
     48    WEBCORE_EXPORT explicit ScriptBuffer(const String&);
    4749
    4850    String toString() const;
     
    5153    ScriptBuffer isolatedCopy() const { return ScriptBuffer(m_buffer ? RefPtr<SharedBuffer>(m_buffer->copy()) : nullptr); }
    5254    explicit operator bool() const { return !!m_buffer; }
     55    bool isEmpty() const { return !m_buffer || !m_buffer->size(); }
    5356
    5457    WEBCORE_EXPORT bool containsSingleFileMappedSegment() const;
     58    void append(const String&);
    5559
    5660private:
     
    5963
    6064bool operator==(const ScriptBuffer&, const ScriptBuffer&);
     65bool operator!=(const ScriptBuffer&, const ScriptBuffer&);
    6166
    6267} // namespace WebCore
  • trunk/Source/WebCore/workers/Worker.cpp

    r274385 r275465  
    234234    }
    235235    m_contextProxy.startWorkerGlobalScope(responseURL, m_name, context->userAgent(responseURL), isOnline, m_scriptLoader->script(), contentSecurityPolicyResponseHeaders, m_shouldBypassMainWorldContentSecurityPolicy, m_workerCreationTime, referrerPolicy, m_type, m_credentials, m_runtimeFlags);
    236     InspectorInstrumentation::scriptImported(*context, m_scriptLoader->identifier(), m_scriptLoader->script());
     236    InspectorInstrumentation::scriptImported(*context, m_scriptLoader->identifier(), m_scriptLoader->script().toString());
    237237}
    238238
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r275428 r275465  
    329329            return WTFMove(*exception);
    330330
    331         InspectorInstrumentation::scriptImported(*this, scriptLoader->identifier(), scriptLoader->script());
    332 
    333         NakedPtr<JSC::Exception> exception;
    334         script()->evaluate(ScriptSourceCode(scriptLoader->script(), URL(scriptLoader->responseURL())), exception);
    335         if (exception) {
    336             script()->setException(exception);
    337             return { };
     331        InspectorInstrumentation::scriptImported(*this, scriptLoader->identifier(), scriptLoader->script().toString());
     332
     333        WeakPtr<ScriptBufferSourceProvider> sourceProvider;
     334        {
     335            NakedPtr<JSC::Exception> exception;
     336            ScriptSourceCode sourceCode(scriptLoader->script(), URL(scriptLoader->responseURL()));
     337            sourceProvider = makeWeakPtr(static_cast<ScriptBufferSourceProvider&>(sourceCode.provider()));
     338            script()->evaluate(sourceCode, exception);
     339            if (exception) {
     340                script()->setException(exception);
     341                return { };
     342            }
    338343        }
     344        if (sourceProvider)
     345            addImportedScriptSourceProvider(url, *sourceProvider);
    339346    }
    340347
     
    530537{
    531538    ASSERT(isContextThread());
     539    deleteJSCodeAndGC(synchronous);
     540    clearDecodedScriptData();
     541}
     542
     543void WorkerGlobalScope::deleteJSCodeAndGC(Synchronous synchronous)
     544{
     545    ASSERT(isContextThread());
    532546
    533547    JSC::JSLockHolder lock(vm());
     
    564578}
    565579
     580void WorkerGlobalScope::setMainScriptSourceProvider(ScriptBufferSourceProvider& provider)
     581{
     582    ASSERT(!m_mainScriptSourceProvider);
     583    m_mainScriptSourceProvider = makeWeakPtr(provider);
     584}
     585
     586void WorkerGlobalScope::addImportedScriptSourceProvider(const URL& url, ScriptBufferSourceProvider& provider)
     587{
     588    m_importedScriptsSourceProviders.ensure(url, [] {
     589        return WeakHashSet<ScriptBufferSourceProvider> { };
     590    }).iterator->value.add(provider);
     591}
     592
     593void WorkerGlobalScope::clearDecodedScriptData()
     594{
     595    ASSERT(isContextThread());
     596
     597    if (m_mainScriptSourceProvider)
     598        m_mainScriptSourceProvider->clearDecodedData();
     599
     600    for (auto& sourceProviders : m_importedScriptsSourceProviders.values()) {
     601        for (auto& sourceProvider : sourceProviders)
     602            sourceProvider.clearDecodedData();
     603    }
     604}
     605
     606void WorkerGlobalScope::updateSourceProviderBuffers(const ScriptBuffer& mainScript, const HashMap<URL, ScriptBuffer>& importedScripts)
     607{
     608    ASSERT(isContextThread());
     609
     610    if (mainScript && m_mainScriptSourceProvider)
     611        m_mainScriptSourceProvider->tryReplaceScriptBuffer(mainScript);
     612
     613    for (auto& pair : importedScripts) {
     614        auto it = m_importedScriptsSourceProviders.find(pair.key);
     615        if (it == m_importedScriptsSourceProviders.end())
     616            continue;
     617        for (auto& sourceProvider : it->value)
     618            sourceProvider.tryReplaceScriptBuffer(pair.value);
     619    }
     620}
     621
    566622} // namespace WebCore
  • trunk/Source/WebCore/workers/WorkerGlobalScope.h

    r275428 r275465  
    3030#include "CacheStorageConnection.h"
    3131#include "ImageBitmap.h"
     32#include "ScriptBufferSourceProvider.h"
    3233#include "ScriptExecutionContext.h"
    3334#include "Supplementable.h"
    3435#include "WorkerOrWorkletGlobalScope.h"
    3536#include "WorkerOrWorkletScriptController.h"
    36 #include <wtf/URL.h>
    3737#include "WorkerCacheStorageConnection.h"
    3838#include "WorkerMessagePortChannelProvider.h"
     
    4040#include <JavaScriptCore/ConsoleMessage.h>
    4141#include <memory>
     42#include <wtf/HashMap.h>
    4243#include <wtf/MemoryPressureHandler.h>
     44#include <wtf/URL.h>
     45#include <wtf/URLHash.h>
     46#include <wtf/WeakHashSet.h>
    4347
    4448namespace WebCore {
     
    131135    static void releaseMemoryInWorkers(Synchronous);
    132136
     137    void setMainScriptSourceProvider(ScriptBufferSourceProvider&);
     138    void addImportedScriptSourceProvider(const URL&, ScriptBufferSourceProvider&);
     139
    133140protected:
    134141    WorkerGlobalScope(WorkerThreadType, const WorkerParameters&, Ref<SecurityOrigin>&&, WorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
    135142
    136143    void applyContentSecurityPolicyResponseHeaders(const ContentSecurityPolicyResponseHeaders&);
     144    void updateSourceProviderBuffers(const ScriptBuffer& mainScript, const HashMap<URL, ScriptBuffer>& importedScripts);
    137145
    138146private:
     
    146154    bool isWorkerGlobalScope() const final { return true; }
    147155
     156    void deleteJSCodeAndGC(Synchronous);
     157    void clearDecodedScriptData();
     158
    148159    URL completeURL(const String&, ForceUTF8 = ForceUTF8::No) const final;
    149160    String userAgent(const URL&) const final;
     
    181192    RefPtr<Performance> m_performance;
    182193    mutable RefPtr<Crypto> m_crypto;
     194
     195    WeakPtr<ScriptBufferSourceProvider> m_mainScriptSourceProvider;
     196    HashMap<URL, WeakHashSet<ScriptBufferSourceProvider>> m_importedScriptsSourceProviders;
    183197
    184198    RefPtr<WorkerCacheStorageConnection> m_cacheStorageConnection;
  • trunk/Source/WebCore/workers/WorkerGlobalScopeProxy.h

    r273299 r275465  
    5151    static WorkerGlobalScopeProxy& create(Worker&);
    5252
    53     virtual void startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const String& sourceCode, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, MonotonicTime timeOrigin, ReferrerPolicy, WorkerType, FetchRequestCredentials, JSC::RuntimeFlags) = 0;
     53    virtual void startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const ScriptBuffer& sourceCode, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, MonotonicTime timeOrigin, ReferrerPolicy, WorkerType, FetchRequestCredentials, JSC::RuntimeFlags) = 0;
    5454    virtual void terminateWorkerGlobalScope() = 0;
    5555    virtual void postMessageToWorkerGlobalScope(MessageWithMessagePorts&&) = 0;
  • trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp

    r275151 r275465  
    7676}
    7777
    78 void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const String& sourceCode, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicyResponseHeaders, bool shouldBypassMainWorldContentSecurityPolicy, MonotonicTime timeOrigin, ReferrerPolicy referrerPolicy, WorkerType workerType, FetchRequestCredentials credentials, JSC::RuntimeFlags runtimeFlags)
     78void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const ScriptBuffer& sourceCode, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicyResponseHeaders, bool shouldBypassMainWorldContentSecurityPolicy, MonotonicTime timeOrigin, ReferrerPolicy referrerPolicy, WorkerType workerType, FetchRequestCredentials credentials, JSC::RuntimeFlags runtimeFlags)
    7979{
    8080    // FIXME: This need to be revisited when we support nested worker one day
  • trunk/Source/WebCore/workers/WorkerMessagingProxy.h

    r274758 r275465  
    5151    // Implementations of WorkerGlobalScopeProxy.
    5252    // (Only use these functions in the worker object thread.)
    53     void startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const String& sourceCode, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, MonotonicTime timeOrigin, ReferrerPolicy, WorkerType, FetchRequestCredentials, JSC::RuntimeFlags) final;
     53    void startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const ScriptBuffer& sourceCode, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, MonotonicTime timeOrigin, ReferrerPolicy, WorkerType, FetchRequestCredentials, JSC::RuntimeFlags) final;
    5454    void terminateWorkerGlobalScope() final;
    5555    void postMessageToWorkerGlobalScope(MessageWithMessagePorts&&) final;
  • trunk/Source/WebCore/workers/WorkerScriptLoader.cpp

    r275443 r275465  
    4545namespace WebCore {
    4646
    47 WorkerScriptLoader::WorkerScriptLoader() = default;
     47WorkerScriptLoader::WorkerScriptLoader()
     48    : m_script(ScriptBuffer::empty())
     49{
     50}
    4851
    4952WorkerScriptLoader::~WorkerScriptLoader() = default;
     
    6265    if (isServiceWorkerGlobalScope) {
    6366        if (auto* scriptResource = downcast<ServiceWorkerGlobalScope>(workerGlobalScope).scriptResource(url)) {
    64             m_script.append(scriptResource->script.toString());
     67            m_script = scriptResource->script;
    6568            m_responseURL = scriptResource->responseURL;
    6669            m_responseMIMEType = scriptResource->mimeType;
     
    103106            return Exception { NetworkError, "mime type is not a supported JavaScript mime type"_s };
    104107
    105         downcast<ServiceWorkerGlobalScope>(workerGlobalScope).setScriptResource(url, ServiceWorkerContextData::ImportedScript { ScriptBuffer { script() }, m_responseURL, m_responseMIMEType });
     108        downcast<ServiceWorkerGlobalScope>(workerGlobalScope).setScriptResource(url, ServiceWorkerContextData::ImportedScript { script(), m_responseURL, m_responseMIMEType });
    106109    }
    107110#endif
     
    212215    if (len == -1)
    213216        len = strlen(data);
    214    
     217
    215218    m_script.append(m_decoder->decode(data, len));
    216219}
     
    244247}
    245248
    246 String WorkerScriptLoader::script()
    247 {
    248     return m_script.toString();
    249 }
    250 
    251249void WorkerScriptLoader::notifyFinished()
    252250{
  • trunk/Source/WebCore/workers/WorkerScriptLoader.h

    r273203 r275465  
    3333#include "ResourceRequest.h"
    3434#include "ResourceResponse.h"
     35#include "ScriptBuffer.h"
    3536#include "ThreadableLoader.h"
    3637#include "ThreadableLoaderClient.h"
     
    6364    void notifyError();
    6465
    65     String script();
     66    const ScriptBuffer& script() { return m_script; }
    6667    const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy() const { return m_contentSecurityPolicy; }
    6768    const String& referrerPolicy() const { return m_referrerPolicy; }
     
    99100    String m_responseEncoding;
    100101    RefPtr<TextResourceDecoder> m_decoder;
    101     StringBuilder m_script;
     102    ScriptBuffer m_script;
    102103    URL m_url;
    103104    URL m_responseURL;
  • trunk/Source/WebCore/workers/WorkerThread.cpp

    r275151 r275465  
    6767    WTF_MAKE_NONCOPYABLE(WorkerThreadStartupData); WTF_MAKE_FAST_ALLOCATED;
    6868public:
    69     WorkerThreadStartupData(const WorkerParameters& params, const String& sourceCode, WorkerThreadStartMode, const SecurityOrigin& topOrigin);
     69    WorkerThreadStartupData(const WorkerParameters& params, const ScriptBuffer& sourceCode, WorkerThreadStartMode, const SecurityOrigin& topOrigin);
    7070
    7171    WorkerParameters params;
    7272    Ref<SecurityOrigin> origin;
    73     String sourceCode;
     73    ScriptBuffer sourceCode;
    7474    WorkerThreadStartMode startMode;
    7575    Ref<SecurityOrigin> topOrigin;
    7676};
    7777
    78 WorkerThreadStartupData::WorkerThreadStartupData(const WorkerParameters& other, const String& sourceCode, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin)
     78WorkerThreadStartupData::WorkerThreadStartupData(const WorkerParameters& other, const ScriptBuffer& sourceCode, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin)
    7979    : params(other.isolatedCopy())
    8080    , origin(SecurityOrigin::create(other.scriptURL)->isolatedCopy())
     
    8585}
    8686
    87 WorkerThread::WorkerThread(const WorkerParameters& params, const String& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerDebuggerProxy& workerDebuggerProxy, WorkerReportingProxy& workerReportingProxy, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, JSC::RuntimeFlags runtimeFlags)
     87WorkerThread::WorkerThread(const WorkerParameters& params, const ScriptBuffer& sourceCode, WorkerLoaderProxy& workerLoaderProxy, WorkerDebuggerProxy& workerDebuggerProxy, WorkerReportingProxy& workerReportingProxy, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, JSC::RuntimeFlags runtimeFlags)
    8888    : WorkerOrWorkletThread(params.identifier.isolatedCopy())
    8989    , m_workerLoaderProxy(workerLoaderProxy)
     
    126126    // We invoke module loader as if we are executing inline module script tag in Document.
    127127
     128    WeakPtr<ScriptBufferSourceProvider> sourceProvider;
    128129    if (m_startupData->params.workerType == WorkerType::Classic) {
    129         globalScope()->script()->evaluate(ScriptSourceCode(m_startupData->sourceCode, URL(m_startupData->params.scriptURL)), &exceptionMessage);
     130        ScriptSourceCode sourceCode(m_startupData->sourceCode, URL(m_startupData->params.scriptURL));
     131        sourceProvider = makeWeakPtr(static_cast<ScriptBufferSourceProvider&>(sourceCode.provider()));
     132        globalScope()->script()->evaluate(sourceCode, &exceptionMessage);
    130133        finishedEvaluatingScript();
    131134    } else {
    132135        auto scriptFetcher = WorkerScriptFetcher::create(globalScope()->credentials(), globalScope()->destination(), globalScope()->referrerPolicy());
    133136        ScriptSourceCode sourceCode(m_startupData->sourceCode, URL(m_startupData->params.scriptURL), { }, JSC::SourceProviderSourceType::Module, scriptFetcher.copyRef());
     137        sourceProvider = makeWeakPtr(static_cast<ScriptBufferSourceProvider&>(sourceCode.provider()));
    134138        MessageQueueWaitResult result = globalScope()->script()->loadModuleSynchronously(scriptFetcher.get(), sourceCode);
    135139        if (result != MessageQueueTerminated) {
     
    146150        }
    147151    }
     152    if (sourceProvider)
     153        globalScope()->setMainScriptSourceProvider(*sourceProvider);
    148154
    149155    // Free the startup data to cause its member variable deref's happen on the worker's thread (since
  • trunk/Source/WebCore/workers/WorkerThread.h

    r275151 r275465  
    3838
    3939class NotificationClient;
     40class ScriptBuffer;
    4041class SecurityOrigin;
    4142class SocketProvider;
     
    9394
    9495protected:
    95     WorkerThread(const WorkerParameters&, const String& sourceCode, WorkerLoaderProxy&, WorkerDebuggerProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, JSC::RuntimeFlags);
     96    WorkerThread(const WorkerParameters&, const ScriptBuffer& sourceCode, WorkerLoaderProxy&, WorkerDebuggerProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, JSC::RuntimeFlags);
    9697
    9798    // Factory method for creating a new worker context for the thread.
  • trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp

    r273224 r275465  
    475475}
    476476
    477 void ServiceWorkerContainer::jobFinishedLoadingScript(ServiceWorkerJob& job, const String& script, const CertificateInfo& certificateInfo, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const String& referrerPolicy)
     477void ServiceWorkerContainer::jobFinishedLoadingScript(ServiceWorkerJob& job, const ScriptBuffer& script, const CertificateInfo& certificateInfo, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const String& referrerPolicy)
    478478{
    479479#ifndef NDEBUG
  • trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h

    r273203 r275465  
    103103    void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) final;
    104104    void startScriptFetchForJob(ServiceWorkerJob&, FetchOptions::Cache) final;
    105     void jobFinishedLoadingScript(ServiceWorkerJob&, const String& script, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy) final;
     105    void jobFinishedLoadingScript(ServiceWorkerJob&, const ScriptBuffer&, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy) final;
    106106    void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&, Exception&&) final;
    107107
  • trunk/Source/WebCore/workers/service/ServiceWorkerFetchResult.h

    r264724 r275465  
    3030#include "ContentSecurityPolicyResponseHeaders.h"
    3131#include "ResourceError.h"
     32#include "ScriptBuffer.h"
    3233#include "ServiceWorkerRegistrationKey.h"
    3334#include "ServiceWorkerTypes.h"
     
    3839    ServiceWorkerJobDataIdentifier jobDataIdentifier;
    3940    ServiceWorkerRegistrationKey registrationKey;
    40     String script;
     41    ScriptBuffer script;
    4142    CertificateInfo certificateInfo;
    4243    ContentSecurityPolicyResponseHeaders contentSecurityPolicy;
  • trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp

    r275443 r275465  
    159159{
    160160    // These scripts should be identical to the ones we have. However, these are mmap'd so using them helps reduce dirty memory usage.
     161    updateSourceProviderBuffers(script, importedScripts);
     162
    161163    if (script) {
    162164        ASSERT(m_contextData.script == script);
  • trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h

    r264724 r275465  
    3636class Exception;
    3737class ResourceError;
     38class ScriptBuffer;
    3839class ServiceWorkerJob;
    39 class SharedBuffer;
    4040struct ServiceWorkerRegistrationData;
    4141
     
    5050    virtual void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) = 0;
    5151    virtual void startScriptFetchForJob(ServiceWorkerJob&, FetchOptions::Cache) = 0;
    52     virtual void jobFinishedLoadingScript(ServiceWorkerJob&, const String& script, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy) = 0;
     52    virtual void jobFinishedLoadingScript(ServiceWorkerJob&, const ScriptBuffer&, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy) = 0;
    5353    virtual void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&, Exception&&) = 0;
    5454};
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp

    r275443 r275465  
    7575
    7676ServiceWorkerThread::ServiceWorkerThread(ServiceWorkerContextData&& data, String&& userAgent, const Settings::Values& settingsValues, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, IDBClient::IDBConnectionProxy* idbConnectionProxy, SocketProvider* socketProvider)
    77     : WorkerThread({ data.scriptURL, emptyString(), "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), platformStrategies()->loaderStrategy()->isOnLine(), data.contentSecurityPolicy, false, MonotonicTime::now(), { }, data.workerType, FetchRequestCredentials::Omit, settingsValues }, data.script.toString(), loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, data.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled())
     77    : WorkerThread({ data.scriptURL, emptyString(), "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), platformStrategies()->loaderStrategy()->isOnLine(), data.contentSecurityPolicy, false, MonotonicTime::now(), { }, data.workerType, FetchRequestCredentials::Omit, settingsValues }, data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, data.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled())
    7878    , m_serviceWorkerIdentifier(data.serviceWorkerIdentifier)
    7979    , m_jobDataIdentifier(data.jobDataIdentifier)
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r275443 r275465  
    638638}
    639639
    640 void SWServer::updateWorker(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerRegistration& registration, const URL& url, const String& script, const CertificateInfo& certificateInfo, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const String& referrerPolicy, WorkerType type, HashMap<URL, ServiceWorkerContextData::ImportedScript>&& scriptResourceMap)
    641 {
    642     tryInstallContextData(ServiceWorkerContextData { jobDataIdentifier, registration.data(), ServiceWorkerIdentifier::generate(), ScriptBuffer { script }, certificateInfo, contentSecurityPolicy, referrerPolicy, url, type, false, WTFMove(scriptResourceMap) });
     640void SWServer::updateWorker(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerRegistration& registration, const URL& url, const ScriptBuffer& script, const CertificateInfo& certificateInfo, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const String& referrerPolicy, WorkerType type, HashMap<URL, ServiceWorkerContextData::ImportedScript>&& scriptResourceMap)
     641{
     642    tryInstallContextData(ServiceWorkerContextData { jobDataIdentifier, registration.data(), ServiceWorkerIdentifier::generate(), script, certificateInfo, contentSecurityPolicy, referrerPolicy, url, type, false, WTFMove(scriptResourceMap) });
    643643}
    644644
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r275443 r275465  
    152152    void startScriptFetch(const ServiceWorkerJobData&, bool shouldRefreshCache);
    153153
    154     void updateWorker(const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const String& script, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy, WorkerType, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&);
     154    void updateWorker(const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const ScriptBuffer&, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const String& referrerPolicy, WorkerType, HashMap<URL, ServiceWorkerContextData::ImportedScript>&&);
    155155    void fireInstallEvent(SWServerWorker&);
    156156    void fireActivateEvent(SWServerWorker&);
  • trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp

    r275443 r275465  
    101101    // flag set, and script's source text is a byte-for-byte match with newestWorker's script resource's source
    102102    // text, then:
    103     if (newestWorker && equalIgnoringFragmentIdentifier(newestWorker->scriptURL(), job.scriptURL) && newestWorker->type() == job.workerType && result.script == newestWorker->script().toString() && doCertificatesMatch(result.certificateInfo, newestWorker->certificateInfo())) {
     103    if (newestWorker && equalIgnoringFragmentIdentifier(newestWorker->scriptURL(), job.scriptURL) && newestWorker->type() == job.workerType && result.script == newestWorker->script() && doCertificatesMatch(result.certificateInfo, newestWorker->certificateInfo())) {
    104104        RELEASE_LOG(ServiceWorker, "%p - SWServerJobQueue::scriptFetchFinished, script and certificate are matching for registrationID=%llu", this, registration->identifier().toUInt64());
    105105        // FIXME: for non classic scripts, check the script’s module record's [[ECMAScriptCode]].
  • trunk/Source/WebKit/ChangeLog

    r275463 r275465  
     12021-04-05  Chris Dumez  <cdumez@apple.com>
     2
     3        Make sure service workers use a ScriptSourceCode backed by file-mapped memory when possible
     4        https://bugs.webkit.org/show_bug.cgi?id=224088
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp:
     9        (WebKit::ServiceWorkerSoftUpdateLoader::didFinishLoading):
     10
    1112021-04-05  Fujii Hironori  <Hironori.Fujii@sony.com>
    212
  • trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp

    r265150 r275465  
    189189    if (m_decoder)
    190190        m_script.append(m_decoder->flush());
    191     m_completionHandler({ m_jobData.identifier(), m_jobData.registrationKey(), m_script.toString(), m_certificateInfo, m_contentSecurityPolicy, m_referrerPolicy, { } });
     191    m_completionHandler({ m_jobData.identifier(), m_jobData.registrationKey(), ScriptBuffer { m_script.toString() }, m_certificateInfo, m_contentSecurityPolicy, m_referrerPolicy, { } });
    192192    didComplete();
    193193}
Note: See TracChangeset for help on using the changeset viewer.