Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 } | 740 } |
| 741 | 741 |
| 742 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); | 742 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); |
| 743 | 743 |
| 744 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 744 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
| 745 | 745 |
| 746 return true; | 746 return true; |
| 747 } | 747 } |
| 748 | 748 |
| 749 | 749 |
| 750 static Failure* ThrowTypeError(Isolate* isolate, | |
| 751 const char* message_id, | |
| 752 const char* arg) { | |
| 753 HandleScope scope(isolate); | |
| 754 Handle<Object> name_obj = | |
| 755 isolate->factory()->NewStringFromAscii(CStrVector(arg)); | |
| 756 Handle<Object> args[1] = { name_obj }; | |
| 757 return isolate->Throw( | |
| 758 *isolate->factory()->NewTypeError( | |
| 759 message_id, HandleVector(args, 1))); | |
| 760 } | |
| 761 | |
| 762 | |
| 750 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { | 763 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { |
| 751 HandleScope scope(isolate); | 764 HandleScope scope(isolate); |
| 752 ASSERT(args.length() == 2); | 765 ASSERT(args.length() == 2); |
| 753 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); | 766 CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0); |
| 754 CONVERT_ARG_HANDLE_CHECKED(Object, byteLength, 1); | 767 CONVERT_ARG_HANDLE_CHECKED(Object, byteLength, 1); |
| 768 | |
| 769 if (!this_obj->IsJSArrayBuffer()) { | |
| 770 return ThrowTypeError(isolate, "constructor_not_function", "ArrayBuffer"); | |
| 771 } | |
| 772 Handle<JSArrayBuffer> holder(JSArrayBuffer::cast(*this_obj)); | |
| 773 if (!holder->byte_length()->IsUndefined()) { | |
| 774 return ThrowTypeError( | |
| 775 isolate, "object_already_initialized", "ArrayBuffer"); | |
| 776 } | |
| 777 | |
| 755 size_t allocated_length; | 778 size_t allocated_length; |
| 756 if (byteLength->IsSmi()) { | 779 if (byteLength->IsSmi()) { |
| 757 allocated_length = Smi::cast(*byteLength)->value(); | 780 allocated_length = Smi::cast(*byteLength)->value(); |
| 758 } else { | 781 } else { |
| 759 ASSERT(byteLength->IsHeapNumber()); | 782 ASSERT(byteLength->IsHeapNumber()); |
| 760 double value = HeapNumber::cast(*byteLength)->value(); | 783 double value = HeapNumber::cast(*byteLength)->value(); |
| 761 | 784 |
| 762 ASSERT(value >= 0); | 785 ASSERT(value >= 0); |
| 763 | 786 |
| 764 if (value > std::numeric_limits<size_t>::max()) { | 787 if (value > std::numeric_limits<size_t>::max()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 ARRAY_ID_UINT16 = 3, | 838 ARRAY_ID_UINT16 = 3, |
| 816 ARRAY_ID_INT16 = 4, | 839 ARRAY_ID_INT16 = 4, |
| 817 ARRAY_ID_UINT32 = 5, | 840 ARRAY_ID_UINT32 = 5, |
| 818 ARRAY_ID_INT32 = 6, | 841 ARRAY_ID_INT32 = 6, |
| 819 ARRAY_ID_FLOAT32 = 7, | 842 ARRAY_ID_FLOAT32 = 7, |
| 820 ARRAY_ID_FLOAT64 = 8, | 843 ARRAY_ID_FLOAT64 = 8, |
| 821 ARRAY_ID_UINT8C = 9 | 844 ARRAY_ID_UINT8C = 9 |
| 822 }; | 845 }; |
| 823 | 846 |
| 824 static void ArrayIdToTypeAndSize( | 847 static void ArrayIdToTypeAndSize( |
| 825 int arrayId, ExternalArrayType* array_type, size_t* element_size) { | 848 int arrayId, |
| 849 ExternalArrayType* array_type, size_t* element_size, const char** name) { | |
| 826 switch (arrayId) { | 850 switch (arrayId) { |
| 827 case ARRAY_ID_UINT8: | 851 case ARRAY_ID_UINT8: |
| 828 *array_type = kExternalUnsignedByteArray; | 852 *array_type = kExternalUnsignedByteArray; |
| 829 *element_size = 1; | 853 *element_size = 1; |
| 854 *name = "Uint8Array"; | |
| 830 break; | 855 break; |
| 831 case ARRAY_ID_INT8: | 856 case ARRAY_ID_INT8: |
| 832 *array_type = kExternalByteArray; | 857 *array_type = kExternalByteArray; |
| 833 *element_size = 1; | 858 *element_size = 1; |
| 859 *name = "Int8Array"; | |
| 834 break; | 860 break; |
| 835 case ARRAY_ID_UINT16: | 861 case ARRAY_ID_UINT16: |
| 836 *array_type = kExternalUnsignedShortArray; | 862 *array_type = kExternalUnsignedShortArray; |
| 837 *element_size = 2; | 863 *element_size = 2; |
| 864 *name = "Uint16Array"; | |
| 838 break; | 865 break; |
| 839 case ARRAY_ID_INT16: | 866 case ARRAY_ID_INT16: |
| 840 *array_type = kExternalShortArray; | 867 *array_type = kExternalShortArray; |
| 841 *element_size = 2; | 868 *element_size = 2; |
| 869 *name = "Int16Array"; | |
| 842 break; | 870 break; |
| 843 case ARRAY_ID_UINT32: | 871 case ARRAY_ID_UINT32: |
| 844 *array_type = kExternalUnsignedIntArray; | 872 *array_type = kExternalUnsignedIntArray; |
| 845 *element_size = 4; | 873 *element_size = 4; |
| 874 *name = "Uint32Array"; | |
| 846 break; | 875 break; |
| 847 case ARRAY_ID_INT32: | 876 case ARRAY_ID_INT32: |
| 848 *array_type = kExternalIntArray; | 877 *array_type = kExternalIntArray; |
| 849 *element_size = 4; | 878 *element_size = 4; |
| 879 *name = "Int32Array"; | |
| 850 break; | 880 break; |
| 851 case ARRAY_ID_FLOAT32: | 881 case ARRAY_ID_FLOAT32: |
| 852 *array_type = kExternalFloatArray; | 882 *array_type = kExternalFloatArray; |
| 853 *element_size = 4; | 883 *element_size = 4; |
| 884 *name = "Float32Array"; | |
| 854 break; | 885 break; |
| 855 case ARRAY_ID_FLOAT64: | 886 case ARRAY_ID_FLOAT64: |
| 856 *array_type = kExternalDoubleArray; | 887 *array_type = kExternalDoubleArray; |
| 857 *element_size = 8; | 888 *element_size = 8; |
| 889 *name = "Float64Array"; | |
| 858 break; | 890 break; |
| 859 case ARRAY_ID_UINT8C: | 891 case ARRAY_ID_UINT8C: |
| 860 *array_type = kExternalPixelArray; | 892 *array_type = kExternalPixelArray; |
| 861 *element_size = 1; | 893 *element_size = 1; |
| 894 *name = "Uint8ClampedArray"; | |
| 862 break; | 895 break; |
| 863 default: | 896 default: |
| 864 UNREACHABLE(); | 897 UNREACHABLE(); |
| 865 } | 898 } |
| 866 } | 899 } |
| 867 | 900 |
| 868 | 901 |
| 869 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { | 902 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { |
| 870 HandleScope scope(isolate); | 903 HandleScope scope(isolate); |
| 871 ASSERT(args.length() == 5); | 904 ASSERT(args.length() == 5); |
| 872 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | 905 CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0); |
| 873 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | 906 CONVERT_SMI_ARG_CHECKED(arrayId, 1); |
| 874 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2); | 907 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2); |
| 875 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3); | 908 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3); |
| 876 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4); | 909 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4); |
| 877 | 910 |
| 911 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | |
| 912 size_t element_size = 1; // Bogus initialization. | |
| 913 const char* name = NULL; // Bogus initialization. | |
| 914 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size, &name); | |
|
arv (Not doing code reviews)
2013/08/04 16:44:28
Can you move this code into the error cases? The c
Dmitry Lomov (no reviews)
2013/08/05 10:15:22
Done. Do you think it's cleaner that way? (Perf im
arv (Not doing code reviews)
2013/08/05 13:34:33
Sorry, I think my comment was bad advice. I didn't
| |
| 915 | |
| 916 if (!this_obj->IsJSTypedArray()) { | |
| 917 return ThrowTypeError(isolate, "constructor_not_function", name); | |
| 918 } | |
| 919 Handle<JSTypedArray> holder(JSTypedArray::cast(*this_obj)); | |
| 920 if (!holder->buffer()->IsUndefined()) { | |
| 921 return ThrowTypeError( | |
| 922 isolate, "object_already_initialized", name); | |
| 923 } | |
| 924 | |
| 878 ASSERT(holder->GetInternalFieldCount() == | 925 ASSERT(holder->GetInternalFieldCount() == |
| 879 v8::ArrayBufferView::kInternalFieldCount); | 926 v8::ArrayBufferView::kInternalFieldCount); |
| 880 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 927 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 881 holder->SetInternalField(i, Smi::FromInt(0)); | 928 holder->SetInternalField(i, Smi::FromInt(0)); |
| 882 } | 929 } |
| 883 | 930 |
| 884 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | |
| 885 size_t element_size = 1; // Bogus initialization. | |
| 886 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | |
| 887 | |
| 888 holder->set_buffer(*buffer); | 931 holder->set_buffer(*buffer); |
| 889 holder->set_byte_offset(*byte_offset_object); | 932 holder->set_byte_offset(*byte_offset_object); |
| 890 holder->set_byte_length(*byte_length_object); | 933 holder->set_byte_length(*byte_length_object); |
| 891 | 934 |
| 892 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); | 935 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); |
| 893 size_t byte_length = NumberToSize(isolate, *byte_length_object); | 936 size_t byte_length = NumberToSize(isolate, *byte_length_object); |
| 894 ASSERT(byte_length % element_size == 0); | 937 ASSERT(byte_length % element_size == 0); |
| 895 size_t length = byte_length / element_size; | 938 size_t length = byte_length / element_size; |
| 896 | 939 |
| 897 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 940 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 909 | 952 |
| 910 | 953 |
| 911 // Initializes a typed array from an array-like object. | 954 // Initializes a typed array from an array-like object. |
| 912 // If an array-like object happens to be a typed array of the same type, | 955 // If an array-like object happens to be a typed array of the same type, |
| 913 // initializes backing store using memove. | 956 // initializes backing store using memove. |
| 914 // | 957 // |
| 915 // Returns true if backing store was initialized or false otherwise. | 958 // Returns true if backing store was initialized or false otherwise. |
| 916 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitializeFromArrayLike) { | 959 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitializeFromArrayLike) { |
| 917 HandleScope scope(isolate); | 960 HandleScope scope(isolate); |
| 918 ASSERT(args.length() == 4); | 961 ASSERT(args.length() == 4); |
| 919 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | 962 CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0); |
| 920 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | 963 CONVERT_SMI_ARG_CHECKED(arrayId, 1); |
| 921 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); | 964 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); |
| 922 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3); | 965 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3); |
| 923 | 966 |
| 967 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | |
| 968 size_t element_size = 1; // Bogus initialization. | |
| 969 const char* name = NULL; // Bogus initialization. | |
| 970 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size, &name); | |
|
arv (Not doing code reviews)
2013/08/04 16:44:28
Ditto
Dmitry Lomov (no reviews)
2013/08/05 10:15:22
Ditto :)
| |
| 971 | |
| 972 if (!this_obj->IsJSTypedArray()) { | |
| 973 return ThrowTypeError(isolate, "constructor_not_function", name); | |
| 974 } | |
| 975 Handle<JSTypedArray> holder(JSTypedArray::cast(*this_obj)); | |
| 976 if (!holder->buffer()->IsUndefined()) { | |
| 977 return ThrowTypeError( | |
| 978 isolate, "object_already_initialized", name); | |
| 979 } | |
| 980 | |
| 924 ASSERT(holder->GetInternalFieldCount() == | 981 ASSERT(holder->GetInternalFieldCount() == |
| 925 v8::ArrayBufferView::kInternalFieldCount); | 982 v8::ArrayBufferView::kInternalFieldCount); |
| 926 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 983 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 927 holder->SetInternalField(i, Smi::FromInt(0)); | 984 holder->SetInternalField(i, Smi::FromInt(0)); |
| 928 } | 985 } |
| 929 | 986 |
| 930 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | |
| 931 size_t element_size = 1; // Bogus initialization. | |
| 932 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | |
| 933 | |
| 934 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 987 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 935 size_t length = NumberToSize(isolate, *length_obj); | 988 size_t length = NumberToSize(isolate, *length_obj); |
| 936 size_t byte_length = length * element_size; | 989 size_t byte_length = length * element_size; |
| 937 if (byte_length < length) { // Overflow | 990 if (byte_length < length) { // Overflow |
| 938 return isolate->Throw(*isolate->factory()-> | 991 return isolate->Throw(*isolate->factory()-> |
| 939 NewRangeError("invalid_array_buffer_length", | 992 NewRangeError("invalid_array_buffer_length", |
| 940 HandleVector<Object>(NULL, 0))); | 993 HandleVector<Object>(NULL, 0))); |
| 941 } | 994 } |
| 942 | 995 |
| 943 // We assume that the caller of this function will initialize holder | 996 // We assume that the caller of this function will initialize holder |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING); | 1135 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING); |
| 1083 } else { // Non-overlapping typed arrays | 1136 } else { // Non-overlapping typed arrays |
| 1084 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING); | 1137 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING); |
| 1085 } | 1138 } |
| 1086 } | 1139 } |
| 1087 | 1140 |
| 1088 | 1141 |
| 1089 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) { | 1142 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) { |
| 1090 HandleScope scope(isolate); | 1143 HandleScope scope(isolate); |
| 1091 ASSERT(args.length() == 4); | 1144 ASSERT(args.length() == 4); |
| 1092 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); | 1145 CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0); |
| 1093 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); | 1146 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); |
| 1094 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2); | 1147 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2); |
| 1095 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3); | 1148 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3); |
| 1096 | 1149 |
| 1150 if (!this_obj->IsJSDataView()) { | |
| 1151 return ThrowTypeError(isolate, "constructor_not_function", "DataView"); | |
| 1152 } | |
| 1153 Handle<JSDataView> holder(JSDataView::cast(*this_obj)); | |
| 1154 if (!holder->buffer()->IsUndefined()) { | |
| 1155 return ThrowTypeError( | |
| 1156 isolate, "object_already_initialized", "DataView"); | |
| 1157 } | |
| 1158 | |
| 1097 ASSERT(holder->GetInternalFieldCount() == | 1159 ASSERT(holder->GetInternalFieldCount() == |
| 1098 v8::ArrayBufferView::kInternalFieldCount); | 1160 v8::ArrayBufferView::kInternalFieldCount); |
| 1099 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 1161 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 1100 holder->SetInternalField(i, Smi::FromInt(0)); | 1162 holder->SetInternalField(i, Smi::FromInt(0)); |
| 1101 } | 1163 } |
| 1102 | 1164 |
| 1103 holder->set_buffer(*buffer); | 1165 holder->set_buffer(*buffer); |
| 1104 ASSERT(byte_offset->IsNumber()); | 1166 ASSERT(byte_offset->IsNumber()); |
| 1105 ASSERT( | 1167 ASSERT( |
| 1106 NumberToSize(isolate, buffer->byte_length()) >= | 1168 NumberToSize(isolate, buffer->byte_length()) >= |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1354 DATA_VIEW_SETTER(Int8, int8_t) | 1416 DATA_VIEW_SETTER(Int8, int8_t) |
| 1355 DATA_VIEW_SETTER(Uint16, uint16_t) | 1417 DATA_VIEW_SETTER(Uint16, uint16_t) |
| 1356 DATA_VIEW_SETTER(Int16, int16_t) | 1418 DATA_VIEW_SETTER(Int16, int16_t) |
| 1357 DATA_VIEW_SETTER(Uint32, uint32_t) | 1419 DATA_VIEW_SETTER(Uint32, uint32_t) |
| 1358 DATA_VIEW_SETTER(Int32, int32_t) | 1420 DATA_VIEW_SETTER(Int32, int32_t) |
| 1359 DATA_VIEW_SETTER(Float32, float) | 1421 DATA_VIEW_SETTER(Float32, float) |
| 1360 DATA_VIEW_SETTER(Float64, double) | 1422 DATA_VIEW_SETTER(Float64, double) |
| 1361 | 1423 |
| 1362 #undef DATA_VIEW_SETTER | 1424 #undef DATA_VIEW_SETTER |
| 1363 | 1425 |
| 1426 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetInitialize) { | |
| 1427 HandleScope scope(isolate); | |
| 1428 ASSERT(args.length() == 1); | |
| 1429 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); | |
| 1430 if (!holder->IsJSSet()) { | |
| 1431 return ThrowTypeError(isolate, "constructor_not_function", "Set"); | |
| 1432 } | |
| 1433 Handle<JSSet> set(JSSet::cast(*holder)); | |
| 1364 | 1434 |
| 1365 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetInitialize) { | 1435 if (!set->table()->IsUndefined()) { |
| 1436 return ThrowTypeError(isolate, "object_already_initialized", "Set"); | |
| 1437 } | |
| 1438 | |
| 1439 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0); | |
| 1440 set->set_table(*table); | |
| 1441 return *holder; | |
| 1442 } | |
| 1443 | |
| 1444 | |
| 1445 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetClear) { | |
| 1366 HandleScope scope(isolate); | 1446 HandleScope scope(isolate); |
| 1367 ASSERT(args.length() == 1); | 1447 ASSERT(args.length() == 1); |
| 1368 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 1448 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
| 1369 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0); | 1449 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0); |
| 1370 holder->set_table(*table); | 1450 holder->set_table(*table); |
| 1371 return *holder; | 1451 return *holder; |
| 1372 } | 1452 } |
| 1373 | 1453 |
| 1374 | 1454 |
| 1375 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAdd) { | 1455 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAdd) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1411 ASSERT(args.length() == 1); | 1491 ASSERT(args.length() == 1); |
| 1412 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 1492 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
| 1413 Handle<ObjectHashSet> table(ObjectHashSet::cast(holder->table())); | 1493 Handle<ObjectHashSet> table(ObjectHashSet::cast(holder->table())); |
| 1414 return Smi::FromInt(table->NumberOfElements()); | 1494 return Smi::FromInt(table->NumberOfElements()); |
| 1415 } | 1495 } |
| 1416 | 1496 |
| 1417 | 1497 |
| 1418 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapInitialize) { | 1498 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapInitialize) { |
| 1419 HandleScope scope(isolate); | 1499 HandleScope scope(isolate); |
| 1420 ASSERT(args.length() == 1); | 1500 ASSERT(args.length() == 1); |
| 1501 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); | |
| 1502 if (!holder->IsJSMap()) { | |
| 1503 return ThrowTypeError(isolate, "constructor_not_function", "Map"); | |
| 1504 } | |
| 1505 Handle<JSMap> map(JSMap::cast(*holder)); | |
| 1506 | |
| 1507 if (!map->table()->IsUndefined()) { | |
| 1508 return ThrowTypeError(isolate, "object_already_initialized", "Map"); | |
| 1509 } | |
| 1510 | |
| 1511 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); | |
| 1512 map->set_table(*table); | |
| 1513 return *holder; | |
| 1514 } | |
| 1515 | |
| 1516 | |
| 1517 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapClear) { | |
| 1518 HandleScope scope(isolate); | |
| 1519 ASSERT(args.length() == 1); | |
| 1421 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); | 1520 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
| 1422 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); | 1521 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0); |
| 1423 holder->set_table(*table); | 1522 holder->set_table(*table); |
| 1424 return *holder; | 1523 return *holder; |
| 1425 } | 1524 } |
| 1426 | 1525 |
| 1427 | 1526 |
| 1428 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGet) { | 1527 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGet) { |
| 1429 HandleScope scope(isolate); | 1528 HandleScope scope(isolate); |
| 1430 ASSERT(args.length() == 2); | 1529 ASSERT(args.length() == 2); |
| 1431 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); | 1530 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
| 1432 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 1531 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1486 static JSWeakCollection* WeakCollectionInitialize(Isolate* isolate, | 1585 static JSWeakCollection* WeakCollectionInitialize(Isolate* isolate, |
| 1487 Handle<JSWeakCollection> weak_collection) { | 1586 Handle<JSWeakCollection> weak_collection) { |
| 1488 ASSERT(weak_collection->map()->inobject_properties() == 0); | 1587 ASSERT(weak_collection->map()->inobject_properties() == 0); |
| 1489 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); | 1588 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); |
| 1490 weak_collection->set_table(*table); | 1589 weak_collection->set_table(*table); |
| 1491 weak_collection->set_next(Smi::FromInt(0)); | 1590 weak_collection->set_next(Smi::FromInt(0)); |
| 1492 return *weak_collection; | 1591 return *weak_collection; |
| 1493 } | 1592 } |
| 1494 | 1593 |
| 1495 | 1594 |
| 1496 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionInitialize) { | 1595 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapInitialize) { |
| 1596 HandleScope scope(isolate); | |
| 1597 ASSERT(args.length() == 1); | |
| 1598 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); | |
| 1599 if (!holder->IsJSWeakMap()) { | |
| 1600 return ThrowTypeError(isolate, "constructor_not_function", "WeakMap"); | |
| 1601 } | |
| 1602 Handle<JSWeakMap> map(JSWeakMap::cast(*holder)); | |
| 1603 if (!map->table()->IsUndefined()) { | |
| 1604 return ThrowTypeError(isolate, "object_already_initialized", "WeakMap"); | |
| 1605 } | |
| 1606 return WeakCollectionInitialize(isolate, map); | |
| 1607 } | |
| 1608 | |
| 1609 | |
| 1610 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakSetInitialize) { | |
| 1611 HandleScope scope(isolate); | |
| 1612 ASSERT(args.length() == 1); | |
| 1613 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); | |
| 1614 if (!holder->IsJSWeakSet()) { | |
| 1615 return ThrowTypeError(isolate, "constructor_not_function", "WeakSet"); | |
| 1616 } | |
| 1617 Handle<JSWeakSet> set(JSWeakSet::cast(*holder)); | |
| 1618 if (!set->table()->IsUndefined()) { | |
| 1619 return ThrowTypeError(isolate, "object_already_initialized", "WeakSet"); | |
| 1620 } | |
| 1621 return WeakCollectionInitialize(isolate, set); | |
| 1622 } | |
| 1623 | |
| 1624 | |
| 1625 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionClear) { | |
| 1497 HandleScope scope(isolate); | 1626 HandleScope scope(isolate); |
| 1498 ASSERT(args.length() == 1); | 1627 ASSERT(args.length() == 1); |
| 1499 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); | 1628 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); |
| 1500 return WeakCollectionInitialize(isolate, weak_collection); | 1629 return WeakCollectionInitialize(isolate, weak_collection); |
| 1501 } | 1630 } |
| 1502 | 1631 |
| 1503 | 1632 |
| 1504 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionGet) { | 1633 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionGet) { |
| 1505 HandleScope scope(isolate); | 1634 HandleScope scope(isolate); |
| 1506 ASSERT(args.length() == 2); | 1635 ASSERT(args.length() == 2); |
| (...skipping 12651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14158 // Handle last resort GC and make sure to allow future allocations | 14287 // Handle last resort GC and make sure to allow future allocations |
| 14159 // to grow the heap without causing GCs (if possible). | 14288 // to grow the heap without causing GCs (if possible). |
| 14160 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14289 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14161 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14290 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14162 "Runtime::PerformGC"); | 14291 "Runtime::PerformGC"); |
| 14163 } | 14292 } |
| 14164 } | 14293 } |
| 14165 | 14294 |
| 14166 | 14295 |
| 14167 } } // namespace v8::internal | 14296 } } // namespace v8::internal |
| OLD | NEW |