Title: [264743] trunk/Source
Revision
264743
Author
[email protected]
Date
2020-07-22 20:33:25 -0700 (Wed, 22 Jul 2020)

Log Message

WTF::Function adoption should be explicit instead of implicit
https://bugs.webkit.org/show_bug.cgi?id=214654

Reviewed by Darin Adler.

Source/_javascript_Core:

* heap/Heap.cpp:
(JSC::Heap::LambdaFinalizerOwner::finalize): Use new adopt function.

Source/WTF:

* wtf/Function.h:
(WTF::Function<Out):
(WTF::adoptImpl): Added an adopt function for Functions and made the
adopting constructor private.

* wtf/cf/RunLoopCF.cpp:
(WTF::RunLoop::dispatch): Use new adopt function.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (264742 => 264743)


--- trunk/Source/_javascript_Core/ChangeLog	2020-07-23 03:01:25 UTC (rev 264742)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-07-23 03:33:25 UTC (rev 264743)
@@ -1,3 +1,13 @@
+2020-07-22  Geoffrey Garen  <[email protected]>
+
+        WTF::Function adoption should be explicit instead of implicit
+        https://bugs.webkit.org/show_bug.cgi?id=214654
+
+        Reviewed by Darin Adler.
+
+        * heap/Heap.cpp:
+        (JSC::Heap::LambdaFinalizerOwner::finalize): Use new adopt function.
+
 2020-07-22  Mark Lam  <[email protected]>
 
         Disallow VM entry when doing a VMInquiry.

Modified: trunk/Source/_javascript_Core/heap/Heap.cpp (264742 => 264743)


--- trunk/Source/_javascript_Core/heap/Heap.cpp	2020-07-23 03:01:25 UTC (rev 264742)
+++ trunk/Source/_javascript_Core/heap/Heap.cpp	2020-07-23 03:33:25 UTC (rev 264743)
@@ -2428,7 +2428,7 @@
 
 void Heap::addFinalizer(JSCell* cell, LambdaFinalizer function)
 {
-    WeakSet::allocate(cell, &m_lambdaFinalizerOwner, function.leakImpl()); // Balanced by LambdaFinalizerOwner::finalize().
+    WeakSet::allocate(cell, &m_lambdaFinalizerOwner, function.leak()); // Balanced by LambdaFinalizerOwner::finalize().
 }
 
 void Heap::CFinalizerOwner::finalize(Handle<Unknown> handle, void* context)
@@ -2441,8 +2441,7 @@
 
 void Heap::LambdaFinalizerOwner::finalize(Handle<Unknown> handle, void* context)
 {
-    LambdaFinalizer::Impl* impl = bitwise_cast<LambdaFinalizer::Impl*>(context);
-    LambdaFinalizer finalizer(impl);
+    auto finalizer = WTF::adopt(static_cast<LambdaFinalizer::Impl*>(context));
     HandleSlot slot = handle.slot();
     finalizer(slot->asCell());
     WeakSet::deallocate(WeakImpl::asWeakImpl(slot));

Modified: trunk/Source/WTF/ChangeLog (264742 => 264743)


--- trunk/Source/WTF/ChangeLog	2020-07-23 03:01:25 UTC (rev 264742)
+++ trunk/Source/WTF/ChangeLog	2020-07-23 03:33:25 UTC (rev 264743)
@@ -1,3 +1,18 @@
+2020-07-22  Geoffrey Garen  <[email protected]>
+
+        WTF::Function adoption should be explicit instead of implicit
+        https://bugs.webkit.org/show_bug.cgi?id=214654
+
+        Reviewed by Darin Adler.
+
+        * wtf/Function.h:
+        (WTF::Function<Out):
+        (WTF::adoptImpl): Added an adopt function for Functions and made the
+        adopting constructor private.
+
+        * wtf/cf/RunLoopCF.cpp:
+        (WTF::RunLoop::dispatch): Use new adopt function.
+
 2020-07-22  Jer Noble  <[email protected]>
 
         Unreviewed build fix after r264710; add a HAVE_AVPLAYER_VIDEORANGEOVERRIDE guard.

Modified: trunk/Source/WTF/wtf/Function.h (264742 => 264743)


--- trunk/Source/WTF/wtf/Function.h	2020-07-23 03:01:25 UTC (rev 264742)
+++ trunk/Source/WTF/wtf/Function.h	2020-07-23 03:33:25 UTC (rev 264743)
@@ -58,6 +58,8 @@
 
 template<typename> class Function;
 
+template<typename Out, typename... In> Function<Out(In...)> adopt(Detail::CallableWrapperBase<Out, In...>*);
+
 template <typename Out, typename... In>
 class Function<Out(In...)> {
     WTF_MAKE_FAST_ALLOCATED;
@@ -66,9 +68,6 @@
 
     Function() = default;
     Function(std::nullptr_t) { }
-    Function(Impl* impl)
-        : m_callableWrapper(impl)
-    { }
 
     template<typename CallableType, class = typename std::enable_if<!(std::is_pointer<CallableType>::value && std::is_function<typename std::remove_pointer<CallableType>::type>::value) && std::is_rvalue_reference<CallableType&&>::value>::type>
     Function(CallableType&& callable)
@@ -106,15 +105,28 @@
         return *this;
     }
 
-    Impl* leakImpl()
+    Impl* leak()
     {
         return m_callableWrapper.release();
     }
 
 private:
+    enum AdoptTag { Adopt };
+    Function(Impl* impl, AdoptTag)
+        : m_callableWrapper(impl)
+    {
+    }
+
+    friend Function adopt<Out, In...>(Impl*);
+
     std::unique_ptr<Impl> m_callableWrapper;
 };
 
+template<typename Out, typename... In> Function<Out(In...)> adopt(Detail::CallableWrapperBase<Out, In...>* impl)
+{
+    return Function<Out(In...)>(impl, Function<Out(In...)>::Adopt);
+}
+
 } // namespace WTF
 
 using WTF::Function;

Modified: trunk/Source/WTF/wtf/cf/RunLoopCF.cpp (264742 => 264743)


--- trunk/Source/WTF/wtf/cf/RunLoopCF.cpp	2020-07-23 03:01:25 UTC (rev 264742)
+++ trunk/Source/WTF/wtf/cf/RunLoopCF.cpp	2020-07-23 03:33:25 UTC (rev 264743)
@@ -91,9 +91,9 @@
 
         CFRunLoopTimerInvalidate(timer);
 
-        Function<void()> function(static_cast<Function<void()>::Impl*>(context));
+        auto function = adopt(static_cast<Function<void()>::Impl*>(context));
         function();
-    }, function.leakImpl());
+    }, function.leak());
 
     for (auto& schedulePair : schedulePairs)
         CFRunLoopAddTimer(schedulePair->runLoop(), timer.get(), schedulePair->mode());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to