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

Side by Side Diff: src/objects.h

Issue 236143002: ES6: Add support for Map.prototype.forEach and Set.prototype.forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: static-ify Created 6 years, 8 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 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // - HeapObject (superclass for everything allocated in the heap) 59 // - HeapObject (superclass for everything allocated in the heap)
60 // - JSReceiver (suitable for property access) 60 // - JSReceiver (suitable for property access)
61 // - JSObject 61 // - JSObject
62 // - JSArray 62 // - JSArray
63 // - JSArrayBuffer 63 // - JSArrayBuffer
64 // - JSArrayBufferView 64 // - JSArrayBufferView
65 // - JSTypedArray 65 // - JSTypedArray
66 // - JSDataView 66 // - JSDataView
67 // - JSSet 67 // - JSSet
68 // - JSMap 68 // - JSMap
69 // - JSSetIterator
70 // - JSMapIterator
69 // - JSWeakCollection 71 // - JSWeakCollection
70 // - JSWeakMap 72 // - JSWeakMap
71 // - JSWeakSet 73 // - JSWeakSet
72 // - JSRegExp 74 // - JSRegExp
73 // - JSFunction 75 // - JSFunction
74 // - JSGeneratorObject 76 // - JSGeneratorObject
75 // - JSModule 77 // - JSModule
76 // - GlobalObject 78 // - GlobalObject
77 // - JSGlobalObject 79 // - JSGlobalObject
78 // - JSBuiltinsObject 80 // - JSBuiltinsObject
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 V(JS_GLOBAL_OBJECT_TYPE) \ 440 V(JS_GLOBAL_OBJECT_TYPE) \
439 V(JS_BUILTINS_OBJECT_TYPE) \ 441 V(JS_BUILTINS_OBJECT_TYPE) \
440 V(JS_GLOBAL_PROXY_TYPE) \ 442 V(JS_GLOBAL_PROXY_TYPE) \
441 V(JS_ARRAY_TYPE) \ 443 V(JS_ARRAY_TYPE) \
442 V(JS_ARRAY_BUFFER_TYPE) \ 444 V(JS_ARRAY_BUFFER_TYPE) \
443 V(JS_TYPED_ARRAY_TYPE) \ 445 V(JS_TYPED_ARRAY_TYPE) \
444 V(JS_DATA_VIEW_TYPE) \ 446 V(JS_DATA_VIEW_TYPE) \
445 V(JS_PROXY_TYPE) \ 447 V(JS_PROXY_TYPE) \
446 V(JS_SET_TYPE) \ 448 V(JS_SET_TYPE) \
447 V(JS_MAP_TYPE) \ 449 V(JS_MAP_TYPE) \
450 V(JS_SET_ITERATOR_TYPE) \
451 V(JS_MAP_ITERATOR_TYPE) \
448 V(JS_WEAK_MAP_TYPE) \ 452 V(JS_WEAK_MAP_TYPE) \
449 V(JS_WEAK_SET_TYPE) \ 453 V(JS_WEAK_SET_TYPE) \
450 V(JS_REGEXP_TYPE) \ 454 V(JS_REGEXP_TYPE) \
451 \ 455 \
452 V(JS_FUNCTION_TYPE) \ 456 V(JS_FUNCTION_TYPE) \
453 V(JS_FUNCTION_PROXY_TYPE) \ 457 V(JS_FUNCTION_PROXY_TYPE) \
454 V(DEBUG_INFO_TYPE) \ 458 V(DEBUG_INFO_TYPE) \
455 V(BREAK_POINT_INFO_TYPE) 459 V(BREAK_POINT_INFO_TYPE)
456 460
457 461
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 JS_MODULE_TYPE, 790 JS_MODULE_TYPE,
787 JS_GLOBAL_OBJECT_TYPE, 791 JS_GLOBAL_OBJECT_TYPE,
788 JS_BUILTINS_OBJECT_TYPE, 792 JS_BUILTINS_OBJECT_TYPE,
789 JS_GLOBAL_PROXY_TYPE, 793 JS_GLOBAL_PROXY_TYPE,
790 JS_ARRAY_TYPE, 794 JS_ARRAY_TYPE,
791 JS_ARRAY_BUFFER_TYPE, 795 JS_ARRAY_BUFFER_TYPE,
792 JS_TYPED_ARRAY_TYPE, 796 JS_TYPED_ARRAY_TYPE,
793 JS_DATA_VIEW_TYPE, 797 JS_DATA_VIEW_TYPE,
794 JS_SET_TYPE, 798 JS_SET_TYPE,
795 JS_MAP_TYPE, 799 JS_MAP_TYPE,
800 JS_SET_ITERATOR_TYPE,
801 JS_MAP_ITERATOR_TYPE,
796 JS_WEAK_MAP_TYPE, 802 JS_WEAK_MAP_TYPE,
797 JS_WEAK_SET_TYPE, 803 JS_WEAK_SET_TYPE,
798 804
799 JS_REGEXP_TYPE, 805 JS_REGEXP_TYPE,
800 806
801 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE 807 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
802 808
803 // Pseudo-types 809 // Pseudo-types
804 FIRST_TYPE = 0x0, 810 FIRST_TYPE = 0x0,
805 LAST_TYPE = JS_FUNCTION_TYPE, 811 LAST_TYPE = JS_FUNCTION_TYPE,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 V(Boolean) \ 1052 V(Boolean) \
1047 V(JSArray) \ 1053 V(JSArray) \
1048 V(JSArrayBuffer) \ 1054 V(JSArrayBuffer) \
1049 V(JSArrayBufferView) \ 1055 V(JSArrayBufferView) \
1050 V(JSTypedArray) \ 1056 V(JSTypedArray) \
1051 V(JSDataView) \ 1057 V(JSDataView) \
1052 V(JSProxy) \ 1058 V(JSProxy) \
1053 V(JSFunctionProxy) \ 1059 V(JSFunctionProxy) \
1054 V(JSSet) \ 1060 V(JSSet) \
1055 V(JSMap) \ 1061 V(JSMap) \
1062 V(JSSetIterator) \
1063 V(JSMapIterator) \
1056 V(JSWeakCollection) \ 1064 V(JSWeakCollection) \
1057 V(JSWeakMap) \ 1065 V(JSWeakMap) \
1058 V(JSWeakSet) \ 1066 V(JSWeakSet) \
1059 V(JSRegExp) \ 1067 V(JSRegExp) \
1060 V(HashTable) \ 1068 V(HashTable) \
1061 V(Dictionary) \ 1069 V(Dictionary) \
1062 V(StringTable) \ 1070 V(StringTable) \
1063 V(JSFunctionResultCache) \ 1071 V(JSFunctionResultCache) \
1064 V(NormalizedMapCache) \ 1072 V(NormalizedMapCache) \
1065 V(CompilationCacheTable) \ 1073 V(CompilationCacheTable) \
(...skipping 3195 matching lines...) Expand 10 before | Expand all | Expand 10 after
4261 // equality operator and Object::GetHash() for the hash function. 4269 // equality operator and Object::GetHash() for the hash function.
4262 // 4270 //
4263 // Based on the "Deterministic Hash Table" as described by Jason Orendorff at 4271 // Based on the "Deterministic Hash Table" as described by Jason Orendorff at
4264 // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables 4272 // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables
4265 // Originally attributed to Tyler Close. 4273 // Originally attributed to Tyler Close.
4266 // 4274 //
4267 // Memory layout: 4275 // Memory layout:
4268 // [0]: bucket count 4276 // [0]: bucket count
4269 // [1]: element count 4277 // [1]: element count
4270 // [2]: deleted element count 4278 // [2]: deleted element count
4271 // [3..(NumberOfBuckets() - 1)]: "hash table", where each item is an offset 4279 // [3]: live iterators (doubly-linked list)
4280 // [4..(NumberOfBuckets() - 1)]: "hash table", where each item is an offset
4272 // into the data table (see below) where the 4281 // into the data table (see below) where the
4273 // first item in this bucket is stored. 4282 // first item in this bucket is stored.
4274 // [3 + NumberOfBuckets()..length]: "data table", an array of length 4283 // [4 + NumberOfBuckets()..length]: "data table", an array of length
4275 // Capacity() * kEntrySize, where the first entrysize 4284 // Capacity() * kEntrySize, where the first entrysize
4276 // items are handled by the derived class and the 4285 // items are handled by the derived class and the
4277 // item at kChainOffset is another entry into the 4286 // item at kChainOffset is another entry into the
4278 // data table indicating the next entry in this hash 4287 // data table indicating the next entry in this hash
4279 // bucket. 4288 // bucket.
4280 template<class Derived, int entrysize> 4289 template<class Derived, class Iterator, int entrysize>
4281 class OrderedHashTable: public FixedArray { 4290 class OrderedHashTable: public FixedArray {
4282 public: 4291 public:
4283 // Returns an OrderedHashTable with a capacity of at least |capacity|. 4292 // Returns an OrderedHashTable with a capacity of at least |capacity|.
4284 static Handle<Derived> Allocate( 4293 static Handle<Derived> Allocate(
4285 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); 4294 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED);
4286 4295
4287 // Returns an OrderedHashTable (possibly |table|) with enough space 4296 // Returns an OrderedHashTable (possibly |table|) with enough space
4288 // to add at least one new element. 4297 // to add at least one new element.
4289 static Handle<Derived> EnsureGrowable(Handle<Derived> table); 4298 static Handle<Derived> EnsureGrowable(Handle<Derived> table);
4290 4299
4291 // Returns an OrderedHashTable (possibly |table|) that's shrunken 4300 // Returns an OrderedHashTable (possibly |table|) that's shrunken
4292 // if possible. 4301 // if possible.
4293 static Handle<Derived> Shrink(Handle<Derived> table); 4302 static Handle<Derived> Shrink(Handle<Derived> table);
4294 4303
4304 // Returns a new empty OrderedHashTable and updates all the iterators to
4305 // point to the new table.
4306 static Handle<Derived> Clear(Handle<Derived> table);
4307
4295 // Returns kNotFound if the key isn't present. 4308 // Returns kNotFound if the key isn't present.
4296 int FindEntry(Object* key); 4309 int FindEntry(Object* key);
4297 4310
4298 int NumberOfElements() { 4311 int NumberOfElements() {
4299 return Smi::cast(get(kNumberOfElementsIndex))->value(); 4312 return Smi::cast(get(kNumberOfElementsIndex))->value();
4300 } 4313 }
4301 4314
4302 int NumberOfDeletedElements() { 4315 int NumberOfDeletedElements() {
4303 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); 4316 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
4304 } 4317 }
4305 4318
4306 int NumberOfBuckets() { 4319 int NumberOfBuckets() {
4307 return Smi::cast(get(kNumberOfBucketsIndex))->value(); 4320 return Smi::cast(get(kNumberOfBucketsIndex))->value();
4308 } 4321 }
4309 4322
4323 // Creates a new iterator associated with this hash table.
4324 // [kind] needs to be one of the OrderedHashTableIterator Kind enum values.
4325 static Handle<Iterator> CreateIterator(Handle<Derived> table, int kind);
4326
4327 Object* iterators() { return get(kIteratorsIndex); }
4328
4329 void set_iterators(Object* value) { set(kIteratorsIndex, value); }
4330
4310 // Returns the index into the data table where the new entry 4331 // Returns the index into the data table where the new entry
4311 // should be placed. The table is assumed to have enough space 4332 // should be placed. The table is assumed to have enough space
4312 // for a new entry. 4333 // for a new entry.
4313 int AddEntry(int hash); 4334 int AddEntry(int hash);
4314 4335
4315 // Removes the entry, and puts the_hole in entrysize pointers 4336 // Removes the entry, and puts the_hole in entrysize pointers
4316 // (leaving the hash table chain intact). 4337 // (leaving the hash table chain intact).
4317 void RemoveEntry(int entry); 4338 void RemoveEntry(int entry);
4318 4339
4319 // Returns an index into |this| for the given entry. 4340 // Returns an index into |this| for the given entry.
4320 int EntryToIndex(int entry) { 4341 int EntryToIndex(int entry) {
4321 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); 4342 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize);
4322 } 4343 }
4323 4344
4345 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
4346
4324 static const int kNotFound = -1; 4347 static const int kNotFound = -1;
4348 static const int kMinCapacity = 4;
4325 4349
4326 private: 4350 private:
4327 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); 4351 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity);
4328 4352
4329 void SetNumberOfBuckets(int num) { 4353 void SetNumberOfBuckets(int num) {
4330 set(kNumberOfBucketsIndex, Smi::FromInt(num)); 4354 set(kNumberOfBucketsIndex, Smi::FromInt(num));
4331 } 4355 }
4332 4356
4333 void SetNumberOfElements(int num) { 4357 void SetNumberOfElements(int num) {
4334 set(kNumberOfElementsIndex, Smi::FromInt(num)); 4358 set(kNumberOfElementsIndex, Smi::FromInt(num));
4335 } 4359 }
4336 4360
4337 void SetNumberOfDeletedElements(int num) { 4361 void SetNumberOfDeletedElements(int num) {
4338 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); 4362 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num));
4339 } 4363 }
4340 4364
4341 int Capacity() { 4365 int Capacity() {
4342 return NumberOfBuckets() * kLoadFactor; 4366 return NumberOfBuckets() * kLoadFactor;
4343 } 4367 }
4344 4368
4345 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
4346
4347 // Returns the next entry for the given entry. 4369 // Returns the next entry for the given entry.
4348 int ChainAt(int entry) { 4370 int ChainAt(int entry) {
4349 return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value(); 4371 return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value();
4350 } 4372 }
4351 4373
4352 int HashToBucket(int hash) { 4374 int HashToBucket(int hash) {
4353 return hash & (NumberOfBuckets() - 1); 4375 return hash & (NumberOfBuckets() - 1);
4354 } 4376 }
4355 4377
4356 int HashToEntry(int hash) { 4378 int HashToEntry(int hash) {
4357 int bucket = HashToBucket(hash); 4379 int bucket = HashToBucket(hash);
4358 return Smi::cast(get(kHashTableStartIndex + bucket))->value(); 4380 return Smi::cast(get(kHashTableStartIndex + bucket))->value();
4359 } 4381 }
4360 4382
4361 static const int kNumberOfBucketsIndex = 0; 4383 static const int kNumberOfBucketsIndex = 0;
4362 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; 4384 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1;
4363 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; 4385 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1;
4364 static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1; 4386 static const int kIteratorsIndex = kNumberOfDeletedElementsIndex + 1;
4387 static const int kHashTableStartIndex = kIteratorsIndex + 1;
4365 4388
4366 static const int kEntrySize = entrysize + 1; 4389 static const int kEntrySize = entrysize + 1;
4367 static const int kChainOffset = entrysize; 4390 static const int kChainOffset = entrysize;
4368 4391
4369 static const int kLoadFactor = 2; 4392 static const int kLoadFactor = 2;
4370 static const int kMaxCapacity = 4393 static const int kMaxCapacity =
4371 (FixedArray::kMaxLength - kHashTableStartIndex) 4394 (FixedArray::kMaxLength - kHashTableStartIndex)
4372 / (1 + (kEntrySize * kLoadFactor)); 4395 / (1 + (kEntrySize * kLoadFactor));
4373 }; 4396 };
4374 4397
4375 4398
4376 class OrderedHashSet: public OrderedHashTable<OrderedHashSet, 1> { 4399 class JSSetIterator;
4400
4401
4402 class OrderedHashSet: public OrderedHashTable<
4403 OrderedHashSet, JSSetIterator, 1> {
4377 public: 4404 public:
4378 static OrderedHashSet* cast(Object* obj) { 4405 static OrderedHashSet* cast(Object* obj) {
4379 ASSERT(obj->IsOrderedHashTable()); 4406 ASSERT(obj->IsOrderedHashTable());
4380 return reinterpret_cast<OrderedHashSet*>(obj); 4407 return reinterpret_cast<OrderedHashSet*>(obj);
4381 } 4408 }
4382 4409
4383 bool Contains(Object* key); 4410 bool Contains(Object* key);
4384 static Handle<OrderedHashSet> Add( 4411 static Handle<OrderedHashSet> Add(
4385 Handle<OrderedHashSet> table, Handle<Object> key); 4412 Handle<OrderedHashSet> table, Handle<Object> key);
4386 static Handle<OrderedHashSet> Remove( 4413 static Handle<OrderedHashSet> Remove(
4387 Handle<OrderedHashSet> table, Handle<Object> key); 4414 Handle<OrderedHashSet> table, Handle<Object> key);
4388 }; 4415 };
4389 4416
4390 4417
4391 class OrderedHashMap: public OrderedHashTable<OrderedHashMap, 2> { 4418 class JSMapIterator;
4419
4420
4421 class OrderedHashMap:public OrderedHashTable<
4422 OrderedHashMap, JSMapIterator, 2> {
4392 public: 4423 public:
4393 static OrderedHashMap* cast(Object* obj) { 4424 static OrderedHashMap* cast(Object* obj) {
4394 ASSERT(obj->IsOrderedHashTable()); 4425 ASSERT(obj->IsOrderedHashTable());
4395 return reinterpret_cast<OrderedHashMap*>(obj); 4426 return reinterpret_cast<OrderedHashMap*>(obj);
4396 } 4427 }
4397 4428
4398 Object* Lookup(Object* key); 4429 Object* Lookup(Object* key);
4399 static Handle<OrderedHashMap> Put( 4430 static Handle<OrderedHashMap> Put(
4400 Handle<OrderedHashMap> table, 4431 Handle<OrderedHashMap> table,
4401 Handle<Object> key, 4432 Handle<Object> key,
(...skipping 3119 matching lines...) Expand 10 before | Expand all | Expand 10 after
7521 static const int kContinuationOffset = kReceiverOffset + kPointerSize; 7552 static const int kContinuationOffset = kReceiverOffset + kPointerSize;
7522 static const int kOperandStackOffset = kContinuationOffset + kPointerSize; 7553 static const int kOperandStackOffset = kContinuationOffset + kPointerSize;
7523 static const int kStackHandlerIndexOffset = 7554 static const int kStackHandlerIndexOffset =
7524 kOperandStackOffset + kPointerSize; 7555 kOperandStackOffset + kPointerSize;
7525 static const int kSize = kStackHandlerIndexOffset + kPointerSize; 7556 static const int kSize = kStackHandlerIndexOffset + kPointerSize;
7526 7557
7527 // Resume mode, for use by runtime functions. 7558 // Resume mode, for use by runtime functions.
7528 enum ResumeMode { NEXT, THROW }; 7559 enum ResumeMode { NEXT, THROW };
7529 7560
7530 // Yielding from a generator returns an object with the following inobject 7561 // Yielding from a generator returns an object with the following inobject
7531 // properties. See Context::generator_result_map() for the map. 7562 // properties. See Context::iterator_result_map() for the map.
7532 static const int kResultValuePropertyIndex = 0; 7563 static const int kResultValuePropertyIndex = 0;
7533 static const int kResultDonePropertyIndex = 1; 7564 static const int kResultDonePropertyIndex = 1;
7534 static const int kResultPropertyCount = 2; 7565 static const int kResultPropertyCount = 2;
7535 7566
7536 static const int kResultValuePropertyOffset = JSObject::kHeaderSize; 7567 static const int kResultValuePropertyOffset = JSObject::kHeaderSize;
7537 static const int kResultDonePropertyOffset = 7568 static const int kResultDonePropertyOffset =
7538 kResultValuePropertyOffset + kPointerSize; 7569 kResultValuePropertyOffset + kPointerSize;
7539 static const int kResultSize = kResultDonePropertyOffset + kPointerSize; 7570 static const int kResultSize = kResultDonePropertyOffset + kPointerSize;
7540 7571
7541 private: 7572 private:
(...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after
9989 DECLARE_VERIFIER(JSMap) 10020 DECLARE_VERIFIER(JSMap)
9990 10021
9991 static const int kTableOffset = JSObject::kHeaderSize; 10022 static const int kTableOffset = JSObject::kHeaderSize;
9992 static const int kSize = kTableOffset + kPointerSize; 10023 static const int kSize = kTableOffset + kPointerSize;
9993 10024
9994 private: 10025 private:
9995 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); 10026 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
9996 }; 10027 };
9997 10028
9998 10029
10030 // OrderedHashTableIterator is an iterator that iterates over the keys and
10031 // values of an OrderedHashTable.
10032 //
10033 // The hash table has a reference to the iterator and the iterators themselves
10034 // have references to the [next_iterator] and [previous_iterator], thus creating
10035 // a double linked list.
10036 //
10037 // When the hash table changes the iterators are called to update their [index]
10038 // and [count]. The hash table calls [EntryRemoved], [TableCompacted] as well
10039 // as [TableCleared].
10040 //
10041 // When an iterator is done it closes itself. It removes itself from the double
10042 // linked list and it sets its [table] to undefined, no longer keeping the
10043 // [table] alive.
10044 template<class Derived, class TableType>
10045 class OrderedHashTableIterator: public JSObject {
10046 public:
10047 // [table]: the backing hash table mapping keys to values.
10048 DECL_ACCESSORS(table, Object)
10049
10050 // [index]: The index into the data table.
10051 DECL_ACCESSORS(index, Smi)
10052
10053 // [count]: The logical index into the data table, ignoring the holes.
10054 DECL_ACCESSORS(count, Smi)
10055
10056 // [kind]: The kind of iteration this is. One of the [Kind] enum values.
10057 DECL_ACCESSORS(kind, Smi)
10058
10059 // [next_iterator]: Used as a double linked list for the live iterators.
10060 DECL_ACCESSORS(next_iterator, Object)
10061
10062 // [previous_iterator]: Used as a double linked list for the live iterators.
10063 DECL_ACCESSORS(previous_iterator, Object)
10064
10065 void OrderedHashTableIteratorPrint(FILE* out);
10066
10067 static const int kTableOffset = JSObject::kHeaderSize;
10068 static const int kIndexOffset = kTableOffset + kPointerSize;
10069 static const int kCountOffset = kIndexOffset + kPointerSize;
10070 static const int kKindOffset = kCountOffset + kPointerSize;
10071 static const int kNextIteratorOffset = kKindOffset + kPointerSize;
10072 static const int kPreviousIteratorOffset = kNextIteratorOffset + kPointerSize;
10073 static const int kSize = kPreviousIteratorOffset + kPointerSize;
10074
10075 enum Kind {
10076 kKindKeys = 1,
10077 kKindValues = 2,
10078 kKindEntries = 3
10079 };
10080
10081 // Called by the underlying [table] when an entry is removed.
10082 void EntryRemoved(int index);
10083
10084 // Called by the underlying [table] when it is compacted/rehashed.
10085 void TableCompacted() {
10086 // All holes have been removed so index is now same as count.
10087 set_index(count());
10088 }
10089
10090 // Called by the underlying [table] when it is cleared.
10091 void TableCleared() {
10092 set_index(Smi::FromInt(0));
10093 set_count(Smi::FromInt(0));
10094 }
10095
10096 // Removes the iterator from the double linked list and removes its reference
10097 // back to the [table].
10098 void Close();
10099
10100 // Returns an iterator result object: {value: any, done: boolean} and moves
10101 // the index to the next valid entry. Closes the iterator if moving past the
10102 // end.
10103 static Handle<JSObject> Next(Handle<Derived> iterator);
10104
10105 private:
10106 // Ensures [index] is not pointing to a hole.
10107 void Seek();
10108
10109 // Moves [index] to next valid entry. Closes the iterator if moving past the
10110 // end.
10111 void MoveNext();
10112
10113 bool Closed() {
10114 return table()->IsUndefined();
10115 }
10116
10117 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator);
10118 };
10119
10120
10121 class JSSetIterator: public OrderedHashTableIterator<JSSetIterator,
10122 OrderedHashSet> {
10123 public:
10124 static Handle<JSSetIterator> Create(Isolate* isolate);
10125
10126 // Dispatched behavior.
10127 DECLARE_PRINTER(JSSetIterator)
10128 DECLARE_VERIFIER(JSSetIterator)
10129
10130 // Casting.
10131 static inline JSSetIterator* cast(Object* obj);
10132
10133 static Handle<Object> ValueForKind(
10134 Handle<JSSetIterator> iterator, int entry_index);
10135
10136 private:
10137 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator);
10138 };
10139
10140
10141 class JSMapIterator: public OrderedHashTableIterator<JSMapIterator,
10142 OrderedHashMap> {
10143 public:
10144 static Handle<JSMapIterator> Create(Isolate* isolate);
10145
10146 // Dispatched behavior.
10147 DECLARE_PRINTER(JSMapIterator)
10148 DECLARE_VERIFIER(JSMapIterator)
10149
10150 // Casting.
10151 static inline JSMapIterator* cast(Object* obj);
10152
10153 static Handle<Object> ValueForKind(
10154 Handle<JSMapIterator> iterator, int entry_index);
10155
10156 private:
10157 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator);
10158 };
10159
10160
9999 // Base class for both JSWeakMap and JSWeakSet 10161 // Base class for both JSWeakMap and JSWeakSet
10000 class JSWeakCollection: public JSObject { 10162 class JSWeakCollection: public JSObject {
10001 public: 10163 public:
10002 // [table]: the backing hash table mapping keys to values. 10164 // [table]: the backing hash table mapping keys to values.
10003 DECL_ACCESSORS(table, Object) 10165 DECL_ACCESSORS(table, Object)
10004 10166
10005 // [next]: linked list of encountered weak maps during GC. 10167 // [next]: linked list of encountered weak maps during GC.
10006 DECL_ACCESSORS(next, Object) 10168 DECL_ACCESSORS(next, Object)
10007 10169
10008 static const int kTableOffset = JSObject::kHeaderSize; 10170 static const int kTableOffset = JSObject::kHeaderSize;
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
11022 } else { 11184 } else {
11023 value &= ~(1 << bit_position); 11185 value &= ~(1 << bit_position);
11024 } 11186 }
11025 return value; 11187 return value;
11026 } 11188 }
11027 }; 11189 };
11028 11190
11029 } } // namespace v8::internal 11191 } } // namespace v8::internal
11030 11192
11031 #endif // V8_OBJECTS_H_ 11193 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698