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/elements.h" | 8 #include "src/elements.h" |
9 #include "src/messages.h" | 9 #include "src/messages.h" |
10 #include "src/runtime/runtime-utils.h" | 10 #include "src/runtime/runtime-utils.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 Handle<Object> key(dictionary->KeyAt(i), array->GetIsolate()); | 291 Handle<Object> key(dictionary->KeyAt(i), array->GetIsolate()); |
292 if (dictionary->IsKey(*key)) { | 292 if (dictionary->IsKey(*key)) { |
293 element_count++; | 293 element_count++; |
294 } | 294 } |
295 } | 295 } |
296 break; | 296 break; |
297 } | 297 } |
298 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: | 298 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: |
299 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: | 299 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: |
300 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 300 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
| 301 case EXTERNAL_##TYPE##_ELEMENTS: \ |
301 case TYPE##_ELEMENTS: | 302 case TYPE##_ELEMENTS: |
302 | 303 |
303 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 304 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
304 #undef TYPED_ARRAY_CASE | 305 #undef TYPED_ARRAY_CASE |
305 // External arrays are always dense. | 306 // External arrays are always dense. |
306 return length; | 307 return length; |
307 } | 308 } |
308 // As an estimate, we assume that the prototype doesn't contain any | 309 // As an estimate, we assume that the prototype doesn't contain any |
309 // inherited elements. | 310 // inherited elements. |
310 return element_count; | 311 return element_count; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 uint32_t index = static_cast<uint32_t>(k->Number()); | 411 uint32_t index = static_cast<uint32_t>(k->Number()); |
411 if (index < range) { | 412 if (index < range) { |
412 indices->Add(index); | 413 indices->Add(index); |
413 } | 414 } |
414 } | 415 } |
415 } | 416 } |
416 break; | 417 break; |
417 } | 418 } |
418 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 419 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
419 case TYPE##_ELEMENTS: \ | 420 case TYPE##_ELEMENTS: \ |
| 421 case EXTERNAL_##TYPE##_ELEMENTS: |
420 | 422 |
421 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 423 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
422 #undef TYPED_ARRAY_CASE | 424 #undef TYPED_ARRAY_CASE |
423 { | 425 { |
424 uint32_t length = static_cast<uint32_t>( | 426 uint32_t length = static_cast<uint32_t>( |
425 FixedArrayBase::cast(object->elements())->length()); | 427 FixedArrayBase::cast(object->elements())->length()); |
426 if (range <= length) { | 428 if (range <= length) { |
427 length = range; | 429 length = range; |
428 // We will add all indices, so we might as well clear it first | 430 // We will add all indices, so we might as well clear it first |
429 // and avoid duplicates. | 431 // and avoid duplicates. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 isolate, element, Object::GetElement(isolate, receiver, index), | 603 isolate, element, Object::GetElement(isolate, receiver, index), |
602 false); | 604 false); |
603 visitor->visit(index, element); | 605 visitor->visit(index, element); |
604 // Skip to next different index (i.e., omit duplicates). | 606 // Skip to next different index (i.e., omit duplicates). |
605 do { | 607 do { |
606 j++; | 608 j++; |
607 } while (j < n && indices[j] == index); | 609 } while (j < n && indices[j] == index); |
608 } | 610 } |
609 break; | 611 break; |
610 } | 612 } |
| 613 case EXTERNAL_UINT8_CLAMPED_ELEMENTS: { |
| 614 Handle<ExternalUint8ClampedArray> pixels( |
| 615 ExternalUint8ClampedArray::cast(receiver->elements())); |
| 616 for (uint32_t j = 0; j < length; j++) { |
| 617 Handle<Smi> e(Smi::FromInt(pixels->get_scalar(j)), isolate); |
| 618 visitor->visit(j, e); |
| 619 } |
| 620 break; |
| 621 } |
611 case UINT8_CLAMPED_ELEMENTS: { | 622 case UINT8_CLAMPED_ELEMENTS: { |
612 Handle<FixedUint8ClampedArray> pixels( | 623 Handle<FixedUint8ClampedArray> pixels( |
613 FixedUint8ClampedArray::cast(receiver->elements())); | 624 FixedUint8ClampedArray::cast(receiver->elements())); |
614 for (uint32_t j = 0; j < length; j++) { | 625 for (uint32_t j = 0; j < length; j++) { |
615 Handle<Smi> e(Smi::FromInt(pixels->get_scalar(j)), isolate); | 626 Handle<Smi> e(Smi::FromInt(pixels->get_scalar(j)), isolate); |
616 visitor->visit(j, e); | 627 visitor->visit(j, e); |
617 } | 628 } |
618 break; | 629 break; |
619 } | 630 } |
| 631 case EXTERNAL_INT8_ELEMENTS: { |
| 632 IterateTypedArrayElements<ExternalInt8Array, int8_t>( |
| 633 isolate, receiver, true, true, visitor); |
| 634 break; |
| 635 } |
620 case INT8_ELEMENTS: { | 636 case INT8_ELEMENTS: { |
621 IterateTypedArrayElements<FixedInt8Array, int8_t>( | 637 IterateTypedArrayElements<FixedInt8Array, int8_t>( |
622 isolate, receiver, true, true, visitor); | 638 isolate, receiver, true, true, visitor); |
623 break; | 639 break; |
624 } | 640 } |
| 641 case EXTERNAL_UINT8_ELEMENTS: { |
| 642 IterateTypedArrayElements<ExternalUint8Array, uint8_t>( |
| 643 isolate, receiver, true, true, visitor); |
| 644 break; |
| 645 } |
625 case UINT8_ELEMENTS: { | 646 case UINT8_ELEMENTS: { |
626 IterateTypedArrayElements<FixedUint8Array, uint8_t>( | 647 IterateTypedArrayElements<FixedUint8Array, uint8_t>( |
627 isolate, receiver, true, true, visitor); | 648 isolate, receiver, true, true, visitor); |
628 break; | 649 break; |
629 } | 650 } |
| 651 case EXTERNAL_INT16_ELEMENTS: { |
| 652 IterateTypedArrayElements<ExternalInt16Array, int16_t>( |
| 653 isolate, receiver, true, true, visitor); |
| 654 break; |
| 655 } |
630 case INT16_ELEMENTS: { | 656 case INT16_ELEMENTS: { |
631 IterateTypedArrayElements<FixedInt16Array, int16_t>( | 657 IterateTypedArrayElements<FixedInt16Array, int16_t>( |
632 isolate, receiver, true, true, visitor); | 658 isolate, receiver, true, true, visitor); |
633 break; | 659 break; |
634 } | 660 } |
| 661 case EXTERNAL_UINT16_ELEMENTS: { |
| 662 IterateTypedArrayElements<ExternalUint16Array, uint16_t>( |
| 663 isolate, receiver, true, true, visitor); |
| 664 break; |
| 665 } |
635 case UINT16_ELEMENTS: { | 666 case UINT16_ELEMENTS: { |
636 IterateTypedArrayElements<FixedUint16Array, uint16_t>( | 667 IterateTypedArrayElements<FixedUint16Array, uint16_t>( |
637 isolate, receiver, true, true, visitor); | 668 isolate, receiver, true, true, visitor); |
638 break; | 669 break; |
639 } | 670 } |
| 671 case EXTERNAL_INT32_ELEMENTS: { |
| 672 IterateTypedArrayElements<ExternalInt32Array, int32_t>( |
| 673 isolate, receiver, true, false, visitor); |
| 674 break; |
| 675 } |
640 case INT32_ELEMENTS: { | 676 case INT32_ELEMENTS: { |
641 IterateTypedArrayElements<FixedInt32Array, int32_t>( | 677 IterateTypedArrayElements<FixedInt32Array, int32_t>( |
642 isolate, receiver, true, false, visitor); | 678 isolate, receiver, true, false, visitor); |
643 break; | 679 break; |
644 } | 680 } |
| 681 case EXTERNAL_UINT32_ELEMENTS: { |
| 682 IterateTypedArrayElements<ExternalUint32Array, uint32_t>( |
| 683 isolate, receiver, true, false, visitor); |
| 684 break; |
| 685 } |
645 case UINT32_ELEMENTS: { | 686 case UINT32_ELEMENTS: { |
646 IterateTypedArrayElements<FixedUint32Array, uint32_t>( | 687 IterateTypedArrayElements<FixedUint32Array, uint32_t>( |
647 isolate, receiver, true, false, visitor); | 688 isolate, receiver, true, false, visitor); |
648 break; | 689 break; |
649 } | 690 } |
| 691 case EXTERNAL_FLOAT32_ELEMENTS: { |
| 692 IterateTypedArrayElements<ExternalFloat32Array, float>( |
| 693 isolate, receiver, false, false, visitor); |
| 694 break; |
| 695 } |
650 case FLOAT32_ELEMENTS: { | 696 case FLOAT32_ELEMENTS: { |
651 IterateTypedArrayElements<FixedFloat32Array, float>( | 697 IterateTypedArrayElements<FixedFloat32Array, float>( |
652 isolate, receiver, false, false, visitor); | 698 isolate, receiver, false, false, visitor); |
653 break; | 699 break; |
654 } | 700 } |
| 701 case EXTERNAL_FLOAT64_ELEMENTS: { |
| 702 IterateTypedArrayElements<ExternalFloat64Array, double>( |
| 703 isolate, receiver, false, false, visitor); |
| 704 break; |
| 705 } |
655 case FLOAT64_ELEMENTS: { | 706 case FLOAT64_ELEMENTS: { |
656 IterateTypedArrayElements<FixedFloat64Array, double>( | 707 IterateTypedArrayElements<FixedFloat64Array, double>( |
657 isolate, receiver, false, false, visitor); | 708 isolate, receiver, false, false, visitor); |
658 break; | 709 break; |
659 } | 710 } |
660 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: | 711 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: |
661 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: { | 712 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: { |
662 for (uint32_t index = 0; index < length; index++) { | 713 for (uint32_t index = 0; index < length; index++) { |
663 HandleScope loop_scope(isolate); | 714 HandleScope loop_scope(isolate); |
664 Handle<Object> element; | 715 Handle<Object> element; |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 #endif | 1226 #endif |
1176 return ArrayConstructorCommon(isolate, constructor, constructor, | 1227 return ArrayConstructorCommon(isolate, constructor, constructor, |
1177 Handle<AllocationSite>::null(), caller_args); | 1228 Handle<AllocationSite>::null(), caller_args); |
1178 } | 1229 } |
1179 | 1230 |
1180 | 1231 |
1181 RUNTIME_FUNCTION(Runtime_NormalizeElements) { | 1232 RUNTIME_FUNCTION(Runtime_NormalizeElements) { |
1182 HandleScope scope(isolate); | 1233 HandleScope scope(isolate); |
1183 DCHECK(args.length() == 1); | 1234 DCHECK(args.length() == 1); |
1184 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); | 1235 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); |
1185 RUNTIME_ASSERT(!array->HasFixedTypedArrayElements() && | 1236 RUNTIME_ASSERT(!array->HasExternalArrayElements() && |
| 1237 !array->HasFixedTypedArrayElements() && |
1186 !array->IsJSGlobalProxy()); | 1238 !array->IsJSGlobalProxy()); |
1187 JSObject::NormalizeElements(array); | 1239 JSObject::NormalizeElements(array); |
1188 return *array; | 1240 return *array; |
1189 } | 1241 } |
1190 | 1242 |
1191 | 1243 |
1192 // GrowArrayElements returns a sentinel Smi if the object was normalized. | 1244 // GrowArrayElements returns a sentinel Smi if the object was normalized. |
1193 RUNTIME_FUNCTION(Runtime_GrowArrayElements) { | 1245 RUNTIME_FUNCTION(Runtime_GrowArrayElements) { |
1194 HandleScope scope(isolate); | 1246 HandleScope scope(isolate); |
1195 DCHECK(args.length() == 2); | 1247 DCHECK(args.length() == 2); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 | 1320 |
1269 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) { | 1321 RUNTIME_FUNCTION(Runtime_FastOneByteArrayJoin) { |
1270 SealHandleScope shs(isolate); | 1322 SealHandleScope shs(isolate); |
1271 DCHECK(args.length() == 2); | 1323 DCHECK(args.length() == 2); |
1272 // Returning undefined means that this fast path fails and one has to resort | 1324 // Returning undefined means that this fast path fails and one has to resort |
1273 // to a slow path. | 1325 // to a slow path. |
1274 return isolate->heap()->undefined_value(); | 1326 return isolate->heap()->undefined_value(); |
1275 } | 1327 } |
1276 } // namespace internal | 1328 } // namespace internal |
1277 } // namespace v8 | 1329 } // namespace v8 |
OLD | NEW |