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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 if ((end - i) > 0 && ObjectIsFrozen(array)) { | 116 if ((end - i) > 0 && ObjectIsFrozen(array)) { |
| 117 throw MakeTypeError("array_functions_on_frozen", | 117 throw MakeTypeError("array_functions_on_frozen", |
| 118 ["Array.prototype.fill"]); | 118 ["Array.prototype.fill"]); |
| 119 } | 119 } |
| 120 | 120 |
| 121 for (; i < end; i++) | 121 for (; i < end; i++) |
| 122 array[i] = value; | 122 array[i] = value; |
| 123 return array; | 123 return array; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // ES6, 22.1.2.1 --- Requires harmony_symbols and harmony_iteration | |
| 127 function ArrayFrom(arrayLike /* [, mapfn [, receiver] ] */) { // length == 1 | |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
Just keep the mapfn and receiver here. You can set
caitp (gmail)
2014/07/02 19:22:05
I haven't found a way to set the arity of a functi
arv (Not doing code reviews)
2014/07/02 19:29:09
%FunctionSetLength(f, len);
| |
| 128 var items = ToObject(arrayLike); | |
| 129 var mapping = false; | |
| 130 var array; | |
| 131 var mapfn; | |
| 132 var receiver; | |
| 133 | |
| 134 if (%_ArgumentsLength() > 1) { | |
| 135 mapfn = %_Arguments(1); | |
| 136 if (%_ArgumentsLength() > 2) { | |
| 137 receiver = %_Arguments(2); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 if (!IS_UNDEFINED(mapfn)) { | |
| 142 if (!IS_SPEC_FUNCTION(mapfn)) { | |
| 143 throw MakeTypeError('called_non_callable', [ mapfn ]); | |
| 144 } | |
| 145 if (IS_NULL_OR_UNDEFINED(receiver)) { | |
| 146 receiver = %GetDefaultReceiver(mapfn) || receiver; | |
| 147 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(mapfn)) { | |
| 148 receiver = ToObject(receiver); | |
| 149 } | |
| 150 mapping = true; | |
| 151 } | |
| 152 | |
| 153 var usingIterator = items[symbolIterator]; | |
| 154 var k = 0; | |
| 155 var value; | |
|
aandrey
2014/07/02 18:28:15
var stepping = mapping && DEBUG_IS_ACTIVE && %Debu
| |
| 156 | |
| 157 if (!IS_UNDEFINED(usingIterator)) { | |
| 158 if (!IS_SPEC_FUNCTION(usingIterator)) { | |
| 159 throw MakeTypeError('called_non_callable', [ usingIterator ]); | |
| 160 } | |
| 161 | |
| 162 var iterator = %_CallFunction(items, usingIterator); | |
| 163 if (!IS_OBJECT(iterator)) { | |
| 164 throw MakeTypeError('iterator_result_not_an_object', [ iterator ]); | |
| 165 } | |
| 166 | |
| 167 array = []; | |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
This should use new this if this is a constructor.
arv (Not doing code reviews)
2014/07/02 18:26:43
The ordering here is not correct.
caitp (gmail)
2014/07/02 19:22:05
You mean, because the array is created after condi
arv (Not doing code reviews)
2014/07/02 19:29:09
We could try to change the spec. But for now, we s
| |
| 168 var next; | |
| 169 while (!(next = iterator.next()).done) { | |
| 170 value = next.value; | |
| 171 if (mapping) { | |
| 172 value = %_CallFunction(receiver, value, k, mapfn); | |
|
aandrey
2014/07/02 18:28:15
if (stepping) %DebugPrepareStepInIfStepping(mapfn)
| |
| 173 } | |
| 174 array[k++] = value; | |
| 175 } | |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
Let putStatus be Put(A, "length", k, true).
is mi
| |
| 176 } else { | |
| 177 var len = +items.length; | |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
How about adding TO_LENGTH to macros.py?
caitp (gmail)
2014/07/02 19:22:05
Will do, but I'm not actually sure this is really
| |
| 178 if (len < +0 || len !== len) { | |
| 179 len = +0; | |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
len = 0
| |
| 180 } | |
| 181 | |
| 182 array = new $Array(len); | |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
new this here as well.
caitp (gmail)
2014/07/02 19:22:05
After reading that, I think I understand what you
arv (Not doing code reviews)
2014/07/02 19:29:09
Unfortunately V8 has no concept of [[Constructor]]
rossberg
2014/07/03 11:16:57
IS_SPEC_FUNCTION is more what you want.
| |
| 183 for (; k < len; ++k) { | |
| 184 value = items[k]; | |
| 185 if (mapping) { | |
| 186 value = %_CallFunction(receiver, value, k, mapfn); | |
|
aandrey
2014/07/02 18:28:15
ditto
| |
| 187 } | |
| 188 array[k] = value; | |
| 189 } | |
| 190 } | |
| 191 | |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
Put length here as well.
| |
| 192 return array; | |
| 193 } | |
| 194 | |
| 126 // ------------------------------------------------------------------- | 195 // ------------------------------------------------------------------- |
| 127 | 196 |
| 128 function HarmonyArrayExtendArrayPrototype() { | 197 function HarmonyArrayExtendArrayPrototype() { |
| 129 %CheckIsBootstrapping(); | 198 %CheckIsBootstrapping(); |
| 130 | 199 |
| 200 // Set up non-enumerable functions on the Array object. | |
| 201 InstallFunctions($Array, DONT_ENUM, $Array( | |
| 202 "from", ArrayFrom | |
| 203 )); | |
| 204 | |
| 131 // Set up the non-enumerable functions on the Array prototype object. | 205 // Set up the non-enumerable functions on the Array prototype object. |
| 132 InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 206 InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
| 133 "find", ArrayFind, | 207 "find", ArrayFind, |
| 134 "findIndex", ArrayFindIndex, | 208 "findIndex", ArrayFindIndex, |
| 135 "fill", ArrayFill | 209 "fill", ArrayFill |
| 136 )); | 210 )); |
| 137 } | 211 } |
| 138 | 212 |
| 139 HarmonyArrayExtendArrayPrototype(); | 213 HarmonyArrayExtendArrayPrototype(); |
| OLD | NEW |