/* static */ bool DebuggerMemory::setTrackingAllocationSites(JSContext *cx, unsigned argc, Value *vp) { THIS_DEBUGGER_MEMORY(cx, argc, vp, "(set trackingAllocationSites)", args, memory); if (!args.requireAtLeast(cx, "(set trackingAllocationSites)", 1)) return false; Debugger *dbg = memory->getDebugger(); bool enabling = ToBoolean(args[0]); if (enabling == dbg->trackingAllocationSites) { // Nothing to do here... args.rval().setUndefined(); return true; } if (enabling) { for (GlobalObjectSet::Range r = dbg->debuggees.all(); !r.empty(); r.popFront()) { JSCompartment *compartment = r.front()->compartment(); if (compartment->hasObjectMetadataCallback()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_OBJECT_METADATA_CALLBACK_ALREADY_SET); return false; } } } for (GlobalObjectSet::Range r = dbg->debuggees.all(); !r.empty(); r.popFront()) { if (enabling) { r.front()->compartment()->setObjectMetadataCallback(SavedStacksMetadataCallback); } else { r.front()->compartment()->forgetObjectMetadataCallback(); } } if (!enabling) dbg->emptyAllocationsLog(); dbg->trackingAllocationSites = enabling; args.rval().setUndefined(); return true; }