Title: [275845] trunk/Source
Revision
275845
Author
[email protected]
Date
2021-04-12 16:14:49 -0700 (Mon, 12 Apr 2021)

Log Message

Modernize uses of ConsoleClient
https://bugs.webkit.org/show_bug.cgi?id=224398

Reviewed by David Kilzer.

ConsoleClient acts like a delegate, so its callers
should be using weak references to it.

Source/_javascript_Core:

* inspector/JSGlobalObjectInspectorController.cpp:
(Inspector::JSGlobalObjectInspectorController::consoleClient const):
* inspector/JSGlobalObjectInspectorController.h:
* runtime/ConsoleClient.h:
* runtime/ConsoleObject.cpp:
(JSC::consoleLogWithLevel):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::setConsoleClient):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::consoleClient const):
(JSC::JSGlobalObject::setConsoleClient): Deleted.

Source/WebCore:

* bindings/js/ScriptCachedFrameData.cpp:
(WebCore::ScriptCachedFrameData::restore):
* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::initScriptForWindowProxy):
* bindings/js/WindowProxy.cpp:
(WebCore::WindowProxy::setDOMWindow):
* workers/WorkerOrWorkletScriptController.cpp:
(WebCore::WorkerOrWorkletScriptController::initScriptWithSubclass):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (275844 => 275845)


--- trunk/Source/_javascript_Core/ChangeLog	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-04-12 23:14:49 UTC (rev 275845)
@@ -1,3 +1,27 @@
+2021-04-12  BJ Burg  <[email protected]>
+
+        Modernize uses of ConsoleClient
+        https://bugs.webkit.org/show_bug.cgi?id=224398
+
+        Reviewed by David Kilzer.
+
+        ConsoleClient acts like a delegate, so its callers
+        should be using weak references to it.
+
+        * inspector/JSGlobalObjectInspectorController.cpp:
+        (Inspector::JSGlobalObjectInspectorController::consoleClient const):
+        * inspector/JSGlobalObjectInspectorController.h:
+        * runtime/ConsoleClient.h:
+        * runtime/ConsoleObject.cpp:
+        (JSC::consoleLogWithLevel):
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        (JSC::JSGlobalObject::setConsoleClient):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::consoleClient const):
+        (JSC::JSGlobalObject::setConsoleClient): Deleted.
+
 2021-04-11  Yusuke Suzuki  <[email protected]>
 
         [JSC] Do not copy StringSwitchJumpTable

Modified: trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp (275844 => 275845)


--- trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp	2021-04-12 23:14:49 UTC (rev 275845)
@@ -198,9 +198,9 @@
     m_consoleAgent->addMessageToConsole(makeUnique<ConsoleMessage>(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, WTFMove(callStack)));
 }
 
-ConsoleClient* JSGlobalObjectInspectorController::consoleClient() const
+WeakPtr<ConsoleClient> JSGlobalObjectInspectorController::consoleClient() const
 {
-    return m_consoleClient.get();
+    return makeWeakPtr(m_consoleClient.get());
 }
 
 bool JSGlobalObjectInspectorController::developerExtrasEnabled() const

Modified: trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.h (275844 => 275845)


--- trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.h	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.h	2021-04-12 23:14:49 UTC (rev 275845)
@@ -81,7 +81,7 @@
 
     void reportAPIException(JSC::JSGlobalObject*, JSC::Exception*);
 
-    JSC::ConsoleClient* consoleClient() const;
+    WeakPtr<JSC::ConsoleClient> consoleClient() const;
 
     bool developerExtrasEnabled() const final;
     bool canAccessInspectedScriptState(JSC::JSGlobalObject*) const final { return true; }

Modified: trunk/Source/_javascript_Core/runtime/ConsoleClient.h (275844 => 275845)


--- trunk/Source/_javascript_Core/runtime/ConsoleClient.h	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/_javascript_Core/runtime/ConsoleClient.h	2021-04-12 23:14:49 UTC (rev 275845)
@@ -27,6 +27,7 @@
 
 #include "ConsoleTypes.h"
 #include <wtf/Forward.h>
+#include <wtf/WeakPtr.h>
 
 namespace Inspector {
 class ScriptArguments;
@@ -37,7 +38,7 @@
 class CallFrame;
 class JSGlobalObject;
 
-class ConsoleClient {
+class ConsoleClient : public CanMakeWeakPtr<ConsoleClient> {
 public:
     virtual ~ConsoleClient() { }
 

Modified: trunk/Source/_javascript_Core/runtime/ConsoleObject.cpp (275844 => 275845)


--- trunk/Source/_javascript_Core/runtime/ConsoleObject.cpp	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/_javascript_Core/runtime/ConsoleObject.cpp	2021-04-12 23:14:49 UTC (rev 275845)
@@ -129,7 +129,7 @@
 
 static EncodedJSValue consoleLogWithLevel(JSGlobalObject* globalObject, CallFrame* callFrame, MessageLevel level)
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -164,7 +164,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncClear, (JSGlobalObject* globalObject, CallFrame*))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -174,7 +174,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncDir, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -184,7 +184,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncDirXML, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -194,7 +194,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncTable, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -204,7 +204,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncTrace, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -216,7 +216,7 @@
 {
     VM& vm = globalObject->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -233,7 +233,7 @@
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncCount, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
-    auto* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -247,7 +247,7 @@
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncCountReset, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
-    auto* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -262,7 +262,7 @@
 {
     VM& vm = globalObject->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -283,7 +283,7 @@
 {
     VM& vm = globalObject->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -304,7 +304,7 @@
 {
     VM& vm = globalObject->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -324,7 +324,7 @@
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncTime, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
-    auto* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -338,7 +338,7 @@
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncTimeLog, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
-    auto* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -352,7 +352,7 @@
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncTimeEnd, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
-    auto* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -365,7 +365,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncTimeStamp, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -375,7 +375,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncGroup, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -385,7 +385,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncGroupCollapsed, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -395,7 +395,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncGroupEnd, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -405,7 +405,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncRecord, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -415,7 +415,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncRecordEnd, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 
@@ -425,7 +425,7 @@
 
 JSC_DEFINE_HOST_FUNCTION(consoleProtoFuncScreenshot, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
-    ConsoleClient* client = globalObject->consoleClient();
+    auto client = globalObject->consoleClient();
     if (!client)
         return JSValue::encode(jsUndefined());
 

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (275844 => 275845)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2021-04-12 23:14:49 UTC (rev 275845)
@@ -54,6 +54,7 @@
 #include "ClonedArguments.h"
 #include "CodeBlock.h"
 #include "CodeBlockSetInlines.h"
+#include "ConsoleClient.h"
 #include "ConsoleObject.h"
 #include "DateConstructor.h"
 #include "DatePrototype.h"
@@ -2362,6 +2363,11 @@
     dataLogLn("Uncaught Exception at run loop: ", exception->value());
 }
 
+void JSGlobalObject::setConsoleClient(WeakPtr<ConsoleClient>&& consoleClient)
+{
+    m_consoleClient = WTFMove(consoleClient);
+}
+
 void JSGlobalObject::setDebugger(Debugger* debugger)
 {
     m_debugger = debugger;

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.h (275844 => 275845)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2021-04-12 23:14:49 UTC (rev 275845)
@@ -51,6 +51,7 @@
 #include <wtf/FixedVector.h>
 #include <wtf/HashSet.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
 
 struct OpaqueJSClass;
 struct OpaqueJSClassContextData;
@@ -561,7 +562,7 @@
     String m_evalDisabledErrorMessage;
     String m_webAssemblyDisabledErrorMessage;
     RuntimeFlags m_runtimeFlags;
-    ConsoleClient* m_consoleClient { nullptr };
+    WeakPtr<ConsoleClient> m_consoleClient;
     Optional<unsigned> m_stackTraceLimit;
 
     template<typename T>
@@ -893,8 +894,8 @@
     static ptrdiff_t globalLexicalBindingEpochOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_globalLexicalBindingEpoch); }
     unsigned* addressOfGlobalLexicalBindingEpoch() { return &m_globalLexicalBindingEpoch; }
 
-    void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; }
-    ConsoleClient* consoleClient() const { return m_consoleClient; }
+    JS_EXPORT_PRIVATE void setConsoleClient(WeakPtr<ConsoleClient>&&);
+    WeakPtr<ConsoleClient> consoleClient() const { return m_consoleClient; }
 
     void setName(const String&);
     const String& name() const { return m_name; }

Modified: trunk/Source/WebCore/ChangeLog (275844 => 275845)


--- trunk/Source/WebCore/ChangeLog	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/WebCore/ChangeLog	2021-04-12 23:14:49 UTC (rev 275845)
@@ -1,3 +1,22 @@
+2021-04-12  BJ Burg  <[email protected]>
+
+        Modernize uses of ConsoleClient
+        https://bugs.webkit.org/show_bug.cgi?id=224398
+
+        Reviewed by David Kilzer.
+
+        ConsoleClient acts like a delegate, so its callers
+        should be using weak references to it.
+
+        * bindings/js/ScriptCachedFrameData.cpp:
+        (WebCore::ScriptCachedFrameData::restore):
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::initScriptForWindowProxy):
+        * bindings/js/WindowProxy.cpp:
+        (WebCore::WindowProxy::setDOMWindow):
+        * workers/WorkerOrWorkletScriptController.cpp:
+        (WebCore::WorkerOrWorkletScriptController::initScriptWithSubclass):
+
 2021-04-12  Chris Dumez  <[email protected]>
 
         webaudio/AudioListener/audiolistener-set-position.html is leaking PannerNodes

Modified: trunk/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp (275844 => 275845)


--- trunk/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp	2021-04-12 23:14:49 UTC (rev 275845)
@@ -91,7 +91,7 @@
         }
 
         if (page)
-            windowProxy->window()->setConsoleClient(&page->console());
+            windowProxy->window()->setConsoleClient(makeWeakPtr(page->console()));
     }
 }
 

Modified: trunk/Source/WebCore/bindings/js/ScriptController.cpp (275844 => 275845)


--- trunk/Source/WebCore/bindings/js/ScriptController.cpp	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/WebCore/bindings/js/ScriptController.cpp	2021-04-12 23:14:49 UTC (rev 275845)
@@ -276,7 +276,7 @@
     if (Page* page = m_frame.page()) {
         windowProxy.attachDebugger(page->debugger());
         windowProxy.window()->setProfileGroup(page->group().identifier());
-        windowProxy.window()->setConsoleClient(&page->console());
+        windowProxy.window()->setConsoleClient(makeWeakPtr(page->console()));
     }
 
     m_frame.loader().dispatchDidClearWindowObjectInWorld(world);

Modified: trunk/Source/WebCore/bindings/js/WindowProxy.cpp (275844 => 275845)


--- trunk/Source/WebCore/bindings/js/WindowProxy.cpp	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/WebCore/bindings/js/WindowProxy.cpp	2021-04-12 23:14:49 UTC (rev 275845)
@@ -188,7 +188,7 @@
         windowProxy->attachDebugger(page ? page->debugger() : nullptr);
         if (page)
             windowProxy->window()->setProfileGroup(page->group().identifier());
-        windowProxy->window()->setConsoleClient(page ? &page->console() : nullptr);
+        windowProxy->window()->setConsoleClient(page ? makeWeakPtr(page->console()) : nullptr);
     }
 }
 

Modified: trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp (275844 => 275845)


--- trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp	2021-04-12 23:12:21 UTC (rev 275844)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp	2021-04-12 23:14:49 UTC (rev 275845)
@@ -518,7 +518,7 @@
     ASSERT(asObject(m_globalScopeWrapper->getPrototypeDirect(*m_vm))->globalObject() == m_globalScopeWrapper);
 
     m_consoleClient = makeUnique<WorkerConsoleClient>(*m_globalScope);
-    m_globalScopeWrapper->setConsoleClient(m_consoleClient.get());
+    m_globalScopeWrapper->setConsoleClient(makeWeakPtr(*m_consoleClient));
 }
 
 void WorkerOrWorkletScriptController::initScript()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to