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 3d23c73d43c297bb6ea06936628761ccf5e5eb31..1fa1a53d1d1cc1bf021859bcdd26bb75f3cda1c6 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| @@ -51,7 +51,7 @@ class DOMObjectHolderBase { |
| public: |
| DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper) |
| - : m_wrapper(isolate, wrapper), m_world(0) {} |
| + : m_wrapper(isolate, wrapper), m_world(nullptr) {} |
| virtual ~DOMObjectHolderBase() {} |
| DOMWrapperWorld* world() const { return m_world; } |
| @@ -84,24 +84,28 @@ class DOMObjectHolder : public DOMObjectHolderBase { |
| unsigned DOMWrapperWorld::isolatedWorldCount = 0; |
| PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(v8::Isolate* isolate, |
| - int worldId) { |
| - return adoptRef(new DOMWrapperWorld(isolate, worldId)); |
| + WorldType worldType) { |
| + DCHECK_NE(WorldType::Isolated, worldType); |
| + return adoptRef( |
| + new DOMWrapperWorld(isolate, worldType, getWorldIdForType(worldType))); |
| } |
| -DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, int worldId) |
| - : m_worldId(worldId), |
| +DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, |
| + WorldType worldType, |
| + int worldId) |
| + : m_worldType(worldType), |
| + m_worldId(worldId), |
| m_domDataStore( |
| WTF::wrapUnique(new DOMDataStore(isolate, isMainWorld()))) { |
| - if (worldId == WorkerWorldId) { |
| + if (isWorkerWorld()) |
| workerWorld() = this; |
| - } |
| } |
| DOMWrapperWorld& DOMWrapperWorld::mainWorld() { |
| ASSERT(isMainThread()); |
| DEFINE_STATIC_REF( |
| DOMWrapperWorld, cachedMainWorld, |
| - (DOMWrapperWorld::create(v8::Isolate::GetCurrent(), MainWorldId))); |
| + (DOMWrapperWorld::create(v8::Isolate::GetCurrent(), WorldType::Main))); |
| return *cachedMainWorld; |
| } |
| @@ -191,7 +195,8 @@ void DOMWrapperWorld::dispose() { |
| #if DCHECK_IS_ON() |
| static bool isIsolatedWorldId(int worldId) { |
| - return MainWorldId < worldId && worldId < IsolatedWorldIdLimit; |
| + return DOMWrapperWorld::MainWorldId < worldId && |
| + worldId < DOMWrapperWorld::IsolatedWorldIdLimit; |
| } |
| #endif |
| @@ -208,7 +213,7 @@ PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::ensureIsolatedWorld( |
| return world.release(); |
| } |
| - world = DOMWrapperWorld::create(isolate, worldId); |
| + world = adoptRef(new DOMWrapperWorld(isolate, WorldType::Isolated, worldId)); |
| result.storedValue->value = world.get(); |
| isolatedWorldCount++; |
| return world.release(); |
| @@ -315,4 +320,23 @@ void DOMWrapperWorld::weakCallbackForDOMObjectHolder( |
| holderBase->world()->unregisterDOMObjectHolder(holderBase); |
| } |
| +int DOMWrapperWorld::getWorldIdForType(WorldType worldType) { |
|
Yuki
2017/03/08 14:07:51
IIUC, this function is going to be used to get an
nhiroki
2017/03/09 03:40:28
I'd prefer to rename this in my second patch that
|
| + switch (worldType) { |
| + case WorldType::Unknown: |
| + return UnknownWorldId; |
|
Yuki
2017/03/08 14:07:51
I think "Unknown" is not a good name.
It seems th
nhiroki
2017/03/09 03:40:28
Done.
|
| + case WorldType::Main: |
| + return MainWorldId; |
| + case WorldType::Isolated: |
| + NOTREACHED(); |
|
Yuki
2017/03/08 14:07:51
Could you add a comment about the reason why we do
nhiroki
2017/03/09 03:40:28
Done.
|
| + return UnknownWorldId; |
| + // Currently, WorldId for a worker/worklet is a fixed value, but this |
| + // doesn't work when multiple worklets are created on a thread. |
| + // TODO(nhiroki): Expand the identifier space for workers/worklets. |
| + case WorldType::Worker: |
| + return WorkerWorldId; |
| + } |
| + NOTREACHED(); |
| + return UnknownWorldId; |
| +} |
| + |
| } // namespace blink |