Title: [220477] trunk/Source
Revision
220477
Author
commit-qu...@webkit.org
Date
2017-08-09 13:57:51 -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 Sam Weinig.

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 (220476 => 220477)


--- trunk/Source/_javascript_Core/ChangeLog	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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 Sam Weinig.
+
+        * 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  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS DnD] ENABLE_DRAG_SUPPORT should be turned off for iOS 10 and enabled by default

Modified: trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp (220476 => 220477)


--- trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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 (220476 => 220477)


--- trunk/Source/WTF/ChangeLog	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/WTF/ChangeLog	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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 Sam Weinig.
+
+        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-09  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, rolling out r220457.

Modified: trunk/Source/WTF/wtf/Function.h (220476 => 220477)


--- trunk/Source/WTF/wtf/Function.h	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/WTF/wtf/Function.h	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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 (220476 => 220477)


--- trunk/Source/WebCore/ChangeLog	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/WebCore/ChangeLog	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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 Sam Weinig.
+
+        * 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  Brady Eidson  <beid...@apple.com>
 
         Teach ScriptExecutionContexts about their SessionID.

Modified: trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h (220476 => 220477)


--- trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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 (220476 => 220477)


--- trunk/Source/WebKit/ChangeLog	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/WebKit/ChangeLog	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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 Sam Weinig.
+
+        * 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-09  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS DnD] ENABLE_DRAG_SUPPORT should be turned off for iOS 10 and enabled by default

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h (220476 => 220477)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2017-08-09 20:28:01 UTC (rev 220476)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2017-08-09 20:57:51 UTC (rev 220477)
@@ -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