Title: [268868] trunk/Source/WebCore
Revision
268868
Author
[email protected]
Date
2020-10-22 09:23:07 -0700 (Thu, 22 Oct 2020)

Log Message

Turn ScriptExecutionContext::vm() into a pure virtual function
https://bugs.webkit.org/show_bug.cgi?id=218057

Reviewed by Geoffrey Garen.

Turn ScriptExecutionContext::vm() into a pure virtual function instead of using a
non-virtual function that does type-checking inside.

* dom/Document.cpp:
(WebCore::Document::vm):
* dom/Document.h:
* dom/EmptyScriptExecutionContext.h:
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::vm): Deleted.
* dom/ScriptExecutionContext.h:
* workers/WorkerOrWorkletGlobalScope.cpp:
(WebCore::WorkerOrWorkletGlobalScope::vm):
* workers/WorkerOrWorkletGlobalScope.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (268867 => 268868)


--- trunk/Source/WebCore/ChangeLog	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/ChangeLog	2020-10-22 16:23:07 UTC (rev 268868)
@@ -1,3 +1,24 @@
+2020-10-22  Chris Dumez  <[email protected]>
+
+        Turn ScriptExecutionContext::vm() into a pure virtual function
+        https://bugs.webkit.org/show_bug.cgi?id=218057
+
+        Reviewed by Geoffrey Garen.
+
+        Turn ScriptExecutionContext::vm() into a pure virtual function instead of using a
+        non-virtual function that does type-checking inside.
+
+        * dom/Document.cpp:
+        (WebCore::Document::vm):
+        * dom/Document.h:
+        * dom/EmptyScriptExecutionContext.h:
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::vm): Deleted.
+        * dom/ScriptExecutionContext.h:
+        * workers/WorkerOrWorkletGlobalScope.cpp:
+        (WebCore::WorkerOrWorkletGlobalScope::vm):
+        * workers/WorkerOrWorkletGlobalScope.h:
+
 2020-10-22  Aditya Keerthi  <[email protected]>
 
         [iOS] Prevent presentation of input peripherals when focusing form controls with a validation message

Modified: trunk/Source/WebCore/dom/Document.cpp (268867 => 268868)


--- trunk/Source/WebCore/dom/Document.cpp	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/dom/Document.cpp	2020-10-22 16:23:07 UTC (rev 268868)
@@ -8669,6 +8669,11 @@
     }
 }
 
+JSC::VM& Document::vm()
+{
+    return commonVM();
+}
+
 } // namespace WebCore
 
 #undef RELEASE_LOG_IF_ALLOWED

Modified: trunk/Source/WebCore/dom/Document.h (268867 => 268868)


--- trunk/Source/WebCore/dom/Document.h	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/dom/Document.h	2020-10-22 16:23:07 UTC (rev 268868)
@@ -1595,6 +1595,8 @@
     bool contains(const Node& node) const { return this == &node.treeScope() && node.isConnected(); }
     bool contains(const Node* node) const { return node && contains(*node); }
 
+    WEBCORE_EXPORT JSC::VM& vm() final;
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClassFlags = DefaultDocumentClass, unsigned constructionFlags = 0);

Modified: trunk/Source/WebCore/dom/EmptyScriptExecutionContext.h (268867 => 268868)


--- trunk/Source/WebCore/dom/EmptyScriptExecutionContext.h	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/dom/EmptyScriptExecutionContext.h	2020-10-22 16:23:07 UTC (rev 268868)
@@ -75,12 +75,15 @@
     bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) final { return false; }
 #endif
 
+    JSC::VM& vm() final { return m_vm; }
+
     using RefCounted::ref;
     using RefCounted::deref;
 
 private:
     EmptyScriptExecutionContext(JSC::VM& vm)
-        : m_origin(SecurityOrigin::createUnique())
+        : m_vm(vm)
+        , m_origin(SecurityOrigin::createUnique())
         , m_eventLoop(EmptyEventLoop::create(vm))
         , m_eventLoopTaskGroup(makeUnique<EventLoopTaskGroup>(m_eventLoop))
     {
@@ -112,6 +115,7 @@
         MicrotaskQueue m_queue;
     };
 
+    Ref<JSC::VM> m_vm;
     Ref<SecurityOrigin> m_origin;
     URL m_url;
     Ref<EmptyEventLoop> m_eventLoop;

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (268867 => 268868)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2020-10-22 16:23:07 UTC (rev 268868)
@@ -477,17 +477,6 @@
     return DOMTimer::defaultAlignmentInterval();
 }
 
-JSC::VM& ScriptExecutionContext::vm()
-{
-    if (is<Document>(*this))
-        return commonVM();
-    if (is<WorkerOrWorkletGlobalScope>(*this))
-        return downcast<WorkerOrWorkletGlobalScope>(*this).script()->vm();
-
-    RELEASE_ASSERT_NOT_REACHED();
-    return commonVM();
-}
-
 RejectedPromiseTracker& ScriptExecutionContext::ensureRejectedPromiseTrackerSlow()
 {
     // ScriptExecutionContext::vm() in Worker is only available after WorkerGlobalScope initialization is done.

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (268867 => 268868)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2020-10-22 16:23:07 UTC (rev 268868)
@@ -211,7 +211,7 @@
     void removeTimeout(int timeoutId) { m_timeouts.remove(timeoutId); }
     DOMTimer* findTimeout(int timeoutId) { return m_timeouts.get(timeoutId); }
 
-    WEBCORE_EXPORT JSC::VM& vm();
+    virtual JSC::VM& vm() = 0;
 
     void adjustMinimumDOMTimerInterval(Seconds oldMinimumTimerInterval);
     virtual Seconds minimumDOMTimerInterval() const;

Modified: trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp (268867 => 268868)


--- trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp	2020-10-22 16:23:07 UTC (rev 268868)
@@ -64,6 +64,11 @@
     m_script = nullptr;
 }
 
+JSC::VM& WorkerOrWorkletGlobalScope::vm()
+{
+    return script()->vm();
+}
+
 void WorkerOrWorkletGlobalScope::disableEval(const String& errorMessage)
 {
     m_script->disableEval(errorMessage);

Modified: trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.h (268867 => 268868)


--- trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.h	2020-10-22 16:01:40 UTC (rev 268867)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.h	2020-10-22 16:23:07 UTC (rev 268868)
@@ -47,6 +47,8 @@
     WorkerOrWorkletScriptController* script() const { return m_script.get(); }
     void clearScript();
 
+    JSC::VM& vm() final;
+
     unsigned long createUniqueIdentifier() { return m_uniqueIdentifier++; }
 
     // ScriptExecutionContext.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to