Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: test/mjsunit/harmony/typedarray-slice.js

Issue 1170023002: Implement %TypedArray%.prototype.slice (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/harmony-typedarray.js ('K') | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-arrays
6
7 var typedArrayConstructors = [
8 Uint8Array,
9 Int8Array,
10 Uint16Array,
11 Int16Array,
12 Uint32Array,
13 Int32Array,
14 Uint8ClampedArray,
15 Float32Array,
16 Float64Array
17 ];
18
19 for (var constructor of typedArrayConstructors) {
20 // Check various variants of empty array's slicing.
21 var array = new constructor(0);
22 for (var i = 0; i < 7; i++) {
23 assertEquals(0, array.slice(0, 0).length);
24 assertEquals(0, array.slice(1, 0).length);
25 assertEquals(0, array.slice(0, 1).length);
26 assertEquals(0, array.slice(-1, 0).length);
27 }
28
29
30 // Check various forms of arguments omission.
31 array = new constructor(7);
32
33 for (var i = 0; i < 7; i++) {
34 assertEquals(array, array.slice());
35 assertEquals(array, array.slice(0));
36 assertEquals(array, array.slice(undefined));
37 assertEquals(array, array.slice("foobar"));
38 assertEquals(array, array.slice(undefined, undefined));
39 }
40
41
42 // Check variants of negatives and positive indices.
43 array = new constructor(7);
44
45 assertEquals(7, array.slice(-100).length);
46 assertEquals(3, array.slice(-3).length);
47 assertEquals(3, array.slice(4).length);
48 assertEquals(1, array.slice(6).length);
49 assertEquals(0, array.slice(7).length);
50 assertEquals(0, array.slice(8).length);
51 assertEquals(0, array.slice(100).length);
52
53 assertEquals(0, array.slice(0, -100).length);
54 assertEquals(4, array.slice(0, -3).length);
55 assertEquals(4, array.slice(0, 4).length);
56 assertEquals(6, array.slice(0, 6).length);
57 assertEquals(7, array.slice(0, 7).length);
58 assertEquals(7, array.slice(0, 8).length);
59 assertEquals(7, array.slice(0, 100).length);
60
61 // Does not permit being called on other types
62 assertThrows(function () {
63 constructor.prototype.slice.call([], 0, 0);
64 }, TypeError);
65
66 // Check that elements are copied properly in slice
67 array = new constructor([1, 2, 3, 4]);
68 var slice = array.slice(1, 3);
69 assertEquals(2, slice.length);
70 assertEquals(2, slice[0]);
71 assertEquals(3, slice[1]);
72 assertTrue(slice instanceof constructor);
73 }
OLDNEW
« src/harmony-typedarray.js ('K') | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698