Index: Source/bindings/v8/DOMWrapperWorld.h |
diff --git a/Source/bindings/v8/DOMWrapperWorld.h b/Source/bindings/v8/DOMWrapperWorld.h |
index 17f23ffdc9e8fbf0a537a457fa62a43b9054ce9d..00abab7aac70ee154a863336e81ea347d6bce7fb 100644 |
--- a/Source/bindings/v8/DOMWrapperWorld.h |
+++ b/Source/bindings/v8/DOMWrapperWorld.h |
@@ -34,11 +34,12 @@ |
#include "bindings/v8/V8DOMActivityLogger.h" |
#include "bindings/v8/V8PerContextData.h" |
#include "platform/weborigin/SecurityOrigin.h" |
-#include <v8.h> |
+#include "wtf/MainThread.h" |
#include "wtf/PassRefPtr.h" |
#include "wtf/RefCounted.h" |
#include "wtf/RefPtr.h" |
#include "wtf/text/WTFString.h" |
+#include <v8.h> |
namespace WebCore { |
@@ -68,12 +69,24 @@ public: |
static DOMWrapperWorld* world(v8::Handle<v8::Context> context) |
{ |
- ASSERT(contextHasCorrectPrototype(context)); |
dcarney
2014/02/27 17:03:44
This ASSERT has saved us a lot of debugging in the
haraken
2014/02/28 00:06:25
Done. Reverted back the ASSERT.
|
- return V8PerContextDataHolder::from(context)->world(); |
+ V8PerContextDataHolder* contextHolder = V8PerContextDataHolder::from(context); |
+ return contextHolder ? contextHolder->world() : 0; |
} |
// Will return null if there is no DOMWrapperWorld for the current v8::Context |
- static DOMWrapperWorld* current(v8::Isolate*); |
+ static DOMWrapperWorld* current(v8::Isolate* isolate) |
+ { |
+ v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
+ if (context.IsEmpty()) { |
+ // It's possible that DOMWrapperWorld::current() is called while window is being initialized. |
+ // To make DOMWrapperWorld::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 |
@@ -108,11 +121,17 @@ 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; |
+ } |
+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; |