1. ms2ger
  2. Spidermonkey patches

Commits

ms2ger  committed 22972fe

Yet another approach to ListenerManager-ContextAllocPolicy.

  • Participants
  • Parent commits 07613c2
  • Branches default

Comments (0)

Files changed (1)

File ListenerManager-ContextAllocPolicy

View file
  • Ignore whitespace
  using namespace mozilla;
  using dom::workers::events::ListenerManager;
  
-@@ -363,18 +363,17 @@ ListenerManager::DispatchEvent(JSContext
+@@ -363,18 +363,18 @@ ListenerManager::DispatchEvent(JSContext
    ListenerCollection* collection =
      GetCollectionForType(&mCollectionHead,
                           INTERNED_STRING_TO_JSID(aCx, eventType));
  
 -  js::ContextAllocPolicy ap(aCx);
 -  js::Vector<jsval, 10, js::ContextAllocPolicy> listeners(ap);
-+  js::Vector<jsval, 10, js::SystemAllocPolicy> listeners;
++  js::ExternallyUsableContextAllocPolicy ap(aCx);
++  js::Vector<jsval, 10, js::ExternallyUsableContextAllocPolicy> listeners(ap);
  
    for (PRCList* elem = PR_NEXT_LINK(&collection->mListenerHead);
         elem != &collection->mListenerHead;
  
      // Listeners that don't want untrusted events will be skipped if this is an
      // untrusted event.
+diff --git a/js/src/jsalloc.h b/js/src/jsalloc.h
+--- a/js/src/jsalloc.h
++++ b/js/src/jsalloc.h
+@@ -111,11 +111,30 @@ class TempAllocPolicy
+ 
+     void free_(void *p) {
+         js_free(p);
+     }
+ 
+     JS_FRIEND_API(void) reportAllocOverflow() const;
+ };
+ 
++class ExternallyUsableContextAllocPolicy
++{
++    JSContext *const cx;
++
++  public:
++    ContextAllocPolicy(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, bytes);
++    }
++    void free_(void *p) { JS_free(cx, p); }
++    void reportAllocOverflow() const { JS_ReportAllocationOverflow(cx); }
++};
++
+ } /* namespace js */
+ 
+ #endif /* jsalloc_h_ */