Chromium Code Reviews| 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 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var GlobalArray = global.Array; | 14 var GlobalArray = global.Array; |
| 15 var GlobalSymbol = global.Symbol; | 15 var GlobalSymbol = global.Symbol; |
| 16 | 16 |
| 17 var GetIterator; | 17 var GetIterator; |
| 18 var GetMethod; | 18 var GetMethod; |
| 19 var MathMax; | 19 var MathMax; |
| 20 var MathMin; | 20 var MathMin; |
| 21 var ObjectIsFrozen; | 21 var ObjectIsFrozen; |
| 22 var ObjectDefineProperty; | |
| 22 | 23 |
| 23 utils.Import(function(from) { | 24 utils.Import(function(from) { |
| 24 GetIterator = from.GetIterator; | 25 GetIterator = from.GetIterator; |
| 25 GetMethod = from.GetMethod; | 26 GetMethod = from.GetMethod; |
| 26 MathMax = from.MathMax; | 27 MathMax = from.MathMax; |
| 27 MathMin = from.MathMin; | 28 MathMin = from.MathMin; |
| 28 ObjectIsFrozen = from.ObjectIsFrozen; | 29 ObjectIsFrozen = from.ObjectIsFrozen; |
| 30 ObjectDefineProperty = from.ObjectDefineProperty; | |
| 29 }); | 31 }); |
| 30 | 32 |
| 31 // ------------------------------------------------------------------- | 33 // ------------------------------------------------------------------- |
| 32 | 34 |
| 33 function InnerArrayCopyWithin(target, start, end, array, length) { | 35 function InnerArrayCopyWithin(target, start, end, array, length) { |
| 34 target = TO_INTEGER(target); | 36 target = TO_INTEGER(target); |
| 35 var to; | 37 var to; |
| 36 if (target < 0) { | 38 if (target < 0) { |
| 37 to = MathMax(length + target, 0); | 39 to = MathMax(length + target, 0); |
| 38 } else { | 40 } else { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 // ES6, draft 04-05-14, section 22.1.3.6 | 186 // ES6, draft 04-05-14, section 22.1.3.6 |
| 185 function ArrayFill(value, start, end) { | 187 function ArrayFill(value, start, end) { |
| 186 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); | 188 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); |
| 187 | 189 |
| 188 var array = $toObject(this); | 190 var array = $toObject(this); |
| 189 var length = TO_UINT32(array.length); | 191 var length = TO_UINT32(array.length); |
| 190 | 192 |
| 191 return InnerArrayFill(value, start, end, array, length); | 193 return InnerArrayFill(value, start, end, array, length); |
| 192 } | 194 } |
| 193 | 195 |
| 196 function AddArrayElement(constructor, array, i, value) { | |
| 197 if (constructor === GlobalArray) { | |
|
Toon Verwaest
2015/06/11 08:03:14
Is this enough? A constructor could return an arra
arv (Not doing code reviews)
2015/06/11 13:04:01
I believe this is fine.
constructor here is the r
Toon Verwaest
2015/06/11 13:09:23
(d8):1: illegal access
adamk
2015/06/11 15:12:10
Do you have Dan's patch patched in? This should go
arv (Not doing code reviews)
2015/06/11 15:19:37
Once we add support for @@species then we will hav
adamk
2015/06/11 15:26:40
Not sure I follow, Array.from/of only look at the
arv (Not doing code reviews)
2015/06/11 15:30:01
You are right. nm.
Toon Verwaest
2015/06/11 15:35:33
Arg, ok, I see. Nevermind ;)
However, shouldn't w
Dan Ehrenberg
2015/06/11 16:27:25
I think GlobalArray will remain a constructor, so
| |
| 198 %AddElement(array, i, value, NONE); | |
| 199 } else { | |
| 200 ObjectDefineProperty(array, i, { value: value }); | |
|
arv (Not doing code reviews)
2015/06/11 13:04:01
non enum? non writable? non configurable?
We real
Dan Ehrenberg
2015/06/11 16:27:25
Fixed the descriptor and added tests.
| |
| 201 } | |
| 202 } | |
| 203 | |
| 194 // ES6, draft 10-14-14, section 22.1.2.1 | 204 // ES6, draft 10-14-14, section 22.1.2.1 |
| 195 function ArrayFrom(arrayLike, mapfn, receiver) { | 205 function ArrayFrom(arrayLike, mapfn, receiver) { |
| 196 var items = $toObject(arrayLike); | 206 var items = $toObject(arrayLike); |
| 197 var mapping = !IS_UNDEFINED(mapfn); | 207 var mapping = !IS_UNDEFINED(mapfn); |
| 198 | 208 |
| 199 if (mapping) { | 209 if (mapping) { |
| 200 if (!IS_SPEC_FUNCTION(mapfn)) { | 210 if (!IS_SPEC_FUNCTION(mapfn)) { |
| 201 throw MakeTypeError(kCalledNonCallable, mapfn); | 211 throw MakeTypeError(kCalledNonCallable, mapfn); |
| 202 } else if (%IsSloppyModeFunction(mapfn)) { | 212 } else if (%IsSloppyModeFunction(mapfn)) { |
| 203 if (IS_NULL(receiver)) { | 213 if (IS_NULL(receiver)) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 231 result.length = k; | 241 result.length = k; |
| 232 return result; | 242 return result; |
| 233 } | 243 } |
| 234 | 244 |
| 235 nextValue = next.value; | 245 nextValue = next.value; |
| 236 if (mapping) { | 246 if (mapping) { |
| 237 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); | 247 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); |
| 238 } else { | 248 } else { |
| 239 mappedValue = nextValue; | 249 mappedValue = nextValue; |
| 240 } | 250 } |
| 241 %AddElement(result, k++, mappedValue, NONE); | 251 AddArrayElement(this, result, k, mappedValue); |
| 252 k++; | |
| 242 } | 253 } |
| 243 } else { | 254 } else { |
| 244 var len = $toLength(items.length); | 255 var len = $toLength(items.length); |
| 245 result = %IsConstructor(this) ? new this(len) : new GlobalArray(len); | 256 result = %IsConstructor(this) ? new this(len) : new GlobalArray(len); |
| 246 | 257 |
| 247 for (k = 0; k < len; ++k) { | 258 for (k = 0; k < len; ++k) { |
| 248 nextValue = items[k]; | 259 nextValue = items[k]; |
| 249 if (mapping) { | 260 if (mapping) { |
| 250 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); | 261 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); |
| 251 } else { | 262 } else { |
| 252 mappedValue = nextValue; | 263 mappedValue = nextValue; |
| 253 } | 264 } |
| 254 %AddElement(result, k, mappedValue, NONE); | 265 AddArrayElement(this, result, k, mappedValue); |
| 255 } | 266 } |
| 256 | 267 |
| 257 result.length = k; | 268 result.length = k; |
| 258 return result; | 269 return result; |
| 259 } | 270 } |
| 260 } | 271 } |
| 261 | 272 |
| 262 // ES6, draft 05-22-14, section 22.1.2.3 | 273 // ES6, draft 05-22-14, section 22.1.2.3 |
| 263 function ArrayOf() { | 274 function ArrayOf() { |
| 264 var length = %_ArgumentsLength(); | 275 var length = %_ArgumentsLength(); |
| 265 var constructor = this; | 276 var constructor = this; |
| 266 // TODO: Implement IsConstructor (ES6 section 7.2.5) | 277 // TODO: Implement IsConstructor (ES6 section 7.2.5) |
| 267 var array = %IsConstructor(constructor) ? new constructor(length) : []; | 278 var array = %IsConstructor(constructor) ? new constructor(length) : []; |
| 268 for (var i = 0; i < length; i++) { | 279 for (var i = 0; i < length; i++) { |
| 269 %AddElement(array, i, %_Arguments(i), NONE); | 280 AddArrayElement(constructor, array, i, %_Arguments(i)); |
| 270 } | 281 } |
| 271 array.length = length; | 282 array.length = length; |
| 272 return array; | 283 return array; |
| 273 } | 284 } |
| 274 | 285 |
| 275 // ------------------------------------------------------------------- | 286 // ------------------------------------------------------------------- |
| 276 | 287 |
| 277 utils.InstallConstants(GlobalSymbol, [ | 288 utils.InstallConstants(GlobalSymbol, [ |
| 278 // TODO(dslomov, caitp): Move to symbol.js when shipping | 289 // TODO(dslomov, caitp): Move to symbol.js when shipping |
| 279 "isConcatSpreadable", symbolIsConcatSpreadable | 290 "isConcatSpreadable", symbolIsConcatSpreadable |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 304 | 315 |
| 305 utils.Export(function(to) { | 316 utils.Export(function(to) { |
| 306 to.ArrayFrom = ArrayFrom; | 317 to.ArrayFrom = ArrayFrom; |
| 307 to.InnerArrayCopyWithin = InnerArrayCopyWithin; | 318 to.InnerArrayCopyWithin = InnerArrayCopyWithin; |
| 308 to.InnerArrayFill = InnerArrayFill; | 319 to.InnerArrayFill = InnerArrayFill; |
| 309 to.InnerArrayFind = InnerArrayFind; | 320 to.InnerArrayFind = InnerArrayFind; |
| 310 to.InnerArrayFindIndex = InnerArrayFindIndex; | 321 to.InnerArrayFindIndex = InnerArrayFindIndex; |
| 311 }); | 322 }); |
| 312 | 323 |
| 313 }) | 324 }) |
| OLD | NEW |