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

Side by Side Diff: Source/bindings/v8/V8PerContextData.cpp

Issue 189513012: DOMDataStore should be cleared when shutting down worker threads (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
« no previous file with comments | « Source/bindings/v8/V8PerContextData.h ('k') | Source/bindings/v8/V8WindowShell.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 { 44 {
45 typename Map::iterator it = map->begin(); 45 typename Map::iterator it = map->begin();
46 for (; it != map->end(); ++it) 46 for (; it != map->end(); ++it)
47 it->value.dispose(); 47 it->value.dispose();
48 map->clear(); 48 map->clear();
49 } 49 }
50 50
51 class V8PerContextDataHolder { 51 class V8PerContextDataHolder {
52 WTF_MAKE_NONCOPYABLE(V8PerContextDataHolder); 52 WTF_MAKE_NONCOPYABLE(V8PerContextDataHolder);
53 public: 53 public:
54 static void install(v8::Handle<v8::Context> context, DOMWrapperWorld* world) 54 static void install(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperWo rld> world)
55 { 55 {
56 new V8PerContextDataHolder(context, world); 56 new V8PerContextDataHolder(context, world);
57 } 57 }
58 58
59 static V8PerContextDataHolder* from(v8::Handle<v8::Context> context) 59 static V8PerContextDataHolder* from(v8::Handle<v8::Context> context)
60 { 60 {
61 V8PerContextDataHolder* holder = static_cast<V8PerContextDataHolder*>(co ntext->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex)); 61 V8PerContextDataHolder* holder = static_cast<V8PerContextDataHolder*>(co ntext->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex));
62 // |holder| must not be 0 because V8PerContextDataHolder is kept alive a s long as the |context| is alive. 62 // |holder| must not be 0 because V8PerContextDataHolder is kept alive a s long as the |context| is alive.
63 // Here we have a handle to the |context|, which means that the V8PerCon textDataHolder is alive. 63 // Here we have a handle to the |context|, which means that the V8PerCon textDataHolder is alive.
64 ASSERT(holder); 64 ASSERT(holder);
65 return holder; 65 return holder;
66 } 66 }
67 67
68 V8PerContextData* perContextData() const { return m_perContextData; } 68 V8PerContextData* perContextData() const { return m_perContextData; }
69 void setPerContextData(V8PerContextData* data) { m_perContextData = data; } 69 void setPerContextData(V8PerContextData* data) { m_perContextData = data; }
70 DOMWrapperWorld* world() const { return m_world; } 70 DOMWrapperWorld* world() const { return m_world.get(); }
71 71
72 private: 72 private:
73 V8PerContextDataHolder(v8::Handle<v8::Context> context, DOMWrapperWorld* wor ld) 73 V8PerContextDataHolder(v8::Handle<v8::Context> context, PassRefPtr<DOMWrappe rWorld> world)
74 : m_context(v8::Isolate::GetCurrent(), context) 74 : m_context(v8::Isolate::GetCurrent(), context)
75 , m_perContextData(0) 75 , m_perContextData(0)
76 , m_world(world) 76 , m_world(world)
77 { 77 {
78 m_context.setWeak(this, &V8PerContextDataHolder::weakCallback); 78 m_context.setWeak(this, &V8PerContextDataHolder::weakCallback);
79 context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, t his); 79 context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, t his);
80 } 80 }
81 81
82 ~V8PerContextDataHolder() { } 82 ~V8PerContextDataHolder() { }
83 83
84 static void weakCallback(const v8::WeakCallbackData<v8::Context, V8PerContex tDataHolder>& data) 84 static void weakCallback(const v8::WeakCallbackData<v8::Context, V8PerContex tDataHolder>& data)
85 { 85 {
86 data.GetValue()->SetAlignedPointerInEmbedderData(v8ContextPerContextData Index, 0); 86 data.GetValue()->SetAlignedPointerInEmbedderData(v8ContextPerContextData Index, 0);
87 delete data.GetParameter(); 87 delete data.GetParameter();
88 } 88 }
89 89
90 ScopedPersistent<v8::Context> m_context; 90 ScopedPersistent<v8::Context> m_context;
91 V8PerContextData* m_perContextData; 91 V8PerContextData* m_perContextData;
92 // This should not be a RefPtr. Otherwise, it creates a cycle: 92 RefPtr<DOMWrapperWorld> m_world;
93 // V8PerContextData => DOMWrapperWorld => DOMDataStore => global objects
94 // => Window or WorkerGlobalScope => V8PerContextData.
95 DOMWrapperWorld* m_world;
96 }; 93 };
97 94
98 V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context, DOMWrapperWo rld* world) 95 V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context, PassRefPtr<D OMWrapperWorld> world)
99 : m_activityLogger(0) 96 : m_activityLogger(0)
100 , m_isolate(context->GetIsolate()) 97 , m_isolate(context->GetIsolate())
101 , m_contextHolder(adoptPtr(new gin::ContextHolder(context->GetIsolate()))) 98 , m_contextHolder(adoptPtr(new gin::ContextHolder(context->GetIsolate())))
102 , m_context(m_isolate, context) 99 , m_context(m_isolate, context)
103 , m_customElementBindings(adoptPtr(new CustomElementBindingMap())) 100 , m_customElementBindings(adoptPtr(new CustomElementBindingMap()))
104 { 101 {
105 m_contextHolder->SetContext(context); 102 m_contextHolder->SetContext(context);
106 V8PerContextDataHolder::install(context, world); 103 V8PerContextDataHolder::install(context, world);
107 V8PerContextDataHolder::from(context)->setPerContextData(this); 104 V8PerContextDataHolder::from(context)->setPerContextData(this);
108 105
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 if (!data->IsString()) 256 if (!data->IsString())
260 return -1; 257 return -1;
261 v8::String::Utf8Value utf8(data); 258 v8::String::Utf8Value utf8(data);
262 char* comma = strnstr(*utf8, ",", utf8.length()); 259 char* comma = strnstr(*utf8, ",", utf8.length());
263 if (!comma) 260 if (!comma)
264 return -1; 261 return -1;
265 return atoi(comma + 1); 262 return atoi(comma + 1);
266 } 263 }
267 264
268 } // namespace WebCore 265 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8PerContextData.h ('k') | Source/bindings/v8/V8WindowShell.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698