Merge mozilla-central to autoland. a=merge CLOSED TREE
[gecko.git] / js / public / RealmIterators.h
blob13f19dbb8fdca474ad9bbb9d7b615c8976393124
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * Various interfaces to iterate over the Realms given various context such as
9 * principals, compartments and GC zones.
12 #ifndef js_RealmIterators_h
13 #define js_RealmIterators_h
15 #include "js/GCAPI.h"
16 #include "js/TypeDecls.h"
18 struct JSPrincipals;
20 namespace JS {
22 class JS_PUBLIC_API AutoRequireNoGC;
24 using IterateRealmCallback = void (*)(JSContext* cx, void* data, Realm* realm,
25 const AutoRequireNoGC& nogc);
27 /**
28 * This function calls |realmCallback| on every realm. Beware that there is no
29 * guarantee that the realm will survive after the callback returns. Also,
30 * barriers are disabled via the TraceSession.
32 extern JS_PUBLIC_API void IterateRealms(JSContext* cx, void* data,
33 IterateRealmCallback realmCallback);
35 /**
36 * Like IterateRealms, but only call the callback for realms using |principals|.
38 extern JS_PUBLIC_API void IterateRealmsWithPrincipals(
39 JSContext* cx, JSPrincipals* principals, void* data,
40 IterateRealmCallback realmCallback);
42 /**
43 * Like IterateRealms, but only iterates realms in |compartment|.
45 extern JS_PUBLIC_API void IterateRealmsInCompartment(
46 JSContext* cx, JS::Compartment* compartment, void* data,
47 IterateRealmCallback realmCallback);
49 /**
50 * An enum that JSIterateCompartmentCallback can return to indicate
51 * whether to keep iterating.
53 enum class CompartmentIterResult { KeepGoing, Stop };
55 } // namespace JS
57 using JSIterateCompartmentCallback =
58 JS::CompartmentIterResult (*)(JSContext*, void*, JS::Compartment*);
60 /**
61 * This function calls |compartmentCallback| on every compartment until either
62 * all compartments have been iterated or CompartmentIterResult::Stop is
63 * returned. Beware that there is no guarantee that the compartment will survive
64 * after the callback returns. Also, barriers are disabled via the TraceSession.
66 extern JS_PUBLIC_API void JS_IterateCompartments(
67 JSContext* cx, void* data,
68 JSIterateCompartmentCallback compartmentCallback);
70 /**
71 * This function calls |compartmentCallback| on every compartment in the given
72 * zone until either all compartments have been iterated or
73 * CompartmentIterResult::Stop is returned. Beware that there is no guarantee
74 * that the compartment will survive after the callback returns. Also, barriers
75 * are disabled via the TraceSession.
77 extern JS_PUBLIC_API void JS_IterateCompartmentsInZone(
78 JSContext* cx, JS::Zone* zone, void* data,
79 JSIterateCompartmentCallback compartmentCallback);
81 #endif /* js_RealmIterators_h */