Bug 1527413 part 2. Add a way to iterate the compartments in a given zone. r=jandem
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 13 Feb 2019 14:10:21 +0000
changeset 458891 6c10cc59703a
parent 458890 4ad4542bccee
child 458892 4f84802c6f0b
push id35551
push usershindli@mozilla.com
push dateWed, 13 Feb 2019 21:34:09 +0000
treeherdermozilla-central@08f794a4928e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1527413
milestone67.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 1527413 part 2. Add a way to iterate the compartments in a given zone. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D19560
js/src/gc/PublicIterators.cpp
js/src/jsapi.h
--- a/js/src/gc/PublicIterators.cpp
+++ b/js/src/gc/PublicIterators.cpp
@@ -222,16 +222,29 @@ JS_PUBLIC_API void JS_IterateCompartment
   for (CompartmentsIter c(cx->runtime()); !c.done(); c.next()) {
     if ((*compartmentCallback)(cx, data, c) ==
         JS::CompartmentIterResult::Stop) {
       break;
     }
   }
 }
 
+JS_PUBLIC_API void JS_IterateCompartmentsInZone(
+    JSContext* cx, JS::Zone* zone, void* data,
+    JSIterateCompartmentCallback compartmentCallback) {
+  AutoTraceSession session(cx->runtime());
+
+  for (CompartmentsInZoneIter c(zone); !c.done(); c.next()) {
+    if ((*compartmentCallback)(cx, data, c) ==
+        JS::CompartmentIterResult::Stop) {
+      break;
+    }
+  }
+}
+
 JS_PUBLIC_API void JS::IterateRealms(JSContext* cx, void* data,
                                      JS::IterateRealmCallback realmCallback) {
   AutoTraceSession session(cx->runtime());
 
   Rooted<Realm*> realm(cx);
   for (RealmsIter r(cx->runtime()); !r.done(); r.next()) {
     realm = r;
     (*realmCallback)(cx, data, realm);
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -587,16 +587,27 @@ typedef JS::CompartmentIterResult (*JSIt
  * returned. Beware that there is no guarantee that the compartment will survive
  * after the callback returns. Also, barriers are disabled via the TraceSession.
  */
 extern JS_PUBLIC_API void JS_IterateCompartments(
     JSContext* cx, void* data,
     JSIterateCompartmentCallback compartmentCallback);
 
 /**
+ * This function calls |compartmentCallback| on every compartment in the given
+ * zone until either all compartments have been iterated or
+ * CompartmentIterResult::Stop is returned. Beware that there is no guarantee
+ * that the compartment will survive after the callback returns. Also, barriers
+ * are disabled via the TraceSession.
+ */
+extern JS_PUBLIC_API void JS_IterateCompartmentsInZone(
+    JSContext* cx, JS::Zone* zone, void* data,
+    JSIterateCompartmentCallback compartmentCallback);
+
+/**
  * Mark a jsid after entering a new compartment. Different zones separately
  * mark the ids in a runtime, and this must be used any time an id is obtained
  * from one compartment and then used in another compartment, unless the two
  * compartments are guaranteed to be in the same zone.
  */
 extern JS_PUBLIC_API void JS_MarkCrossZoneId(JSContext* cx, jsid id);
 
 /**