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