Reviewed by Anders.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Feb 2007 21:56:43 +0000 (21:56 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Feb 2007 21:56:43 +0000 (21:56 +0000)
        - fix <rdar://problem/5000216> JavaScriptGlue framework started turning all CFNumbers
          into signed 32bit values

        Circumstantial evidence seems to indicate that JavaScriptGlue was depending on a bug
        in CFNumber where CFNumberIsFloatType was returning true for 64-bit integer values.

        * JSUtils.cpp: (JSObjectKJSValue): Removed the call to CFNumberIsFloatType in the
        conversion of numeric values, and always use kCFNumberDoubleType, since double is
        the internal format of numbers in JavaScriptCore. There's no value to having a
        separate code path for integers. There's also no reason to check the return value
        from CFNumberGetValue -- if it returns false it still does the best it can to convert
        to a double, which is what we want.

        * UserObjectImp.cpp: (UserObjectImp::toString): Removed a similar code path that
        tried to handle integers separate from double. Instead, always use a double. For
        compatibility, use a format without a decimal point when CFNumberIsFloatType returns
        false. Also removed a bogus cast to float; the "%f" format string takes a double,
        not a float, so all the cast did was cut down on precision.

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

JavaScriptGlue/ChangeLog
JavaScriptGlue/JSUtils.cpp
JavaScriptGlue/UserObjectImp.cpp

index a7b0b581cec9ef2afba19f1dc009ee29f344759b..0cf24ccc158340f3a4f618d18d26d49048257ea5 100644 (file)
@@ -1,3 +1,26 @@
+2007-02-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders.
+
+        - fix <rdar://problem/5000216> JavaScriptGlue framework started turning all CFNumbers
+          into signed 32bit values
+
+        Circumstantial evidence seems to indicate that JavaScriptGlue was depending on a bug
+        in CFNumber where CFNumberIsFloatType was returning true for 64-bit integer values.
+
+        * JSUtils.cpp: (JSObjectKJSValue): Removed the call to CFNumberIsFloatType in the
+        conversion of numeric values, and always use kCFNumberDoubleType, since double is
+        the internal format of numbers in JavaScriptCore. There's no value to having a
+        separate code path for integers. There's also no reason to check the return value
+        from CFNumberGetValue -- if it returns false it still does the best it can to convert
+        to a double, which is what we want.
+
+        * UserObjectImp.cpp: (UserObjectImp::toString): Removed a similar code path that
+        tried to handle integers separate from double. Instead, always use a double. For
+        compatibility, use a format without a decimal point when CFNumberIsFloatType returns
+        false. Also removed a bogus cast to float; the "%f" format string takes a double,
+        not a float, so all the cast did was cut down on precision.
+
 2007-01-25  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Maciej.
index 22d52f354928510f7725e9318481674ff91d5df6..842686eba77cd7e2412f9ef89baeffffcafbd355 100644 (file)
@@ -162,33 +162,16 @@ JSValue *JSObjectKJSValue(JSUserObject* ptr)
                     }
                     else if (typeID == CFNumberGetTypeID())
                     {
-                        if (CFNumberIsFloatType((CFNumberRef)cfType))
-                        {
-                            double num;
-                            if (CFNumberGetValue((CFNumberRef)cfType, kCFNumberDoubleType, &num))
-                            {
-                                result = jsNumber(num);
-                                handled = true;
-                            }
-                        }
-                        else
-                        {
-                            long num;
-                            if (CFNumberGetValue((CFNumberRef)cfType, kCFNumberLongType, &num))
-                            {
-                                result = jsNumber(num);
-                                handled = true;
-                            }
-                        }
+                        double num;
+                        CFNumberGetValue((CFNumberRef)cfType, kCFNumberDoubleType, &num);
+                        result = jsNumber(num);
+                        handled = true;
                     }
                     else if (typeID == CFBooleanGetTypeID())
                     {
                         result = jsBoolean(CFBooleanGetValue((CFBooleanRef)cfType));
                         handled = true;
                     }
-                    else if (typeID == CFDateGetTypeID())
-                    {
-                    }
                     else if (typeID == CFNullGetTypeID())
                     {
                         result = jsNull();
index 247dde6f062fcc3be6cc994f6de48f8e4e26152b..6c1ad9d08a1be35f7e67b4388332c22c3f2eca2a 100644 (file)
@@ -391,25 +391,19 @@ UString UserObjectImp::toString(ExecState *exec) const
             }
             else
             {
-                CFStringRef cfNumStr = 0;
+                CFStringRef cfNumStr;
+                double d = 0;
+                CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d);
                 if (CFNumberIsFloatType((CFNumberRef)cfValue))
                 {
-                    double d = 0;
-                    CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d);
-                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%f"), (float)d);
+                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%f"), d);
                 }
                 else
                 {
-                    int i = 0;
-                    CFNumberGetValue((CFNumberRef)cfValue, kCFNumberIntType, &i);
-                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%d"), (int)i);
-                }
-
-                if (cfNumStr)
-                {
-                    result = CFStringToUString(cfNumStr);
-                    ReleaseCFType(cfNumStr);
+                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%.0f"), d);
                 }
+                result = CFStringToUString(cfNumStr);
+                ReleaseCFType(cfNumStr);
             }
         }
         else if (cfType == CFArrayGetTypeID())