Cleanup: Make QueueTaskToEventLoopFunctionPtr take JSGlobalObject&
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2017 17:53:18 +0000 (17:53 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2017 17:53:18 +0000 (17:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172021

Reviewed by Mark Lam.

Source/JavaScriptCore:

Change the function alias for QueueTaskToEventLoopFunctionPtr to take JSGlobalObject&
instead of a const JSGlobalObject* as all implementations expect to be passed a non-
const, non-null JSGlobalObject object.

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::queueMicrotask):
* runtime/JSGlobalObject.h:
* runtime/VM.cpp:
(JSC::VM::queueMicrotask):
* runtime/VM.h: Remove JS_EXPORT_PRIVATE annotation from queueMicrotask() as
it is only called from JavaScriptCore code.

Source/WebCore:

* bindings/js/JSDOMGlobalObjectTask.cpp: Include header JSDOMGlobalObject.h.
(WebCore::JSGlobalObjectTask::JSGlobalObjectTask): Change type of first argument from JSDOMGlobalObject*
to JSDOMGlobalObject& and update code as necessary. Also, use C++11 brace initialization syntax
for member initializer list.
* bindings/js/JSDOMGlobalObjectTask.h: Remove header JSDOMGlobalObject.h and forward declare
JSDOMGlobalObject and JSC::Microtask.
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowMicrotaskCallback::create):
(WebCore::JSDOMWindowMicrotaskCallback::JSDOMWindowMicrotaskCallback): Change type of first argument
from JSDOMWindowBase* to JSDOMWindowBase& and update code as necessary. Also, use C++11 brace
initialization syntax for member initializer list.
(WebCore::JSDOMWindowBase::queueTaskToEventLoop):
* bindings/js/JSDOMWindowBase.h:
* bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
* bindings/js/JSWorkerGlobalScopeBase.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216768 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMGlobalObjectTask.cpp
Source/WebCore/bindings/js/JSDOMGlobalObjectTask.h
Source/WebCore/bindings/js/JSDOMWindowBase.cpp
Source/WebCore/bindings/js/JSDOMWindowBase.h
Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp
Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.h

index 11dc662..de36d2b 100644 (file)
@@ -1,3 +1,22 @@
+2017-05-12  Daniel Bates  <dabates@apple.com>
+
+        Cleanup: Make QueueTaskToEventLoopFunctionPtr take JSGlobalObject&
+        https://bugs.webkit.org/show_bug.cgi?id=172021
+
+        Reviewed by Mark Lam.
+
+        Change the function alias for QueueTaskToEventLoopFunctionPtr to take JSGlobalObject&
+        instead of a const JSGlobalObject* as all implementations expect to be passed a non-
+        const, non-null JSGlobalObject object.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::queueMicrotask):
+        * runtime/JSGlobalObject.h:
+        * runtime/VM.cpp:
+        (JSC::VM::queueMicrotask):
+        * runtime/VM.h: Remove JS_EXPORT_PRIVATE annotation from queueMicrotask() as
+        it is only called from JavaScriptCore code.
+
 2017-05-12  Michael Saboff  <msaboff@apple.com>
 
         [iOS] Use memory footprint to dynamically adjust behavior of allocators
index 57f4383..13b5c5b 100644 (file)
@@ -1431,11 +1431,11 @@ const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
 void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
 {
     if (globalObjectMethodTable()->queueTaskToEventLoop) {
-        globalObjectMethodTable()->queueTaskToEventLoop(this, WTFMove(task));
+        globalObjectMethodTable()->queueTaskToEventLoop(*this, WTFMove(task));
         return;
     }
 
-    vm().queueMicrotask(this, WTFMove(task));
+    vm().queueMicrotask(*this, WTFMove(task));
 }
 
 bool JSGlobalObject::hasDebugger() const
index b33d6d3..305120c 100644 (file)
@@ -177,7 +177,7 @@ struct GlobalObjectMethodTable {
     typedef RuntimeFlags (*JavaScriptRuntimeFlagsFunctionPtr)(const JSGlobalObject*);
     JavaScriptRuntimeFlagsFunctionPtr javaScriptRuntimeFlags;
 
-    typedef void (*QueueTaskToEventLoopFunctionPtr)(const JSGlobalObject*, Ref<Microtask>&&);
+    typedef void (*QueueTaskToEventLoopFunctionPtr)(JSGlobalObject&, Ref<Microtask>&&);
     QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop;
 
     typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr)(const JSGlobalObject*);
index c3fc541..27a2fcd 100644 (file)
@@ -865,9 +865,9 @@ void VM::dumpTypeProfilerData()
     typeProfiler()->dumpTypeProfilerData(*this);
 }
 
-void VM::queueMicrotask(JSGlobalObject* globalObject, Ref<Microtask>&& task)
+void VM::queueMicrotask(JSGlobalObject& globalObject, Ref<Microtask>&& task)
 {
-    m_microtaskQueue.append(std::make_unique<QueuedTask>(*this, globalObject, WTFMove(task)));
+    m_microtaskQueue.append(std::make_unique<QueuedTask>(*this, &globalObject, WTFMove(task)));
 }
 
 void VM::drainMicrotasks()
index 178a3e2..7a4511a 100644 (file)
@@ -653,7 +653,7 @@ public:
     bool enableControlFlowProfiler();
     bool disableControlFlowProfiler();
 
-    JS_EXPORT_PRIVATE void queueMicrotask(JSGlobalObject*, Ref<Microtask>&&);
+    void queueMicrotask(JSGlobalObject&, Ref<Microtask>&&);
     JS_EXPORT_PRIVATE void drainMicrotasks();
     void setGlobalConstRedeclarationShouldThrow(bool globalConstRedeclarationThrow) { m_globalConstRedeclarationShouldThrow = globalConstRedeclarationThrow; }
     ALWAYS_INLINE bool globalConstRedeclarationShouldThrow() const { return m_globalConstRedeclarationShouldThrow; }
index ce258ff..2c10838 100644 (file)
@@ -1,3 +1,27 @@
+2017-05-12  Daniel Bates  <dabates@apple.com>
+
+        Cleanup: Make QueueTaskToEventLoopFunctionPtr take JSGlobalObject&
+        https://bugs.webkit.org/show_bug.cgi?id=172021
+
+        Reviewed by Mark Lam.
+
+        * bindings/js/JSDOMGlobalObjectTask.cpp: Include header JSDOMGlobalObject.h.
+        (WebCore::JSGlobalObjectTask::JSGlobalObjectTask): Change type of first argument from JSDOMGlobalObject*
+        to JSDOMGlobalObject& and update code as necessary. Also, use C++11 brace initialization syntax
+        for member initializer list.
+        * bindings/js/JSDOMGlobalObjectTask.h: Remove header JSDOMGlobalObject.h and forward declare
+        JSDOMGlobalObject and JSC::Microtask.
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowMicrotaskCallback::create):
+        (WebCore::JSDOMWindowMicrotaskCallback::JSDOMWindowMicrotaskCallback): Change type of first argument
+        from JSDOMWindowBase* to JSDOMWindowBase& and update code as necessary. Also, use C++11 brace
+        initialization syntax for member initializer list.
+        (WebCore::JSDOMWindowBase::queueTaskToEventLoop):
+        * bindings/js/JSDOMWindowBase.h:
+        * bindings/js/JSWorkerGlobalScopeBase.cpp:
+        (WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
+        * bindings/js/JSWorkerGlobalScopeBase.h:
+
 2017-05-12  Jer Noble  <jer.noble@apple.com>
 
         [MediaStream] Streams while play while page is in background can get "stuck" when page is forgrounded.
index 5317780..46d6b32 100644 (file)
@@ -27,6 +27,7 @@
 #include "JSDOMGlobalObjectTask.h"
 
 #include "ActiveDOMCallback.h"
+#include "JSDOMGlobalObject.h"
 #include "JSMainThreadExecState.h"
 #include <heap/StrongInlines.h>
 #include <runtime/Microtask.h>
@@ -38,7 +39,7 @@ namespace WebCore {
 
 class JSGlobalObjectCallback final : public RefCounted<JSGlobalObjectCallback>, private ActiveDOMCallback {
 public:
-    static Ref<JSGlobalObjectCallback> create(JSDOMGlobalObject* globalObject, Ref<Microtask>&& task)
+    static Ref<JSGlobalObjectCallback> create(JSDOMGlobalObject& globalObject, Ref<Microtask>&& task)
     {
         return adoptRef(*new JSGlobalObjectCallback(globalObject, WTFMove(task)));
     }
@@ -70,10 +71,10 @@ public:
     }
 
 private:
-    JSGlobalObjectCallback(JSDOMGlobalObject* globalObject, Ref<Microtask>&& task)
-        : ActiveDOMCallback(globalObject->scriptExecutionContext())
-        , m_globalObject(globalObject->vm(), globalObject)
-        , m_task(WTFMove(task))
+    JSGlobalObjectCallback(JSDOMGlobalObject& globalObject, Ref<Microtask>&& task)
+        : ActiveDOMCallback { globalObject.scriptExecutionContext() }
+        , m_globalObject { globalObject.vm(), &globalObject }
+        , m_task { WTFMove(task) }
     {
     }
 
@@ -81,7 +82,7 @@ private:
     Ref<Microtask> m_task;
 };
 
-JSGlobalObjectTask::JSGlobalObjectTask(JSDOMGlobalObject* globalObject, Ref<Microtask>&& task)
+JSGlobalObjectTask::JSGlobalObjectTask(JSDOMGlobalObject& globalObject, Ref<Microtask>&& task)
     : ScriptExecutionContext::Task({ })
 {
     RefPtr<JSGlobalObjectCallback> callback = JSGlobalObjectCallback::create(globalObject, WTFMove(task));
index cc0ffb0..4455ab1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #pragma once
 
-#include "JSDOMGlobalObject.h"
 #include "ScriptExecutionContext.h"
 
+namespace JSC {
+class Microtask;
+}
+
 namespace WebCore {
 
+class JSDOMGlobalObject;
+
 class JSGlobalObjectTask : public ScriptExecutionContext::Task {
 public:
-    JSGlobalObjectTask(JSDOMGlobalObject*, Ref<JSC::Microtask>&&);
+    JSGlobalObjectTask(JSDOMGlobalObject&, Ref<JSC::Microtask>&&);
 };
 
 } // namespace WebCore
index 9c48a8c..d12f05e 100644 (file)
@@ -200,7 +200,7 @@ RuntimeFlags JSDOMWindowBase::javaScriptRuntimeFlags(const JSGlobalObject* objec
 
 class JSDOMWindowMicrotaskCallback : public RefCounted<JSDOMWindowMicrotaskCallback> {
 public:
-    static Ref<JSDOMWindowMicrotaskCallback> create(JSDOMWindowBase* globalObject, Ref<JSC::Microtask>&& task)
+    static Ref<JSDOMWindowMicrotaskCallback> create(JSDOMWindowBase& globalObject, Ref<JSC::Microtask>&& task)
     {
         return adoptRef(*new JSDOMWindowMicrotaskCallback(globalObject, WTFMove(task)));
     }
@@ -220,9 +220,9 @@ public:
     }
 
 private:
-    JSDOMWindowMicrotaskCallback(JSDOMWindowBase* globalObject, Ref<JSC::Microtask>&& task)
-        : m_globalObject(globalObject->vm(), globalObject)
-        , m_task(WTFMove(task))
+    JSDOMWindowMicrotaskCallback(JSDOMWindowBase& globalObject, Ref<JSC::Microtask>&& task)
+        : m_globalObject { globalObject.vm(), &globalObject }
+        , m_task { WTFMove(task) }
     {
     }
 
@@ -230,12 +230,12 @@ private:
     Ref<JSC::Microtask> m_task;
 };
 
-void JSDOMWindowBase::queueTaskToEventLoop(const JSGlobalObject* object, Ref<JSC::Microtask>&& task)
+void JSDOMWindowBase::queueTaskToEventLoop(JSGlobalObject& object, Ref<JSC::Microtask>&& task)
 {
-    const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object);
+    JSDOMWindowBase& thisObject = static_cast<JSDOMWindowBase&>(object);
 
-    RefPtr<JSDOMWindowMicrotaskCallback> callback = JSDOMWindowMicrotaskCallback::create((JSDOMWindowBase*)thisObject, WTFMove(task));
-    auto microtask = std::make_unique<ActiveDOMCallbackMicrotask>(MicrotaskQueue::mainThreadQueue(), *thisObject->scriptExecutionContext(), [callback]() mutable {
+    RefPtr<JSDOMWindowMicrotaskCallback> callback = JSDOMWindowMicrotaskCallback::create(thisObject, WTFMove(task));
+    auto microtask = std::make_unique<ActiveDOMCallbackMicrotask>(MicrotaskQueue::mainThreadQueue(), *thisObject.scriptExecutionContext(), [callback]() mutable {
         callback->call();
     });
 
index 0256227..664fc53 100644 (file)
@@ -63,7 +63,7 @@ namespace WebCore {
         static bool shouldInterruptScript(const JSC::JSGlobalObject*);
         static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*);
         static JSC::RuntimeFlags javaScriptRuntimeFlags(const JSC::JSGlobalObject*);
-        static void queueTaskToEventLoop(const JSC::JSGlobalObject*, Ref<JSC::Microtask>&&);
+        static void queueTaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&);
         
         void printErrorMessage(const String&) const;
 
index eec4452..760905e 100644 (file)
@@ -114,10 +114,10 @@ RuntimeFlags JSWorkerGlobalScopeBase::javaScriptRuntimeFlags(const JSGlobalObjec
     return thisObject->m_wrapped->thread().runtimeFlags();
 }
 
-void JSWorkerGlobalScopeBase::queueTaskToEventLoop(const JSGlobalObject* object, Ref<JSC::Microtask>&& task)
+void JSWorkerGlobalScopeBase::queueTaskToEventLoop(JSGlobalObject& object, Ref<JSC::Microtask>&& task)
 {
-    const JSWorkerGlobalScopeBase* thisObject = static_cast<const JSWorkerGlobalScopeBase*>(object);
-    thisObject->scriptExecutionContext()->postTask(JSGlobalObjectTask((JSDOMGlobalObject*)thisObject, WTFMove(task)));
+    JSWorkerGlobalScopeBase& thisObject = static_cast<JSWorkerGlobalScopeBase&>(object);
+    thisObject.scriptExecutionContext()->postTask(JSGlobalObjectTask(thisObject, WTFMove(task)));
 }
 
 JSValue toJS(ExecState* exec, JSDOMGlobalObject*, WorkerGlobalScope& workerGlobalScope)
index b0b36f9..e63b174 100644 (file)
@@ -57,7 +57,7 @@ namespace WebCore {
         static bool shouldInterruptScript(const JSC::JSGlobalObject*);
         static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*);
         static JSC::RuntimeFlags javaScriptRuntimeFlags(const JSC::JSGlobalObject*);
-        static void queueTaskToEventLoop(const JSC::JSGlobalObject*, Ref<JSC::Microtask>&&);
+        static void queueTaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&);
 
     protected:
         JSWorkerGlobalScopeBase(JSC::VM&, JSC::Structure*, RefPtr<WorkerGlobalScope>&&);