Bug 989528 - Introduce AutoJSAPIWithErrorsReportedToWindow as a replacement for AutoPushJSContextForErrorReporting. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Mon, 14 Apr 2014 20:26:59 -0700
changeset 196939 b59ad321f19eac4377bf859925b25b74d64f61b4
parent 196938 3c079cc52af9b789e3ef1bf71dbea670d1c3a2cf
child 196940 bcd2cf9e9bdf261b2f3d214742bcdbd31c6441b8
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs989528
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 989528 - Introduce AutoJSAPIWithErrorsReportedToWindow as a replacement for AutoPushJSContextForErrorReporting. r=bz
dom/base/ScriptSettings.cpp
dom/base/ScriptSettings.h
dom/events/EventListenerManager.cpp
js/xpconnect/src/nsCxPusher.h
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -227,16 +227,21 @@ AutoJSAPI::AutoJSAPI(JSContext *aCx, boo
 
   // In general we want to leave the cx in a null compartment, but we let
   // subclasses skip this if they plan to immediately enter a compartment.
   if (!aSkipNullAc) {
     mNullAc.construct(mCx);
   }
 }
 
+AutoJSAPIWithErrorsReportedToWindow::AutoJSAPIWithErrorsReportedToWindow(nsIScriptContext* aScx)
+  : AutoJSAPI(aScx->GetNativeContext(), /* aIsMainThread = */ true)
+{
+}
+
 AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject,
                                  bool aIsMainThread,
                                  JSContext* aCx)
   : AutoJSAPI(aCx ? aCx : FindJSContext(aGlobalObject), aIsMainThread, /* aSkipNullAc = */ true)
   , ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ true)
   , mAc(cx(), aGlobalObject->GetGlobalJSObject())
   , mStack(ScriptSettingsStack::Ref())
 {
--- a/dom/base/ScriptSettings.h
+++ b/dom/base/ScriptSettings.h
@@ -143,16 +143,28 @@ protected:
   AutoJSAPI(JSContext *aCx, bool aIsMainThread, bool aSkipNullAC = false);
 
 private:
   mozilla::Maybe<AutoCxPusher> mCxPusher;
   mozilla::Maybe<JSAutoNullCompartment> mNullAc;
   JSContext *mCx;
 };
 
+// Note - the ideal way to implement this is with an accessor on AutoJSAPI
+// that lets us select the error reporting target. But at present,
+// implementing it that way would require us to destroy and reconstruct
+// mCxPusher, which is pretty wasteful. So we do this for now, since it should
+// be pretty easy to switch things over later.
+//
+// This should only be used on the main thread.
+class AutoJSAPIWithErrorsReportedToWindow : public AutoJSAPI {
+  public:
+    AutoJSAPIWithErrorsReportedToWindow(nsIScriptContext* aScx);
+};
+
 /*
  * A class that represents a new script entry point.
  */
 class AutoEntryScript : public AutoJSAPI,
                         protected ScriptSettingsStackEntry {
 public:
   AutoEntryScript(nsIGlobalObject* aGlobalObject,
                   bool aIsMainThread = NS_IsMainThread(),
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -786,18 +786,20 @@ EventListenerManager::CompileEventHandle
   nsCOMPtr<nsIDocument> doc;
   nsCOMPtr<nsIScriptGlobalObject> global =
     GetScriptGlobalAndDocument(getter_AddRefs(doc));
   NS_ENSURE_STATE(global);
 
   nsIScriptContext* context = global->GetScriptContext();
   NS_ENSURE_STATE(context);
 
-  // Push a context to make sure exceptions are reported in the right place.
-  AutoPushJSContextForErrorReporting cx(context->GetNativeContext());
+  // Activate JSAPI, and make sure that exceptions are reported on the right
+  // Window.
+  AutoJSAPIWithErrorsReportedToWindow jsapi(context);
+  JSContext* cx = jsapi.cx();
 
   nsCOMPtr<nsIAtom> typeAtom = aListener->mTypeAtom;
   nsIAtom* attrName = typeAtom;
 
   // Flag us as not a string so we don't keep trying to compile strings which
   // can't be compiled.
   aListener->mHandlerIsString = false;
 
--- a/js/xpconnect/src/nsCxPusher.h
+++ b/js/xpconnect/src/nsCxPusher.h
@@ -170,21 +170,11 @@ class MOZ_STACK_CLASS AutoPushJSContext 
   Maybe<AutoCxPusher> mPusher;
   JSContext* mCx;
 
 public:
   AutoPushJSContext(JSContext* aCx);
   operator JSContext*() { return mCx; }
 };
 
-/**
- * AutoPushJSContextForErrorReporting has been defined for work being carried
- * out for bug 951991.  It is to be used where an AutoPushJSContext is only
- * being used to make sure errors are reported using the error reporter for the
- * appropriate DOM Window and we don't want to replace it with AutoEntryScript.
- * This will make it easy to find these cases once the JSContext is no longer
- * required for error reporting.
- */
-typedef AutoPushJSContext AutoPushJSContextForErrorReporting;
-
 } // namespace mozilla
 
 #endif /* nsCxPusher_h */