Title: [264242] trunk
Revision
264242
Author
gga...@apple.com
Date
2020-07-10 15:00:33 -0700 (Fri, 10 Jul 2020)

Log Message

Source/_javascript_Core:
JSRunLoopTimer should use WTF::RunLoop rather than custom CF code
https://bugs.webkit.org/show_bug.cgi?id=214102

Reviewed by Darin Adler.

The generic RunLoop codepath was already mostly right. Just needed to
clarify the API to demonstrate that VMs do not hop from one RunLoop
to another.

* runtime/JSRunLoopTimer.cpp:
(JSC::epochTime): Removed the CF path.

(JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData): Include a RunLoop
as a constructor argument so that the web thread can override it.

(JSC::JSRunLoopTimer::Manager::timerDidFireCallback): Removed the CF path.

(JSC::JSRunLoopTimer::Manager::PerVMData::~PerVMData): No need to
explicitly clear our RunLoop -- the RunLoop::Timer destructor will do
the job.

(JSC::JSRunLoopTimer::Manager::timerDidFire):
(JSC::JSRunLoopTimer::Manager::registerVM):
(JSC::JSRunLoopTimer::Manager::scheduleTimer):
(JSC::JSRunLoopTimer::Manager::cancelTimer): Removed the CF path.

(JSC::JSRunLoopTimer::Manager::PerVMData::setRunLoop): Deleted.
(JSC::JSRunLoopTimer::Manager::didChangeRunLoop): Deleted. Changing
RunLoops is not actually a feature we use.

* runtime/JSRunLoopTimer.h:
(JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData): Deleted.
* runtime/PromiseTimer.cpp:
(JSC::PromiseTimer::doWork):
(JSC::PromiseTimer::runRunLoop): Removed the CF path.

* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::create):
(JSC::VM::setRunLoop): Deleted.
* runtime/VM.h:
(JSC::VM::runLoop const): Require a RunLoop in the VM constructor in
order to clarify that we always know our RunLoop and never change it.

Source/WebCore:
JSRunLoopTimer should use WTF::RunLoop rather than custom CF code
https://bugs.webkit.org/show_bug.cgi?id=214102

Reviewed by Darin Adler.

* bindings/js/CommonVM.cpp:
(WebCore::commonVMSlow): Supply a RunLoop at construction time since
JSC requires that now.

Tools:
Add some testing for JSRunLoopTimer
https://bugs.webkit.org/show_bug.cgi?id=214193

Reviewed by Darin Adler.

Add some test coverage to JSRunLoopTimer since I'm changing it.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm: Added.
(-[TestObject dealloc]):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (264241 => 264242)


--- trunk/Source/_javascript_Core/ChangeLog	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-07-10 22:00:33 UTC (rev 264242)
@@ -1,3 +1,49 @@
+2020-07-10  Geoffrey Garen  <gga...@apple.com>
+
+        JSRunLoopTimer should use WTF::RunLoop rather than custom CF code
+        https://bugs.webkit.org/show_bug.cgi?id=214102
+
+        Reviewed by Darin Adler.
+
+        The generic RunLoop codepath was already mostly right. Just needed to
+        clarify the API to demonstrate that VMs do not hop from one RunLoop
+        to another.
+
+        * runtime/JSRunLoopTimer.cpp:
+        (JSC::epochTime): Removed the CF path.
+
+        (JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData): Include a RunLoop
+        as a constructor argument so that the web thread can override it.
+
+        (JSC::JSRunLoopTimer::Manager::timerDidFireCallback): Removed the CF path.
+
+        (JSC::JSRunLoopTimer::Manager::PerVMData::~PerVMData): No need to
+        explicitly clear our RunLoop -- the RunLoop::Timer destructor will do
+        the job.
+
+        (JSC::JSRunLoopTimer::Manager::timerDidFire):
+        (JSC::JSRunLoopTimer::Manager::registerVM):
+        (JSC::JSRunLoopTimer::Manager::scheduleTimer):
+        (JSC::JSRunLoopTimer::Manager::cancelTimer): Removed the CF path.
+
+        (JSC::JSRunLoopTimer::Manager::PerVMData::setRunLoop): Deleted.
+        (JSC::JSRunLoopTimer::Manager::didChangeRunLoop): Deleted. Changing
+        RunLoops is not actually a feature we use.
+
+        * runtime/JSRunLoopTimer.h:
+        (JSC::JSRunLoopTimer::Manager::PerVMData::PerVMData): Deleted.
+        * runtime/PromiseTimer.cpp:
+        (JSC::PromiseTimer::doWork):
+        (JSC::PromiseTimer::runRunLoop): Removed the CF path.
+
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        (JSC::VM::create):
+        (JSC::VM::setRunLoop): Deleted.
+        * runtime/VM.h:
+        (JSC::VM::runLoop const): Require a RunLoop in the VM constructor in
+        order to clarify that we always know our RunLoop and never change it.
+
 2020-07-09  Brian Burg  <bb...@apple.com>
 
         REGRESSION(r262302): ITMLKit debuggables in listings are missing a title, use UUID instead

Modified: trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp (264241 => 264242)


--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp	2020-07-10 22:00:33 UTC (rev 264242)
@@ -40,47 +40,13 @@
 
 static inline JSRunLoopTimer::Manager::EpochTime epochTime(Seconds delay)
 {
-#if USE(CF)
-    return Seconds { CFAbsoluteTimeGetCurrent() + delay.value() };
-#else
     return MonotonicTime::now().secondsSinceEpoch() + delay;
-#endif
 }
 
-#if USE(CF)
-void JSRunLoopTimer::Manager::timerDidFireCallback(CFRunLoopTimerRef, void* contextPtr)
+JSRunLoopTimer::Manager::PerVMData::PerVMData(Manager& manager, RunLoop& runLoop)
+    : runLoop(runLoop)
+    , timer(makeUnique<RunLoop::Timer<Manager>>(runLoop, &manager, &JSRunLoopTimer::Manager::timerDidFireCallback))
 {
-    static_cast<JSRunLoopTimer::Manager*>(contextPtr)->timerDidFire();
-}
-
-void JSRunLoopTimer::Manager::PerVMData::setRunLoop(Manager* manager, CFRunLoopRef newRunLoop)
-{
-    if (runLoop) {
-        CFRunLoopRemoveTimer(runLoop.get(), timer.get(), kCFRunLoopCommonModes);
-        CFRunLoopTimerInvalidate(timer.get());
-        runLoop.clear();
-        timer.clear();
-    }
-
-    if (newRunLoop) {
-        runLoop = newRunLoop;
-        memset(&context, 0, sizeof(CFRunLoopTimerContext));
-        RELEASE_ASSERT(manager);
-        context.info = manager;
-        timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade.seconds(), CFAbsoluteTimeGetCurrent() + s_decade.seconds(), 0, 0, JSRunLoopTimer::Manager::timerDidFireCallback, &context));
-        CFRunLoopAddTimer(runLoop.get(), timer.get(), kCFRunLoopCommonModes);
-
-        EpochTime scheduleTime = epochTime(s_decade);
-        for (auto& pair : timers)
-            scheduleTime = std::min(pair.second, scheduleTime);
-        CFRunLoopTimerSetNextFireDate(timer.get(), scheduleTime.value());
-    }
-}
-#else
-JSRunLoopTimer::Manager::PerVMData::PerVMData(Manager& manager)
-    : runLoop(&RunLoop::current())
-    , timer(makeUnique<RunLoop::Timer<Manager>>(*runLoop, &manager, &JSRunLoopTimer::Manager::timerDidFireCallback))
-{
 #if USE(GLIB_EVENT_LOOP)
     timer->setPriority(RunLoopSourcePriority::_javascript_Timer);
     timer->setName("[_javascript_Core] JSRunLoopTimer");
@@ -91,13 +57,9 @@
 {
     timerDidFire();
 }
-#endif
 
 JSRunLoopTimer::Manager::PerVMData::~PerVMData()
 {
-#if USE(CF)
-    setRunLoop(nullptr, nullptr);
-#endif
 }
 
 void JSRunLoopTimer::Manager::timerDidFire()
@@ -106,21 +68,12 @@
 
     {
         auto locker = holdLock(m_lock);
-#if USE(CF)
-        CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
-#else
         RunLoop* currentRunLoop = &RunLoop::current();
-#endif
         EpochTime nowEpochTime = epochTime(0_s);
         for (auto& entry : m_mapping) {
             PerVMData& data = ""
-#if USE(CF)
-            if (data.runLoop.get() != currentRunLoop)
+            if (data.runLoop.ptr() != currentRunLoop)
                 continue;
-#else
-            if (data.runLoop != currentRunLoop)
-                continue;
-#endif
             
             EpochTime scheduleTime = epochTime(s_decade);
             for (size_t i = 0; i < data.timers.size(); ++i) {
@@ -140,11 +93,7 @@
                 timersToFire.append(WTFMove(pair.first));
             }
 
-#if USE(CF)
-            CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
-#else
             data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
-#endif
         }
     }
 
@@ -164,10 +113,7 @@
 
 void JSRunLoopTimer::Manager::registerVM(VM& vm)
 {
-    auto data = ""
-#if USE(CF)
-    data->setRunLoop(this, vm.runLoop());
-#endif
+    auto data = "" vm.runLoop());
 
     auto locker = holdLock(m_lock);
     auto addResult = m_mapping.add({ vm.apiLock() }, WTFMove(data));
@@ -205,11 +151,7 @@
     if (!found)
         data.timers.append({ timer, fireEpochTime });
 
-#if USE(CF)
-    CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
-#else
     data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
-#endif
 }
 
 void JSRunLoopTimer::Manager::cancelTimer(JSRunLoopTimer& timer)
@@ -240,11 +182,7 @@
         scheduleTime = std::min(scheduleTime, data.timers[i].second);
     }
 
-#if USE(CF)
-    CFRunLoopTimerSetNextFireDate(data.timer.get(), scheduleTime.value());
-#else
     data.timer->startOneShot(std::max(0_s, scheduleTime - MonotonicTime::now().secondsSinceEpoch()));
-#endif
 }
 
 Optional<Seconds> JSRunLoopTimer::Manager::timeUntilFire(JSRunLoopTimer& timer)
@@ -264,18 +202,6 @@
     return WTF::nullopt;
 }
 
-#if USE(CF)
-void JSRunLoopTimer::Manager::didChangeRunLoop(VM& vm, CFRunLoopRef newRunLoop)
-{
-    auto locker = holdLock(m_lock);
-    auto iter = m_mapping.find({ vm.apiLock() });
-    RELEASE_ASSERT(iter != m_mapping.end());
-
-    PerVMData& data = ""
-    data.setRunLoop(this, newRunLoop);
-}
-#endif
-
 void JSRunLoopTimer::timerDidFire()
 {
     NO_TAIL_CALLS();

Modified: trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h (264241 => 264242)


--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h	2020-07-10 22:00:33 UTC (rev 264242)
@@ -33,10 +33,6 @@
 #include <wtf/SharedTask.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
-#if USE(CF)
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
 namespace JSC {
 
 class JSLock;
@@ -50,11 +46,8 @@
     class Manager {
         WTF_MAKE_FAST_ALLOCATED;
         WTF_MAKE_NONCOPYABLE(Manager);
-#if USE(CF)
-        static void timerDidFireCallback(CFRunLoopTimerRef, void*);
-#else
         void timerDidFireCallback();
-#endif
+
         Manager() = default;
 
         void timerDidFire();
@@ -70,10 +63,6 @@
 
         Optional<Seconds> timeUntilFire(JSRunLoopTimer&);
 
-#if USE(CF)
-        void didChangeRunLoop(VM&, CFRunLoopRef newRunLoop);
-#endif
-
     private:
         Lock m_lock;
 
@@ -81,22 +70,11 @@
             WTF_MAKE_FAST_ALLOCATED;
             WTF_MAKE_NONCOPYABLE(PerVMData);
         public:
-#if USE(CF)
-            PerVMData(Manager&) { }
-#else
-            PerVMData(Manager&);
-#endif
+            PerVMData(Manager&, WTF::RunLoop&);
             ~PerVMData();
 
-#if USE(CF)
-            void setRunLoop(Manager*, CFRunLoopRef);
-            RetainPtr<CFRunLoopTimerRef> timer;
-            RetainPtr<CFRunLoopRef> runLoop;
-            CFRunLoopTimerContext context;
-#else
-            RunLoop* runLoop;
+            Ref<WTF::RunLoop> runLoop;
             std::unique_ptr<RunLoop::Timer<Manager>> timer;
-#endif
             Vector<std::pair<Ref<JSRunLoopTimer>, EpochTime>> timers;
         };
 

Modified: trunk/Source/_javascript_Core/runtime/PromiseTimer.cpp (264241 => 264242)


--- trunk/Source/_javascript_Core/runtime/PromiseTimer.cpp	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/_javascript_Core/runtime/PromiseTimer.cpp	2020-07-10 22:00:33 UTC (rev 264242)
@@ -70,13 +70,8 @@
         }
     }
 
-    if (m_pendingPromises.isEmpty() && m_shouldStopRunLoopWhenAllPromisesFinish) {
-#if USE(CF)
-        CFRunLoopStop(vm.runLoop());
-#else
+    if (m_pendingPromises.isEmpty() && m_shouldStopRunLoopWhenAllPromisesFinish)
         RunLoop::current().stop();
-#endif
-    }
 
     m_taskLock.unlock();
 }
@@ -84,17 +79,10 @@
 void PromiseTimer::runRunLoop()
 {
     ASSERT(!m_apiLock->vm()->currentThreadIsHoldingAPILock());
-#if USE(CF)
-    ASSERT(CFRunLoopGetCurrent() == m_apiLock->vm()->runLoop());
-#endif
+    ASSERT(&RunLoop::current() == &m_apiLock->vm()->runLoop());
     m_shouldStopRunLoopWhenAllPromisesFinish = true;
-    if (m_pendingPromises.size()) {
-#if USE(CF)
-        CFRunLoopRun();
-#else
+    if (m_pendingPromises.size())
         RunLoop::run();
-#endif
-    }
 }
 
 void PromiseTimer::addPendingPromise(VM& vm, JSPromise* ticket, Vector<Strong<JSCell>>&& dependencies)

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (264241 => 264242)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2020-07-10 22:00:33 UTC (rev 264242)
@@ -262,12 +262,10 @@
 
 static bool vmCreationShouldCrash = false;
 
-VM::VM(VMType vmType, HeapType heapType)
+VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop)
     : m_id(nextID())
     , m_apiLock(adoptRef(new JSLock(this)))
-#if USE(CF)
-    , m_runLoop(CFRunLoopGetCurrent())
-#endif // USE(CF)
+    , m_runLoop(runLoop ? *runLoop : WTF::RunLoop::current())
     , m_random(Options::seedOfVMRandomForFuzzer() ? Options::seedOfVMRandomForFuzzer() : cryptographicallyRandomNumber())
     , m_integrityRandom(*this)
     , heap(*this, heapType)
@@ -671,9 +669,9 @@
     return adoptRef(*new VM(APIContextGroup, heapType));
 }
 
-Ref<VM> VM::create(HeapType heapType)
+Ref<VM> VM::create(HeapType heapType, WTF::RunLoop* runLoop)
 {
-    return adoptRef(*new VM(Default, heapType));
+    return adoptRef(*new VM(Default, heapType, runLoop));
 }
 
 bool VM::sharedInstanceExists()
@@ -1355,15 +1353,6 @@
 }
 #endif
 
-#if USE(CF)
-void VM::setRunLoop(CFRunLoopRef runLoop)
-{
-    ASSERT(runLoop);
-    m_runLoop = runLoop;
-    JSRunLoopTimer::Manager::shared().didChangeRunLoop(*this, runLoop);
-}
-#endif // USE(CF)
-
 ScratchBuffer* VM::scratchBufferForSize(size_t size)
 {
     if (!size)

Modified: trunk/Source/_javascript_Core/runtime/VM.h (264241 => 264242)


--- trunk/Source/_javascript_Core/runtime/VM.h	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2020-07-10 22:00:33 UTC (rev 264242)
@@ -94,6 +94,7 @@
 #endif
 
 namespace WTF {
+class RunLoop;
 class SimpleStats;
 } // namespace WTF
 using WTF::SimpleStats;
@@ -312,7 +313,7 @@
     JS_EXPORT_PRIVATE static bool sharedInstanceExists();
     JS_EXPORT_PRIVATE static VM& sharedInstance();
 
-    JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap);
+    JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap, WTF::RunLoop* = nullptr);
     static Ref<VM> createContextGroup(HeapType = SmallHeap);
     JS_EXPORT_PRIVATE ~VM();
 
@@ -353,10 +354,7 @@
 
     unsigned m_id;
     RefPtr<JSLock> m_apiLock;
-#if USE(CF)
-    // These need to be initialized before heap below.
-    RetainPtr<CFRunLoopRef> m_runLoop;
-#endif
+    Ref<WTF::RunLoop> m_runLoop;
 
     WeakRandom m_random;
     Integrity::Random m_integrityRandom;
@@ -1079,10 +1077,7 @@
     bool needExceptionCheck() const { return m_needExceptionCheck; }
 #endif
 
-#if USE(CF)
-    CFRunLoopRef runLoop() const { return m_runLoop.get(); }
-    JS_EXPORT_PRIVATE void setRunLoop(CFRunLoopRef);
-#endif // USE(CF)
+    WTF::RunLoop& runLoop() const { return m_runLoop; }
 
     static void setCrashOnVMCreation(bool);
 
@@ -1106,7 +1101,7 @@
 private:
     friend class LLIntOffsetsExtractor;
 
-    VM(VMType, HeapType);
+    VM(VMType, HeapType, WTF::RunLoop* = nullptr);
     static VM*& sharedInstanceInternal();
     void createNativeThunk();
 

Modified: trunk/Source/WebCore/ChangeLog (264241 => 264242)


--- trunk/Source/WebCore/ChangeLog	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/WebCore/ChangeLog	2020-07-10 22:00:33 UTC (rev 264242)
@@ -1,3 +1,14 @@
+2020-07-10  Geoffrey Garen  <gga...@apple.com>
+
+        JSRunLoopTimer should use WTF::RunLoop rather than custom CF code
+        https://bugs.webkit.org/show_bug.cgi?id=214102
+
+        Reviewed by Darin Adler.
+
+        * bindings/js/CommonVM.cpp:
+        (WebCore::commonVMSlow): Supply a RunLoop at construction time since
+        JSC requires that now.
+
 2020-07-10  Guowei Yang  <guowei_y...@apple.com>
 
         Removing usage of "using namespace WebCore" from TextTrackRepresentationCocoa.mm

Modified: trunk/Source/WebCore/bindings/js/CommonVM.cpp (264241 => 264242)


--- trunk/Source/WebCore/bindings/js/CommonVM.cpp	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Source/WebCore/bindings/js/CommonVM.cpp	2020-07-10 22:00:33 UTC (rev 264242)
@@ -55,8 +55,14 @@
     // Also, initializeMainThread() does nothing on iOS.
     ScriptController::initializeMainThread();
 
-    auto& vm = JSC::VM::create(JSC::LargeHeap).leakRef();
+#if USE(WEB_THREAD)
+    RunLoop* runLoop = &RunLoop::web();
+#else
+    RunLoop* runLoop = nullptr;
+#endif
 
+    auto& vm = JSC::VM::create(JSC::LargeHeap, runLoop).leakRef();
+
     g_commonVMOrNull = &vm;
 
     vm.heap.acquireAccess(); // At any time, we may do things that affect the GC.
@@ -64,7 +70,6 @@
 #if PLATFORM(IOS_FAMILY)
     if (WebThreadIsEnabled())
         vm.apiLock().makeWebThreadAware();
-    vm.setRunLoop(WebThreadRunLoop());
     vm.heap.machineThreads().addCurrentThread();
 #endif
 

Modified: trunk/Tools/ChangeLog (264241 => 264242)


--- trunk/Tools/ChangeLog	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Tools/ChangeLog	2020-07-10 22:00:33 UTC (rev 264242)
@@ -1,3 +1,17 @@
+2020-07-10  Geoffrey Garen  <gga...@apple.com>
+
+        Add some testing for JSRunLoopTimer
+        https://bugs.webkit.org/show_bug.cgi?id=214193
+
+        Reviewed by Darin Adler.
+
+        Add some test coverage to JSRunLoopTimer since I'm changing it.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm: Added.
+        (-[TestObject dealloc]):
+        (TestWebKitAPI::TEST):
+
 2020-07-10  Aakash Jain  <aakash_j...@apple.com>
 
         [EWS] layout-test results shouldn't be hosted on ews server

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (264241 => 264242)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-10 21:57:57 UTC (rev 264241)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-10 22:00:33 UTC (rev 264242)
@@ -87,6 +87,7 @@
 		11B7FD28219F47110069B27F /* FirstMeaningfulPaintMilestone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 11B7FD22219F46DD0069B27F /* FirstMeaningfulPaintMilestone.cpp */; };
 		11C2598D21FA6324004C9E23 /* async-script-load.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 11C2598C21FA618D004C9E23 /* async-script-load.html */; };
 		143DDE9820C9018B007F76FA /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 574F55D0204D471C002948C6 /* Security.framework */; };
+		14CC42E624B8D8FA00E64F48 /* JSRunLoopTimer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 14CC42E524B8D8FA00E64F48 /* JSRunLoopTimer.mm */; };
 		1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
 		1A3524AE1D63A4FB0031729B /* Scope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3524AC1D63A4FB0031729B /* Scope.cpp */; };
 		1A4F81CF1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A4F81CD1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm */; };
@@ -1689,6 +1690,7 @@
 		11C2598C21FA618D004C9E23 /* async-script-load.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "async-script-load.html"; sourceTree = "<group>"; };
 		14464012167A8305000BD218 /* LayoutUnitTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutUnitTests.cpp; sourceTree = "<group>"; };
 		144D40EC221B46A7004B474F /* UUID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UUID.cpp; sourceTree = "<group>"; };
+		14CC42E524B8D8FA00E64F48 /* JSRunLoopTimer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JSRunLoopTimer.mm; sourceTree = "<group>"; };
 		14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SaturatedArithmeticOperations.cpp; sourceTree = "<group>"; };
 		1A02C84B125D4A5E00E3F4BD /* find.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = find.html; sourceTree = "<group>"; };
 		1A02C84E125D4A8400E3F4BD /* Find.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Find.cpp; sourceTree = "<group>"; };
@@ -3052,6 +3054,14 @@
 			name = cocoa;
 			sourceTree = "<group>";
 		};
+		14CC42E024B8D7E700E64F48 /* _javascript_Core */ = {
+			isa = PBXGroup;
+			children = (
+				14CC42E524B8D8FA00E64F48 /* JSRunLoopTimer.mm */,
+			);
+			path = _javascript_Core;
+			sourceTree = "<group>";
+		};
 		1AB674ADFE9D54B511CA2CBB /* Products */ = {
 			isa = PBXGroup;
 			children = (
@@ -4264,6 +4274,7 @@
 			isa = PBXGroup;
 			children = (
 				7560917619259C59009EF06E /* ios */,
+				14CC42E024B8D7E700E64F48 /* _javascript_Core */,
 				C07E6CAD13FD67650038B22B /* mac */,
 				C08587F913FEC39B001EF4E5 /* TestWebKitAPI */,
 				440A1D3614A01000008A66F2 /* WebCore */,
@@ -5084,6 +5095,7 @@
 				51820A4D22F4EE7F00DF0A01 /* _javascript_URLNavigation.mm in Sources */,
 				5C0160C121A132460077FA32 /* JITEnabled.mm in Sources */,
 				E35FC7B222B82A7300F32F98 /* JSLockTakesWebThreadLock.mm in Sources */,
+				14CC42E624B8D8FA00E64F48 /* JSRunLoopTimer.mm in Sources */,
 				7CCE7EC41A411A7E00447C4C /* JSWrapperForNodeInWebFrame.mm in Sources */,
 				F45E15732112CE2900307E82 /* KeyboardInputTestsIOS.mm in Sources */,
 				278E3E1923CD842F005A6B80 /* KeyedCoding.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm (0 => 264242)


--- trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm	2020-07-10 22:00:33 UTC (rev 264242)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "WTFStringUtilities.h"
+#import <_javascript_Core/_javascript_Core.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/RunLoop.h>
+#import <wtf/URL.h>
+#import <wtf/Vector.h>
+#import <wtf/cocoa/NSURLExtras.h>
+#import <wtf/cocoa/VectorCocoa.h>
+#import <wtf/text/WTFString.h>
+
+static bool s_isRunningRunLoop;
+static bool s_done;
+static WTF::RunLoop* s_expectedRunLoop;
+
+@interface TestObject : NSObject
+- (void)dealloc;
+@end
+
+@implementation TestObject
+- (void)dealloc
+{
+    if (s_isRunningRunLoop) {
+        EXPECT_EQ(&RunLoop::current(), s_expectedRunLoop);
+        s_done = true;
+    }
+
+    [super dealloc];
+}
+@end
+
+namespace TestWebKitAPI {
+
+// _javascript_Core's behavior at the time of writing is that destructors
+// run asynchronously on the thread that allocated the VM, unless they run
+// synchronously during an API call on some other thread.
+
+TEST(_javascript_Core, IncrementalSweeperMainThread)
+{
+    auto context = adoptNS([JSContext new]);
+    s_expectedRunLoop = &RunLoop::current();
+
+    while (!s_done) {
+        @autoreleasepool {
+            for (size_t i = 0; i < 1000; ++i) {
+                auto object = adoptNS([TestObject new]);
+                auto jsObject = adoptNS([JSValue valueWithObject:object.get() inContext:context.get()]);
+            }
+            JSGarbageCollect([context.get() JSGlobalContextRef]);
+            
+            s_isRunningRunLoop = true;
+            RunLoop::current().cycle();
+            s_isRunningRunLoop = false;
+        }
+    }
+    EXPECT_TRUE(true);
+}
+
+TEST(_javascript_Core, IncrementalSweeperSecondaryThread)
+{
+    auto context = adoptNS([JSContext new]);
+    s_expectedRunLoop = &RunLoop::current();
+
+    while (!s_done) {
+        @autoreleasepool {
+            dispatch_sync(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+                @autoreleasepool {
+                    for (size_t i = 0; i < 1000; ++i) {
+                        auto object = adoptNS([TestObject new]);
+                        auto jsObject = adoptNS([JSValue valueWithObject:object.get() inContext:context.get()]);
+                    }
+                    JSGarbageCollect([context.get() JSGlobalContextRef]);
+
+                    s_isRunningRunLoop = true;
+                    RunLoop::current().cycle();
+                    s_isRunningRunLoop = false;
+                }
+            });
+
+            s_isRunningRunLoop = true;
+            RunLoop::current().cycle();
+            s_isRunningRunLoop = false;
+        }
+    }
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to