constants are always typed to 'int' https://bugs.webkit.org/show_bug.cgi?id=130775
authortonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Mar 2014 17:51:51 +0000 (17:51 +0000)
committertonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Mar 2014 17:51:51 +0000 (17:51 +0000)
Reviewed by Darin Adler.
Patch by Antonio Gomes <a1.gomes@sisa.samsung.com>

Patch fixes a bug where all constant getter generated
methods were returning 'integer' values due to static_cast.

Compilers should be smarth enough to properly infer which
jsNumber class construtor to call given a literal value.

Patch also fixes a bug where values whose representation
is bigger an integer maximum were overflowing. For instance,
NodeFilter.SHOW_ALL (0xFFFFFFFF).

Tests:
Binding tests updated.
Rebaselined fast/dom/constants.html

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
* bindings/scripts/test/JS/JSTestInterface.cpp:
(WebCore::jsTestInterfaceIMPLEMENTSCONSTANT1):
(WebCore::jsTestInterfaceIMPLEMENTSCONSTANT2):
(WebCore::jsTestInterfaceSUPPLEMENTALCONSTANT1):
(WebCore::jsTestInterfaceSUPPLEMENTALCONSTANT2):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjCONDITIONAL_CONST):
(WebCore::jsTestObjCONST_VALUE_0):
(WebCore::jsTestObjCONST_VALUE_1):
(WebCore::jsTestObjCONST_VALUE_2):
(WebCore::jsTestObjCONST_VALUE_4):
(WebCore::jsTestObjCONST_VALUE_8):
(WebCore::jsTestObjCONST_VALUE_9):
(WebCore::jsTestObjCONST_VALUE_11):
(WebCore::jsTestObjCONST_VALUE_12):
(WebCore::jsTestObjCONST_VALUE_13):
(WebCore::jsTestObjCONST_VALUE_14):
(WebCore::jsTestObjCONST_JAVASCRIPT):
(WebCore::jsTestObjReadonly):

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

LayoutTests/fast/dom/constants-expected.txt
LayoutTests/fast/dom/constants.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

index 332face..47fc5b2 100644 (file)
@@ -27,7 +27,7 @@ PASS: window.CSSValue.CSS_CUSTOM should be 3 and is.
 PASS: nodeFilter.FILTER_ACCEPT should be 1 and is.
 PASS: nodeFilter.FILTER_REJECT should be 2 and is.
 PASS: nodeFilter.FILTER_SKIP should be 3 and is.
-PASS: nodeFilter.SHOW_ALL should be -1 and is.
+PASS: nodeFilter.SHOW_ALL should be 4294967295 and is.
 PASS: nodeFilter.SHOW_ELEMENT should be 1 and is.
 PASS: nodeFilter.SHOW_ATTRIBUTE should be 2 and is.
 PASS: nodeFilter.SHOW_TEXT should be 4 and is.
@@ -43,7 +43,7 @@ PASS: nodeFilter.SHOW_NOTATION should be 2048 and is.
 PASS: window.NodeFilter.FILTER_ACCEPT should be 1 and is.
 PASS: window.NodeFilter.FILTER_REJECT should be 2 and is.
 PASS: window.NodeFilter.FILTER_SKIP should be 3 and is.
-PASS: window.NodeFilter.SHOW_ALL should be -1 and is.
+PASS: window.NodeFilter.SHOW_ALL should be 4294967295 and is.
 PASS: window.NodeFilter.SHOW_ELEMENT should be 1 and is.
 PASS: window.NodeFilter.SHOW_ATTRIBUTE should be 2 and is.
 PASS: window.NodeFilter.SHOW_TEXT should be 4 and is.
index ed1dac4..dce2588 100644 (file)
@@ -80,7 +80,7 @@ function test() {
     shouldBe("nodeFilter.FILTER_ACCEPT", 1);
     shouldBe("nodeFilter.FILTER_REJECT", 2);
     shouldBe("nodeFilter.FILTER_SKIP", 3);
-    shouldBe("nodeFilter.SHOW_ALL", -1);
+    shouldBe("nodeFilter.SHOW_ALL", 0xFFFFFFFF);
     shouldBe("nodeFilter.SHOW_ELEMENT", 0x00000001);
     shouldBe("nodeFilter.SHOW_ATTRIBUTE", 0x00000002);
     shouldBe("nodeFilter.SHOW_TEXT", 0x00000004);
@@ -97,7 +97,7 @@ function test() {
     shouldBe("window.NodeFilter.FILTER_ACCEPT", 1);
     shouldBe("window.NodeFilter.FILTER_REJECT", 2);
     shouldBe("window.NodeFilter.FILTER_SKIP", 3);
-    shouldBe("window.NodeFilter.SHOW_ALL", -1);
+    shouldBe("window.NodeFilter.SHOW_ALL", 0xFFFFFFFF);
     shouldBe("window.NodeFilter.SHOW_ELEMENT", 0x00000001);
     shouldBe("window.NodeFilter.SHOW_ATTRIBUTE", 0x00000002);
     shouldBe("window.NodeFilter.SHOW_TEXT", 0x00000004);
index c1d2513..f8bf8c9 100644 (file)
@@ -1,3 +1,46 @@
+2014-03-26  Antonio Gomes  <a1.gomes@sisa.samsung.com>
+
+        [Bindings] constants are always typed to 'int'
+        https://bugs.webkit.org/show_bug.cgi?id=130775
+
+        Reviewed by Darin Adler.
+
+        Patch fixes a bug where all constant getter generated
+        methods were returning 'integer' values due to static_cast.
+
+        Compilers should be smarth enough to properly infer which
+        jsNumber class construtor to call given a literal value.
+
+        Patch also fixes a bug where values whose representation
+        is bigger an integer maximum were overflowing. For instance,
+        NodeFilter.SHOW_ALL (0xFFFFFFFF).
+
+        Tests:
+        Binding tests updated.
+        Rebaselined fast/dom/constants.html
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        * bindings/scripts/test/JS/JSTestInterface.cpp:
+        (WebCore::jsTestInterfaceIMPLEMENTSCONSTANT1):
+        (WebCore::jsTestInterfaceIMPLEMENTSCONSTANT2):
+        (WebCore::jsTestInterfaceSUPPLEMENTALCONSTANT1):
+        (WebCore::jsTestInterfaceSUPPLEMENTALCONSTANT2):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjCONDITIONAL_CONST):
+        (WebCore::jsTestObjCONST_VALUE_0):
+        (WebCore::jsTestObjCONST_VALUE_1):
+        (WebCore::jsTestObjCONST_VALUE_2):
+        (WebCore::jsTestObjCONST_VALUE_4):
+        (WebCore::jsTestObjCONST_VALUE_8):
+        (WebCore::jsTestObjCONST_VALUE_9):
+        (WebCore::jsTestObjCONST_VALUE_11):
+        (WebCore::jsTestObjCONST_VALUE_12):
+        (WebCore::jsTestObjCONST_VALUE_13):
+        (WebCore::jsTestObjCONST_VALUE_14):
+        (WebCore::jsTestObjCONST_JAVASCRIPT):
+        (WebCore::jsTestObjReadonly):
+
 2014-03-28  Myles C. Maxfield  <mmaxfield@apple.com>
 
         A TrailingObject's endpoint might get decremented twice
index 7e09687..4a9c12c 100644 (file)
@@ -2821,14 +2821,13 @@ sub GenerateImplementation
                 push(@implContent, "#if ${conditionalString}\n");
             }
 
-            # FIXME: this casts into int to match our previous behavior which turned 0xFFFFFFFF in -1 for NodeFilter.SHOW_ALL
             push(@implContent, "EncodedJSValue ${getter}(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)\n");
             push(@implContent, "{\n");
             if ($constant->type eq "DOMString") {
                 push(@implContent, "    return JSValue::encode(jsStringOrNull(exec, String(" . $constant->value . ")));\n");
             } else {
                 push(@implContent, "    UNUSED_PARAM(exec);\n");
-                push(@implContent, "    return JSValue::encode(jsNumber(static_cast<int>(" . $constant->value . ")));\n");
+                push(@implContent, "    return JSValue::encode(jsNumber(" . $constant->value . "));\n");
             }
             push(@implContent, "}\n\n");
             push(@implContent, "#endif\n") if $conditional;
index bd783ab..51aa10e 100644 (file)
@@ -932,7 +932,7 @@ EncodedJSValue JSC_HOST_CALL jsTestInterfaceConstructorFunctionSupplementalMetho
 EncodedJSValue jsTestInterfaceIMPLEMENTSCONSTANT1(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(1)));
+    return JSValue::encode(jsNumber(1));
 }
 
 #endif
@@ -940,7 +940,7 @@ EncodedJSValue jsTestInterfaceIMPLEMENTSCONSTANT1(ExecState* exec, JSObject*, En
 EncodedJSValue jsTestInterfaceIMPLEMENTSCONSTANT2(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(2)));
+    return JSValue::encode(jsNumber(2));
 }
 
 #endif
@@ -948,7 +948,7 @@ EncodedJSValue jsTestInterfaceIMPLEMENTSCONSTANT2(ExecState* exec, JSObject*, En
 EncodedJSValue jsTestInterfaceSUPPLEMENTALCONSTANT1(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(1)));
+    return JSValue::encode(jsNumber(1));
 }
 
 #endif
@@ -956,7 +956,7 @@ EncodedJSValue jsTestInterfaceSUPPLEMENTALCONSTANT1(ExecState* exec, JSObject*,
 EncodedJSValue jsTestInterfaceSUPPLEMENTALCONSTANT2(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(2)));
+    return JSValue::encode(jsNumber(2));
 }
 
 #endif
index b81e21b..a141e5e 100644 (file)
@@ -4689,44 +4689,44 @@ void JSTestObj::visitChildren(JSCell* cell, SlotVisitor& visitor)
 EncodedJSValue jsTestObjCONDITIONAL_CONST(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(0)));
+    return JSValue::encode(jsNumber(0));
 }
 
 #endif
 EncodedJSValue jsTestObjCONST_VALUE_0(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(0)));
+    return JSValue::encode(jsNumber(0));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_1(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(1)));
+    return JSValue::encode(jsNumber(1));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_2(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(2)));
+    return JSValue::encode(jsNumber(2));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_4(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(4)));
+    return JSValue::encode(jsNumber(4));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_8(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(8)));
+    return JSValue::encode(jsNumber(8));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_9(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(-1)));
+    return JSValue::encode(jsNumber(-1));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_10(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
@@ -4737,37 +4737,37 @@ EncodedJSValue jsTestObjCONST_VALUE_10(ExecState* exec, JSObject*, EncodedJSValu
 EncodedJSValue jsTestObjCONST_VALUE_11(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(0xffffffff)));
+    return JSValue::encode(jsNumber(0xffffffff));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_12(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(0x01)));
+    return JSValue::encode(jsNumber(0x01));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_13(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(0X20)));
+    return JSValue::encode(jsNumber(0X20));
 }
 
 EncodedJSValue jsTestObjCONST_VALUE_14(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(0x1abc)));
+    return JSValue::encode(jsNumber(0x1abc));
 }
 
 EncodedJSValue jsTestObjCONST_JAVASCRIPT(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(15)));
+    return JSValue::encode(jsNumber(15));
 }
 
 EncodedJSValue jsTestObjReadonly(ExecState* exec, JSObject*, EncodedJSValue, PropertyName)
 {
     UNUSED_PARAM(exec);
-    return JSValue::encode(jsNumber(static_cast<int>(0)));
+    return JSValue::encode(jsNumber(0));
 }
 
 bool JSTestObjOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)