Let the bindings generator use WTF::Optional for optional parameters using [Clamp]
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2016 23:31:39 +0000 (23:31 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2016 23:31:39 +0000 (23:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157077

Reviewed by Darin Adler.

Let the bindings generator use WTF::Optional for optional parameters using [Clamp],
if they do not have a default value.

* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::close):
* Modules/websockets/WebSocket.h:
* Modules/websockets/WebSocket.idl:
* bindings/scripts/CodeGeneratorJS.pm:
(CanUseWTFOptionalForParameter): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200158 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/websockets/WebSocket.cpp
Source/WebCore/Modules/websockets/WebSocket.h
Source/WebCore/Modules/websockets/WebSocket.idl
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp

index 8a58cff..b105524 100644 (file)
@@ -1,3 +1,20 @@
+2016-04-27  Chris Dumez  <cdumez@apple.com>
+
+        Let the bindings generator use WTF::Optional for optional parameters using [Clamp]
+        https://bugs.webkit.org/show_bug.cgi?id=157077
+
+        Reviewed by Darin Adler.
+
+        Let the bindings generator use WTF::Optional for optional parameters using [Clamp],
+        if they do not have a default value.
+
+        * Modules/websockets/WebSocket.cpp:
+        (WebCore::WebSocket::close):
+        * Modules/websockets/WebSocket.h:
+        * Modules/websockets/WebSocket.idl:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (CanUseWTFOptionalForParameter): Deleted.
+
 2016-04-26  Ada Chan  <adachan@apple.com>
 
         Set WebVideoFullscreenInterfaceMac up as a client of WebPlaybackSessionInterfaceMac to listen for playback state changes
index b18f27d..30b0c59 100644 (file)
@@ -375,8 +375,9 @@ void WebSocket::send(Blob& binaryData, ExceptionCode& ec)
     m_channel->send(binaryData);
 }
 
-void WebSocket::close(int code, const String& reason, ExceptionCode& ec)
+void WebSocket::close(Optional<unsigned short> optionalCode, const String& reason, ExceptionCode& ec)
 {
+    int code = optionalCode ? optionalCode.value() : static_cast<int>(WebSocketChannel::CloseEventCodeNotSpecified);
     if (code == WebSocketChannel::CloseEventCodeNotSpecified)
         LOG(Network, "WebSocket %p close() without code and reason", this);
     else {
index 4e8be1c..e38d103 100644 (file)
@@ -76,9 +76,7 @@ public:
     void send(JSC::ArrayBufferView*, ExceptionCode&);
     void send(Blob&, ExceptionCode&);
 
-    void close(int code, const String& reason, ExceptionCode&);
-    void close(ExceptionCode& ec) { close(WebSocketChannel::CloseEventCodeNotSpecified, String(), ec); }
-    void close(int code, ExceptionCode& ec) { close(code, String(), ec); }
+    void close(Optional<unsigned short> code, const String& reason, ExceptionCode&);
 
     const URL& url() const;
     State readyState() const;
index 92900f6..3922725 100644 (file)
@@ -67,5 +67,5 @@
     [RaisesException] void send(Blob data);
     [RaisesException] void send(DOMString data);
 
-    [RaisesException] void close([Clamp] optional unsigned short code, optional DOMString reason);
+    [RaisesException] void close([Clamp] optional unsigned short code, optional DOMString reason = null);
 };
index 8d1e4fd..5fd894e 100644 (file)
@@ -3377,7 +3377,6 @@ sub CanUseWTFOptionalForParameter
 
     # FIXME: We should progressively stop blacklisting each type below
     # and eventually get rid of this function entirely.
-    return 0 if $parameter->extendedAttributes->{"Clamp"};
     return 0 if $parameter->isVariadic;
     return 0 if $codeGenerator->IsCallbackInterface($type);
     return 0 if $codeGenerator->IsEnumType($type);
index c41e489..b462fab 100644 (file)
@@ -553,14 +553,7 @@ EncodedJSValue JSC_HOST_CALL jsTestTypedefsPrototypeFunctionFuncWithClamp(ExecSt
     unsigned long long arg1 = toUInt64(state, state->argument(0), Clamp);
     if (UNLIKELY(state->hadException()))
         return JSValue::encode(jsUndefined());
-
-    size_t argsCount = state->argumentCount();
-    if (argsCount <= 1) {
-        impl.funcWithClamp(arg1);
-        return JSValue::encode(jsUndefined());
-    }
-
-    unsigned long long arg2 = toUInt64(state, state->argument(1), Clamp);
+    Optional<unsigned long long> arg2 = state->argument(1).isUndefined() ? Optional<unsigned long long>() : toUInt64(state, state->uncheckedArgument(1), Clamp);
     if (UNLIKELY(state->hadException()))
         return JSValue::encode(jsUndefined());
     impl.funcWithClamp(arg1, arg2);