https://bugs.webkit.org/show_bug.cgi?id=92642
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jul 2012 16:32:57 +0000 (16:32 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jul 2012 16:32:57 +0000 (16:32 +0000)
[Bindings]Remove custom JS/V8 bindings for WebSocket::close() using [Clamp]

Patch by Vineet Chaudhary <rgf748@motorola.com> on 2012-07-30
Reviewed by Kentaro Hara.

With support of [Clamp] as extended attribute we can replace custom bindings from WebSocket::close().
Spec for WebSocket::close() : http://www.whatwg.org/specs/web-apps/current-work/multipage/network.html#websocket

No new tests. There should be no behavioural changes
Existing tests under http/websocket/tests/hybi/ should cover this.

* Modules/websockets/WebSocket.h:
(WebCore::WebSocket::close):
* Modules/websockets/WebSocket.idl: Used [Clamp].
* bindings/js/JSWebSocketCustom.cpp: Removed custom call close().
(WebCore):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheck):
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateParametersCheck):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionClassMethodWithClamp):
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::TestObjV8Internal::classMethodWithClampCallback):
* bindings/v8/custom/V8WebSocketCustom.cpp: Removed custom call close().
(WebCore):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/websockets/WebSocket.h
Source/WebCore/Modules/websockets/WebSocket.idl
Source/WebCore/bindings/js/JSWebSocketCustom.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp
Source/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp

index d9353c2..ff91796 100644 (file)
@@ -1,3 +1,32 @@
+2012-07-30  Vineet Chaudhary  <rgf748@motorola.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=92642
+        [Bindings]Remove custom JS/V8 bindings for WebSocket::close() using [Clamp]
+
+        Reviewed by Kentaro Hara.
+
+        With support of [Clamp] as extended attribute we can replace custom bindings from WebSocket::close().
+        Spec for WebSocket::close() : http://www.whatwg.org/specs/web-apps/current-work/multipage/network.html#websocket
+
+        No new tests. There should be no behavioural changes 
+        Existing tests under http/websocket/tests/hybi/ should cover this.
+
+        * Modules/websockets/WebSocket.h:
+        (WebCore::WebSocket::close):
+        * Modules/websockets/WebSocket.idl: Used [Clamp].
+        * bindings/js/JSWebSocketCustom.cpp: Removed custom call close().
+        (WebCore):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateParametersCheck):
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateParametersCheck):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionClassMethodWithClamp):
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::TestObjV8Internal::classMethodWithClampCallback):
+        * bindings/v8/custom/V8WebSocketCustom.cpp: Removed custom call close().
+        (WebCore):
+
 2012-07-29  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: Resource agent's reference to cached resources should be weak.
index 54d027e..6818732 100644 (file)
@@ -38,6 +38,7 @@
 #include "EventNames.h"
 #include "EventTarget.h"
 #include "KURL.h"
+#include "WebSocketChannel.h"
 #include "WebSocketChannelClient.h"
 #include <wtf/Forward.h>
 #include <wtf/OwnPtr.h>
@@ -73,6 +74,8 @@ public:
     bool 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); }
 
     const KURL& url() const;
     State readyState() const;
index 92835ae..b3bb1cf 100644 (file)
@@ -73,8 +73,7 @@ module websockets {
         // boolean send(in DOMString data) raises(DOMException);
         [Custom] boolean send(in DOMString data) raises(DOMException);
 
-        // FIXME: Implement and apply [Clamp] attribute instead of [Custom].
-        [Custom] void close(in [Optional] unsigned short code, in [Optional] DOMString reason) raises(DOMException);
+        void close(in [Clamp, Optional] unsigned short code, in [Optional] DOMString reason) raises(DOMException);
 
         // EventTarget interface
         void addEventListener(in DOMString type,
index 49b822a..bbd5c8c 100644 (file)
@@ -116,38 +116,6 @@ JSValue JSWebSocket::send(ExecState* exec)
     return jsBoolean(result);
 }
 
-JSValue JSWebSocket::close(ExecState* exec)
-{
-    // FIXME: We should implement [Clamp] for IDL binding code generator, and
-    // remove this custom method.
-    WebSocket* webSocket = static_cast<WebSocket*>(impl());
-    size_t argumentCount = exec->argumentCount();
-    int code = WebSocketChannel::CloseEventCodeNotSpecified;
-    String reason = "";
-    if (argumentCount >= 1) {
-        JSValue v = exec->argument(0);
-        double x = v.toNumber(exec);
-        double maxValue = static_cast<double>(std::numeric_limits<uint16_t>::max());
-        double minValue = static_cast<double>(std::numeric_limits<uint16_t>::min());
-        if (isnan(x))
-            x = 0.0;
-        else
-            x = clampTo(x, minValue, maxValue);
-        code = clampToInteger(x);
-        if (argumentCount >= 2) {
-            reason = ustringToString(exec->argument(1).toString(exec)->value(exec));
-            if (exec->hadException()) {
-                setDOMException(exec, SYNTAX_ERR);
-                return jsUndefined();
-            }
-        }
-    }
-    ExceptionCode ec = 0;
-    webSocket->close(code, reason, ec);
-    setDOMException(exec, ec);
-    return jsUndefined();
-}
-
 } // namespace WebCore
 
 #endif
index c3d9ad4..1b797c0 100644 (file)
@@ -2613,7 +2613,7 @@ sub GenerateParametersCheck
                 push(@$outputArray, "    double $nativeValue = exec->argument($argsIndex).toNumber(exec);\n");
                 push(@$outputArray, "    if (exec->hadException())\n");
                 push(@$outputArray, "        return JSValue::encode(jsUndefined());\n\n");
-                push(@$outputArray, "    if (!isnan(objArgsShortNativeValue))\n");
+                push(@$outputArray, "    if (!isnan($nativeValue))\n");
                 push(@$outputArray, "        $name = clampTo<$argType>($nativeValue);\n\n");
         } else {
             # If the "StrictTypeChecking" extended attribute is present, and the argument's type is an
index 3a0f7d5..a4192bf 100644 (file)
@@ -1683,7 +1683,7 @@ sub GenerateParametersCheck
         } elsif ($parameter->extendedAttributes->{"Clamp"}) {
                 my $nativeValue = "${parameterName}NativeValue";
                 my $paramType = $parameter->type;
-                $parameterCheckString .= "    $paramType $parameterName = 0\n";
+                $parameterCheckString .= "    $paramType $parameterName = 0;\n";
                 $parameterCheckString .= "    EXCEPTION_BLOCK(double, $nativeValue, args[$paramIndex]->NumberValue());\n";
                 $parameterCheckString .= "    if (!isnan($nativeValue))\n";
                 $parameterCheckString .= "        $parameterName = clampTo<$paramType>($nativeValue);\n";
index b1d6c60..bd79006 100644 (file)
@@ -2369,7 +2369,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionClassMethodWithClamp(Exec
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
-    if (!isnan(objArgsShortNativeValue))
+    if (!isnan(objArgsLongNativeValue))
         objArgsLong = clampTo<unsigned long>(objArgsLongNativeValue);
 
     impl->classMethodWithClamp(objArgsShort, objArgsLong);
index 1f0773d..2dbb97b 100644 (file)
@@ -1728,11 +1728,11 @@ static v8::Handle<v8::Value> classMethodWithClampCallback(const v8::Arguments& a
     if (args.Length() < 2)
         return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
     TestObj* imp = V8TestObj::toNative(args.Holder());
-    unsigned short objArgsShort = 0
+    unsigned short objArgsShort = 0;
     EXCEPTION_BLOCK(double, objArgsShortNativeValue, args[0]->NumberValue());
     if (!isnan(objArgsShortNativeValue))
         objArgsShort = clampTo<unsigned short>(objArgsShortNativeValue);
-    unsigned long objArgsLong = 0
+    unsigned long objArgsLong = 0;
     EXCEPTION_BLOCK(double, objArgsLongNativeValue, args[1]->NumberValue());
     if (!isnan(objArgsLongNativeValue))
         objArgsLong = clampTo<unsigned long>(objArgsLongNativeValue);
index f0109c7..2d8318c 100644 (file)
@@ -144,38 +144,6 @@ v8::Handle<v8::Value> V8WebSocket::sendCallback(const v8::Arguments& args)
     return v8Boolean(result, args.GetIsolate());
 }
 
-v8::Handle<v8::Value> V8WebSocket::closeCallback(const v8::Arguments& args)
-{
-    // FIXME: We should implement [Clamp] for IDL binding code generator, and
-    // remove this custom method.
-    WebSocket* webSocket = toNative(args.Holder());
-    int argumentCount = args.Length();
-    int code = WebSocketChannel::CloseEventCodeNotSpecified;
-    String reason = "";
-    if (argumentCount >= 1) {
-        double x = args[0]->NumberValue();
-        double maxValue = static_cast<double>(std::numeric_limits<uint16_t>::max());
-        double minValue = static_cast<double>(std::numeric_limits<uint16_t>::min());
-        if (isnan(x))
-            x = 0.0;
-        else
-            x = clampTo(x, minValue, maxValue);
-        code = clampToInteger(x);
-        if (argumentCount >= 2) {
-            v8::TryCatch tryCatch;
-            v8::Handle<v8::String> reasonValue = args[1]->ToString();
-            if (tryCatch.HasCaught())
-                return throwError(tryCatch.Exception(), args.GetIsolate());
-            reason = toWebCoreString(reasonValue);
-        }
-    }
-    ExceptionCode ec = 0;
-    webSocket->close(code, reason, ec);
-    if (ec)
-        return throwError(ec, args.GetIsolate());
-    return v8::Undefined();
-}
-
 }  // namespace WebCore
 
 #endif  // ENABLE(WEB_SOCKETS)