Index: test/mjsunit/harmony/typedarrays.js |
diff --git a/test/mjsunit/harmony/typedarrays.js b/test/mjsunit/harmony/typedarrays.js |
index 70bd17e3382db1cdb115d5aae6e48cf9141bc82a..8c520151e86e8d2d16bb02ffbc666baacff34d59 100644 |
--- a/test/mjsunit/harmony/typedarrays.js |
+++ b/test/mjsunit/harmony/typedarrays.js |
@@ -69,21 +69,21 @@ function TestByteLengthNotWritable() { |
TestByteLengthNotWritable(); |
-function TestSlice(expectedResultLen, initialLen, start, end) { |
- var ab = new ArrayBuffer(initialLen); |
- var a1 = new Uint8Array(ab); |
- for (var i = 0; i < a1.length; i++) { |
- a1[i] = 0xCA; |
- } |
- var slice = ab.slice(start, end); |
- assertSame(expectedResultLen, slice.byteLength); |
- var a2 = new Uint8Array(slice); |
- for (var i = 0; i < a2.length; i++) { |
- assertSame(0xCA, a2[i]); |
+function TestArrayBufferSlice() { |
+ function TestSlice(expectedResultLen, initialLen, start, end) { |
+ var ab = new ArrayBuffer(initialLen); |
+ var a1 = new Uint8Array(ab); |
+ for (var i = 0; i < a1.length; i++) { |
+ a1[i] = 0xCA; |
+ } |
+ var slice = ab.slice(start, end); |
+ assertSame(expectedResultLen, slice.byteLength); |
+ var a2 = new Uint8Array(slice); |
+ for (var i = 0; i < a2.length; i++) { |
+ assertSame(0xCA, a2[i]); |
+ } |
} |
-} |
-function TestArrayBufferSlice() { |
var ab = new ArrayBuffer(1024); |
var ab1 = ab.slice(512, 1024); |
assertSame(512, ab1.byteLength); |
@@ -119,6 +119,55 @@ function TestArrayBufferSlice() { |
TestArrayBufferSlice(); |
+function TestTypedArraySlice() { |
+ function TestSlice(expectedResultLen, initialLen, start, end) { |
+ var a1 = new Uint32Array(initialLen); |
+ for (var i = 0; i < a1.length; i++) { |
+ a1[i] = 0x12345678; |
+ } |
+ var slice = a1.slice(start, end); |
+ assertSame(expectedResultLen, slice.length); |
+ var a2 = new Uint32Array(slice); |
+ for (var i = 0; i < a2.length; i++) { |
+ assertSame(0x12345678, a2[i]); |
+ } |
+ } |
+ |
+ var ab = new Uint32Array(1024); |
+ var ab1 = ab.slice(512, 1024); |
+ assertSame(512, ab1.length); |
+ |
+ TestSlice(512, 1024, 512, 1024); |
+ TestSlice(512, 1024, 512); |
+ |
+ TestSlice(0, 0, 1, 20); |
+ TestSlice(100, 100, 0, 100); |
+ TestSlice(100, 100, 0, 1000); |
+ |
+ TestSlice(0, 100, 5, 1); |
+ |
+ TestSlice(1, 100, -11, -10); |
+ TestSlice(9, 100, -10, 99); |
+ TestSlice(0, 100, -10, 80); |
+ TestSlice(10, 100, 80, -10); |
+ |
+ TestSlice(10, 100, 90, "100"); |
+ TestSlice(10, 100, "90", "100"); |
+ |
+ TestSlice(0, 100, 90, "abc"); |
+ TestSlice(10, 100, "abc", 10); |
+ |
+ TestSlice(10, 100, 0.96, 10.96); |
+ TestSlice(10, 100, 0.96, 10.01); |
+ TestSlice(10, 100, 0.01, 10.01); |
+ TestSlice(10, 100, 0.01, 10.96); |
+ |
+ TestSlice(10, 100, 90); |
+ TestSlice(10, 100, -10); |
+} |
+ |
+TestTypedArraySlice(); |
+ |
// Typed arrays |
function TestTypedArray(constr, elementSize, typicalElement) { |