| OLD | NEW |
| 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() { | 5 (function() { |
| 6 | 6 |
| 7 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 var GlobalArray = global.Array; | 11 var GlobalArray = global.Array; |
| 12 var GlobalSymbol = global.Symbol; | 12 var GlobalSymbol = global.Symbol; |
| 13 | 13 |
| 14 // ------------------------------------------------------------------- | 14 // ------------------------------------------------------------------- |
| 15 | 15 |
| 16 // ES6 draft 03-17-15, section 22.1.3.3 | |
| 17 function ArrayCopyWithin(target, start, end) { | |
| 18 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin"); | |
| 19 | |
| 20 var array = TO_OBJECT_INLINE(this); | |
| 21 var length = ToLength(array.length); | |
| 22 | |
| 23 target = TO_INTEGER(target); | |
| 24 var to; | |
| 25 if (target < 0) { | |
| 26 to = $max(length + target, 0); | |
| 27 } else { | |
| 28 to = $min(target, length); | |
| 29 } | |
| 30 | |
| 31 start = TO_INTEGER(start); | |
| 32 var from; | |
| 33 if (start < 0) { | |
| 34 from = $max(length + start, 0); | |
| 35 } else { | |
| 36 from = $min(start, length); | |
| 37 } | |
| 38 | |
| 39 end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); | |
| 40 var final; | |
| 41 if (end < 0) { | |
| 42 final = $max(length + end, 0); | |
| 43 } else { | |
| 44 final = $min(end, length); | |
| 45 } | |
| 46 | |
| 47 var count = $min(final - from, length - to); | |
| 48 var direction = 1; | |
| 49 if (from < to && to < (from + count)) { | |
| 50 direction = -1; | |
| 51 from = from + count - 1; | |
| 52 to = to + count - 1; | |
| 53 } | |
| 54 | |
| 55 while (count > 0) { | |
| 56 if (from in array) { | |
| 57 array[to] = array[from]; | |
| 58 } else { | |
| 59 delete array[to]; | |
| 60 } | |
| 61 from = from + direction; | |
| 62 to = to + direction; | |
| 63 count--; | |
| 64 } | |
| 65 | |
| 66 return array; | |
| 67 } | |
| 68 | |
| 69 // ES6 draft 07-15-13, section 15.4.3.23 | 16 // ES6 draft 07-15-13, section 15.4.3.23 |
| 70 function ArrayFind(predicate /* thisArg */) { // length == 1 | 17 function ArrayFind(predicate /* thisArg */) { // length == 1 |
| 71 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); | 18 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); |
| 72 | 19 |
| 73 var array = ToObject(this); | 20 var array = ToObject(this); |
| 74 var length = ToInteger(array.length); | 21 var length = ToInteger(array.length); |
| 75 | 22 |
| 76 if (!IS_SPEC_FUNCTION(predicate)) { | 23 if (!IS_SPEC_FUNCTION(predicate)) { |
| 77 throw MakeTypeError(kCalledNonCallable, predicate); | 24 throw MakeTypeError(kCalledNonCallable, predicate); |
| 78 } | 25 } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 return array; | 209 return array; |
| 263 } | 210 } |
| 264 | 211 |
| 265 // ------------------------------------------------------------------- | 212 // ------------------------------------------------------------------- |
| 266 | 213 |
| 267 InstallConstants(GlobalSymbol, [ | 214 InstallConstants(GlobalSymbol, [ |
| 268 // TODO(dslomov, caitp): Move to symbol.js when shipping | 215 // TODO(dslomov, caitp): Move to symbol.js when shipping |
| 269 "isConcatSpreadable", symbolIsConcatSpreadable | 216 "isConcatSpreadable", symbolIsConcatSpreadable |
| 270 ]); | 217 ]); |
| 271 | 218 |
| 272 %FunctionSetLength(ArrayCopyWithin, 2); | |
| 273 %FunctionSetLength(ArrayFrom, 1); | 219 %FunctionSetLength(ArrayFrom, 1); |
| 274 | 220 |
| 275 // Set up non-enumerable functions on the Array object. | 221 // Set up non-enumerable functions on the Array object. |
| 276 InstallFunctions(GlobalArray, DONT_ENUM, [ | 222 InstallFunctions(GlobalArray, DONT_ENUM, [ |
| 277 "from", ArrayFrom, | 223 "from", ArrayFrom, |
| 278 "of", ArrayOf | 224 "of", ArrayOf |
| 279 ]); | 225 ]); |
| 280 | 226 |
| 281 // Set up the non-enumerable functions on the Array prototype object. | 227 // Set up the non-enumerable functions on the Array prototype object. |
| 282 InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ | 228 InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ |
| 283 "copyWithin", ArrayCopyWithin, | |
| 284 "find", ArrayFind, | 229 "find", ArrayFind, |
| 285 "findIndex", ArrayFindIndex, | 230 "findIndex", ArrayFindIndex, |
| 286 "fill", ArrayFill | 231 "fill", ArrayFill |
| 287 ]); | 232 ]); |
| 288 | 233 |
| 289 })(); | 234 })(); |
| OLD | NEW |