Changeset 210627 in webkit


Ignore:
Timestamp:
Jan 12, 2017 1:01:40 AM (7 years ago)
Author:
Yusuke Suzuki
Message:

Implement InlineClassicScript
https://bugs.webkit.org/show_bug.cgi?id=166925

Reviewed by Ryosuke Niwa.

Source/JavaScriptCore:

Add ScriptFetcher field for SourceOrigin.

  • runtime/SourceOrigin.h:

(JSC::SourceOrigin::SourceOrigin):
(JSC::SourceOrigin::fetcher):

Source/WebCore:

As of r210585, ScriptFetcher functionality is decoupled from ScriptElement.
This patch is a further cleanup. We introduce InlineClassicScript, which is
similar to LoadableClassicScript / LoadableModuleScript. And we move ScriptFetcher
functionality from LoadableScript to CachedScriptFetcher, which is the base
class of InlineClassicScript and LoadableScript.

And we start setting this CachedScriptFetcher to the member of JSC::SourceOrigin.
This allows us to examine the ScriptFetcher from the SourceOrigin.
When dynamic-import operator is called, we need to get the ScriptFetcher from the
caller script SourceOrigin since the subsequent module loading needs to know the
metadata about fetching and ScriptFetcher delivers it.

No behavior change.

  • CMakeLists.txt:
  • bindings/js/CachedModuleScript.cpp:

(WebCore::CachedModuleScript::load):

  • bindings/js/CachedModuleScript.h:
  • bindings/js/CachedModuleScriptLoader.cpp:

(WebCore::CachedModuleScriptLoader::create):
(WebCore::CachedModuleScriptLoader::CachedModuleScriptLoader):
(WebCore::CachedModuleScriptLoader::load):

  • bindings/js/CachedModuleScriptLoader.h:
  • bindings/js/CachedScriptFetcher.cpp: Copied from Source/WebCore/dom/LoadableScript.cpp.

(WebCore::CachedScriptFetcher::requestScriptWithCache):

  • bindings/js/CachedScriptFetcher.h: Copied from Source/JavaScriptCore/runtime/SourceOrigin.h.

(WebCore::CachedScriptFetcher::CachedScriptFetcher):

  • bindings/js/CachedScriptSourceProvider.h:

(WebCore::CachedScriptSourceProvider::create):
(WebCore::CachedScriptSourceProvider::CachedScriptSourceProvider):
(WebCore::makeSource): Deleted.

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::loadModuleScript):

  • bindings/js/ScriptController.h:
  • bindings/js/ScriptModuleLoader.cpp:

(WebCore::ScriptModuleLoader::fetch):
(WebCore::ScriptModuleLoader::notifyFinished):

  • bindings/js/ScriptSourceCode.h:

(WebCore::ScriptSourceCode::ScriptSourceCode):
(WebCore::ScriptSourceCode::m_url):

  • dom/InlineClassicScript.cpp: Added.

(WebCore::InlineClassicScript::create):

  • dom/InlineClassicScript.h: Added.
  • dom/LoadableClassicScript.cpp:

(WebCore::LoadableClassicScript::execute):

  • dom/LoadableScript.cpp:

(WebCore::LoadableScript::requestScriptWithCache): Deleted.

  • dom/LoadableScript.h:

(WebCore::LoadableScript::LoadableScript):
(): Deleted.

  • dom/ScriptElement.cpp:

(WebCore::ScriptElement::prepareScript):
(WebCore::ScriptElement::requestModuleScript):
(WebCore::ScriptElement::executePendingScript):

  • html/parser/HTMLScriptRunner.cpp:

(WebCore::HTMLScriptRunner::runScript):

  • xml/parser/XMLDocumentParserLibxml2.cpp:

(WebCore::XMLDocumentParser::endElementNs):

Location:
trunk/Source
Files:
2 added
19 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r210609 r210627  
     12017-01-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Implement InlineClassicScript
     4        https://bugs.webkit.org/show_bug.cgi?id=166925
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Add ScriptFetcher field for SourceOrigin.
     9
     10        * runtime/SourceOrigin.h:
     11        (JSC::SourceOrigin::SourceOrigin):
     12        (JSC::SourceOrigin::fetcher):
     13
    1142017-01-11  Andreas Kling  <akling@apple.com>
    215
  • trunk/Source/JavaScriptCore/runtime/SourceOrigin.h

    r210149 r210627  
    2626#pragma once
    2727
     28#include "ScriptFetcher.h"
    2829#include <wtf/text/WTFString.h>
    2930
     
    3738    }
    3839
     40    explicit SourceOrigin(const String& string, Ref<ScriptFetcher>&& fetcher)
     41        : m_string(string)
     42        , m_fetcher(WTFMove(fetcher))
     43    {
     44    }
     45
    3946    SourceOrigin() = default;
    4047
     
    4249    bool isNull() const { return m_string.isNull(); }
    4350
     51    ScriptFetcher* fetcher() const { return m_fetcher.get(); }
     52
    4453private:
    4554    String m_string;
     55    RefPtr<ScriptFetcher> m_fetcher;
    4656};
    4757
  • trunk/Source/WebCore/CMakeLists.txt

    r210588 r210627  
    10681068    bindings/js/CachedModuleScript.cpp
    10691069    bindings/js/CachedModuleScriptLoader.cpp
     1070    bindings/js/CachedScriptFetcher.cpp
    10701071    bindings/js/CallbackFunction.cpp
    10711072    bindings/js/CommonVM.cpp
     
    14431444    dom/IdTargetObserver.cpp
    14441445    dom/IdTargetObserverRegistry.cpp
     1446    dom/InlineClassicScript.cpp
    14451447    dom/InlineStyleSheetOwner.cpp
    14461448    dom/InputEvent.cpp
  • trunk/Source/WebCore/ChangeLog

    r210621 r210627  
     12017-01-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Implement InlineClassicScript
     4        https://bugs.webkit.org/show_bug.cgi?id=166925
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        As of r210585, ScriptFetcher functionality is decoupled from ScriptElement.
     9        This patch is a further cleanup. We introduce InlineClassicScript, which is
     10        similar to LoadableClassicScript / LoadableModuleScript. And we move ScriptFetcher
     11        functionality from LoadableScript to CachedScriptFetcher, which is the base
     12        class of InlineClassicScript and LoadableScript.
     13
     14        And we start setting this CachedScriptFetcher to the member of JSC::SourceOrigin.
     15        This allows us to examine the ScriptFetcher from the SourceOrigin.
     16        When dynamic-import operator is called, we need to get the ScriptFetcher from the
     17        caller script SourceOrigin since the subsequent module loading needs to know the
     18        metadata about fetching and ScriptFetcher delivers it.
     19
     20        No behavior change.
     21
     22        * CMakeLists.txt:
     23        * bindings/js/CachedModuleScript.cpp:
     24        (WebCore::CachedModuleScript::load):
     25        * bindings/js/CachedModuleScript.h:
     26        * bindings/js/CachedModuleScriptLoader.cpp:
     27        (WebCore::CachedModuleScriptLoader::create):
     28        (WebCore::CachedModuleScriptLoader::CachedModuleScriptLoader):
     29        (WebCore::CachedModuleScriptLoader::load):
     30        * bindings/js/CachedModuleScriptLoader.h:
     31        * bindings/js/CachedScriptFetcher.cpp: Copied from Source/WebCore/dom/LoadableScript.cpp.
     32        (WebCore::CachedScriptFetcher::requestScriptWithCache):
     33        * bindings/js/CachedScriptFetcher.h: Copied from Source/JavaScriptCore/runtime/SourceOrigin.h.
     34        (WebCore::CachedScriptFetcher::CachedScriptFetcher):
     35        * bindings/js/CachedScriptSourceProvider.h:
     36        (WebCore::CachedScriptSourceProvider::create):
     37        (WebCore::CachedScriptSourceProvider::CachedScriptSourceProvider):
     38        (WebCore::makeSource): Deleted.
     39        * bindings/js/ScriptController.cpp:
     40        (WebCore::ScriptController::loadModuleScriptInWorld):
     41        (WebCore::ScriptController::loadModuleScript):
     42        * bindings/js/ScriptController.h:
     43        * bindings/js/ScriptModuleLoader.cpp:
     44        (WebCore::ScriptModuleLoader::fetch):
     45        (WebCore::ScriptModuleLoader::notifyFinished):
     46        * bindings/js/ScriptSourceCode.h:
     47        (WebCore::ScriptSourceCode::ScriptSourceCode):
     48        (WebCore::ScriptSourceCode::m_url):
     49        * dom/InlineClassicScript.cpp: Added.
     50        (WebCore::InlineClassicScript::create):
     51        * dom/InlineClassicScript.h: Added.
     52        * dom/LoadableClassicScript.cpp:
     53        (WebCore::LoadableClassicScript::execute):
     54        * dom/LoadableScript.cpp:
     55        (WebCore::LoadableScript::requestScriptWithCache): Deleted.
     56        * dom/LoadableScript.h:
     57        (WebCore::LoadableScript::LoadableScript):
     58        (): Deleted.
     59        * dom/ScriptElement.cpp:
     60        (WebCore::ScriptElement::prepareScript):
     61        (WebCore::ScriptElement::requestModuleScript):
     62        (WebCore::ScriptElement::executePendingScript):
     63        * html/parser/HTMLScriptRunner.cpp:
     64        (WebCore::HTMLScriptRunner::runScript):
     65        * xml/parser/XMLDocumentParserLibxml2.cpp:
     66        (WebCore::XMLDocumentParser::endElementNs):
     67
    1682017-01-11  Eric Carlson  <eric.carlson@apple.com>
    269
  • trunk/Source/WebCore/bindings/js/CachedModuleScript.cpp

    r210585 r210627  
    4444}
    4545
    46 void CachedModuleScript::load(Document& document, const URL& rootURL, LoadableScript& loadableScript)
     46void CachedModuleScript::load(Document& document, const URL& rootURL, CachedScriptFetcher& scriptFetcher)
    4747{
    4848    if (auto* frame = document.frame())
    49         frame->script().loadModuleScript(*this, rootURL.string(), loadableScript);
     49        frame->script().loadModuleScript(*this, rootURL.string(), scriptFetcher);
    5050}
    5151
    52 void CachedModuleScript::load(Document& document, const ScriptSourceCode& sourceCode, LoadableScript& loadableScript)
     52void CachedModuleScript::load(Document& document, const ScriptSourceCode& sourceCode, CachedScriptFetcher& scriptFetcher)
    5353{
    5454    if (auto* frame = document.frame())
    55         frame->script().loadModuleScript(*this, sourceCode, loadableScript);
     55        frame->script().loadModuleScript(*this, sourceCode, scriptFetcher);
    5656}
    5757
  • trunk/Source/WebCore/bindings/js/CachedModuleScript.h

    r210585 r210627  
    5353    static Ref<CachedModuleScript> create();
    5454
    55     void load(Document&, const URL& rootURL, LoadableScript&);
    56     void load(Document&, const ScriptSourceCode&, LoadableScript&);
     55    void load(Document&, const URL& rootURL, CachedScriptFetcher&);
     56    void load(Document&, const ScriptSourceCode&, CachedScriptFetcher&);
    5757
    5858private:
  • trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp

    r210585 r210627  
    2828
    2929#include "CachedScript.h"
     30#include "CachedScriptFetcher.h"
    3031#include "DOMWrapperWorld.h"
    3132#include "Frame.h"
    3233#include "JSDOMBinding.h"
    33 #include "LoadableScript.h"
    3434#include "ResourceLoaderOptions.h"
    3535#include "ScriptController.h"
     
    3939namespace WebCore {
    4040
    41 Ref<CachedModuleScriptLoader> CachedModuleScriptLoader::create(CachedModuleScriptLoaderClient& client, DeferredPromise& promise)
     41Ref<CachedModuleScriptLoader> CachedModuleScriptLoader::create(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher)
    4242{
    43     return adoptRef(*new CachedModuleScriptLoader(client, promise));
     43    return adoptRef(*new CachedModuleScriptLoader(client, promise, scriptFetcher));
    4444}
    4545
    46 CachedModuleScriptLoader::CachedModuleScriptLoader(CachedModuleScriptLoaderClient& client, DeferredPromise& promise)
     46CachedModuleScriptLoader::CachedModuleScriptLoader(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher)
    4747    : m_client(&client)
    4848    , m_promise(&promise)
     49    , m_scriptFetcher(scriptFetcher)
    4950{
    5051}
     
    5859}
    5960
    60 bool CachedModuleScriptLoader::load(Document& document, LoadableScript& loadableScript, const URL& sourceURL)
     61bool CachedModuleScriptLoader::load(Document& document, const URL& sourceURL)
    6162{
    6263    ASSERT(!m_cachedScript);
    63     m_cachedScript = loadableScript.requestScriptWithCache(document, sourceURL);
     64    m_cachedScript = m_scriptFetcher->requestScriptWithCache(document, sourceURL);
    6465    if (!m_cachedScript)
    6566        return false;
  • trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.h

    r210585 r210627  
    3636class CachedModuleScriptLoaderClient;
    3737class CachedScript;
     38class CachedScriptFetcher;
    3839class DeferredPromise;
    3940class Document;
    4041class JSDOMGlobalObject;
    41 class LoadableScript;
    4242class URL;
    4343
    4444class CachedModuleScriptLoader final : public RefCounted<CachedModuleScriptLoader>, private CachedResourceClient {
    4545public:
    46     static Ref<CachedModuleScriptLoader> create(CachedModuleScriptLoaderClient&, DeferredPromise&);
     46    static Ref<CachedModuleScriptLoader> create(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
    4747
    4848    virtual ~CachedModuleScriptLoader();
    4949
    50     bool load(Document&, LoadableScript&, const URL& sourceURL);
     50    bool load(Document&, const URL& sourceURL);
    5151
     52    CachedScriptFetcher& scriptFetcher() { return m_scriptFetcher.get(); }
    5253    CachedScript* cachedScript() { return m_cachedScript.get(); }
    5354
     
    5960
    6061private:
    61     CachedModuleScriptLoader(CachedModuleScriptLoaderClient&, DeferredPromise&);
     62    CachedModuleScriptLoader(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
    6263
    6364    void notifyFinished(CachedResource&) final;
     
    6566    CachedModuleScriptLoaderClient* m_client { nullptr };
    6667    RefPtr<DeferredPromise> m_promise;
     68    Ref<CachedScriptFetcher> m_scriptFetcher;
    6769    CachedResourceHandle<CachedScript> m_cachedScript;
    6870};
  • trunk/Source/WebCore/bindings/js/CachedScriptFetcher.cpp

    r210626 r210627  
    11/*
    2  * Copyright (C) 2016 Apple, Inc. All Rights Reserved.
     2 * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 #include "LoadableScript.h"
     27#include "CachedScriptFetcher.h"
    2828
    2929#include "CachedResourceLoader.h"
     
    3131#include "ContentSecurityPolicy.h"
    3232#include "Document.h"
    33 #include "LoadableScriptClient.h"
    3433#include "Settings.h"
    3534
    3635namespace WebCore {
    3736
    38 void LoadableScript::addClient(LoadableScriptClient& client)
    39 {
    40     m_clients.add(&client);
    41     if (isLoaded()) {
    42         Ref<LoadableScript> protectedThis(*this);
    43         client.notifyFinished(*this);
    44     }
    45 }
    46 
    47 void LoadableScript::removeClient(LoadableScriptClient& client)
    48 {
    49     m_clients.remove(&client);
    50 }
    51 
    52 void LoadableScript::notifyClientFinished()
    53 {
    54     RefPtr<LoadableScript> protectedThis(this);
    55 
    56     Vector<LoadableScriptClient*> vector;
    57     for (auto& pair : m_clients)
    58         vector.append(pair.key);
    59     for (auto& client : vector)
    60         client->notifyFinished(*this);
    61 }
    62 
    63 CachedResourceHandle<CachedScript> LoadableScript::requestScriptWithCache(Document& document, const URL& sourceURL) const
     37CachedResourceHandle<CachedScript> CachedScriptFetcher::requestScriptWithCache(Document& document, const URL& sourceURL) const
    6438{
    6539    auto* settings = document.settings();
  • trunk/Source/WebCore/bindings/js/CachedScriptFetcher.h

    r210626 r210627  
    11/*
    2  * Copyright (C) 2016 Yusuke Suzuki <utatane.tea@gmail.com>.
     2 * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
     28#include "CachedResourceHandle.h"
     29#include <runtime/ScriptFetcher.h>
    2830#include <wtf/text/WTFString.h>
    2931
    30 namespace JSC {
     32namespace WebCore {
    3133
    32 class SourceOrigin {
     34class CachedScript;
     35class Document;
     36class URL;
     37
     38class CachedScriptFetcher : public JSC::ScriptFetcher {
    3339public:
    34     explicit SourceOrigin(const String& string)
    35         : m_string(string)
     40    CachedResourceHandle<CachedScript> requestScriptWithCache(Document&, const URL& sourceURL) const;
     41
     42protected:
     43    CachedScriptFetcher(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
     44        : m_nonce(nonce)
     45        , m_crossOriginMode(crossOriginMode)
     46        , m_charset(charset)
     47        , m_initiatorName(initiatorName)
     48        , m_isInUserAgentShadowTree(isInUserAgentShadowTree)
    3649    {
    3750    }
    3851
    39     SourceOrigin() = default;
    40 
    41     const String& string() const { return m_string; }
    42     bool isNull() const { return m_string.isNull(); }
    43 
    4452private:
    45     String m_string;
     53    String m_nonce;
     54    String m_crossOriginMode;
     55    String m_charset;
     56    AtomicString m_initiatorName;
     57    bool m_isInUserAgentShadowTree { false };
    4658};
    4759
    48 } // namespace JSC
     60} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/CachedScriptSourceProvider.h

    r210149 r210627  
    2929#include "CachedResourceHandle.h"
    3030#include "CachedScript.h"
     31#include "CachedScriptFetcher.h"
    3132#include <parser/SourceCode.h>
    3233#include <parser/SourceProvider.h>
     
    3738    WTF_MAKE_FAST_ALLOCATED;
    3839public:
    39     static Ref<CachedScriptSourceProvider> create(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType) { return adoptRef(*new CachedScriptSourceProvider(cachedScript, sourceType)); }
     40    static Ref<CachedScriptSourceProvider> create(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher) { return adoptRef(*new CachedScriptSourceProvider(cachedScript, sourceType, WTFMove(scriptFetcher))); }
    4041
    4142    virtual ~CachedScriptSourceProvider()
     
    4849
    4950private:
    50     CachedScriptSourceProvider(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType)
    51         : SourceProvider(JSC::SourceOrigin { cachedScript->response().url() }, cachedScript->response().url(), TextPosition(), sourceType)
     51    CachedScriptSourceProvider(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher)
     52        : SourceProvider(JSC::SourceOrigin { cachedScript->response().url(), WTFMove(scriptFetcher) }, cachedScript->response().url(), TextPosition(), sourceType)
    5253        , m_cachedScript(cachedScript)
    5354    {
     
    5859};
    5960
    60 inline JSC::SourceCode makeSource(CachedScript* cachedScript)
    61 {
    62     return JSC::SourceCode(CachedScriptSourceProvider::create(cachedScript, JSC::SourceProviderSourceType::Program));
    63 }
    64 
    6561} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r210585 r210627  
    2424#include "BridgeJSC.h"
    2525#include "CachedModuleScript.h"
     26#include "CachedScriptFetcher.h"
    2627#include "CommonVM.h"
    2728#include "ContentSecurityPolicy.h"
     
    187188}
    188189
    189 void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const String& moduleName, LoadableScript& loadableScript, DOMWrapperWorld& world)
     190void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const String& moduleName, CachedScriptFetcher& scriptFetcher, DOMWrapperWorld& world)
    190191{
    191192    JSLockHolder lock(world.vm());
     
    194195    auto& state = *shell.window()->globalExec();
    195196
    196     auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetcher::create(state.vm(), { &loadableScript }));
     197    auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetcher::create(state.vm(), { &scriptFetcher }));
    197198    setupModuleScriptHandlers(moduleScript, promise, world);
    198199}
    199200
    200 void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const String& moduleName, LoadableScript& loadableScript)
    201 {
    202     loadModuleScriptInWorld(moduleScript, moduleName, loadableScript, mainThreadNormalWorld());
    203 }
    204 
    205 void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, LoadableScript& loadableScript, DOMWrapperWorld& world)
     201void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const String& moduleName, CachedScriptFetcher& scriptFetcher)
     202{
     203    loadModuleScriptInWorld(moduleScript, moduleName, scriptFetcher, mainThreadNormalWorld());
     204}
     205
     206void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, CachedScriptFetcher& scriptFetcher, DOMWrapperWorld& world)
    206207{
    207208    JSLockHolder lock(world.vm());
     
    210211    auto& state = *shell.window()->globalExec();
    211212
    212     auto& promise = JSMainThreadExecState::loadModule(state, sourceCode.jsSourceCode(), JSC::JSScriptFetcher::create(state.vm(), { &loadableScript }));
     213    auto& promise = JSMainThreadExecState::loadModule(state, sourceCode.jsSourceCode(), JSC::JSScriptFetcher::create(state.vm(), { &scriptFetcher }));
    213214    setupModuleScriptHandlers(moduleScript, promise, world);
    214215}
    215216
    216 void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, LoadableScript& loadableScript)
    217 {
    218     loadModuleScriptInWorld(moduleScript, sourceCode, loadableScript, mainThreadNormalWorld());
     217void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, CachedScriptFetcher& scriptFetcher)
     218{
     219    loadModuleScriptInWorld(moduleScript, sourceCode, scriptFetcher, mainThreadNormalWorld());
    219220}
    220221
  • trunk/Source/WebCore/bindings/js/ScriptController.h

    r210585 r210627  
    5353
    5454class CachedModuleScript;
     55class CachedScriptFetcher;
    5556class Frame;
    5657class HTMLDocument;
    5758class HTMLPlugInElement;
    58 class LoadableScript;
    5959class SecurityOrigin;
    6060class ScriptSourceCode;
     
    115115    JSC::JSValue evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld&, ExceptionDetails* = nullptr);
    116116
    117     void loadModuleScriptInWorld(CachedModuleScript&, const String& moduleName, LoadableScript&, DOMWrapperWorld&);
    118     void loadModuleScript(CachedModuleScript&, const String& moduleName, LoadableScript&);
    119     void loadModuleScriptInWorld(CachedModuleScript&, const ScriptSourceCode&, LoadableScript&, DOMWrapperWorld&);
    120     void loadModuleScript(CachedModuleScript&, const ScriptSourceCode&, LoadableScript&);
     117    void loadModuleScriptInWorld(CachedModuleScript&, const String& moduleName, CachedScriptFetcher&, DOMWrapperWorld&);
     118    void loadModuleScript(CachedModuleScript&, const String& moduleName, CachedScriptFetcher&);
     119    void loadModuleScriptInWorld(CachedModuleScript&, const ScriptSourceCode&, CachedScriptFetcher&, DOMWrapperWorld&);
     120    void loadModuleScript(CachedModuleScript&, const ScriptSourceCode&, CachedScriptFetcher&);
    121121
    122122    JSC::JSValue linkAndEvaluateModuleScriptInWorld(CachedModuleScript& , DOMWrapperWorld&);
  • trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp

    r210585 r210627  
    160160
    161161    if (auto* frame = m_document.frame()) {
    162         auto loader = CachedModuleScriptLoader::create(*this, deferred.get());
     162        auto loader = CachedModuleScriptLoader::create(*this, deferred.get(), *static_cast<CachedScriptFetcher*>(JSC::jsCast<JSC::JSScriptFetcher*>(scriptFetcher)->fetcher()));
    163163        m_loaders.add(loader.copyRef());
    164         if (!loader->load(m_document, *static_cast<LoadableScript*>(JSC::jsCast<JSC::JSScriptFetcher*>(scriptFetcher)->fetcher()), completedURL)) {
     164        if (!loader->load(m_document, completedURL)) {
    165165            loader->clearClient();
    166166            m_loaders.remove(WTFMove(loader));
     
    244244
    245245    m_requestURLToResponseURLMap.add(cachedScript.url(), cachedScript.response().url());
    246     ScriptSourceCode scriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module);
     246    ScriptSourceCode scriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module, loader.scriptFetcher());
    247247    promise->resolveWithCallback([] (JSC::ExecState& state, JSDOMGlobalObject&, JSC::SourceCode sourceCode) {
    248248        return JSC::JSSourceCode::create(state.vm(), WTFMove(sourceCode));
  • trunk/Source/WebCore/bindings/js/ScriptSourceCode.h

    r210149 r210627  
    3333#include "CachedResourceHandle.h"
    3434#include "CachedScript.h"
     35#include "CachedScriptFetcher.h"
    3536#include "CachedScriptSourceProvider.h"
    3637#include "URL.h"
     
    5051    }
    5152
    52     explicit ScriptSourceCode(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType)
    53         : m_provider(CachedScriptSourceProvider::create(cachedScript, sourceType))
     53    ScriptSourceCode(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher)
     54        : m_provider(CachedScriptSourceProvider::create(cachedScript, sourceType, WTFMove(scriptFetcher)))
    5455        , m_code(m_provider)
    5556        , m_cachedScript(cachedScript)
     57    {
     58    }
     59
     60    ScriptSourceCode(const String& source, const URL& url, const TextPosition& startPosition, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher)
     61        : m_provider(JSC::StringSourceProvider::create(source, JSC::SourceOrigin { url.string(), WTFMove(scriptFetcher) }, url.string(), startPosition, sourceType))
     62        , m_code(m_provider, startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt())
     63        , m_url(url)
    5664    {
    5765    }
  • trunk/Source/WebCore/dom/LoadableClassicScript.cpp

    r210585 r210627  
    105105{
    106106    ASSERT(!error());
    107     scriptElement.executeClassicScript(ScriptSourceCode(m_cachedScript.get(), JSC::SourceProviderSourceType::Program));
     107    scriptElement.executeClassicScript(ScriptSourceCode(m_cachedScript.get(), JSC::SourceProviderSourceType::Program, *this));
    108108}
    109109
  • trunk/Source/WebCore/dom/LoadableScript.cpp

    r210585 r210627  
    6161}
    6262
    63 CachedResourceHandle<CachedScript> LoadableScript::requestScriptWithCache(Document& document, const URL& sourceURL) const
    64 {
    65     auto* settings = document.settings();
    66     if (settings && !settings->isScriptEnabled())
    67         return nullptr;
    68 
    69     ASSERT(document.contentSecurityPolicy());
    70     bool hasKnownNonce = document.contentSecurityPolicy()->allowScriptWithNonce(m_nonce, m_isInUserAgentShadowTree);
    71     ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
    72     options.contentSecurityPolicyImposition = hasKnownNonce ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
    73 
    74     CachedResourceRequest request(ResourceRequest(sourceURL), options);
    75     request.setAsPotentiallyCrossOrigin(m_crossOriginMode, document);
    76     request.upgradeInsecureRequestIfNeeded(document);
    77 
    78     request.setCharset(m_charset);
    79     request.setInitiator(m_initiatorName);
    80 
    81     return document.cachedResourceLoader().requestScript(WTFMove(request));
    8263}
    83 
    84 }
  • trunk/Source/WebCore/dom/LoadableScript.h

    r210585 r210627  
    2626#pragma once
    2727
    28 #include "CachedResourceHandle.h"
     28#include "CachedScriptFetcher.h"
    2929#include <runtime/ConsoleTypes.h>
    30 #include <runtime/JSScriptFetcher.h>
    3130#include <wtf/HashCountedSet.h>
    3231#include <wtf/RefCounted.h>
     
    3534namespace WebCore {
    3635
    37 class CachedScript;
    38 class Document;
    3936class LoadableScriptClient;
    4037class ScriptElement;
    41 class URL;
    4238
    43 class LoadableScript : public JSC::ScriptFetcher {
     39class LoadableScript : public CachedScriptFetcher {
    4440public:
    4541    enum class ErrorType {
     
    7470    virtual bool isModuleScript() const { return false; }
    7571
    76     CachedResourceHandle<CachedScript> requestScriptWithCache(Document&, const URL& sourceURL) const;
    77 
    7872protected:
    7973    LoadableScript(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
    80         : m_nonce(nonce)
    81         , m_crossOriginMode(crossOriginMode)
    82         , m_charset(charset)
    83         , m_initiatorName(initiatorName)
    84         , m_isInUserAgentShadowTree(isInUserAgentShadowTree)
     74        : CachedScriptFetcher(nonce, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
    8575    {
    8676    }
     
    8979
    9080private:
    91     String m_nonce;
    92     String m_crossOriginMode;
    93     String m_charset;
    94     AtomicString m_initiatorName;
    95     bool m_isInUserAgentShadowTree { false };
    96 
    9781    HashCountedSet<LoadableScriptClient*> m_clients;
    9882};
  • trunk/Source/WebCore/dom/ScriptElement.cpp

    r210585 r210627  
    3939#include "HTMLParserIdioms.h"
    4040#include "IgnoreDestructiveWriteCountIncrementer.h"
     41#include "InlineClassicScript.h"
    4142#include "LoadableClassicScript.h"
    4243#include "LoadableModuleScript.h"
     
    276277        ASSERT(scriptType == ScriptType::Classic);
    277278        TextPosition position = document.isInDocumentWrite() ? TextPosition() : scriptStartPosition;
    278         executeClassicScript(ScriptSourceCode(scriptContent(), document.url(), position, JSC::SourceProviderSourceType::Program));
     279        executeClassicScript(ScriptSourceCode(scriptContent(), document.url(), position, JSC::SourceProviderSourceType::Program, InlineClassicScript::create(*this)));
    279280    }
    280281
     
    349350    }
    350351
     352    auto script = LoadableModuleScript::create(nonce, crossOriginMode, scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
     353
    351354    TextPosition position = m_element.document().isInDocumentWrite() ? TextPosition() : scriptStartPosition;
    352     ScriptSourceCode sourceCode(scriptContent(), m_element.document().url(), position, JSC::SourceProviderSourceType::Module);
     355    ScriptSourceCode sourceCode(scriptContent(), m_element.document().url(), position, JSC::SourceProviderSourceType::Module, script.copyRef());
    353356
    354357    ASSERT(m_element.document().contentSecurityPolicy());
     
    358361        return false;
    359362
    360     auto script = LoadableModuleScript::create(nonce, crossOriginMode, scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
    361363    script->load(m_element.document(), sourceCode);
    362364    m_loadableScript = WTFMove(script);
     
    427429        ASSERT(!pendingScript.error());
    428430        ASSERT_WITH_MESSAGE(scriptType() == ScriptType::Classic, "Module script always have a loadableScript pointer.");
    429         executeClassicScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition(), JSC::SourceProviderSourceType::Program));
     431        executeClassicScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition(), JSC::SourceProviderSourceType::Program, InlineClassicScript::create(*this)));
    430432        dispatchLoadEvent();
    431433    }
  • trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp

    r210319 r210627  
    3636#include "HTMLScriptRunnerHost.h"
    3737#include "IgnoreDestructiveWriteCountIncrementer.h"
     38#include "InlineClassicScript.h"
    3839#include "Microtasks.h"
    3940#include "MutationObserver.h"
     
    259260            m_parserBlockingScript = PendingScript::create(scriptElement, scriptStartPosition);
    260261        else
    261             scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.element().textContent(), documentURLForScriptExecution(m_document), scriptStartPosition));
     262            scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.element().textContent(), documentURLForScriptExecution(m_document), scriptStartPosition, JSC::SourceProviderSourceType::Program, InlineClassicScript::create(scriptElement)));
    262263    } else
    263264        requestParsingBlockingScript(scriptElement);
  • trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp

    r210319 r210627  
    3939#include "HTMLHtmlElement.h"
    4040#include "HTMLTemplateElement.h"
     41#include "InlineClassicScript.h"
    4142#include "Page.h"
    4243#include "PendingScript.h"
     
    878879
    879880        if (scriptElement.readyToBeParserExecuted())
    880             scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.scriptContent(), document()->url(), m_scriptStartPosition));
     881            scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.scriptContent(), document()->url(), m_scriptStartPosition, JSC::SourceProviderSourceType::Program, InlineClassicScript::create(scriptElement)));
    881882        else if (scriptElement.willBeParserExecuted() && scriptElement.loadableScript()) {
    882883            m_pendingScript = PendingScript::create(scriptElement, *scriptElement.loadableScript());
Note: See TracChangeset for help on using the changeset viewer.