From 0844833fbda97b99f98456f6c413d66a1f748ee0 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 15 Jan 2012 09:13:09 +0100 Subject: [PATCH] Bug 677079 - Part j: Stop using js::ContextAllocPolicy in ListenerManager.cpp; r=bent+sfink --- dom/workers/ListenerManager.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/dom/workers/ListenerManager.cpp b/dom/workers/ListenerManager.cpp index ec7409a3dfc..863a8b7b017 100644 --- a/dom/workers/ListenerManager.cpp +++ b/dom/workers/ListenerManager.cpp @@ -40,8 +40,8 @@ #include "ListenerManager.h" +#include "jsalloc.h" #include "jsapi.h" -#include "jscntxt.h" #include "jsfriendapi.h" #include "js/Vector.h" @@ -317,6 +317,25 @@ ListenerManager::GetEventListener(JSContext* aCx, JSString* aType, 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) @@ -368,8 +387,8 @@ ListenerManager::DispatchEvent(JSContext* aCx, JSObject* aTarget, return true; } - js::ContextAllocPolicy ap(aCx); - js::Vector listeners(ap); + ExternallyUsableContextAllocPolicy ap(aCx); + js::Vector listeners(ap); for (PRCList* elem = PR_NEXT_LINK(&collection->mListenerHead); elem != &collection->mListenerHead;