Fix String.prototype.slice with boundary values
authorSimon Hausmann <simon.hausmann@digia.com>
Tue, 22 Jan 2013 12:52:13 +0000 (13:52 +0100)
committerLars Knoll <lars.knoll@digia.com>
Tue, 22 Jan 2013 14:12:54 +0000 (15:12 +0100)
The bounding must be done on doubles to be spec compliant.

Change-Id: Ic4a0311893680ca3855fe83e5075f65b05a26abf
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
qv4stringobject.cpp
tests/TestExpectations

index 178c625..7766b10 100644 (file)
@@ -488,24 +488,27 @@ Value StringPrototype::method_search(ExecutionContext *ctx)
 Value StringPrototype::method_slice(ExecutionContext *ctx)
 {
     const QString text = getThisString(ctx);
-    const int length = text.length();
+    const double length = text.length();
 
-    int start = int (ctx->argument(0).toInteger(ctx));
-    int end = ctx->argument(1).isUndefined()
-            ? length : int (ctx->argument(1).toInteger(ctx));
+    double start = ctx->argument(0).toInteger(ctx);
+    double end = ctx->argument(1).isUndefined()
+            ? length : ctx->argument(1).toInteger(ctx);
 
     if (start < 0)
-        start = qMax(length + start, 0);
+        start = qMax(length + start, 0.);
     else
         start = qMin(start, length);
 
     if (end < 0)
-        end = qMax(length + end, 0);
+        end = qMax(length + end, 0.);
     else
         end = qMin(end, length);
 
-    int count = qMax(0, end - start);
-    return Value::fromString(ctx, text.mid(start, count));
+    const int intStart = int(start);
+    const int intEnd = int(end);
+
+    int count = qMax(0, intEnd - intStart);
+    return Value::fromString(ctx, text.mid(intStart, count));
 }
 
 Value StringPrototype::method_split(ExecutionContext *ctx)
index a5a9f02..2fd3077 100644 (file)
@@ -540,8 +540,6 @@ S15.4.4.8_A3_T2 failing
 S15.4.4.8_A3_T3 failing
 S15.4.4.8_A4_T1 failing
 S15.4.4.8_A4_T2 failing
-S15.5.4.13_A2_T2 failing
-S15.5.4.13_A3_T3 failing
 15.5.4.20-4-1 failing
 S15.5.4.8_A1_T4 failing
 S15.7.4.5_A1.4_T01 failing