Bug 677079 - Part j: Stop using js::ContextAllocPolicy in ListenerManager.cpp; r=bent+sfink
authorMs2ger <ms2ger@gmail.com>
Sun, 15 Jan 2012 09:13:09 +0100
changeset 85687 be5a53604bc33bfde4d010714c3eb56a96a730b1
parent 85686 f9fe45249420b8b0b0d216cc57e40498f866b726
child 85688 46b5d4c3b3d8fd767add83477e36d55139edc33a
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs677079
milestone12.0a1
Bug 677079 - Part j: Stop using js::ContextAllocPolicy in ListenerManager.cpp; r=bent+sfink
dom/workers/ListenerManager.cpp
--- a/dom/workers/ListenerManager.cpp
+++ b/dom/workers/ListenerManager.cpp
@@ -35,18 +35,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/Util.h"
 
 #include "ListenerManager.h"
 
+#include "jsalloc.h"
 #include "jsapi.h"
-#include "jscntxt.h"
 #include "jsfriendapi.h"
 #include "js/Vector.h"
 
 #include "Events.h"
 
 using namespace mozilla;
 using dom::workers::events::ListenerManager;
 
@@ -312,16 +312,35 @@ ListenerManager::GetEventListener(JSCont
         return true;
       }
     }
   }
   *aListenerVal = JSVAL_VOID;
   return true;
 }
 
+class ExternallyUsableContextAllocPolicy
+{
+    JSContext *const cx;
+
+  public:
+    ExternallyUsableContextAllocPolicy(JSContext *cx) : cx(cx) {}
+    JSContext *context() const { return cx; }
+    void *malloc_(size_t bytes) {
+        JSAutoRequest ar(cx);
+        return JS_malloc(cx, bytes);
+    }
+    void *realloc_(void *p, size_t oldBytes, size_t bytes) {
+        JSAutoRequest ar(cx);
+        return JS_realloc(cx, p, bytes);
+    }
+    void free_(void *p) { JS_free(cx, p); }
+    void reportAllocOverflow() const { JS_ReportAllocationOverflow(cx); }
+};
+
 bool
 ListenerManager::DispatchEvent(JSContext* aCx, JSObject* aTarget,
                                JSObject* aEvent, bool* aPreventDefaultCalled)
 {
   if (!events::IsSupportedEventClass(aCx, aEvent)) {
     JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
                          JSMSG_INCOMPATIBLE_METHOD,
                          "EventTarget", "dispatchEvent", "Event object");
@@ -363,18 +382,18 @@ ListenerManager::DispatchEvent(JSContext
   ListenerCollection* collection =
     GetCollectionForType(&mCollectionHead,
                          INTERNED_STRING_TO_JSID(aCx, eventType));
   if (!collection) {
     *aPreventDefaultCalled = false;
     return true;
   }
 
-  js::ContextAllocPolicy ap(aCx);
-  js::Vector<jsval, 10, js::ContextAllocPolicy> listeners(ap);
+  ExternallyUsableContextAllocPolicy ap(aCx);
+  js::Vector<jsval, 10, ExternallyUsableContextAllocPolicy> listeners(ap);
 
   for (PRCList* elem = PR_NEXT_LINK(&collection->mListenerHead);
        elem != &collection->mListenerHead;
        elem = PR_NEXT_LINK(elem)) {
     Listener* listener = static_cast<Listener*>(elem);
 
     // Listeners that don't want untrusted events will be skipped if this is an
     // untrusted event.