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

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

Issue 2827443002: Reland [typedarrays] Check detached buffer at start of typed array methods (Closed)
Patch Set: rebase 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-every.js ('k') | test/mjsunit/es6/typedarray-find.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 intArrayConstructors = [ 7 var intArrayConstructors = [
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 ]; 15 ];
14 16
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 new constructor(3).fill(p); 62 new constructor(3).fill(p);
61 assertEquals(["Symbol(Symbol.toPrimitive)", "valueOf", "toString", "Symbol(Sym bol.toStringTag)"], s); 63 assertEquals(["Symbol(Symbol.toPrimitive)", "valueOf", "toString", "Symbol(Sym bol.toStringTag)"], s);
62 64
63 // Shadowing length doesn't affect fill, unlike Array.prototype.fill 65 // Shadowing length doesn't affect fill, unlike Array.prototype.fill
64 var a = new constructor([2, 2]); 66 var a = new constructor([2, 2]);
65 Object.defineProperty(a, 'length', {value: 1}); 67 Object.defineProperty(a, 'length', {value: 1});
66 a.fill(3); 68 a.fill(3);
67 assertArrayEquals([3, 3], [a[0], a[1]]); 69 assertArrayEquals([3, 3], [a[0], a[1]]);
68 Array.prototype.fill.call(a, 4); 70 Array.prototype.fill.call(a, 4);
69 assertArrayEquals([4, 3], [a[0], a[1]]); 71 assertArrayEquals([4, 3], [a[0], a[1]]);
72
73 // Detached Operation
74 var tmp = {
75 [Symbol.toPrimitive]() {
76 assertUnreachable("Parameter should not be processed when " +
77 "array.[[ViewedArrayBuffer]] is neutered.");
78 return 0;
79 }
80 };
81 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
82 %ArrayBufferNeuter(array.buffer);
83 assertThrows(() => array.fill(tmp), TypeError);
70 } 84 }
71 85
72 for (var constructor of intArrayConstructors) { 86 for (var constructor of intArrayConstructors) {
73 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(undef ined)); 87 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(undef ined));
74 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill()); 88 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill());
75 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill("abcd ")); 89 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill("abcd "));
76 } 90 }
77 91
78 for (var constructor of floatArrayConstructors) { 92 for (var constructor of floatArrayConstructors) {
79 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill(undefined)); 93 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill(undefined));
80 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill()); 94 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill());
81 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill("abcd")); 95 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill("abcd"));
82 } 96 }
83 97
84 // Clamping 98 // Clamping
85 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- 10)); 99 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- 10));
86 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1000)); 100 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1000));
87 101
88 assertArrayEquals([1, 1, 1, 1, 1], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50001)); 102 assertArrayEquals([1, 1, 1, 1, 1], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50001));
89 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50000)); 103 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50000));
90 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .49999)); 104 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .49999));
91 // Check round half to even 105 // Check round half to even
92 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1 .50000)); 106 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1 .50000));
93 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50000)); 107 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50000));
94 assertArrayEquals([3, 3, 3, 3, 3], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50001)); 108 assertArrayEquals([3, 3, 3, 3, 3], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50001));
95 // Check infinity clamping. 109 // Check infinity clamping.
96 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- Infinity)); 110 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- Infinity));
97 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(Infinity)); 111 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(Infinity));
OLDNEW
« no previous file with comments | « test/mjsunit/es6/typedarray-every.js ('k') | test/mjsunit/es6/typedarray-find.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698