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 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 // JSReceiver includes types on which properties can be defined, i.e., | 1346 // JSReceiver includes types on which properties can be defined, i.e., |
1347 // JSObject and JSProxy. | 1347 // JSObject and JSProxy. |
1348 class JSReceiver: public HeapObject { | 1348 class JSReceiver: public HeapObject { |
1349 public: | 1349 public: |
1350 enum DeleteMode { | 1350 enum DeleteMode { |
1351 NORMAL_DELETION, | 1351 NORMAL_DELETION, |
1352 STRICT_DELETION, | 1352 STRICT_DELETION, |
1353 FORCE_DELETION | 1353 FORCE_DELETION |
1354 }; | 1354 }; |
1355 | 1355 |
| 1356 // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas |
| 1357 // a keyed store is of the form a[expression] = foo. |
| 1358 enum StoreFromKeyed { |
| 1359 MAY_BE_STORE_FROM_KEYED, |
| 1360 CERTAINLY_NOT_STORE_FROM_KEYED |
| 1361 }; |
| 1362 |
1356 // Casting. | 1363 // Casting. |
1357 static inline JSReceiver* cast(Object* obj); | 1364 static inline JSReceiver* cast(Object* obj); |
1358 | 1365 |
1359 static Handle<Object> SetProperty(Handle<JSReceiver> object, | 1366 static Handle<Object> SetProperty(Handle<JSReceiver> object, |
1360 Handle<String> key, | 1367 Handle<String> key, |
1361 Handle<Object> value, | 1368 Handle<Object> value, |
1362 PropertyAttributes attributes, | 1369 PropertyAttributes attributes, |
1363 StrictModeFlag strict_mode); | 1370 StrictModeFlag strict_mode); |
1364 // Can cause GC. | 1371 // Can cause GC. |
1365 MUST_USE_RESULT MaybeObject* SetProperty(String* key, | 1372 MUST_USE_RESULT MaybeObject* SetProperty( |
1366 Object* value, | 1373 String* key, |
1367 PropertyAttributes attributes, | 1374 Object* value, |
1368 StrictModeFlag strict_mode); | 1375 PropertyAttributes attributes, |
1369 MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, | 1376 StrictModeFlag strict_mode, |
1370 String* key, | 1377 StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED); |
1371 Object* value, | 1378 MUST_USE_RESULT MaybeObject* SetProperty( |
1372 PropertyAttributes attributes, | 1379 LookupResult* result, |
1373 StrictModeFlag strict_mode); | 1380 String* key, |
| 1381 Object* value, |
| 1382 PropertyAttributes attributes, |
| 1383 StrictModeFlag strict_mode, |
| 1384 StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED); |
1374 MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter, | 1385 MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter, |
1375 Object* value); | 1386 Object* value); |
1376 | 1387 |
1377 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); | 1388 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
1378 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); | 1389 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
1379 | 1390 |
1380 // Set the index'th array element. | 1391 // Set the index'th array element. |
1381 // Can cause GC, or return failure if GC is required. | 1392 // Can cause GC, or return failure if GC is required. |
1382 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, | 1393 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
1383 Object* value, | 1394 Object* value, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 | 1528 |
1518 MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, | 1529 MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
1519 Object* structure, | 1530 Object* structure, |
1520 String* name); | 1531 String* name); |
1521 | 1532 |
1522 // Can cause GC. | 1533 // Can cause GC. |
1523 MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, | 1534 MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
1524 String* key, | 1535 String* key, |
1525 Object* value, | 1536 Object* value, |
1526 PropertyAttributes attributes, | 1537 PropertyAttributes attributes, |
1527 StrictModeFlag strict_mode); | 1538 StrictModeFlag strict_mode, |
| 1539 StoreFromKeyed store_mode); |
1528 MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( | 1540 MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
1529 LookupResult* result, | 1541 LookupResult* result, |
1530 String* name, | 1542 String* name, |
1531 Object* value, | 1543 Object* value, |
1532 bool check_prototype, | 1544 bool check_prototype, |
1533 StrictModeFlag strict_mode); | 1545 StrictModeFlag strict_mode); |
1534 MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( | 1546 MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
1535 Object* structure, | 1547 Object* structure, |
1536 String* name, | 1548 String* name, |
1537 Object* value, | 1549 Object* value, |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 | 1926 |
1915 // Converts a descriptor of any other type to a real field, | 1927 // Converts a descriptor of any other type to a real field, |
1916 // backed by the properties array. Descriptors of visible | 1928 // backed by the properties array. Descriptors of visible |
1917 // types, such as CONSTANT_FUNCTION, keep their enumeration order. | 1929 // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
1918 MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( | 1930 MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
1919 String* name, | 1931 String* name, |
1920 Object* new_value, | 1932 Object* new_value, |
1921 PropertyAttributes attributes); | 1933 PropertyAttributes attributes); |
1922 | 1934 |
1923 // Add a property to a fast-case object. | 1935 // Add a property to a fast-case object. |
1924 MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, | 1936 MUST_USE_RESULT MaybeObject* AddFastProperty( |
1925 Object* value, | 1937 String* name, |
1926 PropertyAttributes attributes); | 1938 Object* value, |
| 1939 PropertyAttributes attributes, |
| 1940 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
1927 | 1941 |
1928 // Add a property to a slow-case object. | 1942 // Add a property to a slow-case object. |
1929 MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, | 1943 MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
1930 Object* value, | 1944 Object* value, |
1931 PropertyAttributes attributes); | 1945 PropertyAttributes attributes); |
1932 | 1946 |
1933 // Add a property to an object. | 1947 // Add a property to an object. |
1934 MUST_USE_RESULT MaybeObject* AddProperty(String* name, | 1948 MUST_USE_RESULT MaybeObject* AddProperty( |
1935 Object* value, | 1949 String* name, |
1936 PropertyAttributes attributes, | 1950 Object* value, |
1937 StrictModeFlag strict_mode); | 1951 PropertyAttributes attributes, |
| 1952 StrictModeFlag strict_mode, |
| 1953 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
1938 | 1954 |
1939 // Convert the object to use the canonical dictionary | 1955 // Convert the object to use the canonical dictionary |
1940 // representation. If the object is expected to have additional properties | 1956 // representation. If the object is expected to have additional properties |
1941 // added this number can be indicated to have the backing store allocated to | 1957 // added this number can be indicated to have the backing store allocated to |
1942 // an initial capacity for holding these properties. | 1958 // an initial capacity for holding these properties. |
1943 static void NormalizeProperties(Handle<JSObject> object, | 1959 static void NormalizeProperties(Handle<JSObject> object, |
1944 PropertyNormalizationMode mode, | 1960 PropertyNormalizationMode mode, |
1945 int expected_additional_properties); | 1961 int expected_additional_properties); |
1946 | 1962 |
1947 MUST_USE_RESULT MaybeObject* NormalizeProperties( | 1963 MUST_USE_RESULT MaybeObject* NormalizeProperties( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2047 int number_of_slow_unused_elements_; | 2063 int number_of_slow_unused_elements_; |
2048 }; | 2064 }; |
2049 | 2065 |
2050 void IncrementSpillStatistics(SpillInformation* info); | 2066 void IncrementSpillStatistics(SpillInformation* info); |
2051 #endif | 2067 #endif |
2052 Object* SlowReverseLookup(Object* value); | 2068 Object* SlowReverseLookup(Object* value); |
2053 | 2069 |
2054 // Maximal number of fast properties for the JSObject. Used to | 2070 // Maximal number of fast properties for the JSObject. Used to |
2055 // restrict the number of map transitions to avoid an explosion in | 2071 // restrict the number of map transitions to avoid an explosion in |
2056 // the number of maps for objects used as dictionaries. | 2072 // the number of maps for objects used as dictionaries. |
2057 inline bool TooManyFastProperties(int properties); | 2073 inline bool TooManyFastProperties(int properties, StoreFromKeyed store_mode); |
2058 | 2074 |
2059 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). | 2075 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
2060 // Also maximal value of JSArray's length property. | 2076 // Also maximal value of JSArray's length property. |
2061 static const uint32_t kMaxElementCount = 0xffffffffu; | 2077 static const uint32_t kMaxElementCount = 0xffffffffu; |
2062 | 2078 |
2063 // Constants for heuristics controlling conversion of fast elements | 2079 // Constants for heuristics controlling conversion of fast elements |
2064 // to slow elements. | 2080 // to slow elements. |
2065 | 2081 |
2066 // Maximal gap that can be introduced by adding an element beyond | 2082 // Maximal gap that can be introduced by adding an element beyond |
2067 // the current elements length. | 2083 // the current elements length. |
2068 static const uint32_t kMaxGap = 1024; | 2084 static const uint32_t kMaxGap = 1024; |
2069 | 2085 |
2070 // Maximal length of fast elements array that won't be checked for | 2086 // Maximal length of fast elements array that won't be checked for |
2071 // being dense enough on expansion. | 2087 // being dense enough on expansion. |
2072 static const int kMaxUncheckedFastElementsLength = 5000; | 2088 static const int kMaxUncheckedFastElementsLength = 5000; |
2073 | 2089 |
2074 // Same as above but for old arrays. This limit is more strict. We | 2090 // Same as above but for old arrays. This limit is more strict. We |
2075 // don't want to be wasteful with long lived objects. | 2091 // don't want to be wasteful with long lived objects. |
2076 static const int kMaxUncheckedOldFastElementsLength = 500; | 2092 static const int kMaxUncheckedOldFastElementsLength = 500; |
2077 | 2093 |
2078 static const int kInitialMaxFastElementArray = 100000; | 2094 static const int kInitialMaxFastElementArray = 100000; |
2079 static const int kFastPropertiesSoftLimit = 12; | 2095 static const int kFastPropertiesSoftLimit = 12; |
2080 static const int kMaxFastProperties = 32; | 2096 static const int kMaxFastProperties = 64; |
2081 static const int kMaxInstanceSize = 255 * kPointerSize; | 2097 static const int kMaxInstanceSize = 255 * kPointerSize; |
2082 // When extending the backing storage for property values, we increase | 2098 // When extending the backing storage for property values, we increase |
2083 // its size by more than the 1 entry necessary, so sequentially adding fields | 2099 // its size by more than the 1 entry necessary, so sequentially adding fields |
2084 // to the same object requires fewer allocations and copies. | 2100 // to the same object requires fewer allocations and copies. |
2085 static const int kFieldsAdded = 3; | 2101 static const int kFieldsAdded = 3; |
2086 | 2102 |
2087 // Layout description. | 2103 // Layout description. |
2088 static const int kPropertiesOffset = HeapObject::kHeaderSize; | 2104 static const int kPropertiesOffset = HeapObject::kHeaderSize; |
2089 static const int kElementsOffset = kPropertiesOffset + kPointerSize; | 2105 static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
2090 static const int kHeaderSize = kElementsOffset + kPointerSize; | 2106 static const int kHeaderSize = kElementsOffset + kPointerSize; |
(...skipping 6607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8698 } else { | 8714 } else { |
8699 value &= ~(1 << bit_position); | 8715 value &= ~(1 << bit_position); |
8700 } | 8716 } |
8701 return value; | 8717 return value; |
8702 } | 8718 } |
8703 }; | 8719 }; |
8704 | 8720 |
8705 } } // namespace v8::internal | 8721 } } // namespace v8::internal |
8706 | 8722 |
8707 #endif // V8_OBJECTS_H_ | 8723 #endif // V8_OBJECTS_H_ |
OLD | NEW |