Bug 785191: Push a null JSContext when binding / unbinding image elements in a document. r=bz
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 23 Aug 2012 16:24:58 -0700
changeset 105273 6e67b20609d24dc062fc89a6eb6ffd8682cdf6fe
parent 105257 7fb25861ffd9d6b23d10d783f8e68160f3527315
child 105274 8eb991da28afe836f0d718411b6ca10cb8f74267
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersbz
bugs785191
milestone17.0a1
Bug 785191: Push a null JSContext when binding / unbinding image elements in a document. r=bz
content/base/src/nsImageLoadingContent.cpp
--- a/content/base/src/nsImageLoadingContent.cpp
+++ b/content/base/src/nsImageLoadingContent.cpp
@@ -1153,30 +1153,40 @@ nsImageLoadingContent::BindToTree(nsIDoc
                                   nsIContent* aBindingParent,
                                   bool aCompileEventHandlers)
 {
   // We may be entering the document, so if our image should be tracked,
   // track it.
   if (!aDocument)
     return;
 
+  // Push a null JSContext on the stack so that callbacks triggered by the
+  // below code won't think they're being called from JS.
+  nsCxPusher pusher;
+  pusher.PushNull();
+
   if (mCurrentRequestFlags & REQUEST_SHOULD_BE_TRACKED)
     aDocument->AddImage(mCurrentRequest);
   if (mPendingRequestFlags & REQUEST_SHOULD_BE_TRACKED)
     aDocument->AddImage(mPendingRequest);
 }
 
 void
 nsImageLoadingContent::UnbindFromTree(bool aDeep, bool aNullParent)
 {
   // We may be leaving the document, so if our image is tracked, untrack it.
   nsCOMPtr<nsIDocument> doc = GetOurCurrentDoc();
   if (!doc)
     return;
 
+  // Push a null JSContext on the stack so that callbacks triggered by the
+  // below code won't think they're being called from JS.
+  nsCxPusher pusher;
+  pusher.PushNull();
+
   if (mCurrentRequestFlags & REQUEST_SHOULD_BE_TRACKED)
     doc->RemoveImage(mCurrentRequest);
   if (mPendingRequestFlags & REQUEST_SHOULD_BE_TRACKED)
     doc->RemoveImage(mPendingRequest);
 }
 
 nsresult
 nsImageLoadingContent::TrackImage(imgIRequest* aImage)