Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| index 9e6672465511eb4ba8ab3d079ed680d821684127..c92eb5f0e1ffdd7e3564d6acc47e2aeb0730faf1 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| @@ -91,7 +91,11 @@ PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(v8::Isolate* isolate, |
| DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, int worldId) |
| : m_worldId(worldId), |
| m_domDataStore( |
| - WTF::wrapUnique(new DOMDataStore(isolate, isMainWorld()))) {} |
| + WTF::wrapUnique(new DOMDataStore(isolate, isMainWorld()))) { |
| + if (worldId == WorkerWorldId) { |
|
sof
2017/02/01 22:05:19
nit: isWorkerWorld()
|
| + workerWorld() = this; |
| + } |
| +} |
| DOMWrapperWorld& DOMWrapperWorld::mainWorld() { |
| ASSERT(isMainThread()); |
| @@ -101,6 +105,12 @@ DOMWrapperWorld& DOMWrapperWorld::mainWorld() { |
| return *cachedMainWorld; |
| } |
| +DOMWrapperWorld*& DOMWrapperWorld::workerWorld() { |
| + DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<DOMWrapperWorld*>, workerWorld, |
| + new ThreadSpecific<DOMWrapperWorld*>); |
| + return *workerWorld; |
| +} |
| + |
| PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::fromWorldId(v8::Isolate* isolate, |
| int worldId) { |
| if (worldId == MainWorldId) |
| @@ -128,15 +138,19 @@ void DOMWrapperWorld::allWorldsInMainThread( |
| void DOMWrapperWorld::markWrappersInAllWorlds( |
| ScriptWrappable* scriptWrappable, |
| const ScriptWrappableVisitor* visitor) { |
| - // TODO(hlopko): Currently wrapper in one world will keep wrappers in all |
| - // worlds alive (possibly holding on entire documents). This is neither |
| - // needed (there is no way to get from one wrapper to another), nor wanted |
| - // (big performance and memory overhead). |
| + // Handle marking in per-worker wrapper worlds. |
| + if (!isMainThread()) { |
| + DCHECK(ThreadState::current()->isolate()); |
| + if (workerWorld()) { |
| + DOMDataStore& dataStore = workerWorld()->domDataStore(); |
| + if (dataStore.containsWrapper(scriptWrappable)) { |
| + dataStore.markWrapper(scriptWrappable); |
| + } |
| + } |
| + return; |
| + } |
| - // Marking for the main world |
| scriptWrappable->markWrapper(visitor); |
| - if (!isMainThread()) |
| - return; |
| WorldMap& isolatedWorlds = isolatedWorldMap(); |
| for (auto& world : isolatedWorlds.values()) { |
| DOMDataStore& dataStore = world->domDataStore(); |
| @@ -173,6 +187,10 @@ DOMWrapperWorld::~DOMWrapperWorld() { |
| dispose(); |
| + if (m_worldId == WorkerWorldId) { |
|
sof
2017/02/01 22:05:19
isWorkerWorld()
|
| + workerWorld() = nullptr; |
| + } |
| + |
| if (!isIsolatedWorld()) |
| return; |