Reviewed by Darin.

        - Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=5409
        slice() testcase doesn't pass

        Modified String.slice to deal with funky values.
        Updated test results. We now pass <js1_2/String/slice.js>.

        * kjs/string_object.cpp:
        (StringProtoFuncImp::callAsFunction):
        * tests/mozilla/expected.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@11077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/kjs/string_object.cpp b/JavaScriptCore/kjs/string_object.cpp
index abd4139..8283bc1 100644
--- a/JavaScriptCore/kjs/string_object.cpp
+++ b/JavaScriptCore/kjs/string_object.cpp
@@ -510,31 +510,21 @@
     break;
   case Slice:
     {
-        // The arg processing is very much like ArrayProtoFunc::Slice
-        double begin = args[0]->toInteger(exec);
-        if (begin >= 0) { // false for NaN
-          if (begin > len)
-            begin = len;
-        } else {
-          begin += len;
-          if (!(begin >= 0)) // true for NaN
-            begin = 0;
-        }
-        double end = len;
-        if (!args[1]->isUndefined()) {
-          end = args[1]->toInteger(exec);
-          if (end >= 0) { // false for NaN
-            if (end > len)
-              end = len;
-          } else {
-            end += len;
-            if (!(end >= 0)) // true for NaN
-              end = 0;
-          }
-        }
-        //printf( "Slicing from %d to %d \n", begin, end );
-        result = String(s.substr(static_cast<int>(begin), static_cast<int>(end-begin)));
-        break;
+      // The arg processing is very much like ArrayProtoFunc::Slice
+      double start = a0->toInteger(exec);
+      double end = a1->isUndefined() ? len : a1->toInteger(exec);
+      double from = start < 0 ? len + start : start;
+      double to = end < 0 ? len + end : end;
+      if (to > from && to > 0 && from < len) {
+        if (from < 0)
+          from = 0;
+        if (to > len)
+          to = len;
+        result = String(s.substr(static_cast<int>(from), static_cast<int>(to - from)));
+      } else {
+        result = String("");
+      }
+      break;
     }
     case Split: {
     ObjectImp *constructor = exec->lexicalInterpreter()->builtinArray();