Chromium Code Reviews| Index: Source/bindings/v8/DOMWrapperWorld.h |
| diff --git a/Source/bindings/v8/DOMWrapperWorld.h b/Source/bindings/v8/DOMWrapperWorld.h |
| index aea72c3739191564e0e02293ecf8235066eaa110..0f67215db1e21dc1e1ec01c48ce670b266f74503 100644 |
| --- a/Source/bindings/v8/DOMWrapperWorld.h |
| +++ b/Source/bindings/v8/DOMWrapperWorld.h |
| @@ -33,6 +33,7 @@ |
| #include "bindings/v8/V8PerContextData.h" |
| #include "platform/weborigin/SecurityOrigin.h" |
| +#include "wtf/MainThread.h" |
| #include "wtf/PassRefPtr.h" |
| #include "wtf/RefCounted.h" |
| #include "wtf/RefPtr.h" |
| @@ -68,12 +69,28 @@ public: |
| static DOMWrapperWorld* world(v8::Handle<v8::Context> context) |
| { |
| - ASSERT(contextHasCorrectPrototype(context)); |
|
haraken
2014/03/04 04:19:45
I removed this ASSERT for the following reasons:
|
| return V8PerContextData::world(context); |
| } |
| - // Will return null if there is no DOMWrapperWorld for the current v8::Context |
| - static DOMWrapperWorld* current(v8::Isolate*); |
| + // Will return null if there is no DOMWrapperWorld for the current context. |
| + static DOMWrapperWorld* current(v8::Isolate* isolate) |
| + { |
| + v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| + if (context.IsEmpty()) { |
| + // If a worker thread calls current() with an empty context, it means that there is no DOMWrapperWorld. |
| + if (!isMainThread()) |
| + return 0; |
| + |
| + // If the main thread calls current() with an empty context, it's possible that |
| + // current() is being called while window is being initialized. |
| + // In order to make current() workable during the initialization phase, |
| + // we cache the world of the initializing window on worldOfInitializingWindow. |
| + // If there is no initiazing window, worldOfInitializingWindow is 0. |
| + return worldOfInitializingWindow; |
| + } |
| + return world(context); |
| + } |
| + |
| static DOMWrapperWorld* mainWorld(); |
| // Associates an isolated world (see above for description) with a security |
| @@ -103,11 +120,19 @@ public: |
| int extensionGroup() const { return m_extensionGroup; } |
| DOMDataStore& domDataStore() { return *m_domDataStore; } |
| -private: |
| - static unsigned isolatedWorldCount; |
| + static void setWorldOfInitializingWindow(DOMWrapperWorld* world) |
| + { |
| + ASSERT(isMainThread()); |
| + worldOfInitializingWindow = world; |
| + } |
| + // FIXME: Remove this method once we fix crbug.com/345014. |
| + static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; } |
| +private: |
| DOMWrapperWorld(int worldId, int extensionGroup); |
| - static bool contextHasCorrectPrototype(v8::Handle<v8::Context>); |
| + |
| + static unsigned isolatedWorldCount; |
| + static DOMWrapperWorld* worldOfInitializingWindow; |
| const int m_worldId; |
| const int m_extensionGroup; |