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..46f68642c9dd203e5909b52552e4682283178f50 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp |
| @@ -46,12 +46,33 @@ |
| namespace blink { |
| +// Returns an identifier for a given world type other than WorldType::Isolated. |
| +// IsolatedWorld has its unique convention to allocate an identifier. |
| +int getWorldIdForType(WorldType worldType) { |
| + switch (worldType) { |
| + case WorldType::Unknown: |
| + return UnknownWorldId; |
| + case WorldType::Main: |
| + return MainWorldId; |
| + case WorldType::Isolated: |
| + NOTREACHED(); |
|
haraken
2017/03/08 09:39:09
Why is it not reached?
nhiroki
2017/03/08 10:24:52
Because IsolatedWorld is created by DOMWrapperWorl
haraken
2017/03/08 10:27:47
Hmm. So an ID for an isolated world is provided ex
nhiroki
2017/03/08 10:44:22
That's right.
|
| + return -1; |
| + // Currently, WorldId for a worker/worklet is fixed value, but this doesn't |
|
peria
2017/03/08 09:48:19
*a* fixed value
nhiroki
2017/03/08 10:24:52
Done.
|
| + // 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 -1; |
| +} |
| + |
| class DOMObjectHolderBase { |
| USING_FAST_MALLOC(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 +105,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; |
| } |
| @@ -208,7 +233,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(); |