Revision: 2567
Author: [email protected]
Date: Tue Jul 28 14:26:31 2009
Log: Merge r2564 to branches/1.2:
- Clamp double values as doubles to get a free NaN check and
   to handle infinity properly.

Review URL: http://codereview.chromium.org/159537
http://code.google.com/p/v8/source/detail?r=2567

Modified:
  /branches/1.2/src/objects.cc
  /branches/1.2/src/version.cc
  /branches/1.2/test/cctest/test-api.cc

=======================================
--- /branches/1.2/src/objects.cc        Tue Jul 28 06:14:21 2009
+++ /branches/1.2/src/objects.cc        Tue Jul 28 14:26:31 2009
@@ -7056,28 +7056,32 @@
  Object* PixelArray::SetValue(uint32_t index, Object* value) {
    uint8_t clamped_value = 0;
    if (index < static_cast<uint32_t>(length())) {
-    int int_value = 0;
      if (value->IsSmi()) {
-      int_value = Smi::cast(value)->value();
+      int int_value = Smi::cast(value)->value();
+      if (int_value < 0) {
+        clamped_value = 0;
+      } else if (int_value > 255) {
+        clamped_value = 255;
+      } else {
+        clamped_value = static_cast<uint8_t>(int_value);
+      }
      } else if (value->IsHeapNumber()) {
        double double_value = HeapNumber::cast(value)->value();
-      if (!isnan(double_value)) {
-        // NaN clamps to zero (default). Other doubles are rounded to
-        // the nearest integer.
-        int_value = static_cast<int>(double_value + 0.5);
+      if (!(double_value > 0)) {
+        // NaN and less than zero clamp to zero.
+        clamped_value = 0;
+      } else if (double_value > 255) {
+        // Greater than 255 clamp to 255.
+        clamped_value = 255;
+      } else {
+        // Other doubles are rounded to the nearest integer.
+        clamped_value = static_cast<uint8_t>(double_value + 0.5);
        }
      } else {
        // Clamp undefined to zero (default). All other types have been
        // converted to a number type further up in the call chain.
        ASSERT(value->IsUndefined());
      }
-    if (int_value < 0) {
-      clamped_value = 0;
-    } else if (int_value > 255) {
-      clamped_value = 255;
-    } else {
-      clamped_value = static_cast<uint8_t>(int_value);
-    }
      set(index, clamped_value);
    }
    return Smi::FromInt(clamped_value);
=======================================
--- /branches/1.2/src/version.cc        Tue Jul 28 06:14:21 2009
+++ /branches/1.2/src/version.cc        Tue Jul 28 14:26:31 2009
@@ -35,7 +35,7 @@
  #define MAJOR_VERSION     1
  #define MINOR_VERSION     2
  #define BUILD_NUMBER      14
-#define PATCH_LEVEL       10
+#define PATCH_LEVEL       11
  #define CANDIDATE_VERSION false

  // Define SONAME to have the SCons build the put a specific SONAME into the
=======================================
--- /branches/1.2/test/cctest/test-api.cc       Tue Jul 28 04:43:17 2009
+++ /branches/1.2/test/cctest/test-api.cc       Tue Jul 28 14:26:31 2009
@@ -7234,6 +7234,20 @@
    CHECK_EQ(0, result->Int32Value());
    CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(5))->value());

+  result = CompileRun("for (var i = 0; i < 8; i++) {"
+                      "  pixels[8] = Infinity;"
+                      "}"
+                      "pixels[8];");
+  CHECK_EQ(255, result->Int32Value());
+  CHECK_EQ(255, i::Smi::cast(jsobj->GetElement(8))->value());
+
+  result = CompileRun("for (var i = 0; i < 8; i++) {"
+                      "  pixels[9] = -Infinity;"
+                      "}"
+                      "pixels[9];");
+  CHECK_EQ(0, result->Int32Value());
+  CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(9))->value());
+
    result = CompileRun("pixels[3] = 33;"
                        "delete pixels[3];"
                        "pixels[3];");

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to