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