Title: [288900] trunk/Source/WebCore
Revision
288900
Author
[email protected]
Date
2022-02-01 11:12:52 -0800 (Tue, 01 Feb 2022)

Log Message

Use more AtomString and un-inline code for ScriptElementCachedScriptFetcher and its subclasses
https://bugs.webkit.org/show_bug.cgi?id=235919

Reviewed by Darin Adler.

Use more AtomString and moved code from header files to cpp files where appropriate.

* dom/InlineClassicScript.cpp:
(WebCore::InlineClassicScript::InlineClassicScript):
* dom/InlineClassicScript.h:
* dom/LoadableClassicScript.cpp:
(WebCore::LoadableClassicScript::create):
(WebCore::LoadableClassicScript::LoadableClassicScript):
* dom/LoadableClassicScript.h:
* dom/LoadableModuleScript.cpp:
(WebCore::LoadableModuleScript::create):
(WebCore::LoadableModuleScript::LoadableModuleScript):
* dom/LoadableModuleScript.h:
* dom/LoadableScript.h:
(WebCore::LoadableScript::LoadableScript):
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::ScriptElement): Call document() and scriptableDocumentParser() once. 
(WebCore::ScriptElement::requestClassicScript):
(WebCore::ScriptElement::requestModuleScript):
* dom/ScriptElementCachedScriptFetcher.h:
(WebCore::ScriptElementCachedScriptFetcher::ScriptElementCachedScriptFetcher):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288899 => 288900)


--- trunk/Source/WebCore/ChangeLog	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/ChangeLog	2022-02-01 19:12:52 UTC (rev 288900)
@@ -1,3 +1,32 @@
+2022-02-01  Ryosuke Niwa  <[email protected]>
+
+        Use more AtomString and un-inline code for ScriptElementCachedScriptFetcher and its subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=235919
+
+        Reviewed by Darin Adler.
+
+        Use more AtomString and moved code from header files to cpp files where appropriate.
+
+        * dom/InlineClassicScript.cpp:
+        (WebCore::InlineClassicScript::InlineClassicScript):
+        * dom/InlineClassicScript.h:
+        * dom/LoadableClassicScript.cpp:
+        (WebCore::LoadableClassicScript::create):
+        (WebCore::LoadableClassicScript::LoadableClassicScript):
+        * dom/LoadableClassicScript.h:
+        * dom/LoadableModuleScript.cpp:
+        (WebCore::LoadableModuleScript::create):
+        (WebCore::LoadableModuleScript::LoadableModuleScript):
+        * dom/LoadableModuleScript.h:
+        * dom/LoadableScript.h:
+        (WebCore::LoadableScript::LoadableScript):
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::ScriptElement): Call document() and scriptableDocumentParser() once. 
+        (WebCore::ScriptElement::requestClassicScript):
+        (WebCore::ScriptElement::requestModuleScript):
+        * dom/ScriptElementCachedScriptFetcher.h:
+        (WebCore::ScriptElementCachedScriptFetcher::ScriptElementCachedScriptFetcher):
+
 2022-02-01  Jer Noble  <[email protected]>
 
         [Cocoa] "index 0 out of bounds" exception in AVTrackPrivateAVFObjCImpl::videoTrackConfiguration()

Modified: trunk/Source/WebCore/dom/InlineClassicScript.cpp (288899 => 288900)


--- trunk/Source/WebCore/dom/InlineClassicScript.cpp	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/InlineClassicScript.cpp	2022-02-01 19:12:52 UTC (rev 288900)
@@ -43,4 +43,9 @@
         element.isInUserAgentShadowTree()));
 }
 
+InlineClassicScript::InlineClassicScript(const AtomString& nonce, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
+    : ScriptElementCachedScriptFetcher(nonce, ReferrerPolicy::EmptyString, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
+{
 }
+
+}

Modified: trunk/Source/WebCore/dom/InlineClassicScript.h (288899 => 288900)


--- trunk/Source/WebCore/dom/InlineClassicScript.h	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/InlineClassicScript.h	2022-02-01 19:12:52 UTC (rev 288900)
@@ -39,10 +39,7 @@
     bool isModuleScript() const final { return false; }
 
 private:
-    InlineClassicScript(const String& nonce, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
-        : ScriptElementCachedScriptFetcher(nonce, ReferrerPolicy::EmptyString, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
-    {
-    }
+    InlineClassicScript(const AtomString& nonce, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree);
 };
 
 }

Modified: trunk/Source/WebCore/dom/LoadableClassicScript.cpp (288899 => 288900)


--- trunk/Source/WebCore/dom/LoadableClassicScript.cpp	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/LoadableClassicScript.cpp	2022-02-01 19:12:52 UTC (rev 288900)
@@ -36,11 +36,18 @@
 
 namespace WebCore {
 
-Ref<LoadableClassicScript> LoadableClassicScript::create(const String& nonce, const String& integrityMetadata, ReferrerPolicy policy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree, bool isAsync)
+Ref<LoadableClassicScript> LoadableClassicScript::create(const AtomString& nonce, const AtomString& integrityMetadata, ReferrerPolicy policy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree, bool isAsync)
 {
     return adoptRef(*new LoadableClassicScript(nonce, integrityMetadata, policy, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree, isAsync));
 }
 
+LoadableClassicScript::LoadableClassicScript(const String& nonce, const AtomString& integrity, ReferrerPolicy policy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree, bool isAsync)
+    : LoadableScript(nonce, policy, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
+    , m_integrity(integrity)
+    , m_isAsync(isAsync)
+{
+}
+
 LoadableClassicScript::~LoadableClassicScript()
 {
     if (m_cachedScript)

Modified: trunk/Source/WebCore/dom/LoadableClassicScript.h (288899 => 288900)


--- trunk/Source/WebCore/dom/LoadableClassicScript.h	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/LoadableClassicScript.h	2022-02-01 19:12:52 UTC (rev 288900)
@@ -41,7 +41,7 @@
 public:
     virtual ~LoadableClassicScript();
 
-    static Ref<LoadableClassicScript> create(const String& nonce, const String& integrity, ReferrerPolicy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree, bool isAsync);
+    static Ref<LoadableClassicScript> create(const AtomString& nonce, const AtomString& integrity, ReferrerPolicy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree, bool isAsync);
     bool isLoaded() const final;
     std::optional<Error> error() const final;
     bool wasCanceled() const final;
@@ -56,18 +56,13 @@
     bool load(Document&, const URL&);
 
 private:
-    LoadableClassicScript(const String& nonce, const String& integrity, ReferrerPolicy policy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree, bool isAsync)
-        : LoadableScript(nonce, policy, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
-        , m_integrity(integrity)
-        , m_isAsync(isAsync)
-    {
-    }
+    LoadableClassicScript(const String& nonce, const AtomString& integrity, ReferrerPolicy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree, bool isAsync);
 
     void notifyFinished(CachedResource&, const NetworkLoadMetrics&) final;
 
     CachedResourceHandle<CachedScript> m_cachedScript { };
     std::optional<Error> m_error { std::nullopt };
-    String m_integrity;
+    const AtomString m_integrity;
     bool m_isAsync { false };
 };
 

Modified: trunk/Source/WebCore/dom/LoadableModuleScript.cpp (288899 => 288900)


--- trunk/Source/WebCore/dom/LoadableModuleScript.cpp	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/LoadableModuleScript.cpp	2022-02-01 19:12:52 UTC (rev 288900)
@@ -34,12 +34,12 @@
 
 namespace WebCore {
 
-Ref<LoadableModuleScript> LoadableModuleScript::create(const String& nonce, const String& integrity, ReferrerPolicy policy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
+Ref<LoadableModuleScript> LoadableModuleScript::create(const AtomString& nonce, const AtomString& integrity, ReferrerPolicy policy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
 {
     return adoptRef(*new LoadableModuleScript(nonce, integrity, policy, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree));
 }
 
-LoadableModuleScript::LoadableModuleScript(const String& nonce, const String& integrity, ReferrerPolicy policy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
+LoadableModuleScript::LoadableModuleScript(const AtomString& nonce, const AtomString& integrity, ReferrerPolicy policy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
     : LoadableScript(nonce, policy, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
     , m_parameters(ModuleFetchParameters::create(integrity, /* isTopLevelModule */ true))
 {

Modified: trunk/Source/WebCore/dom/LoadableModuleScript.h (288899 => 288900)


--- trunk/Source/WebCore/dom/LoadableModuleScript.h	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/LoadableModuleScript.h	2022-02-01 19:12:52 UTC (rev 288900)
@@ -37,7 +37,7 @@
 public:
     virtual ~LoadableModuleScript();
 
-    static Ref<LoadableModuleScript> create(const String& nonce, const String& integrity, ReferrerPolicy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree);
+    static Ref<LoadableModuleScript> create(const AtomString& nonce, const AtomString& integrity, ReferrerPolicy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree);
 
     bool isLoaded() const final;
     std::optional<Error> error() const final;
@@ -59,7 +59,7 @@
     ModuleFetchParameters& parameters() { return m_parameters.get(); }
 
 private:
-    LoadableModuleScript(const String& nonce, const String& integrity, ReferrerPolicy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree);
+    LoadableModuleScript(const AtomString& nonce, const AtomString& integrity, ReferrerPolicy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree);
 
     Ref<ModuleFetchParameters> m_parameters;
     RefPtr<UniquedStringImpl> m_moduleKey;

Modified: trunk/Source/WebCore/dom/LoadableScript.h (288899 => 288900)


--- trunk/Source/WebCore/dom/LoadableScript.h	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/LoadableScript.h	2022-02-01 19:12:52 UTC (rev 288900)
@@ -70,7 +70,7 @@
     void removeClient(LoadableScriptClient&);
 
 protected:
-    LoadableScript(const String& nonce, ReferrerPolicy policy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
+    LoadableScript(const AtomString& nonce, ReferrerPolicy policy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
         : ScriptElementCachedScriptFetcher(nonce, policy, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
     {
     }

Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (288899 => 288900)


--- trunk/Source/WebCore/dom/ScriptElement.cpp	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp	2022-02-01 19:12:52 UTC (rev 288900)
@@ -81,8 +81,11 @@
     , m_creationTime(MonotonicTime::now())
     , m_userGestureToken(UserGestureIndicator::currentUserGesture())
 {
-    if (parserInserted && m_element.document().scriptableDocumentParser() && !m_element.document().isInDocumentWrite())
-        m_startLineNumber = m_element.document().scriptableDocumentParser()->textPosition().m_line;
+    if (parserInserted) {
+        Ref document = m_element.document();
+        if (RefPtr parser = document->scriptableDocumentParser(); parser && !document->isInDocumentWrite())
+            m_startLineNumber = parser->textPosition().m_line;
+    }
 }
 
 void ScriptElement::didFinishInsertingNode()
@@ -288,15 +291,8 @@
     ASSERT(m_element.isConnected());
     ASSERT(!m_loadableScript);
     if (!stripLeadingAndTrailingHTMLSpaces(sourceURL).isEmpty()) {
-        auto script = LoadableClassicScript::create(
-            m_element.nonce(),
-            m_element.attributeWithoutSynchronization(HTMLNames::integrityAttr).string(),
-            referrerPolicy(),
-            m_element.attributeWithoutSynchronization(HTMLNames::crossoriginAttr),
-            scriptCharset(),
-            m_element.localName(),
-            m_element.isInUserAgentShadowTree(),
-            hasAsyncAttribute());
+        auto script = LoadableClassicScript::create(m_element.nonce(), m_element.attributeWithoutSynchronization(HTMLNames::integrityAttr), referrerPolicy(),
+            m_element.attributeWithoutSynchronization(HTMLNames::crossoriginAttr), scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree(), hasAsyncAttribute());
 
         auto scriptURL = m_element.document().completeURL(sourceURL);
         m_element.document().willLoadScriptElement(scriptURL);
@@ -345,14 +341,8 @@
         }
 
         m_isExternalScript = true;
-        auto script = LoadableModuleScript::create(
-            nonce,
-            m_element.attributeWithoutSynchronization(HTMLNames::integrityAttr).string(),
-            referrerPolicy(),
-            crossOriginMode,
-            scriptCharset(),
-            m_element.localName(),
-            m_element.isInUserAgentShadowTree());
+        auto script = LoadableModuleScript::create(nonce, m_element.attributeWithoutSynchronization(HTMLNames::integrityAttr), referrerPolicy(), crossOriginMode,
+            scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
         m_loadableScript = WTFMove(script);
         if (auto* frame = m_element.document().frame()) {
             auto& script = downcast<LoadableModuleScript>(*m_loadableScript.get());

Modified: trunk/Source/WebCore/dom/ScriptElementCachedScriptFetcher.h (288899 => 288900)


--- trunk/Source/WebCore/dom/ScriptElementCachedScriptFetcher.h	2022-02-01 19:11:38 UTC (rev 288899)
+++ trunk/Source/WebCore/dom/ScriptElementCachedScriptFetcher.h	2022-02-01 19:12:52 UTC (rev 288900)
@@ -41,7 +41,7 @@
     const String& crossOriginMode() const { return m_crossOriginMode; }
 
 protected:
-    ScriptElementCachedScriptFetcher(const String& nonce, ReferrerPolicy policy, const String& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
+    ScriptElementCachedScriptFetcher(const AtomString& nonce, ReferrerPolicy policy, const AtomString& crossOriginMode, const String& charset, const AtomString& initiatorName, bool isInUserAgentShadowTree)
         : CachedScriptFetcher(nonce, policy, charset, initiatorName, isInUserAgentShadowTree)
         , m_crossOriginMode(crossOriginMode)
     {
@@ -48,7 +48,7 @@
     }
 
 private:
-    String m_crossOriginMode;
+    const AtomString m_crossOriginMode;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to