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

Side by Side Diff: src/harmony-array.js

Issue 1309243003: ES6: Array.prototype.slice and friends should use ToLength instead of ToUint32 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 'use strict'; 7 'use strict';
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var GetIterator; 14 var GetIterator;
15 var GetMethod; 15 var GetMethod;
16 var GlobalArray = global.Array; 16 var GlobalArray = global.Array;
17 var GlobalSymbol = global.Symbol; 17 var GlobalSymbol = global.Symbol;
18 var MathMax; 18 var MathMax;
19 var MathMin; 19 var MathMin;
20 var ObjectIsFrozen; 20 var ObjectIsFrozen;
21 var ObjectDefineProperty; 21 var ObjectDefineProperty;
22 var ToNumber; 22 var ToNumber;
23 var ToLengthFlagged;
23 24
24 utils.Import(function(from) { 25 utils.Import(function(from) {
25 GetIterator = from.GetIterator; 26 GetIterator = from.GetIterator;
26 GetMethod = from.GetMethod; 27 GetMethod = from.GetMethod;
27 MathMax = from.MathMax; 28 MathMax = from.MathMax;
28 MathMin = from.MathMin; 29 MathMin = from.MathMin;
29 ObjectIsFrozen = from.ObjectIsFrozen; 30 ObjectIsFrozen = from.ObjectIsFrozen;
30 ObjectDefineProperty = from.ObjectDefineProperty; 31 ObjectDefineProperty = from.ObjectDefineProperty;
31 ToNumber = from.ToNumber; 32 ToNumber = from.ToNumber;
33 ToLengthFlagged = from.ToLengthFlagged;
32 }); 34 });
33 35
34 // ------------------------------------------------------------------- 36 // -------------------------------------------------------------------
35 37
36 function InnerArrayCopyWithin(target, start, end, array, length) { 38 function InnerArrayCopyWithin(target, start, end, array, length) {
37 target = TO_INTEGER(target); 39 target = TO_INTEGER(target);
38 var to; 40 var to;
39 if (target < 0) { 41 if (target < 0) {
40 to = MathMax(length + target, 0); 42 to = MathMax(length + target, 0);
41 } else { 43 } else {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 for (; i < end; i++) 184 for (; i < end; i++)
183 array[i] = value; 185 array[i] = value;
184 return array; 186 return array;
185 } 187 }
186 188
187 // ES6, draft 04-05-14, section 22.1.3.6 189 // ES6, draft 04-05-14, section 22.1.3.6
188 function ArrayFill(value, start, end) { 190 function ArrayFill(value, start, end) {
189 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); 191 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill");
190 192
191 var array = TO_OBJECT(this); 193 var array = TO_OBJECT(this);
192 var length = TO_UINT32(array.length); 194 var length = ToLengthFlagged(array.length);
193 195
194 return InnerArrayFill(value, start, end, array, length); 196 return InnerArrayFill(value, start, end, array, length);
195 } 197 }
196 198
197 function AddArrayElement(constructor, array, i, value) { 199 function AddArrayElement(constructor, array, i, value) {
198 if (constructor === GlobalArray) { 200 if (constructor === GlobalArray) {
199 %AddElement(array, i, value); 201 %AddElement(array, i, value);
200 } else { 202 } else {
201 ObjectDefineProperty(array, i, { 203 ObjectDefineProperty(array, i, {
202 value: value, writable: true, configurable: true, enumerable: true 204 value: value, writable: true, configurable: true, enumerable: true
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 315
314 utils.Export(function(to) { 316 utils.Export(function(to) {
315 to.ArrayFrom = ArrayFrom; 317 to.ArrayFrom = ArrayFrom;
316 to.InnerArrayCopyWithin = InnerArrayCopyWithin; 318 to.InnerArrayCopyWithin = InnerArrayCopyWithin;
317 to.InnerArrayFill = InnerArrayFill; 319 to.InnerArrayFill = InnerArrayFill;
318 to.InnerArrayFind = InnerArrayFind; 320 to.InnerArrayFind = InnerArrayFind;
319 to.InnerArrayFindIndex = InnerArrayFindIndex; 321 to.InnerArrayFindIndex = InnerArrayFindIndex;
320 }); 322 });
321 323
322 }) 324 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698