Title: [220457] trunk/Source
Revision
220457
Author
commit-qu...@webkit.org
Date
2017-08-09 08:59:01 -0700 (Wed, 09 Aug 2017)

Log Message

WTF::Function does not allow for reference / non-default constructible return types
https://bugs.webkit.org/show_bug.cgi?id=175244

Patch by Sam Weinig <s...@webkit.org> on 2017-08-09
Reviewed by Chris Dumez.

Source/_javascript_Core:

* runtime/ArrayBuffer.cpp:
(JSC::ArrayBufferContents::transferTo):
Call reset(), rather than clear() to avoid the call to destroy() in clear(). The
destroy call needed to be a no-op anyway, since the data is being moved.

Source/WebCore:

* bindings/js/JSCustomElementInterface.h:
(WebCore::JSCustomElementInterface::invokeCallback):
Update the default value for the addArguments parameter to be an empty lambda, rather than
default initialization, which leads to a null WTF::Function. This allows us to remove support
for calling null WTF::Function. No change in behavior.

Source/WebKit:

* UIProcess/WebResourceLoadStatisticsStore.h:
Update the default value for the updateCookiePartitioningForDomainsHandler parameter to be an
empty lambda, rather than default initialization, which leads to a null WTF::Function. This allows
us to remove support for calling null WTF::Function. No change in behavior.

Source/WTF:

When Function, then NoncopyableFunction, was templatized to allow non-void return values
in r201493, it maintained the behavior of being callable even if the Function was null.
To accomplish this, when null, the default construction of the return parameter was used.
This means Function can't be used with return types that are not default constructible,
such as reference types and Ref.

This behavior of returning something when null is surprising, as this is not how normal
functions behave, and not very useful. Instead, we now assert that the function is not
null when being called.

* wtf/Function.h:
(WTF::Function operator(...)):
Instead of allowing a null callable wrapper by returning the default construction of
the return type, assert that the wrapper is there when calling a Function.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (220456 => 220457)


--- trunk/Source/_javascript_Core/ChangeLog	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-08-09 15:59:01 UTC (rev 220457)
@@ -1,3 +1,15 @@
+2017-08-09  Sam Weinig  <s...@webkit.org>
+
+        WTF::Function does not allow for reference / non-default constructible return types
+        https://bugs.webkit.org/show_bug.cgi?id=175244
+
+        Reviewed by Chris Dumez.
+
+        * runtime/ArrayBuffer.cpp:
+        (JSC::ArrayBufferContents::transferTo):
+        Call reset(), rather than clear() to avoid the call to destroy() in clear(). The
+        destroy call needed to be a no-op anyway, since the data is being moved.
+
 2017-08-09  Oleksandr Skachkov  <gskach...@gmail.com>
 
         REGRESSION: 2 test262/test/language/statements/async-function failures

Modified: trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp (220456 => 220457)


--- trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp	2017-08-09 15:59:01 UTC (rev 220457)
@@ -132,7 +132,7 @@
     other.m_sizeInBytes = m_sizeInBytes;
     other.m_destructor = WTFMove(m_destructor);
     other.m_shared = m_shared;
-    clear();
+    reset();
 }
 
 void ArrayBufferContents::copyTo(ArrayBufferContents& other)

Modified: trunk/Source/WTF/ChangeLog (220456 => 220457)


--- trunk/Source/WTF/ChangeLog	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/WTF/ChangeLog	2017-08-09 15:59:01 UTC (rev 220457)
@@ -1,3 +1,25 @@
+2017-08-09  Sam Weinig  <s...@webkit.org>
+
+        WTF::Function does not allow for reference / non-default constructible return types
+        https://bugs.webkit.org/show_bug.cgi?id=175244
+
+        Reviewed by Chris Dumez.
+
+        When Function, then NoncopyableFunction, was templatized to allow non-void return values
+        in r201493, it maintained the behavior of being callable even if the Function was null.
+        To accomplish this, when null, the default construction of the return parameter was used.
+        This means Function can't be used with return types that are not default constructible,
+        such as reference types and Ref.
+
+        This behavior of returning something when null is surprising, as this is not how normal
+        functions behave, and not very useful. Instead, we now assert that the function is not
+        null when being called.
+
+        * wtf/Function.h:
+        (WTF::Function operator(...)):
+        Instead of allowing a null callable wrapper by returning the default construction of
+        the return type, assert that the wrapper is there when calling a Function.
+
 2017-08-08  Filip Pizlo  <fpi...@apple.com>
 
         Baseline JIT should do caging

Modified: trunk/Source/WTF/wtf/Function.h (220456 => 220457)


--- trunk/Source/WTF/wtf/Function.h	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/WTF/wtf/Function.h	2017-08-09 15:59:01 UTC (rev 220457)
@@ -52,9 +52,8 @@
 
     Out operator()(In... in) const
     {
-        if (m_callableWrapper)
-            return m_callableWrapper->call(std::forward<In>(in)...);
-        return Out();
+        ASSERT(m_callableWrapper);
+        return m_callableWrapper->call(std::forward<In>(in)...);
     }
 
     explicit operator bool() const { return !!m_callableWrapper; }

Modified: trunk/Source/WebCore/ChangeLog (220456 => 220457)


--- trunk/Source/WebCore/ChangeLog	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/WebCore/ChangeLog	2017-08-09 15:59:01 UTC (rev 220457)
@@ -1,3 +1,16 @@
+2017-08-09  Sam Weinig  <s...@webkit.org>
+
+        WTF::Function does not allow for reference / non-default constructible return types
+        https://bugs.webkit.org/show_bug.cgi?id=175244
+
+        Reviewed by Chris Dumez.
+
+        * bindings/js/JSCustomElementInterface.h:
+        (WebCore::JSCustomElementInterface::invokeCallback):
+        Update the default value for the addArguments parameter to be an empty lambda, rather than
+        default initialization, which leads to a null WTF::Function. This allows us to remove support
+        for calling null WTF::Function. No change in behavior.
+
 2017-08-09  Andy Estes  <aes...@apple.com>
 
         [QuickLook] Use case-insensitive comparison of preview MIME types

Modified: trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h (220456 => 220457)


--- trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h	2017-08-09 15:59:01 UTC (rev 220457)
@@ -94,7 +94,7 @@
 
     RefPtr<Element> tryToConstructCustomElement(Document&, const AtomicString&);
 
-    void invokeCallback(Element&, JSC::JSObject* callback, const WTF::Function<void(JSC::ExecState*, JSDOMGlobalObject*, JSC::MarkedArgumentBuffer&)>& addArguments = { });
+    void invokeCallback(Element&, JSC::JSObject* callback, const WTF::Function<void(JSC::ExecState*, JSDOMGlobalObject*, JSC::MarkedArgumentBuffer&)>& addArguments = [](JSC::ExecState*, JSDOMGlobalObject*, JSC::MarkedArgumentBuffer&) { });
 
     QualifiedName m_name;
     JSC::Weak<JSC::JSObject> m_constructor;

Modified: trunk/Source/WebKit/ChangeLog (220456 => 220457)


--- trunk/Source/WebKit/ChangeLog	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/WebKit/ChangeLog	2017-08-09 15:59:01 UTC (rev 220457)
@@ -1,3 +1,15 @@
+2017-08-09  Sam Weinig  <s...@webkit.org>
+
+        WTF::Function does not allow for reference / non-default constructible return types
+        https://bugs.webkit.org/show_bug.cgi?id=175244
+
+        Reviewed by Chris Dumez.
+
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+        Update the default value for the updateCookiePartitioningForDomainsHandler parameter to be an 
+        empty lambda, rather than default initialization, which leads to a null WTF::Function. This allows
+        us to remove support for calling null WTF::Function. No change in behavior.
+
 2017-08-08  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Unreviewed, rolling out r220393.

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h (220456 => 220457)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2017-08-09 15:52:19 UTC (rev 220456)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2017-08-09 15:59:01 UTC (rev 220457)
@@ -60,7 +60,7 @@
 class WebResourceLoadStatisticsStore final : public IPC::Connection::WorkQueueMessageReceiver {
 public:
     using UpdateCookiePartitioningForDomainsHandler = WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, ShouldClearFirst)>;
-    static Ref<WebResourceLoadStatisticsStore> create(const String& resourceLoadStatisticsDirectory, Function<void (const String&)>&& testingCallback, UpdateCookiePartitioningForDomainsHandler&& updateCookiePartitioningForDomainsHandler = { })
+    static Ref<WebResourceLoadStatisticsStore> create(const String& resourceLoadStatisticsDirectory, Function<void (const String&)>&& testingCallback, UpdateCookiePartitioningForDomainsHandler&& updateCookiePartitioningForDomainsHandler = [](const Vector<String>&, const Vector<String>&, ShouldClearFirst) { })
     {
         return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory, WTFMove(testingCallback), WTFMove(updateCookiePartitioningForDomainsHandler)));
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to