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

Side by Side Diff: test/mjsunit/es6/typedarray-indexing.js

Issue 2744283002: [typedarrays] Implement %TypedArray%.prototype.lastIndexOf in C++ (Closed)
Patch Set: Correct integral value check Created 3 years, 9 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
« no previous file with comments | « src/js/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
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var typedArrayConstructors = [ 5 var typedArrayConstructors = [
6 Uint8Array, 6 Uint8Array,
7 Int8Array, 7 Int8Array,
8 Uint16Array, 8 Uint16Array,
9 Int16Array, 9 Int16Array,
10 Uint32Array, 10 Uint32Array,
(...skipping 24 matching lines...) Expand all
35 assertEquals(3, array.indexOf(1, 1)); 35 assertEquals(3, array.indexOf(1, 1));
36 assertEquals(3, array.indexOf(1, 3)); 36 assertEquals(3, array.indexOf(1, 3));
37 assertEquals(6, array.indexOf(1, 4)); 37 assertEquals(6, array.indexOf(1, 4));
38 38
39 // Basic TypedArray function properties 39 // Basic TypedArray function properties
40 assertEquals(1, array.indexOf.length); 40 assertEquals(1, array.indexOf.length);
41 assertThrows(function(){ array.indexOf.call([1], 1); }, TypeError); 41 assertThrows(function(){ array.indexOf.call([1], 1); }, TypeError);
42 Object.defineProperty(array, 'length', {value: 1}); 42 Object.defineProperty(array, 'length', {value: 1});
43 assertEquals(array.indexOf(2), 1); 43 assertEquals(array.indexOf(2), 1);
44 44
45 // Index of infinite value
46 array = new constructor([NaN, 2, 3, +Infinity, -Infinity, 5, 6]);
47 if (constructor == Float32Array || constructor == Float64Array) {
48 assertEquals(3, array.indexOf(Infinity));
49 assertEquals(4, array.indexOf(-Infinity));
50 } else {
51 assertEquals(-1, array.indexOf(Infinity));
52 assertEquals(-1, array.indexOf(-Infinity));
53 }
54 assertEquals(-1, array.indexOf(NaN));
45 55
46 // ---------------------------------------------------------------------- 56 // ----------------------------------------------------------------------
47 // %TypedArray%.prototype.lastIndexOf. 57 // %TypedArray%.prototype.lastIndexOf.
48 // ---------------------------------------------------------------------- 58 // ----------------------------------------------------------------------
49 array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]); 59 array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]);
50 60
51 // Negative cases. 61 // Negative cases.
52 assertEquals(-1, new constructor([]).lastIndexOf(1)); 62 assertEquals(-1, new constructor([]).lastIndexOf(1));
53 assertEquals(-1, array.lastIndexOf(1, -17)); 63 assertEquals(-1, array.lastIndexOf(1, -17));
54 64
55 assertEquals(9, array.lastIndexOf(1)); 65 assertEquals(9, array.lastIndexOf(1));
56 // Index out of range. 66 // Index out of range.
57 assertEquals(9, array.lastIndexOf(1, array.length)); 67 assertEquals(9, array.lastIndexOf(1, array.length));
58 // Index in range. 68 // Index in range.
59 assertEquals(0, array.lastIndexOf(1, 2)); 69 assertEquals(0, array.lastIndexOf(1, 2));
60 assertEquals(3, array.lastIndexOf(1, 4)); 70 assertEquals(3, array.lastIndexOf(1, 4));
61 assertEquals(3, array.lastIndexOf(1, 3)); 71 assertEquals(3, array.lastIndexOf(1, 3));
62 // Negative index in range. 72 // Negative index in range.
63 assertEquals(0, array.lastIndexOf(1, -11)); 73 assertEquals(0, array.lastIndexOf(1, -11));
64 74
65 // Basic TypedArray function properties 75 // Basic TypedArray function properties
66 assertEquals(1, array.lastIndexOf.length); 76 assertEquals(1, array.lastIndexOf.length);
67 assertThrows(function(){ array.lastIndexOf.call([1], 1); }, TypeError); 77 assertThrows(function(){ array.lastIndexOf.call([1], 1); }, TypeError);
68 Object.defineProperty(array, 'length', {value: 1}); 78 Object.defineProperty(array, 'length', {value: 1});
69 assertEquals(array.lastIndexOf(2), 10); 79 assertEquals(array.lastIndexOf(2), 10);
70 delete array.length; 80 delete array.length;
81
82 // Index of infinite value
83 array = new constructor([NaN, 2, 3, +Infinity, -Infinity, 5, 6]);
84 if (constructor == Float32Array || constructor == Float64Array) {
85 assertEquals(3, array.lastIndexOf(Infinity));
86 assertEquals(4, array.lastIndexOf(-Infinity));
87 } else {
88 assertEquals(-1, array.lastIndexOf(Infinity));
89 assertEquals(-1, array.lastIndexOf(-Infinity));
90 }
91 assertEquals(-1, array.lastIndexOf(NaN));
71 } 92 }
OLDNEW
« no previous file with comments | « src/js/typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698