| OLD | NEW |
| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 using namespace v8::internal; | 36 using namespace v8::internal; |
| 37 | 37 |
| 38 | 38 |
| 39 static Isolate* GetIsolateFrom(LocalContext* context) { | 39 static Isolate* GetIsolateFrom(LocalContext* context) { |
| 40 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); | 40 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 | 43 |
| 44 static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) { | 44 static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) { |
| 45 Factory* factory = isolate->factory(); | 45 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); |
| 46 Handle<Map> map = factory->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); | |
| 47 Handle<JSObject> weakmap_obj = factory->NewJSObjectFromMap(map); | |
| 48 Handle<JSWeakMap> weakmap(JSWeakMap::cast(*weakmap_obj)); | |
| 49 // Do not leak handles for the hash table, it would make entries strong. | 46 // Do not leak handles for the hash table, it would make entries strong. |
| 50 { | 47 { |
| 51 HandleScope scope(isolate); | 48 HandleScope scope(isolate); |
| 52 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1); | 49 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1); |
| 53 weakmap->set_table(*table); | 50 weakmap->set_table(*table); |
| 54 } | 51 } |
| 55 return weakmap; | 52 return weakmap; |
| 56 } | 53 } |
| 57 | 54 |
| 58 static void PutIntoWeakMap(Handle<JSWeakMap> weakmap, | 55 static void PutIntoWeakMap(Handle<JSWeakMap> weakmap, |
| 59 Handle<JSObject> key, | 56 Handle<JSObject> key, |
| 60 Handle<Object> value) { | 57 Handle<Object> value) { |
| 61 Handle<ObjectHashTable> table = ObjectHashTable::Put( | 58 Runtime::WeakCollectionSet(weakmap, key, value); |
| 62 Handle<ObjectHashTable>(ObjectHashTable::cast(weakmap->table())), | |
| 63 Handle<JSObject>(JSObject::cast(*key)), | |
| 64 value); | |
| 65 weakmap->set_table(*table); | |
| 66 } | 59 } |
| 67 | 60 |
| 68 static int NumberOfWeakCalls = 0; | 61 static int NumberOfWeakCalls = 0; |
| 69 static void WeakPointerCallback( | 62 static void WeakPointerCallback( |
| 70 const v8::WeakCallbackData<v8::Value, void>& data) { | 63 const v8::WeakCallbackData<v8::Value, void>& data) { |
| 71 std::pair<v8::Persistent<v8::Value>*, int>* p = | 64 std::pair<v8::Persistent<v8::Value>*, int>* p = |
| 72 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>( | 65 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>( |
| 73 data.GetParameter()); | 66 data.GetParameter()); |
| 74 DCHECK_EQ(1234, p->second); | 67 DCHECK_EQ(1234, p->second); |
| 75 NumberOfWeakCalls++; | 68 NumberOfWeakCalls++; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 { | 259 { |
| 267 HandleScope scope(isolate); | 260 HandleScope scope(isolate); |
| 268 AllocateJSWeakMap(isolate); | 261 AllocateJSWeakMap(isolate); |
| 269 SimulateIncrementalMarking(heap); | 262 SimulateIncrementalMarking(heap); |
| 270 } | 263 } |
| 271 // The weak map is marked black here but leaving the handle scope will make | 264 // The weak map is marked black here but leaving the handle scope will make |
| 272 // the object unreachable. Aborting incremental marking will clear all the | 265 // the object unreachable. Aborting incremental marking will clear all the |
| 273 // marking bits which makes the weak map garbage. | 266 // marking bits which makes the weak map garbage. |
| 274 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 267 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 275 } | 268 } |
| OLD | NEW |