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

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

Issue 2778623003: [typedarrays] Check detached buffer at start of typed array methods (Closed)
Patch Set: pass test262 for subarray Created 3 years, 8 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 | « test/mjsunit/es6/typedarray-foreach.js ('k') | test/mjsunit/es6/typedarray-iteration.js » ('j') | 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 // Flags: --allow-natives-syntax
6
5 var typedArrayConstructors = [ 7 var typedArrayConstructors = [
6 Uint8Array, 8 Uint8Array,
7 Int8Array, 9 Int8Array,
8 Uint16Array, 10 Uint16Array,
9 Int16Array, 11 Int16Array,
10 Uint32Array, 12 Uint32Array,
11 Int32Array, 13 Int32Array,
12 Uint8ClampedArray, 14 Uint8ClampedArray,
13 Float32Array, 15 Float32Array,
14 Float64Array 16 Float64Array
15 ]; 17 ];
16 18
19 var tmp = {
20 [Symbol.toPrimitive]() {
21 assertUnreachable("Parameter should not be processed when " +
22 "array.[[ViewedArrayBuffer]] is neutered.");
23 return 0;
24 }
25 };
26
17 for (var constructor of typedArrayConstructors) { 27 for (var constructor of typedArrayConstructors) {
18 var array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]); 28 var array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]);
19 29
20 // ---------------------------------------------------------------------- 30 // ----------------------------------------------------------------------
21 // %TypedArray%.prototype.indexOf. 31 // %TypedArray%.prototype.indexOf.
22 // ---------------------------------------------------------------------- 32 // ----------------------------------------------------------------------
23 33
24 // Negative cases. 34 // Negative cases.
25 assertEquals(-1, new constructor([]).indexOf(1)); 35 assertEquals(-1, new constructor([]).indexOf(1));
26 assertEquals(-1, array.indexOf(4)); 36 assertEquals(-1, array.indexOf(4));
(...skipping 19 matching lines...) Expand all
46 array = new constructor([NaN, 2, 3, +Infinity, -Infinity, 5, 6]); 56 array = new constructor([NaN, 2, 3, +Infinity, -Infinity, 5, 6]);
47 if (constructor == Float32Array || constructor == Float64Array) { 57 if (constructor == Float32Array || constructor == Float64Array) {
48 assertEquals(3, array.indexOf(Infinity)); 58 assertEquals(3, array.indexOf(Infinity));
49 assertEquals(4, array.indexOf(-Infinity)); 59 assertEquals(4, array.indexOf(-Infinity));
50 } else { 60 } else {
51 assertEquals(-1, array.indexOf(Infinity)); 61 assertEquals(-1, array.indexOf(Infinity));
52 assertEquals(-1, array.indexOf(-Infinity)); 62 assertEquals(-1, array.indexOf(-Infinity));
53 } 63 }
54 assertEquals(-1, array.indexOf(NaN)); 64 assertEquals(-1, array.indexOf(NaN));
55 65
66 // Detached Operation
67 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
68 %ArrayBufferNeuter(array.buffer);
69
70 assertThrows(() => array.indexOf(tmp), TypeError);
71
56 // ---------------------------------------------------------------------- 72 // ----------------------------------------------------------------------
57 // %TypedArray%.prototype.lastIndexOf. 73 // %TypedArray%.prototype.lastIndexOf.
58 // ---------------------------------------------------------------------- 74 // ----------------------------------------------------------------------
59 array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]); 75 array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]);
60 76
61 // Negative cases. 77 // Negative cases.
62 assertEquals(-1, new constructor([]).lastIndexOf(1)); 78 assertEquals(-1, new constructor([]).lastIndexOf(1));
63 assertEquals(-1, array.lastIndexOf(1, -17)); 79 assertEquals(-1, array.lastIndexOf(1, -17));
64 80
65 assertEquals(9, array.lastIndexOf(1)); 81 assertEquals(9, array.lastIndexOf(1));
(...skipping 16 matching lines...) Expand all
82 // Index of infinite value 98 // Index of infinite value
83 array = new constructor([NaN, 2, 3, +Infinity, -Infinity, 5, 6]); 99 array = new constructor([NaN, 2, 3, +Infinity, -Infinity, 5, 6]);
84 if (constructor == Float32Array || constructor == Float64Array) { 100 if (constructor == Float32Array || constructor == Float64Array) {
85 assertEquals(3, array.lastIndexOf(Infinity)); 101 assertEquals(3, array.lastIndexOf(Infinity));
86 assertEquals(4, array.lastIndexOf(-Infinity)); 102 assertEquals(4, array.lastIndexOf(-Infinity));
87 } else { 103 } else {
88 assertEquals(-1, array.lastIndexOf(Infinity)); 104 assertEquals(-1, array.lastIndexOf(Infinity));
89 assertEquals(-1, array.lastIndexOf(-Infinity)); 105 assertEquals(-1, array.lastIndexOf(-Infinity));
90 } 106 }
91 assertEquals(-1, array.lastIndexOf(NaN)); 107 assertEquals(-1, array.lastIndexOf(NaN));
108
109 // Detached Operation
110 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
111 %ArrayBufferNeuter(array.buffer);
112 assertThrows(() => array.lastIndexOf(tmp), TypeError);
92 } 113 }
OLDNEW
« no previous file with comments | « test/mjsunit/es6/typedarray-foreach.js ('k') | test/mjsunit/es6/typedarray-iteration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698