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 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 if (i > length) i = length; | 166 if (i > length) i = length; |
167 } | 167 } |
168 | 168 |
169 if (end < 0) { | 169 if (end < 0) { |
170 end += length; | 170 end += length; |
171 if (end < 0) end = 0; | 171 if (end < 0) end = 0; |
172 } else { | 172 } else { |
173 if (end > length) end = length; | 173 if (end > length) end = length; |
174 } | 174 } |
175 | 175 |
176 if ((end - i) > 0 && ObjectIsFrozen(array)) { | 176 if ((end - i) > 0 && $objectIsFrozen(array)) { |
177 throw MakeTypeError(kArrayFunctionsOnFrozen); | 177 throw MakeTypeError(kArrayFunctionsOnFrozen); |
178 } | 178 } |
179 | 179 |
180 for (; i < end; i++) | 180 for (; i < end; i++) |
181 array[i] = value; | 181 array[i] = value; |
182 return array; | 182 return array; |
183 } | 183 } |
184 | 184 |
185 // ES6, draft 10-14-14, section 22.1.2.1 | 185 // ES6, draft 10-14-14, section 22.1.2.1 |
186 function ArrayFrom(arrayLike, mapfn, receiver) { | 186 function ArrayFrom(arrayLike, mapfn, receiver) { |
187 var items = ToObject(arrayLike); | 187 var items = ToObject(arrayLike); |
188 var mapping = !IS_UNDEFINED(mapfn); | 188 var mapping = !IS_UNDEFINED(mapfn); |
189 | 189 |
190 if (mapping) { | 190 if (mapping) { |
191 if (!IS_SPEC_FUNCTION(mapfn)) { | 191 if (!IS_SPEC_FUNCTION(mapfn)) { |
192 throw MakeTypeError(kCalledNonCallable, mapfn); | 192 throw MakeTypeError(kCalledNonCallable, mapfn); |
193 } else if (IS_NULL_OR_UNDEFINED(receiver)) { | 193 } else if (IS_NULL_OR_UNDEFINED(receiver)) { |
194 receiver = %GetDefaultReceiver(mapfn) || receiver; | 194 receiver = %GetDefaultReceiver(mapfn) || receiver; |
195 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(mapfn)) { | 195 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(mapfn)) { |
196 receiver = ToObject(receiver); | 196 receiver = ToObject(receiver); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 var iterable = GetMethod(items, symbolIterator); | 200 var iterable = $getMethod(items, symbolIterator); |
201 var k; | 201 var k; |
202 var result; | 202 var result; |
203 var mappedValue; | 203 var mappedValue; |
204 var nextValue; | 204 var nextValue; |
205 | 205 |
206 if (!IS_UNDEFINED(iterable)) { | 206 if (!IS_UNDEFINED(iterable)) { |
207 result = %IsConstructor(this) ? new this() : []; | 207 result = %IsConstructor(this) ? new this() : []; |
208 | 208 |
209 var iterator = GetIterator(items, iterable); | 209 var iterator = $getIterator(items, iterable); |
210 | 210 |
211 k = 0; | 211 k = 0; |
212 while (true) { | 212 while (true) { |
213 var next = iterator.next(); | 213 var next = iterator.next(); |
214 | 214 |
215 if (!IS_OBJECT(next)) { | 215 if (!IS_OBJECT(next)) { |
216 throw MakeTypeError("iterator_result_not_an_object", [next]); | 216 throw MakeTypeError("iterator_result_not_an_object", [next]); |
217 } | 217 } |
218 | 218 |
219 if (next.done) { | 219 if (next.done) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 var array = %IsConstructor(constructor) ? new constructor(length) : []; | 256 var array = %IsConstructor(constructor) ? new constructor(length) : []; |
257 for (var i = 0; i < length; i++) { | 257 for (var i = 0; i < length; i++) { |
258 %AddElement(array, i, %_Arguments(i), NONE); | 258 %AddElement(array, i, %_Arguments(i), NONE); |
259 } | 259 } |
260 array.length = length; | 260 array.length = length; |
261 return array; | 261 return array; |
262 } | 262 } |
263 | 263 |
264 // ------------------------------------------------------------------- | 264 // ------------------------------------------------------------------- |
265 | 265 |
266 InstallConstants(GlobalSymbol, [ | 266 $installConstants(GlobalSymbol, [ |
267 // TODO(dslomov, caitp): Move to symbol.js when shipping | 267 // TODO(dslomov, caitp): Move to symbol.js when shipping |
268 "isConcatSpreadable", symbolIsConcatSpreadable | 268 "isConcatSpreadable", symbolIsConcatSpreadable |
269 ]); | 269 ]); |
270 | 270 |
271 %FunctionSetLength(ArrayCopyWithin, 2); | 271 %FunctionSetLength(ArrayCopyWithin, 2); |
272 %FunctionSetLength(ArrayFrom, 1); | 272 %FunctionSetLength(ArrayFrom, 1); |
273 | 273 |
274 // Set up non-enumerable functions on the Array object. | 274 // Set up non-enumerable functions on the Array object. |
275 InstallFunctions(GlobalArray, DONT_ENUM, [ | 275 $installFunctions(GlobalArray, DONT_ENUM, [ |
276 "from", ArrayFrom, | 276 "from", ArrayFrom, |
277 "of", ArrayOf | 277 "of", ArrayOf |
278 ]); | 278 ]); |
279 | 279 |
280 // Set up the non-enumerable functions on the Array prototype object. | 280 // Set up the non-enumerable functions on the Array prototype object. |
281 InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ | 281 $installFunctions(GlobalArray.prototype, DONT_ENUM, [ |
282 "copyWithin", ArrayCopyWithin, | 282 "copyWithin", ArrayCopyWithin, |
283 "find", ArrayFind, | 283 "find", ArrayFind, |
284 "findIndex", ArrayFindIndex, | 284 "findIndex", ArrayFindIndex, |
285 "fill", ArrayFill | 285 "fill", ArrayFill |
286 ]); | 286 ]); |
287 | 287 |
288 })(); | 288 })(); |
OLD | NEW |