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

Side by Side Diff: test/mjsunit/es6/typedarray-fill.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-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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 Symbol(Symbol.toStringTag) 71 Symbol(Symbol.toStringTag)
70 `); 72 `);
71 73
72 // Shadowing length doesn't affect fill, unlike Array.prototype.fill 74 // Shadowing length doesn't affect fill, unlike Array.prototype.fill
73 var a = new constructor([2, 2]); 75 var a = new constructor([2, 2]);
74 Object.defineProperty(a, 'length', {value: 1}); 76 Object.defineProperty(a, 'length', {value: 1});
75 a.fill(3); 77 a.fill(3);
76 assertArrayEquals([3, 3], [a[0], a[1]]); 78 assertArrayEquals([3, 3], [a[0], a[1]]);
77 Array.prototype.fill.call(a, 4); 79 Array.prototype.fill.call(a, 4);
78 assertArrayEquals([4, 3], [a[0], a[1]]); 80 assertArrayEquals([4, 3], [a[0], a[1]]);
81
82 // Detached Operation
83 var tmp = {
84 [Symbol.toPrimitive]() {
85 assertUnreachable("Parameter should not be processed when " +
86 "array.[[ViewedArrayBuffer]] is neutered.");
87 return 0;
88 }
89 };
90
91 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
92 %ArrayBufferNeuter(array.buffer);
93 assertThrows(() => array.fill(tmp), TypeError);
79 } 94 }
80 95
81 for (var constructor of intArrayConstructors) { 96 for (var constructor of intArrayConstructors) {
82 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(undef ined)); 97 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(undef ined));
83 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill()); 98 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill());
84 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill("abcd ")); 99 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill("abcd "));
85 } 100 }
86 101
87 for (var constructor of floatArrayConstructors) { 102 for (var constructor of floatArrayConstructors) {
88 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill(undefined)); 103 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill(undefined));
89 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill()); 104 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill());
90 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill("abcd")); 105 assertArrayEquals([NaN, NaN, NaN, NaN, NaN], new constructor([0, 0, 0, 0, 0]). fill("abcd"));
91 } 106 }
92 107
93 // Clamping 108 // Clamping
94 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- 10)); 109 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- 10));
95 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1000)); 110 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1000));
96 111
97 assertArrayEquals([1, 1, 1, 1, 1], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50001)); 112 assertArrayEquals([1, 1, 1, 1, 1], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50001));
98 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50000)); 113 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50000));
99 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .49999)); 114 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .49999));
100 // Check round half to even 115 // Check round half to even
101 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1 .50000)); 116 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1 .50000));
102 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50000)); 117 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50000));
103 assertArrayEquals([3, 3, 3, 3, 3], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50001)); 118 assertArrayEquals([3, 3, 3, 3, 3], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50001));
104 // Check infinity clamping. 119 // Check infinity clamping.
105 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- Infinity)); 120 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- Infinity));
106 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(Infinity)); 121 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