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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/runtime/runtime-utils.h" | 8 #include "src/runtime/runtime-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 if (!iter.IsAtEnd()) { | 432 if (!iter.IsAtEnd()) { |
433 // The prototype will usually have no inherited element indices, | 433 // The prototype will usually have no inherited element indices, |
434 // but we have to check. | 434 // but we have to check. |
435 CollectElementIndices( | 435 CollectElementIndices( |
436 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), range, | 436 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), range, |
437 indices); | 437 indices); |
438 } | 438 } |
439 } | 439 } |
440 | 440 |
441 | 441 |
442 static bool IterateElementsSlow(Isolate* isolate, Handle<JSObject> receiver, | |
443 uint32_t length, ArrayConcatVisitor* visitor) { | |
444 for (uint32_t i = 0; i < length; ++i) { | |
445 HandleScope loop_scope(isolate); | |
446 Maybe<bool> maybe = JSReceiver::HasElement(receiver, i); | |
447 if (!maybe.has_value) return false; | |
448 if (maybe.value) { | |
449 Handle<Object> element_value; | |
450 // Call GetElement on receiver, not its prototype, or getters won't | |
451 // have the correct receiver. | |
452 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
453 isolate, element_value, | |
454 Runtime::GetElementOrCharAt(isolate, receiver, i), false); | |
455 visitor->visit(i, element_value); | |
456 } | |
457 } | |
458 visitor->increase_index_offset(length); | |
459 return true; | |
460 } | |
461 | |
462 | |
442 /** | 463 /** |
443 * A helper function that visits elements of a JSObject in numerical | 464 * A helper function that visits elements of a JSObject in numerical |
444 * order. | 465 * order. |
445 * | 466 * |
446 * The visitor argument called for each existing element in the array | 467 * The visitor argument called for each existing element in the array |
447 * with the element index and the element's value. | 468 * with the element index and the element's value. |
448 * Afterwards it increments the base-index of the visitor by the array | 469 * Afterwards it increments the base-index of the visitor by the array |
449 * length. | 470 * length. |
450 * Returns false if any access threw an exception, otherwise true. | 471 * Returns false if any access threw an exception, otherwise true. |
451 */ | 472 */ |
(...skipping 10 matching lines...) Expand all Loading... | |
462 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val, | 483 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val, |
463 Runtime::GetObjectProperty(isolate, receiver, key), false); | 484 Runtime::GetObjectProperty(isolate, receiver, key), false); |
464 // TODO(caitp): Support larger element indexes (up to 2^53-1). | 485 // TODO(caitp): Support larger element indexes (up to 2^53-1). |
465 if (!val->ToUint32(&length)) { | 486 if (!val->ToUint32(&length)) { |
466 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val, | 487 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val, |
467 Execution::ToLength(isolate, val), false); | 488 Execution::ToLength(isolate, val), false); |
468 val->ToUint32(&length); | 489 val->ToUint32(&length); |
469 } | 490 } |
470 } | 491 } |
471 | 492 |
493 if (receiver->elements() == isolate->heap()->empty_fixed_array()) { | |
Dmitry Lomov (no reviews)
2014/12/16 15:25:45
Let's aim for 'make it right, then make it fast' a
caitp (gmail)
2014/12/16 15:33:36
So more of an `if (!(receiver->IsJSArray() || rece
| |
494 return IterateElementsSlow(isolate, receiver, length, visitor); | |
495 } | |
496 | |
472 switch (receiver->GetElementsKind()) { | 497 switch (receiver->GetElementsKind()) { |
473 case FAST_SMI_ELEMENTS: | 498 case FAST_SMI_ELEMENTS: |
474 case FAST_ELEMENTS: | 499 case FAST_ELEMENTS: |
475 case FAST_HOLEY_SMI_ELEMENTS: | 500 case FAST_HOLEY_SMI_ELEMENTS: |
476 case FAST_HOLEY_ELEMENTS: { | 501 case FAST_HOLEY_ELEMENTS: { |
477 // Run through the elements FixedArray and use HasElement and GetElement | 502 // Run through the elements FixedArray and use HasElement and GetElement |
478 // to check the prototype for missing elements. | 503 // to check the prototype for missing elements. |
479 Handle<FixedArray> elements(FixedArray::cast(receiver->elements())); | 504 Handle<FixedArray> elements(FixedArray::cast(receiver->elements())); |
480 int fast_length = static_cast<int>(length); | 505 int fast_length = static_cast<int>(length); |
481 DCHECK(fast_length <= elements->length()); | 506 DCHECK(fast_length <= elements->length()); |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 } | 1308 } |
1284 | 1309 |
1285 | 1310 |
1286 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) { | 1311 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) { |
1287 SealHandleScope shs(isolate); | 1312 SealHandleScope shs(isolate); |
1288 DCHECK(args.length() == 2); | 1313 DCHECK(args.length() == 2); |
1289 return isolate->heap()->undefined_value(); | 1314 return isolate->heap()->undefined_value(); |
1290 } | 1315 } |
1291 } | 1316 } |
1292 } // namespace v8::internal | 1317 } // namespace v8::internal |
OLD | NEW |