Bug 749128 - Make sure to have JSContext before creating TabChildGlobal, r=jst
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 26 Apr 2012 23:56:46 +0300
changeset 92489 dca63f21e6d238c6c0e9d3a96f2ec58ddb07039d
parent 92488 b952bb042f129b3ac3083209ecc447b080c3ed6d
child 92490 0d6b3c17b8398654e7cf9b8c367e02cd775ba841
push idunknown
push userunknown
push dateunknown
reviewersjst
bugs749128
milestone15.0a1
Bug 749128 - Make sure to have JSContext before creating TabChildGlobal, r=jst
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -902,16 +902,18 @@ TabChild::InitTabChildGlobal()
 
   mTabChildGlobal = scope;
 
   nsISupports* scopeSupports =
     NS_ISUPPORTS_CAST(nsIDOMEventTarget*, scope);
   
   NS_ENSURE_TRUE(InitTabChildGlobalInternal(scopeSupports), false); 
 
+  scope->Init();
+
   nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(chromeHandler);
   NS_ENSURE_TRUE(root, false);
   root->SetParentTarget(scope);
   return true;
 }
 
 bool
 TabChild::InitWidget(const nsIntSize& size)
@@ -985,23 +987,29 @@ SendAsyncMessageToParent(void* aCallback
 {
   return static_cast<TabChild*>(aCallbackData)->
     SendAsyncMessage(nsString(aMessage), nsString(aJSON));
 }
 
 TabChildGlobal::TabChildGlobal(TabChild* aTabChild)
 : mTabChild(aTabChild)
 {
+}
+
+void
+TabChildGlobal::Init()
+{
+  NS_ASSERTION(!mMessageManager, "Re-initializing?!?");
   mMessageManager = new nsFrameMessageManager(false,
                                               SendSyncMessageToParent,
                                               SendAsyncMessageToParent,
                                               nsnull,
                                               mTabChild,
                                               nsnull,
-                                              aTabChild->GetJSContext());
+                                              mTabChild->GetJSContext());
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(TabChildGlobal)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TabChildGlobal,
                                                 nsDOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mMessageManager)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -89,16 +89,17 @@ class PContentDialogChild;
 
 class TabChildGlobal : public nsDOMEventTargetHelper,
                        public nsIContentFrameMessageManager,
                        public nsIScriptObjectPrincipal,
                        public nsIScriptContextPrincipal
 {
 public:
   TabChildGlobal(TabChild* aTabChild);
+  void Init();
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TabChildGlobal, nsDOMEventTargetHelper)
   NS_FORWARD_SAFE_NSIFRAMEMESSAGEMANAGER(mMessageManager)
   NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
                              const jsval& aObject,
                              JSContext* aCx,
                              PRUint8 aArgc,
                              jsval* aRetval)