| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 var needs_wrapper = false; | 95 var needs_wrapper = false; |
| 96 if (IS_NULL(thisArg)) { | 96 if (IS_NULL(thisArg)) { |
| 97 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; | 97 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; |
| 98 } else if (!IS_UNDEFINED(thisArg)) { | 98 } else if (!IS_UNDEFINED(thisArg)) { |
| 99 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); | 99 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); |
| 100 } | 100 } |
| 101 | 101 |
| 102 for (var i = 0; i < length; i++) { | 102 for (var i = 0; i < length; i++) { |
| 103 if (i in array) { | 103 var element = array[i]; |
| 104 var element = array[i]; | 104 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; |
| 105 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; | 105 if (%_CallFunction(newThisArg, element, i, array, predicate)) { |
| 106 if (%_CallFunction(newThisArg, element, i, array, predicate)) { | 106 return element; |
| 107 return element; | |
| 108 } | |
| 109 } | 107 } |
| 110 } | 108 } |
| 111 | 109 |
| 112 return; | 110 return; |
| 113 } | 111 } |
| 114 | 112 |
| 115 // ES6 draft 07-15-13, section 15.4.3.23 | 113 // ES6 draft 07-15-13, section 15.4.3.23 |
| 116 function ArrayFind(predicate, thisArg) { | 114 function ArrayFind(predicate, thisArg) { |
| 117 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); | 115 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); |
| 118 | 116 |
| 119 var array = $toObject(this); | 117 var array = $toObject(this); |
| 120 var length = $toInteger(array.length); | 118 var length = $toInteger(array.length); |
| 121 | 119 |
| 122 return InnerArrayFind(predicate, thisArg, array, length); | 120 return InnerArrayFind(predicate, thisArg, array, length); |
| 123 } | 121 } |
| 124 | 122 |
| 125 function InnerArrayFindIndex(predicate, thisArg, array, length) { | 123 function InnerArrayFindIndex(predicate, thisArg, array, length) { |
| 126 if (!IS_SPEC_FUNCTION(predicate)) { | 124 if (!IS_SPEC_FUNCTION(predicate)) { |
| 127 throw MakeTypeError(kCalledNonCallable, predicate); | 125 throw MakeTypeError(kCalledNonCallable, predicate); |
| 128 } | 126 } |
| 129 | 127 |
| 130 var needs_wrapper = false; | 128 var needs_wrapper = false; |
| 131 if (IS_NULL(thisArg)) { | 129 if (IS_NULL(thisArg)) { |
| 132 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; | 130 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; |
| 133 } else if (!IS_UNDEFINED(thisArg)) { | 131 } else if (!IS_UNDEFINED(thisArg)) { |
| 134 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); | 132 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg); |
| 135 } | 133 } |
| 136 | 134 |
| 137 for (var i = 0; i < length; i++) { | 135 for (var i = 0; i < length; i++) { |
| 138 if (i in array) { | 136 var element = array[i]; |
| 139 var element = array[i]; | 137 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; |
| 140 var newThisArg = needs_wrapper ? $toObject(thisArg) : thisArg; | 138 if (%_CallFunction(newThisArg, element, i, array, predicate)) { |
| 141 if (%_CallFunction(newThisArg, element, i, array, predicate)) { | 139 return i; |
| 142 return i; | |
| 143 } | |
| 144 } | 140 } |
| 145 } | 141 } |
| 146 | 142 |
| 147 return -1; | 143 return -1; |
| 148 } | 144 } |
| 149 | 145 |
| 150 // ES6 draft 07-15-13, section 15.4.3.24 | 146 // ES6 draft 07-15-13, section 15.4.3.24 |
| 151 function ArrayFindIndex(predicate, thisArg) { | 147 function ArrayFindIndex(predicate, thisArg) { |
| 152 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); | 148 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); |
| 153 | 149 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 304 |
| 309 utils.Export(function(to) { | 305 utils.Export(function(to) { |
| 310 to.ArrayFrom = ArrayFrom; | 306 to.ArrayFrom = ArrayFrom; |
| 311 to.InnerArrayCopyWithin = InnerArrayCopyWithin; | 307 to.InnerArrayCopyWithin = InnerArrayCopyWithin; |
| 312 to.InnerArrayFill = InnerArrayFill; | 308 to.InnerArrayFill = InnerArrayFill; |
| 313 to.InnerArrayFind = InnerArrayFind; | 309 to.InnerArrayFind = InnerArrayFind; |
| 314 to.InnerArrayFindIndex = InnerArrayFindIndex; | 310 to.InnerArrayFindIndex = InnerArrayFindIndex; |
| 315 }); | 311 }); |
| 316 | 312 |
| 317 }) | 313 }) |
| OLD | NEW |