OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
9 #include "src/elements.h" | 9 #include "src/elements.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); | 199 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); |
200 | 200 |
201 if (!array->elements()->IsDictionary()) { | 201 if (!array->elements()->IsDictionary()) { |
202 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() || | 202 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() || |
203 array->HasFastDoubleElements()); | 203 array->HasFastDoubleElements()); |
204 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); | 204 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); |
205 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); | 205 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); |
206 } | 206 } |
207 | 207 |
208 KeyAccumulator accumulator(isolate); | 208 KeyAccumulator accumulator(isolate); |
| 209 // No need to separate protoype levels sicne we only get numbers/element keys |
| 210 accumulator.NextPrototype(); |
209 for (PrototypeIterator iter(isolate, array, | 211 for (PrototypeIterator iter(isolate, array, |
210 PrototypeIterator::START_AT_RECEIVER); | 212 PrototypeIterator::START_AT_RECEIVER); |
211 !iter.IsAtEnd(); iter.Advance()) { | 213 !iter.IsAtEnd(); iter.Advance()) { |
212 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() || | 214 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() || |
213 PrototypeIterator::GetCurrent<JSObject>(iter) | 215 PrototypeIterator::GetCurrent<JSObject>(iter) |
214 ->HasIndexedInterceptor()) { | 216 ->HasIndexedInterceptor()) { |
215 // Bail out if we find a proxy or interceptor, likely not worth | 217 // Bail out if we find a proxy or interceptor, likely not worth |
216 // collecting keys in that case. | 218 // collecting keys in that case. |
217 return *isolate->factory()->NewNumberFromUint(length); | 219 return *isolate->factory()->NewNumberFromUint(length); |
218 } | 220 } |
219 Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter); | 221 Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter); |
220 Handle<FixedArray> current_keys = | 222 JSObject::CollectOwnElementKeys(current, &accumulator, NONE); |
221 isolate->factory()->NewFixedArray(current->NumberOfOwnElements(NONE)); | |
222 current->GetOwnElementKeys(*current_keys, NONE); | |
223 accumulator.AddKeys(current_keys, INCLUDE_SYMBOLS); | |
224 } | 223 } |
225 // Erase any keys >= length. | 224 // Erase any keys >= length. |
226 // TODO(adamk): Remove this step when the contract of %GetArrayKeys | 225 // TODO(adamk): Remove this step when the contract of %GetArrayKeys |
227 // is changed to let this happen on the JS side. | 226 // is changed to let this happen on the JS side. |
228 Handle<FixedArray> keys = accumulator.GetKeys(); | 227 Handle<FixedArray> keys = accumulator.GetKeys(KEEP_NUMBERS); |
229 for (int i = 0; i < keys->length(); i++) { | 228 for (int i = 0; i < keys->length(); i++) { |
230 if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i); | 229 if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i); |
231 } | 230 } |
232 return *isolate->factory()->NewJSArrayWithElements(keys); | 231 return *isolate->factory()->NewJSArrayWithElements(keys); |
233 } | 232 } |
234 | 233 |
235 | 234 |
236 static Object* ArrayConstructorCommon(Isolate* isolate, | 235 static Object* ArrayConstructorCommon(Isolate* isolate, |
237 Handle<JSFunction> constructor, | 236 Handle<JSFunction> constructor, |
238 Handle<JSFunction> original_constructor, | 237 Handle<JSFunction> original_constructor, |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 491 |
493 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) { | 492 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) { |
494 SealHandleScope shs(isolate); | 493 SealHandleScope shs(isolate); |
495 DCHECK(args.length() == 2); | 494 DCHECK(args.length() == 2); |
496 // Returning undefined means that this fast path fails and one has to resort | 495 // Returning undefined means that this fast path fails and one has to resort |
497 // to a slow path. | 496 // to a slow path. |
498 return isolate->heap()->undefined_value(); | 497 return isolate->heap()->undefined_value(); |
499 } | 498 } |
500 } // namespace internal | 499 } // namespace internal |
501 } // namespace v8 | 500 } // namespace v8 |
OLD | NEW |