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

Side by Side Diff: src/objects.h

Issue 8372027: Implement Harmony sets and maps. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 2 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // 45 //
46 // Inheritance hierarchy: 46 // Inheritance hierarchy:
47 // - MaybeObject (an object or a failure) 47 // - MaybeObject (an object or a failure)
48 // - Failure (immediate for marking failed operation) 48 // - Failure (immediate for marking failed operation)
49 // - Object 49 // - Object
50 // - Smi (immediate small integer) 50 // - Smi (immediate small integer)
51 // - HeapObject (superclass for everything allocated in the heap) 51 // - HeapObject (superclass for everything allocated in the heap)
52 // - JSReceiver (suitable for property access) 52 // - JSReceiver (suitable for property access)
53 // - JSObject 53 // - JSObject
54 // - JSArray 54 // - JSArray
55 // - JSSet
56 // - JSMap
55 // - JSWeakMap 57 // - JSWeakMap
56 // - JSRegExp 58 // - JSRegExp
57 // - JSFunction 59 // - JSFunction
58 // - GlobalObject 60 // - GlobalObject
59 // - JSGlobalObject 61 // - JSGlobalObject
60 // - JSBuiltinsObject 62 // - JSBuiltinsObject
61 // - JSGlobalProxy 63 // - JSGlobalProxy
62 // - JSValue 64 // - JSValue
63 // - JSMessageObject 65 // - JSMessageObject
64 // - JSProxy 66 // - JSProxy
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE 623 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
622 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE 624 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
623 625
624 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE 626 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
625 JS_OBJECT_TYPE, 627 JS_OBJECT_TYPE,
626 JS_CONTEXT_EXTENSION_OBJECT_TYPE, 628 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
627 JS_GLOBAL_OBJECT_TYPE, 629 JS_GLOBAL_OBJECT_TYPE,
628 JS_BUILTINS_OBJECT_TYPE, 630 JS_BUILTINS_OBJECT_TYPE,
629 JS_GLOBAL_PROXY_TYPE, 631 JS_GLOBAL_PROXY_TYPE,
630 JS_ARRAY_TYPE, 632 JS_ARRAY_TYPE,
633 JS_SET_TYPE,
634 JS_MAP_TYPE,
631 JS_WEAK_MAP_TYPE, 635 JS_WEAK_MAP_TYPE,
632 636
633 JS_REGEXP_TYPE, 637 JS_REGEXP_TYPE,
634 638
635 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE 639 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
636 640
637 // Pseudo-types 641 // Pseudo-types
638 FIRST_TYPE = 0x0, 642 FIRST_TYPE = 0x0,
639 LAST_TYPE = JS_FUNCTION_TYPE, 643 LAST_TYPE = JS_FUNCTION_TYPE,
640 INVALID_TYPE = FIRST_TYPE - 1, 644 INVALID_TYPE = FIRST_TYPE - 1,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 V(Oddball) \ 817 V(Oddball) \
814 V(SharedFunctionInfo) \ 818 V(SharedFunctionInfo) \
815 V(JSValue) \ 819 V(JSValue) \
816 V(JSMessageObject) \ 820 V(JSMessageObject) \
817 V(StringWrapper) \ 821 V(StringWrapper) \
818 V(Foreign) \ 822 V(Foreign) \
819 V(Boolean) \ 823 V(Boolean) \
820 V(JSArray) \ 824 V(JSArray) \
821 V(JSProxy) \ 825 V(JSProxy) \
822 V(JSFunctionProxy) \ 826 V(JSFunctionProxy) \
827 V(JSSet) \
828 V(JSMap) \
823 V(JSWeakMap) \ 829 V(JSWeakMap) \
824 V(JSRegExp) \ 830 V(JSRegExp) \
825 V(HashTable) \ 831 V(HashTable) \
826 V(Dictionary) \ 832 V(Dictionary) \
827 V(SymbolTable) \ 833 V(SymbolTable) \
828 V(JSFunctionResultCache) \ 834 V(JSFunctionResultCache) \
829 V(NormalizedMapCache) \ 835 V(NormalizedMapCache) \
830 V(CompilationCacheTable) \ 836 V(CompilationCacheTable) \
831 V(CodeCacheHashTable) \ 837 V(CodeCacheHashTable) \
832 V(PolymorphicCodeCacheHashTable) \ 838 V(PolymorphicCodeCacheHashTable) \
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 935
930 static Handle<Object> GetElement(Handle<Object> object, uint32_t index); 936 static Handle<Object> GetElement(Handle<Object> object, uint32_t index);
931 inline MaybeObject* GetElement(uint32_t index); 937 inline MaybeObject* GetElement(uint32_t index);
932 // For use when we know that no exception can be thrown. 938 // For use when we know that no exception can be thrown.
933 inline Object* GetElementNoExceptionThrown(uint32_t index); 939 inline Object* GetElementNoExceptionThrown(uint32_t index);
934 MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); 940 MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index);
935 941
936 // Return the object's prototype (might be Heap::null_value()). 942 // Return the object's prototype (might be Heap::null_value()).
937 Object* GetPrototype(); 943 Object* GetPrototype();
938 944
945 // Returns the permanent hash code associated with this object depending on
946 // the actual object type.
947 uint32_t GetHash();
rossberg 2011/10/24 15:44:11 It is not very intuitive that this function fails
Michael Starzinger 2011/10/25 11:17:26 Done. As discussed extensively offline, the only f
948
949 // Checks whether this object has the same value as the given one. This
950 // function is implemented according to ES5, section 9.12 and can be used
951 // to implement the Harmony "egal" function.
952 bool SameValue(Object* other);
953
939 // Tries to convert an object to an array index. Returns true and sets 954 // Tries to convert an object to an array index. Returns true and sets
940 // the output parameter if it succeeds. 955 // the output parameter if it succeeds.
941 inline bool ToArrayIndex(uint32_t* index); 956 inline bool ToArrayIndex(uint32_t* index);
942 957
943 // Returns true if this is a JSValue containing a string and the index is 958 // Returns true if this is a JSValue containing a string and the index is
944 // < the length of the string. Used to implement [] on strings. 959 // < the length of the string. Used to implement [] on strings.
945 inline bool IsStringObjectWithCharacterAt(uint32_t index); 960 inline bool IsStringObjectWithCharacterAt(uint32_t index);
946 961
947 #ifdef DEBUG 962 #ifdef DEBUG
948 // Verify a pointer is a valid object pointer. 963 // Verify a pointer is a valid object pointer.
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 inline bool HasLocalProperty(String* name); 1392 inline bool HasLocalProperty(String* name);
1378 inline bool HasElement(uint32_t index); 1393 inline bool HasElement(uint32_t index);
1379 1394
1380 // Return the object's prototype (might be Heap::null_value()). 1395 // Return the object's prototype (might be Heap::null_value()).
1381 inline Object* GetPrototype(); 1396 inline Object* GetPrototype();
1382 1397
1383 // Set the object's prototype (only JSReceiver and null are allowed). 1398 // Set the object's prototype (only JSReceiver and null are allowed).
1384 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, 1399 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
1385 bool skip_hidden_prototypes); 1400 bool skip_hidden_prototypes);
1386 1401
1402 // Checks whether the object has a permanent object identity hash. If this
1403 // function returns true, GetIdentityHash will never fail.
1404 inline bool HasIdentityHash();
1405
1387 // Retrieves a permanent object identity hash code. The undefined value might 1406 // Retrieves a permanent object identity hash code. The undefined value might
1388 // be returned in case no has been created yet and OMIT_CREATION was used. 1407 // be returned in case no has been created yet and OMIT_CREATION was used.
1389 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); 1408 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1390 1409
1391 // Lookup a property. If found, the result is valid and has 1410 // Lookup a property. If found, the result is valid and has
1392 // detailed information. 1411 // detailed information.
1393 void LocalLookup(String* name, LookupResult* result); 1412 void LocalLookup(String* name, LookupResult* result);
1394 void Lookup(String* name, LookupResult* result); 1413 void Lookup(String* name, LookupResult* result);
1395 1414
1396 protected: 1415 protected:
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 // Remove all entries were key is a number and (from <= key && key < to). 2962 // Remove all entries were key is a number and (from <= key && key < to).
2944 void RemoveNumberEntries(uint32_t from, uint32_t to); 2963 void RemoveNumberEntries(uint32_t from, uint32_t to);
2945 2964
2946 // Bit masks. 2965 // Bit masks.
2947 static const int kRequiresSlowElementsMask = 1; 2966 static const int kRequiresSlowElementsMask = 1;
2948 static const int kRequiresSlowElementsTagSize = 1; 2967 static const int kRequiresSlowElementsTagSize = 1;
2949 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; 2968 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
2950 }; 2969 };
2951 2970
2952 2971
2972 template <int entrysize>
2953 class ObjectHashTableShape { 2973 class ObjectHashTableShape {
2954 public: 2974 public:
2955 static inline bool IsMatch(JSReceiver* key, Object* other); 2975 static inline bool IsMatch(Object* key, Object* other);
2956 static inline uint32_t Hash(JSReceiver* key); 2976 static inline uint32_t Hash(Object* key);
2957 static inline uint32_t HashForObject(JSReceiver* key, Object* object); 2977 static inline uint32_t HashForObject(Object* key, Object* object);
2958 MUST_USE_RESULT static inline MaybeObject* AsObject(JSReceiver* key); 2978 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key);
2959 static const int kPrefixSize = 0; 2979 static const int kPrefixSize = 0;
2960 static const int kEntrySize = 2; 2980 static const int kEntrySize = entrysize;
2961 }; 2981 };
2962 2982
2963 2983
2964 // ObjectHashTable maps keys that are JavaScript objects to object values by 2984 // ObjectHashSet holds keys that are arbitrary objects by using the identity
2985 // hash of the key for hashing purposes.
2986 class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> {
2987 public:
2988 static inline ObjectHashSet* cast(Object* obj) {
2989 ASSERT(obj->IsHashTable());
2990 return reinterpret_cast<ObjectHashSet*>(obj);
2991 }
2992
2993 // Looks up whether the given key is part of this hash set.
2994 bool Contains(Object* key);
2995
2996 // Adds the given key to this hash set.
2997 MUST_USE_RESULT MaybeObject* Add(Object* key);
2998
2999 // Removes the given key from this hash set.
3000 MUST_USE_RESULT MaybeObject* Remove(Object* key);
3001 };
3002
3003
3004 // ObjectHashTable maps keys that are arbitrary objects to object values by
2965 // using the identity hash of the key for hashing purposes. 3005 // using the identity hash of the key for hashing purposes.
2966 class ObjectHashTable: public HashTable<ObjectHashTableShape, JSReceiver*> { 3006 class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> {
2967 public: 3007 public:
2968 static inline ObjectHashTable* cast(Object* obj) { 3008 static inline ObjectHashTable* cast(Object* obj) {
2969 ASSERT(obj->IsHashTable()); 3009 ASSERT(obj->IsHashTable());
2970 return reinterpret_cast<ObjectHashTable*>(obj); 3010 return reinterpret_cast<ObjectHashTable*>(obj);
2971 } 3011 }
2972 3012
2973 // Looks up the value associated with the given key. The undefined value is 3013 // Looks up the value associated with the given key. The undefined value is
2974 // returned in case the key is not present. 3014 // returned in case the key is not present.
2975 Object* Lookup(JSReceiver* key); 3015 Object* Lookup(Object* key);
2976 3016
2977 // Adds (or overwrites) the value associated with the given key. Mapping a 3017 // Adds (or overwrites) the value associated with the given key. Mapping a
2978 // key to the undefined value causes removal of the whole entry. 3018 // key to the undefined value causes removal of the whole entry.
2979 MUST_USE_RESULT MaybeObject* Put(JSReceiver* key, Object* value); 3019 MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value);
2980 3020
2981 private: 3021 private:
2982 friend class MarkCompactCollector; 3022 friend class MarkCompactCollector;
2983 3023
2984 void AddEntry(int entry, JSReceiver* key, Object* value); 3024 void AddEntry(int entry, Object* key, Object* value);
2985 void RemoveEntry(int entry, Heap* heap); 3025 void RemoveEntry(int entry, Heap* heap);
2986 inline void RemoveEntry(int entry); 3026 inline void RemoveEntry(int entry);
2987 3027
2988 // Returns the index to the value of an entry. 3028 // Returns the index to the value of an entry.
2989 static inline int EntryToValueIndex(int entry) { 3029 static inline int EntryToValueIndex(int entry) {
2990 return EntryToIndex(entry) + 1; 3030 return EntryToIndex(entry) + 1;
2991 } 3031 }
2992 }; 3032 };
2993 3033
2994 3034
(...skipping 3980 matching lines...) Expand 10 before | Expand all | Expand 10 after
6975 7015
6976 typedef FixedBodyDescriptor<kHandlerOffset, 7016 typedef FixedBodyDescriptor<kHandlerOffset,
6977 kConstructTrapOffset + kPointerSize, 7017 kConstructTrapOffset + kPointerSize,
6978 kSize> BodyDescriptor; 7018 kSize> BodyDescriptor;
6979 7019
6980 private: 7020 private:
6981 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); 7021 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy);
6982 }; 7022 };
6983 7023
6984 7024
7025 // The JSSet describes EcmaScript Harmony maps
7026 class JSSet: public JSObject {
7027 public:
7028 // [set]: the backing hash set containing keys.
7029 DECL_ACCESSORS(table, Object)
7030
7031 // Casting.
7032 static inline JSSet* cast(Object* obj);
7033
7034 #ifdef OBJECT_PRINT
7035 inline void JSSetPrint() {
7036 JSSetPrint(stdout);
7037 }
7038 void JSSetPrint(FILE* out);
7039 #endif
7040 #ifdef DEBUG
7041 void JSSetVerify();
7042 #endif
7043
7044 static const int kTableOffset = JSObject::kHeaderSize;
7045 static const int kSize = kTableOffset + kPointerSize;
7046
7047 private:
7048 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
7049 };
7050
7051
7052 // The JSMap describes EcmaScript Harmony maps
7053 class JSMap: public JSObject {
7054 public:
7055 // [table]: the backing hash table mapping keys to values.
7056 DECL_ACCESSORS(table, Object)
7057
7058 // Casting.
7059 static inline JSMap* cast(Object* obj);
7060
7061 #ifdef OBJECT_PRINT
7062 inline void JSMapPrint() {
7063 JSMapPrint(stdout);
7064 }
7065 void JSMapPrint(FILE* out);
7066 #endif
7067 #ifdef DEBUG
7068 void JSMapVerify();
7069 #endif
7070
7071 static const int kTableOffset = JSObject::kHeaderSize;
7072 static const int kSize = kTableOffset + kPointerSize;
7073
7074 private:
7075 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
7076 };
7077
7078
6985 // The JSWeakMap describes EcmaScript Harmony weak maps 7079 // The JSWeakMap describes EcmaScript Harmony weak maps
6986 class JSWeakMap: public JSObject { 7080 class JSWeakMap: public JSObject {
6987 public: 7081 public:
6988 // [table]: the backing hash table mapping keys to values. 7082 // [table]: the backing hash table mapping keys to values.
6989 DECL_ACCESSORS(table, Object) 7083 DECL_ACCESSORS(table, Object)
6990 7084
6991 // [next]: linked list of encountered weak maps during GC. 7085 // [next]: linked list of encountered weak maps during GC.
6992 DECL_ACCESSORS(next, Object) 7086 DECL_ACCESSORS(next, Object)
6993 7087
6994 // Unchecked accessors to be used during GC. 7088 // Unchecked accessors to be used during GC.
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
7654 } else { 7748 } else {
7655 value &= ~(1 << bit_position); 7749 value &= ~(1 << bit_position);
7656 } 7750 }
7657 return value; 7751 return value;
7658 } 7752 }
7659 }; 7753 };
7660 7754
7661 } } // namespace v8::internal 7755 } } // namespace v8::internal
7662 7756
7663 #endif // V8_OBJECTS_H_ 7757 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698