Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (264261 => 264262)
--- trunk/Source/_javascript_Core/ChangeLog 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-07-11 04:35:03 UTC (rev 264262)
@@ -1,3 +1,16 @@
+2020-07-10 Chris Dumez <[email protected]>
+
+ Unreviewed, reverting r264242.
+
+ Caused many crashes on iOS bots
+
+ Reverted changeset:
+
+ "JSRunLoopTimer should use WTF::RunLoop rather than custom CF
+ code"
+ https://bugs.webkit.org/show_bug.cgi?id=214102
+ https://trac.webkit.org/changeset/264242
+
2020-07-10 Geoffrey Garen <[email protected]>
JSRunLoopTimer should use WTF::RunLoop rather than custom CF code
Modified: trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp (264261 => 264262)
--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.cpp 2020-07-11 04:35:03 UTC (rev 264262)
@@ -40,13 +40,47 @@
static inline JSRunLoopTimer::Manager::EpochTime epochTime(Seconds delay)
{
+#if USE(CF)
+ return Seconds { CFAbsoluteTimeGetCurrent() + delay.value() };
+#else
return MonotonicTime::now().secondsSinceEpoch() + delay;
+#endif
}
-JSRunLoopTimer::Manager::PerVMData::PerVMData(Manager& manager, RunLoop& runLoop)
- : runLoop(runLoop)
- , timer(makeUnique<RunLoop::Timer<Manager>>(runLoop, &manager, &JSRunLoopTimer::Manager::timerDidFireCallback))
+#if USE(CF)
+void JSRunLoopTimer::Manager::timerDidFireCallback(CFRunLoopTimerRef, void* contextPtr)
{
+ 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");
@@ -57,9 +91,13 @@
{
timerDidFire();
}
+#endif
JSRunLoopTimer::Manager::PerVMData::~PerVMData()
{
+#if USE(CF)
+ setRunLoop(nullptr, nullptr);
+#endif
}
void JSRunLoopTimer::Manager::timerDidFire()
@@ -68,12 +106,21 @@
{
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 (data.runLoop.ptr() != currentRunLoop)
+#if USE(CF)
+ if (data.runLoop.get() != currentRunLoop)
continue;
+#else
+ if (data.runLoop != currentRunLoop)
+ continue;
+#endif
EpochTime scheduleTime = epochTime(s_decade);
for (size_t i = 0; i < data.timers.size(); ++i) {
@@ -93,7 +140,11 @@
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
}
}
@@ -113,7 +164,10 @@
void JSRunLoopTimer::Manager::registerVM(VM& vm)
{
- auto data = "" vm.runLoop());
+ auto data = ""
+#if USE(CF)
+ data->setRunLoop(this, vm.runLoop());
+#endif
auto locker = holdLock(m_lock);
auto addResult = m_mapping.add({ vm.apiLock() }, WTFMove(data));
@@ -151,7 +205,11 @@
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)
@@ -182,7 +240,11 @@
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)
@@ -202,6 +264,18 @@
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 (264261 => 264262)
--- trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/_javascript_Core/runtime/JSRunLoopTimer.h 2020-07-11 04:35:03 UTC (rev 264262)
@@ -33,6 +33,10 @@
#include <wtf/SharedTask.h>
#include <wtf/ThreadSafeRefCounted.h>
+#if USE(CF)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
namespace JSC {
class JSLock;
@@ -46,8 +50,11 @@
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();
@@ -63,6 +70,10 @@
Optional<Seconds> timeUntilFire(JSRunLoopTimer&);
+#if USE(CF)
+ void didChangeRunLoop(VM&, CFRunLoopRef newRunLoop);
+#endif
+
private:
Lock m_lock;
@@ -70,11 +81,22 @@
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(PerVMData);
public:
- PerVMData(Manager&, WTF::RunLoop&);
+#if USE(CF)
+ PerVMData(Manager&) { }
+#else
+ PerVMData(Manager&);
+#endif
~PerVMData();
- Ref<WTF::RunLoop> runLoop;
+#if USE(CF)
+ void setRunLoop(Manager*, CFRunLoopRef);
+ RetainPtr<CFRunLoopTimerRef> timer;
+ RetainPtr<CFRunLoopRef> runLoop;
+ CFRunLoopTimerContext context;
+#else
+ 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 (264261 => 264262)
--- trunk/Source/_javascript_Core/runtime/PromiseTimer.cpp 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/_javascript_Core/runtime/PromiseTimer.cpp 2020-07-11 04:35:03 UTC (rev 264262)
@@ -70,8 +70,13 @@
}
}
- if (m_pendingPromises.isEmpty() && m_shouldStopRunLoopWhenAllPromisesFinish)
+ if (m_pendingPromises.isEmpty() && m_shouldStopRunLoopWhenAllPromisesFinish) {
+#if USE(CF)
+ CFRunLoopStop(vm.runLoop());
+#else
RunLoop::current().stop();
+#endif
+ }
m_taskLock.unlock();
}
@@ -79,10 +84,17 @@
void PromiseTimer::runRunLoop()
{
ASSERT(!m_apiLock->vm()->currentThreadIsHoldingAPILock());
- ASSERT(&RunLoop::current() == &m_apiLock->vm()->runLoop());
+#if USE(CF)
+ ASSERT(CFRunLoopGetCurrent() == m_apiLock->vm()->runLoop());
+#endif
m_shouldStopRunLoopWhenAllPromisesFinish = true;
- if (m_pendingPromises.size())
+ if (m_pendingPromises.size()) {
+#if USE(CF)
+ CFRunLoopRun();
+#else
RunLoop::run();
+#endif
+ }
}
void PromiseTimer::addPendingPromise(VM& vm, JSPromise* ticket, Vector<Strong<JSCell>>&& dependencies)
Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (264261 => 264262)
--- trunk/Source/_javascript_Core/runtime/VM.cpp 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp 2020-07-11 04:35:03 UTC (rev 264262)
@@ -262,10 +262,12 @@
static bool vmCreationShouldCrash = false;
-VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop)
+VM::VM(VMType vmType, HeapType heapType)
: m_id(nextID())
, m_apiLock(adoptRef(new JSLock(this)))
- , m_runLoop(runLoop ? *runLoop : WTF::RunLoop::current())
+#if USE(CF)
+ , m_runLoop(CFRunLoopGetCurrent())
+#endif // USE(CF)
, m_random(Options::seedOfVMRandomForFuzzer() ? Options::seedOfVMRandomForFuzzer() : cryptographicallyRandomNumber())
, m_integrityRandom(*this)
, heap(*this, heapType)
@@ -669,9 +671,9 @@
return adoptRef(*new VM(APIContextGroup, heapType));
}
-Ref<VM> VM::create(HeapType heapType, WTF::RunLoop* runLoop)
+Ref<VM> VM::create(HeapType heapType)
{
- return adoptRef(*new VM(Default, heapType, runLoop));
+ return adoptRef(*new VM(Default, heapType));
}
bool VM::sharedInstanceExists()
@@ -1353,6 +1355,15 @@
}
#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 (264261 => 264262)
--- trunk/Source/_javascript_Core/runtime/VM.h 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/_javascript_Core/runtime/VM.h 2020-07-11 04:35:03 UTC (rev 264262)
@@ -94,7 +94,6 @@
#endif
namespace WTF {
-class RunLoop;
class SimpleStats;
} // namespace WTF
using WTF::SimpleStats;
@@ -313,7 +312,7 @@
JS_EXPORT_PRIVATE static bool sharedInstanceExists();
JS_EXPORT_PRIVATE static VM& sharedInstance();
- JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap, WTF::RunLoop* = nullptr);
+ JS_EXPORT_PRIVATE static Ref<VM> create(HeapType = SmallHeap);
static Ref<VM> createContextGroup(HeapType = SmallHeap);
JS_EXPORT_PRIVATE ~VM();
@@ -354,7 +353,10 @@
unsigned m_id;
RefPtr<JSLock> m_apiLock;
- Ref<WTF::RunLoop> m_runLoop;
+#if USE(CF)
+ // These need to be initialized before heap below.
+ RetainPtr<CFRunLoopRef> m_runLoop;
+#endif
WeakRandom m_random;
Integrity::Random m_integrityRandom;
@@ -1077,7 +1079,10 @@
bool needExceptionCheck() const { return m_needExceptionCheck; }
#endif
- WTF::RunLoop& runLoop() const { return m_runLoop; }
+#if USE(CF)
+ CFRunLoopRef runLoop() const { return m_runLoop.get(); }
+ JS_EXPORT_PRIVATE void setRunLoop(CFRunLoopRef);
+#endif // USE(CF)
static void setCrashOnVMCreation(bool);
@@ -1101,7 +1106,7 @@
private:
friend class LLIntOffsetsExtractor;
- VM(VMType, HeapType, WTF::RunLoop* = nullptr);
+ VM(VMType, HeapType);
static VM*& sharedInstanceInternal();
void createNativeThunk();
Modified: trunk/Source/WebCore/ChangeLog (264261 => 264262)
--- trunk/Source/WebCore/ChangeLog 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/WebCore/ChangeLog 2020-07-11 04:35:03 UTC (rev 264262)
@@ -1,3 +1,16 @@
+2020-07-10 Chris Dumez <[email protected]>
+
+ Unreviewed, reverting r264242.
+
+ Caused many crashes on iOS bots
+
+ Reverted changeset:
+
+ "JSRunLoopTimer should use WTF::RunLoop rather than custom CF
+ code"
+ https://bugs.webkit.org/show_bug.cgi?id=214102
+ https://trac.webkit.org/changeset/264242
+
2020-07-10 Brady Eidson <[email protected]>
Cleanup GameController framework button binding with some constants
Modified: trunk/Source/WebCore/bindings/js/CommonVM.cpp (264261 => 264262)
--- trunk/Source/WebCore/bindings/js/CommonVM.cpp 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Source/WebCore/bindings/js/CommonVM.cpp 2020-07-11 04:35:03 UTC (rev 264262)
@@ -55,14 +55,8 @@
// Also, initializeMainThread() does nothing on iOS.
ScriptController::initializeMainThread();
-#if USE(WEB_THREAD)
- RunLoop* runLoop = &RunLoop::web();
-#else
- RunLoop* runLoop = nullptr;
-#endif
+ auto& vm = JSC::VM::create(JSC::LargeHeap).leakRef();
- 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.
@@ -70,6 +64,7 @@
#if PLATFORM(IOS_FAMILY)
if (WebThreadIsEnabled())
vm.apiLock().makeWebThreadAware();
+ vm.setRunLoop(WebThreadRunLoop());
vm.heap.machineThreads().addCurrentThread();
#endif
Modified: trunk/Tools/ChangeLog (264261 => 264262)
--- trunk/Tools/ChangeLog 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Tools/ChangeLog 2020-07-11 04:35:03 UTC (rev 264262)
@@ -1,3 +1,16 @@
+2020-07-10 Chris Dumez <[email protected]>
+
+ Unreviewed, reverting r264242.
+
+ Caused many crashes on iOS bots
+
+ Reverted changeset:
+
+ "JSRunLoopTimer should use WTF::RunLoop rather than custom CF
+ code"
+ https://bugs.webkit.org/show_bug.cgi?id=214102
+ https://trac.webkit.org/changeset/264242
+
2020-07-10 Fujii Hironori <[email protected]>
[TestWebKitAPI][Win] Remove WEBCORE_EXPORT and WEBCORE_TESTSUPPORT_EXPORT definitions in PlatformWin.cmake
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (264261 => 264262)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-07-11 04:35:03 UTC (rev 264262)
@@ -87,7 +87,6 @@
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 */; };
@@ -1690,7 +1689,6 @@
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>"; };
@@ -3054,14 +3052,6 @@
name = cocoa;
sourceTree = "<group>";
};
- 14CC42E024B8D7E700E64F48 /* _javascript_Core */ = {
- isa = PBXGroup;
- children = (
- 14CC42E524B8D8FA00E64F48 /* JSRunLoopTimer.mm */,
- );
- path = _javascript_Core;
- sourceTree = "<group>";
- };
1AB674ADFE9D54B511CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
@@ -4274,7 +4264,6 @@
isa = PBXGroup;
children = (
7560917619259C59009EF06E /* ios */,
- 14CC42E024B8D7E700E64F48 /* _javascript_Core */,
C07E6CAD13FD67650038B22B /* mac */,
C08587F913FEC39B001EF4E5 /* TestWebKitAPI */,
440A1D3614A01000008A66F2 /* WebCore */,
@@ -5095,7 +5084,6 @@
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 */,
Deleted: trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm (264261 => 264262)
--- trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm 2020-07-11 04:32:34 UTC (rev 264261)
+++ trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/JSRunLoopTimer.mm 2020-07-11 04:35:03 UTC (rev 264262)
@@ -1,113 +0,0 @@
-/*
- * 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