OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 }; | 1795 }; |
1796 | 1796 |
1797 | 1797 |
1798 enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING }; | 1798 enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING }; |
1799 | 1799 |
1800 | 1800 |
1801 // JSReceiver includes types on which properties can be defined, i.e., | 1801 // JSReceiver includes types on which properties can be defined, i.e., |
1802 // JSObject and JSProxy. | 1802 // JSObject and JSProxy. |
1803 class JSReceiver: public HeapObject { | 1803 class JSReceiver: public HeapObject { |
1804 public: | 1804 public: |
| 1805 // [properties]: Backing storage for properties. |
| 1806 // properties is a FixedArray in the fast case and a Dictionary in the |
| 1807 // slow case. |
| 1808 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1809 inline void initialize_properties(); |
| 1810 inline bool HasFastProperties(); |
| 1811 // Gets slow properties for non-global objects. |
| 1812 inline NameDictionary* property_dictionary(); |
| 1813 |
1805 DECLARE_CAST(JSReceiver) | 1814 DECLARE_CAST(JSReceiver) |
1806 | 1815 |
1807 // ES6 section 7.1.1 ToPrimitive | 1816 // ES6 section 7.1.1 ToPrimitive |
1808 MUST_USE_RESULT static MaybeHandle<Object> ToPrimitive( | 1817 MUST_USE_RESULT static MaybeHandle<Object> ToPrimitive( |
1809 Handle<JSReceiver> receiver, | 1818 Handle<JSReceiver> receiver, |
1810 ToPrimitiveHint hint = ToPrimitiveHint::kDefault); | 1819 ToPrimitiveHint hint = ToPrimitiveHint::kDefault); |
1811 MUST_USE_RESULT static MaybeHandle<Object> OrdinaryToPrimitive( | 1820 MUST_USE_RESULT static MaybeHandle<Object> OrdinaryToPrimitive( |
1812 Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint); | 1821 Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint); |
1813 | 1822 |
1814 static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver); | 1823 static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1953 return GetKeys(object, JSReceiver::OWN_ONLY, ALL_PROPERTIES, | 1962 return GetKeys(object, JSReceiver::OWN_ONLY, ALL_PROPERTIES, |
1954 CONVERT_TO_STRING); | 1963 CONVERT_TO_STRING); |
1955 } | 1964 } |
1956 | 1965 |
1957 // Computes the enumerable keys for a JSObject. Used for implementing | 1966 // Computes the enumerable keys for a JSObject. Used for implementing |
1958 // "for (n in object) { }". | 1967 // "for (n in object) { }". |
1959 MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys( | 1968 MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys( |
1960 Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter, | 1969 Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter, |
1961 GetKeysConversion keys_conversion = KEEP_NUMBERS); | 1970 GetKeysConversion keys_conversion = KEEP_NUMBERS); |
1962 | 1971 |
| 1972 // Layout description. |
| 1973 static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 1974 static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize; |
| 1975 |
1963 private: | 1976 private: |
1964 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); | 1977 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
1965 }; | 1978 }; |
1966 | 1979 |
1967 | 1980 |
1968 // The JSObject describes real heap allocated JavaScript objects with | 1981 // The JSObject describes real heap allocated JavaScript objects with |
1969 // properties. | 1982 // properties. |
1970 // Note that the map of JSObject changes during execution to enable inline | 1983 // Note that the map of JSObject changes during execution to enable inline |
1971 // caching. | 1984 // caching. |
1972 class JSObject: public JSReceiver { | 1985 class JSObject: public JSReceiver { |
1973 public: | 1986 public: |
1974 static MUST_USE_RESULT MaybeHandle<JSObject> New( | 1987 static MUST_USE_RESULT MaybeHandle<JSObject> New( |
1975 Handle<JSFunction> constructor, Handle<JSReceiver> new_target, | 1988 Handle<JSFunction> constructor, Handle<JSReceiver> new_target, |
1976 Handle<AllocationSite> site = Handle<AllocationSite>::null()); | 1989 Handle<AllocationSite> site = Handle<AllocationSite>::null()); |
1977 | 1990 |
1978 // [properties]: Backing storage for properties. | |
1979 // properties is a FixedArray in the fast case and a Dictionary in the | |
1980 // slow case. | |
1981 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. | |
1982 inline void initialize_properties(); | |
1983 inline bool HasFastProperties(); | |
1984 // Gets slow properties for non-global objects. | |
1985 inline NameDictionary* property_dictionary(); | |
1986 // Gets global object properties. | 1991 // Gets global object properties. |
1987 inline GlobalDictionary* global_dictionary(); | 1992 inline GlobalDictionary* global_dictionary(); |
1988 | 1993 |
1989 static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object); | 1994 static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object); |
1990 | 1995 |
1991 // [elements]: The elements (properties with names that are integers). | 1996 // [elements]: The elements (properties with names that are integers). |
1992 // | 1997 // |
1993 // Elements can be in two general modes: fast and slow. Each mode | 1998 // Elements can be in two general modes: fast and slow. Each mode |
1994 // corrensponds to a set of object representations of elements that | 1999 // corrensponds to a set of object representations of elements that |
1995 // have something in common. | 2000 // have something in common. |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2467 // not to arbitrary other JSObject maps. | 2472 // not to arbitrary other JSObject maps. |
2468 static const int kInitialGlobalObjectUnusedPropertiesCount = 4; | 2473 static const int kInitialGlobalObjectUnusedPropertiesCount = 4; |
2469 | 2474 |
2470 static const int kMaxInstanceSize = 255 * kPointerSize; | 2475 static const int kMaxInstanceSize = 255 * kPointerSize; |
2471 // When extending the backing storage for property values, we increase | 2476 // When extending the backing storage for property values, we increase |
2472 // its size by more than the 1 entry necessary, so sequentially adding fields | 2477 // its size by more than the 1 entry necessary, so sequentially adding fields |
2473 // to the same object requires fewer allocations and copies. | 2478 // to the same object requires fewer allocations and copies. |
2474 static const int kFieldsAdded = 3; | 2479 static const int kFieldsAdded = 3; |
2475 | 2480 |
2476 // Layout description. | 2481 // Layout description. |
2477 static const int kPropertiesOffset = HeapObject::kHeaderSize; | 2482 static const int kElementsOffset = JSReceiver::kHeaderSize; |
2478 static const int kElementsOffset = kPropertiesOffset + kPointerSize; | |
2479 static const int kHeaderSize = kElementsOffset + kPointerSize; | 2483 static const int kHeaderSize = kElementsOffset + kPointerSize; |
2480 | 2484 |
2481 STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize); | 2485 STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize); |
2482 | 2486 |
2483 typedef FlexibleBodyDescriptor<kPropertiesOffset> BodyDescriptor; | 2487 typedef FlexibleBodyDescriptor<JSReceiver::kPropertiesOffset> BodyDescriptor; |
2484 | 2488 |
2485 // Enqueue change record for Object.observe. May cause GC. | 2489 // Enqueue change record for Object.observe. May cause GC. |
2486 MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord( | 2490 MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord( |
2487 Handle<JSObject> object, const char* type, Handle<Name> name, | 2491 Handle<JSObject> object, const char* type, Handle<Name> name, |
2488 Handle<Object> old_value); | 2492 Handle<Object> old_value); |
2489 | 2493 |
2490 // Gets the number of currently used elements. | 2494 // Gets the number of currently used elements. |
2491 int GetFastElementsUsage(); | 2495 int GetFastElementsUsage(); |
2492 | 2496 |
2493 // Deletes an existing named property in a normalized object. | 2497 // Deletes an existing named property in a normalized object. |
(...skipping 7122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9616 Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy, | 9620 Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy, |
9617 PropertyFilter filter, KeyAccumulator* accumulator); | 9621 PropertyFilter filter, KeyAccumulator* accumulator); |
9618 | 9622 |
9619 MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( | 9623 MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( |
9620 LookupIterator* it); | 9624 LookupIterator* it); |
9621 | 9625 |
9622 // Dispatched behavior. | 9626 // Dispatched behavior. |
9623 DECLARE_PRINTER(JSProxy) | 9627 DECLARE_PRINTER(JSProxy) |
9624 DECLARE_VERIFIER(JSProxy) | 9628 DECLARE_VERIFIER(JSProxy) |
9625 | 9629 |
9626 // Layout description. We add padding so that a proxy has the same | 9630 // Layout description. |
9627 // size as a virgin JSObject. This is essential for becoming a JSObject | 9631 static const int kTargetOffset = JSReceiver::kHeaderSize; |
9628 // upon freeze. | |
9629 static const int kTargetOffset = HeapObject::kHeaderSize; | |
9630 static const int kHandlerOffset = kTargetOffset + kPointerSize; | 9632 static const int kHandlerOffset = kTargetOffset + kPointerSize; |
9631 static const int kHashOffset = kHandlerOffset + kPointerSize; | 9633 static const int kHashOffset = kHandlerOffset + kPointerSize; |
9632 static const int kSize = kHashOffset + kPointerSize; | 9634 static const int kSize = kHashOffset + kPointerSize; |
9633 | 9635 |
9634 typedef FixedBodyDescriptor<kTargetOffset, kSize, kSize> BodyDescriptor; | 9636 typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize> |
| 9637 BodyDescriptor; |
9635 | 9638 |
9636 MUST_USE_RESULT Object* GetIdentityHash(); | 9639 MUST_USE_RESULT Object* GetIdentityHash(); |
9637 | 9640 |
9638 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy); | 9641 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy); |
9639 | 9642 |
9640 private: | 9643 private: |
9641 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); | 9644 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
9642 }; | 9645 }; |
9643 | 9646 |
9644 | 9647 |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10739 } | 10742 } |
10740 return value; | 10743 return value; |
10741 } | 10744 } |
10742 }; | 10745 }; |
10743 | 10746 |
10744 | 10747 |
10745 } // NOLINT, false-positive due to second-order macros. | 10748 } // NOLINT, false-positive due to second-order macros. |
10746 } // NOLINT, false-positive due to second-order macros. | 10749 } // NOLINT, false-positive due to second-order macros. |
10747 | 10750 |
10748 #endif // V8_OBJECTS_H_ | 10751 #endif // V8_OBJECTS_H_ |
OLD | NEW |