| 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(global, utils) { | 5 (function(global, utils) { | 
| 6 | 6 | 
| 7 'use strict'; | 7 'use strict'; | 
| 8 | 8 | 
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); | 
| 10 | 10 | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 78   } | 78   } | 
| 79 | 79 | 
| 80   return array; | 80   return array; | 
| 81 } | 81 } | 
| 82 | 82 | 
| 83 // ES6 draft 03-17-15, section 22.1.3.3 | 83 // ES6 draft 03-17-15, section 22.1.3.3 | 
| 84 function ArrayCopyWithin(target, start, end) { | 84 function ArrayCopyWithin(target, start, end) { | 
| 85   CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin"); | 85   CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin"); | 
| 86 | 86 | 
| 87   var array = TO_OBJECT(this); | 87   var array = TO_OBJECT(this); | 
| 88   var length = $toLength(array.length); | 88   var length = TO_LENGTH(array.length); | 
| 89 | 89 | 
| 90   return InnerArrayCopyWithin(target, start, end, array, length); | 90   return InnerArrayCopyWithin(target, start, end, array, length); | 
| 91 } | 91 } | 
| 92 | 92 | 
| 93 function InnerArrayFind(predicate, thisArg, array, length) { | 93 function InnerArrayFind(predicate, thisArg, array, length) { | 
| 94   if (!IS_CALLABLE(predicate)) { | 94   if (!IS_CALLABLE(predicate)) { | 
| 95     throw MakeTypeError(kCalledNonCallable, predicate); | 95     throw MakeTypeError(kCalledNonCallable, predicate); | 
| 96   } | 96   } | 
| 97 | 97 | 
| 98   for (var i = 0; i < length; i++) { | 98   for (var i = 0; i < length; i++) { | 
| 99     var element = array[i]; | 99     var element = array[i]; | 
| 100     if (%_Call(predicate, thisArg, element, i, array)) { | 100     if (%_Call(predicate, thisArg, element, i, array)) { | 
| 101       return element; | 101       return element; | 
| 102     } | 102     } | 
| 103   } | 103   } | 
| 104 | 104 | 
| 105   return; | 105   return; | 
| 106 } | 106 } | 
| 107 | 107 | 
| 108 // ES6 draft 07-15-13, section 15.4.3.23 | 108 // ES6 draft 07-15-13, section 15.4.3.23 | 
| 109 function ArrayFind(predicate, thisArg) { | 109 function ArrayFind(predicate, thisArg) { | 
| 110   CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); | 110   CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); | 
| 111 | 111 | 
| 112   var array = TO_OBJECT(this); | 112   var array = TO_OBJECT(this); | 
| 113   var length = $toInteger(array.length); | 113   var length = TO_INTEGER(array.length); | 
| 114 | 114 | 
| 115   return InnerArrayFind(predicate, thisArg, array, length); | 115   return InnerArrayFind(predicate, thisArg, array, length); | 
| 116 } | 116 } | 
| 117 | 117 | 
| 118 function InnerArrayFindIndex(predicate, thisArg, array, length) { | 118 function InnerArrayFindIndex(predicate, thisArg, array, length) { | 
| 119   if (!IS_CALLABLE(predicate)) { | 119   if (!IS_CALLABLE(predicate)) { | 
| 120     throw MakeTypeError(kCalledNonCallable, predicate); | 120     throw MakeTypeError(kCalledNonCallable, predicate); | 
| 121   } | 121   } | 
| 122 | 122 | 
| 123   for (var i = 0; i < length; i++) { | 123   for (var i = 0; i < length; i++) { | 
| 124     var element = array[i]; | 124     var element = array[i]; | 
| 125     if (%_Call(predicate, thisArg, element, i, array)) { | 125     if (%_Call(predicate, thisArg, element, i, array)) { | 
| 126       return i; | 126       return i; | 
| 127     } | 127     } | 
| 128   } | 128   } | 
| 129 | 129 | 
| 130   return -1; | 130   return -1; | 
| 131 } | 131 } | 
| 132 | 132 | 
| 133 // ES6 draft 07-15-13, section 15.4.3.24 | 133 // ES6 draft 07-15-13, section 15.4.3.24 | 
| 134 function ArrayFindIndex(predicate, thisArg) { | 134 function ArrayFindIndex(predicate, thisArg) { | 
| 135   CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); | 135   CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); | 
| 136 | 136 | 
| 137   var array = TO_OBJECT(this); | 137   var array = TO_OBJECT(this); | 
| 138   var length = $toInteger(array.length); | 138   var length = TO_INTEGER(array.length); | 
| 139 | 139 | 
| 140   return InnerArrayFindIndex(predicate, thisArg, array, length); | 140   return InnerArrayFindIndex(predicate, thisArg, array, length); | 
| 141 } | 141 } | 
| 142 | 142 | 
| 143 // ES6, draft 04-05-14, section 22.1.3.6 | 143 // ES6, draft 04-05-14, section 22.1.3.6 | 
| 144 function InnerArrayFill(value, start, end, array, length) { | 144 function InnerArrayFill(value, start, end, array, length) { | 
| 145   var i = IS_UNDEFINED(start) ? 0 : TO_INTEGER(start); | 145   var i = IS_UNDEFINED(start) ? 0 : TO_INTEGER(start); | 
| 146   var end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); | 146   var end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); | 
| 147 | 147 | 
| 148   if (i < 0) { | 148   if (i < 0) { | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 226       nextValue = next.value; | 226       nextValue = next.value; | 
| 227       if (mapping) { | 227       if (mapping) { | 
| 228         mappedValue = %_Call(mapfn, receiver, nextValue, k); | 228         mappedValue = %_Call(mapfn, receiver, nextValue, k); | 
| 229       } else { | 229       } else { | 
| 230         mappedValue = nextValue; | 230         mappedValue = nextValue; | 
| 231       } | 231       } | 
| 232       AddArrayElement(this, result, k, mappedValue); | 232       AddArrayElement(this, result, k, mappedValue); | 
| 233       k++; | 233       k++; | 
| 234     } | 234     } | 
| 235   } else { | 235   } else { | 
| 236     var len = $toLength(items.length); | 236     var len = TO_LENGTH(items.length); | 
| 237     result = %IsConstructor(this) ? new this(len) : new GlobalArray(len); | 237     result = %IsConstructor(this) ? new this(len) : new GlobalArray(len); | 
| 238 | 238 | 
| 239     for (k = 0; k < len; ++k) { | 239     for (k = 0; k < len; ++k) { | 
| 240       nextValue = items[k]; | 240       nextValue = items[k]; | 
| 241       if (mapping) { | 241       if (mapping) { | 
| 242         mappedValue = %_Call(mapfn, receiver, nextValue, k); | 242         mappedValue = %_Call(mapfn, receiver, nextValue, k); | 
| 243       } else { | 243       } else { | 
| 244         mappedValue = nextValue; | 244         mappedValue = nextValue; | 
| 245       } | 245       } | 
| 246       AddArrayElement(this, result, k, mappedValue); | 246       AddArrayElement(this, result, k, mappedValue); | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 291 | 291 | 
| 292 utils.Export(function(to) { | 292 utils.Export(function(to) { | 
| 293   to.ArrayFrom = ArrayFrom; | 293   to.ArrayFrom = ArrayFrom; | 
| 294   to.InnerArrayCopyWithin = InnerArrayCopyWithin; | 294   to.InnerArrayCopyWithin = InnerArrayCopyWithin; | 
| 295   to.InnerArrayFill = InnerArrayFill; | 295   to.InnerArrayFill = InnerArrayFill; | 
| 296   to.InnerArrayFind = InnerArrayFind; | 296   to.InnerArrayFind = InnerArrayFind; | 
| 297   to.InnerArrayFindIndex = InnerArrayFindIndex; | 297   to.InnerArrayFindIndex = InnerArrayFindIndex; | 
| 298 }); | 298 }); | 
| 299 | 299 | 
| 300 }) | 300 }) | 
| OLD | NEW | 
|---|