Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/runtime.cc

Issue 21924007: Make new Harmony constructors subclassing-friendly (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.h ('k') | src/typedarray.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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) {
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;
830 break; 854 break;
831 case ARRAY_ID_INT8: 855 case ARRAY_ID_INT8:
832 *array_type = kExternalByteArray; 856 *array_type = kExternalByteArray;
833 *element_size = 1; 857 *element_size = 1;
834 break; 858 break;
835 case ARRAY_ID_UINT16: 859 case ARRAY_ID_UINT16:
(...skipping 23 matching lines...) Expand all
859 case ARRAY_ID_UINT8C: 883 case ARRAY_ID_UINT8C:
860 *array_type = kExternalPixelArray; 884 *array_type = kExternalPixelArray;
861 *element_size = 1; 885 *element_size = 1;
862 break; 886 break;
863 default: 887 default:
864 UNREACHABLE(); 888 UNREACHABLE();
865 } 889 }
866 } 890 }
867 891
868 892
893 static const char * GetTypedArrayName(int arrayId) {
894 switch (arrayId) {
895 case ARRAY_ID_UINT8:
896 return "Uint8Array";
897 case ARRAY_ID_INT8:
898 return "Int8Array";
899 case ARRAY_ID_UINT16:
900 return "Uint16Array";
901 case ARRAY_ID_INT16:
902 return "Int16Array";
903 case ARRAY_ID_UINT32:
904 return "Uint32Array";
905 case ARRAY_ID_INT32:
906 return "Int32Array";
907 case ARRAY_ID_FLOAT32:
908 return "Float32Array";
909 case ARRAY_ID_FLOAT64:
910 return "Float64Array";
911 case ARRAY_ID_UINT8C:
912 return "Uint8ClampedArray";
913 default:
914 UNREACHABLE();
915 return NULL;
916 }
917 }
918
919
869 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { 920 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
870 HandleScope scope(isolate); 921 HandleScope scope(isolate);
871 ASSERT(args.length() == 5); 922 ASSERT(args.length() == 5);
872 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 923 CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0);
873 CONVERT_SMI_ARG_CHECKED(arrayId, 1); 924 CONVERT_SMI_ARG_CHECKED(arrayId, 1);
874 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2); 925 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2);
875 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3); 926 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3);
876 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4); 927 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4);
877 928
929 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
930 size_t element_size = 1; // Bogus initialization.
931 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
932
933 if (!this_obj->IsJSTypedArray()) {
934 return ThrowTypeError(isolate, "constructor_not_function",
935 GetTypedArrayName(arrayId));
936 }
937 Handle<JSTypedArray> holder(JSTypedArray::cast(*this_obj));
938 if (!holder->buffer()->IsUndefined()) {
939 return ThrowTypeError(
940 isolate, "object_already_initialized", GetTypedArrayName(arrayId));
941 }
942
878 ASSERT(holder->GetInternalFieldCount() == 943 ASSERT(holder->GetInternalFieldCount() ==
879 v8::ArrayBufferView::kInternalFieldCount); 944 v8::ArrayBufferView::kInternalFieldCount);
880 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 945 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
881 holder->SetInternalField(i, Smi::FromInt(0)); 946 holder->SetInternalField(i, Smi::FromInt(0));
882 } 947 }
883 948
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); 949 holder->set_buffer(*buffer);
889 holder->set_byte_offset(*byte_offset_object); 950 holder->set_byte_offset(*byte_offset_object);
890 holder->set_byte_length(*byte_length_object); 951 holder->set_byte_length(*byte_length_object);
891 952
892 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); 953 size_t byte_offset = NumberToSize(isolate, *byte_offset_object);
893 size_t byte_length = NumberToSize(isolate, *byte_length_object); 954 size_t byte_length = NumberToSize(isolate, *byte_length_object);
894 ASSERT(byte_length % element_size == 0); 955 ASSERT(byte_length % element_size == 0);
895 size_t length = byte_length / element_size; 956 size_t length = byte_length / element_size;
896 957
897 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 958 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
(...skipping 11 matching lines...) Expand all
909 970
910 971
911 // Initializes a typed array from an array-like object. 972 // 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, 973 // If an array-like object happens to be a typed array of the same type,
913 // initializes backing store using memove. 974 // initializes backing store using memove.
914 // 975 //
915 // Returns true if backing store was initialized or false otherwise. 976 // Returns true if backing store was initialized or false otherwise.
916 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitializeFromArrayLike) { 977 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitializeFromArrayLike) {
917 HandleScope scope(isolate); 978 HandleScope scope(isolate);
918 ASSERT(args.length() == 4); 979 ASSERT(args.length() == 4);
919 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 980 CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0);
920 CONVERT_SMI_ARG_CHECKED(arrayId, 1); 981 CONVERT_SMI_ARG_CHECKED(arrayId, 1);
921 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); 982 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2);
922 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3); 983 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3);
923 984
985 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
986 size_t element_size = 1; // Bogus initialization.
987 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
988
989 if (!this_obj->IsJSTypedArray()) {
990 return ThrowTypeError(isolate, "constructor_not_function",
991 GetTypedArrayName(arrayId));
992 }
993 Handle<JSTypedArray> holder(JSTypedArray::cast(*this_obj));
994 if (!holder->buffer()->IsUndefined()) {
995 return ThrowTypeError(
996 isolate, "object_already_initialized", GetTypedArrayName(arrayId));
997 }
998
924 ASSERT(holder->GetInternalFieldCount() == 999 ASSERT(holder->GetInternalFieldCount() ==
925 v8::ArrayBufferView::kInternalFieldCount); 1000 v8::ArrayBufferView::kInternalFieldCount);
926 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 1001 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
927 holder->SetInternalField(i, Smi::FromInt(0)); 1002 holder->SetInternalField(i, Smi::FromInt(0));
928 } 1003 }
929 1004
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(); 1005 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
935 size_t length = NumberToSize(isolate, *length_obj); 1006 size_t length = NumberToSize(isolate, *length_obj);
936 size_t byte_length = length * element_size; 1007 size_t byte_length = length * element_size;
937 if (byte_length < length) { // Overflow 1008 if (byte_length < length) { // Overflow
938 return isolate->Throw(*isolate->factory()-> 1009 return isolate->Throw(*isolate->factory()->
939 NewRangeError("invalid_array_buffer_length", 1010 NewRangeError("invalid_array_buffer_length",
940 HandleVector<Object>(NULL, 0))); 1011 HandleVector<Object>(NULL, 0)));
941 } 1012 }
942 1013
943 // We assume that the caller of this function will initialize holder 1014 // We assume that the caller of this function will initialize holder
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING); 1153 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING);
1083 } else { // Non-overlapping typed arrays 1154 } else { // Non-overlapping typed arrays
1084 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING); 1155 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING);
1085 } 1156 }
1086 } 1157 }
1087 1158
1088 1159
1089 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) { 1160 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) {
1090 HandleScope scope(isolate); 1161 HandleScope scope(isolate);
1091 ASSERT(args.length() == 4); 1162 ASSERT(args.length() == 4);
1092 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); 1163 CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0);
1093 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); 1164 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1);
1094 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2); 1165 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2);
1095 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3); 1166 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3);
1096 1167
1168 if (!this_obj->IsJSDataView()) {
1169 return ThrowTypeError(isolate, "constructor_not_function", "DataView");
1170 }
1171 Handle<JSDataView> holder(JSDataView::cast(*this_obj));
1172 if (!holder->buffer()->IsUndefined()) {
1173 return ThrowTypeError(
1174 isolate, "object_already_initialized", "DataView");
1175 }
1176
1097 ASSERT(holder->GetInternalFieldCount() == 1177 ASSERT(holder->GetInternalFieldCount() ==
1098 v8::ArrayBufferView::kInternalFieldCount); 1178 v8::ArrayBufferView::kInternalFieldCount);
1099 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 1179 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
1100 holder->SetInternalField(i, Smi::FromInt(0)); 1180 holder->SetInternalField(i, Smi::FromInt(0));
1101 } 1181 }
1102 1182
1103 holder->set_buffer(*buffer); 1183 holder->set_buffer(*buffer);
1104 ASSERT(byte_offset->IsNumber()); 1184 ASSERT(byte_offset->IsNumber());
1105 ASSERT( 1185 ASSERT(
1106 NumberToSize(isolate, buffer->byte_length()) >= 1186 NumberToSize(isolate, buffer->byte_length()) >=
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 DATA_VIEW_SETTER(Int8, int8_t) 1434 DATA_VIEW_SETTER(Int8, int8_t)
1355 DATA_VIEW_SETTER(Uint16, uint16_t) 1435 DATA_VIEW_SETTER(Uint16, uint16_t)
1356 DATA_VIEW_SETTER(Int16, int16_t) 1436 DATA_VIEW_SETTER(Int16, int16_t)
1357 DATA_VIEW_SETTER(Uint32, uint32_t) 1437 DATA_VIEW_SETTER(Uint32, uint32_t)
1358 DATA_VIEW_SETTER(Int32, int32_t) 1438 DATA_VIEW_SETTER(Int32, int32_t)
1359 DATA_VIEW_SETTER(Float32, float) 1439 DATA_VIEW_SETTER(Float32, float)
1360 DATA_VIEW_SETTER(Float64, double) 1440 DATA_VIEW_SETTER(Float64, double)
1361 1441
1362 #undef DATA_VIEW_SETTER 1442 #undef DATA_VIEW_SETTER
1363 1443
1444 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetInitialize) {
1445 HandleScope scope(isolate);
1446 ASSERT(args.length() == 1);
1447 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
1448 if (!holder->IsJSSet()) {
1449 return ThrowTypeError(isolate, "constructor_not_function", "Set");
1450 }
1451 Handle<JSSet> set(JSSet::cast(*holder));
1364 1452
1365 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetInitialize) { 1453 if (!set->table()->IsUndefined()) {
1454 return ThrowTypeError(isolate, "object_already_initialized", "Set");
1455 }
1456
1457 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0);
1458 set->set_table(*table);
1459 return *holder;
1460 }
1461
1462
1463 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetClear) {
1366 HandleScope scope(isolate); 1464 HandleScope scope(isolate);
1367 ASSERT(args.length() == 1); 1465 ASSERT(args.length() == 1);
1368 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); 1466 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
1369 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0); 1467 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0);
1370 holder->set_table(*table); 1468 holder->set_table(*table);
1371 return *holder; 1469 return *holder;
1372 } 1470 }
1373 1471
1374 1472
1375 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAdd) { 1473 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAdd) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 ASSERT(args.length() == 1); 1509 ASSERT(args.length() == 1);
1412 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); 1510 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
1413 Handle<ObjectHashSet> table(ObjectHashSet::cast(holder->table())); 1511 Handle<ObjectHashSet> table(ObjectHashSet::cast(holder->table()));
1414 return Smi::FromInt(table->NumberOfElements()); 1512 return Smi::FromInt(table->NumberOfElements());
1415 } 1513 }
1416 1514
1417 1515
1418 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapInitialize) { 1516 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapInitialize) {
1419 HandleScope scope(isolate); 1517 HandleScope scope(isolate);
1420 ASSERT(args.length() == 1); 1518 ASSERT(args.length() == 1);
1519 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
1520 if (!holder->IsJSMap()) {
1521 return ThrowTypeError(isolate, "constructor_not_function", "Map");
1522 }
1523 Handle<JSMap> map(JSMap::cast(*holder));
1524
1525 if (!map->table()->IsUndefined()) {
1526 return ThrowTypeError(isolate, "object_already_initialized", "Map");
1527 }
1528
1529 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0);
1530 map->set_table(*table);
1531 return *holder;
1532 }
1533
1534
1535 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapClear) {
1536 HandleScope scope(isolate);
1537 ASSERT(args.length() == 1);
1421 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); 1538 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
1422 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); 1539 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0);
1423 holder->set_table(*table); 1540 holder->set_table(*table);
1424 return *holder; 1541 return *holder;
1425 } 1542 }
1426 1543
1427 1544
1428 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGet) { 1545 RUNTIME_FUNCTION(MaybeObject*, Runtime_MapGet) {
1429 HandleScope scope(isolate); 1546 HandleScope scope(isolate);
1430 ASSERT(args.length() == 2); 1547 ASSERT(args.length() == 2);
1431 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); 1548 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
1432 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 1549 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 static JSWeakCollection* WeakCollectionInitialize(Isolate* isolate, 1603 static JSWeakCollection* WeakCollectionInitialize(Isolate* isolate,
1487 Handle<JSWeakCollection> weak_collection) { 1604 Handle<JSWeakCollection> weak_collection) {
1488 ASSERT(weak_collection->map()->inobject_properties() == 0); 1605 ASSERT(weak_collection->map()->inobject_properties() == 0);
1489 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0); 1606 Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0);
1490 weak_collection->set_table(*table); 1607 weak_collection->set_table(*table);
1491 weak_collection->set_next(Smi::FromInt(0)); 1608 weak_collection->set_next(Smi::FromInt(0));
1492 return *weak_collection; 1609 return *weak_collection;
1493 } 1610 }
1494 1611
1495 1612
1496 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionInitialize) { 1613 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapInitialize) {
1614 HandleScope scope(isolate);
1615 ASSERT(args.length() == 1);
1616 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
1617 if (!holder->IsJSWeakMap()) {
1618 return ThrowTypeError(isolate, "constructor_not_function", "WeakMap");
1619 }
1620 Handle<JSWeakMap> map(JSWeakMap::cast(*holder));
1621 if (!map->table()->IsUndefined()) {
1622 return ThrowTypeError(isolate, "object_already_initialized", "WeakMap");
1623 }
1624 return WeakCollectionInitialize(isolate, map);
1625 }
1626
1627
1628 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakSetInitialize) {
1629 HandleScope scope(isolate);
1630 ASSERT(args.length() == 1);
1631 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
1632 if (!holder->IsJSWeakSet()) {
1633 return ThrowTypeError(isolate, "constructor_not_function", "WeakSet");
1634 }
1635 Handle<JSWeakSet> set(JSWeakSet::cast(*holder));
1636 if (!set->table()->IsUndefined()) {
1637 return ThrowTypeError(isolate, "object_already_initialized", "WeakSet");
1638 }
1639 return WeakCollectionInitialize(isolate, set);
1640 }
1641
1642
1643 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionClear) {
1497 HandleScope scope(isolate); 1644 HandleScope scope(isolate);
1498 ASSERT(args.length() == 1); 1645 ASSERT(args.length() == 1);
1499 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 1646 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
1500 return WeakCollectionInitialize(isolate, weak_collection); 1647 return WeakCollectionInitialize(isolate, weak_collection);
1501 } 1648 }
1502 1649
1503 1650
1504 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionGet) { 1651 RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionGet) {
1505 HandleScope scope(isolate); 1652 HandleScope scope(isolate);
1506 ASSERT(args.length() == 2); 1653 ASSERT(args.length() == 2);
(...skipping 12651 matching lines...) Expand 10 before | Expand all | Expand 10 after
14158 // Handle last resort GC and make sure to allow future allocations 14305 // Handle last resort GC and make sure to allow future allocations
14159 // to grow the heap without causing GCs (if possible). 14306 // to grow the heap without causing GCs (if possible).
14160 isolate->counters()->gc_last_resort_from_js()->Increment(); 14307 isolate->counters()->gc_last_resort_from_js()->Increment();
14161 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14308 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14162 "Runtime::PerformGC"); 14309 "Runtime::PerformGC");
14163 } 14310 }
14164 } 14311 }
14165 14312
14166 14313
14167 } } // namespace v8::internal 14314 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698