Bug 909490, part 2 - Add callback for zone destruction. r=billm

This commit is contained in:
Andrew McCreight 2013-09-25 13:41:25 -07:00
parent 04485adc4e
commit 03c332e10a
5 changed files with 19 additions and 0 deletions

View File

@ -908,6 +908,12 @@ JS_SetDestroyCompartmentCallback(JSRuntime *rt, JSDestroyCompartmentCallback cal
rt->destroyCompartmentCallback = callback;
}
JS_PUBLIC_API(void)
JS_SetDestroyZoneCallback(JSRuntime *rt, JSZoneCallback callback)
{
rt->destroyZoneCallback = callback;
}
JS_PUBLIC_API(void)
JS_SetCompartmentNameCallback(JSRuntime *rt, JSCompartmentNameCallback callback)
{

View File

@ -841,6 +841,9 @@ typedef JSObject *
typedef void
(* JSDestroyCompartmentCallback)(JSFreeOp *fop, JSCompartment *compartment);
typedef void
(* JSZoneCallback)(JS::Zone *zone);
typedef void
(* JSCompartmentNameCallback)(JSRuntime *rt, JSCompartment *compartment,
char *buf, size_t bufsize);
@ -1623,6 +1626,9 @@ JS_GetImplementationVersion(void);
extern JS_PUBLIC_API(void)
JS_SetDestroyCompartmentCallback(JSRuntime *rt, JSDestroyCompartmentCallback callback);
extern JS_PUBLIC_API(void)
JS_SetDestroyZoneCallback(JSRuntime *rt, JSZoneCallback callback);
extern JS_PUBLIC_API(void)
JS_SetCompartmentNameCallback(JSRuntime *rt, JSCompartmentNameCallback callback);

View File

@ -2614,6 +2614,7 @@ static void
SweepZones(FreeOp *fop, bool lastGC)
{
JSRuntime *rt = fop->runtime();
JSZoneCallback callback = rt->destroyZoneCallback;
/* Skip the atomsCompartment zone. */
Zone **read = rt->zones.begin() + 1;
@ -2628,6 +2629,8 @@ SweepZones(FreeOp *fop, bool lastGC)
if (!zone->hold && zone->wasGCStarted()) {
if (zone->allocator.arenas.arenaListsAreEmpty() || lastGC) {
zone->allocator.arenas.checkEmptyFreeLists();
if (callback)
callback(zone);
SweepCompartments(fop, zone, false, lastGC);
JS_ASSERT(zone->compartments.empty());
fop->delete_(zone);

View File

@ -146,6 +146,7 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
nativeStackBase(0),
cxCallback(nullptr),
destroyCompartmentCallback(nullptr),
destroyZoneCallback(nullptr),
compartmentNameCallback(nullptr),
activityCallback(nullptr),
activityCallbackArg(nullptr),

View File

@ -950,6 +950,9 @@ struct JSRuntime : public JS::shadow::Runtime,
/* Compartment destroy callback. */
JSDestroyCompartmentCallback destroyCompartmentCallback;
/* Zone destroy callback. */
JSZoneCallback destroyZoneCallback;
/* Call this to get the name of a compartment. */
JSCompartmentNameCallback compartmentNameCallback;