@@ -368,9 +368,7 @@ Breakpoint::Breakpoint(Debugger* debugger, BreakpointSite* site,
368368
369369void Breakpoint::destroy (JSFreeOp* fop,
370370 MayDestroySite mayDestroySite /* true */ ) {
371- if (debugger->enabled ) {
372- site->dec (fop);
373- }
371+ site->dec (fop);
374372 debugger->breakpoints .remove (this );
375373 site->breakpoints .remove (this );
376374 gc::Cell* cell = site->owningCellUnbarriered ();
@@ -425,7 +423,6 @@ Debugger::Debugger(JSContext* cx, NativeObject* dbg)
425423 : object(dbg),
426424 debuggees(cx->zone ()),
427425 uncaughtExceptionHook(nullptr ),
428- enabled(true ),
429426 allowUnobservedAsmJS(false ),
430427 collectCoverageInfo(false ),
431428 observedGCs(cx->zone ()),
@@ -682,9 +679,8 @@ static bool DebuggerExists(
682679
683680/* static */
684681bool Debugger::hasLiveHook (GlobalObject* global, Hook which) {
685- return DebuggerExists (global, [=](Debugger* dbg) {
686- return dbg->enabled && dbg->getHook (which);
687- });
682+ return DebuggerExists (global,
683+ [=](Debugger* dbg) { return dbg->getHook (which); });
688684}
689685
690686/* static */
@@ -722,10 +718,6 @@ JSObject* Debugger::getHook(Hook hook) const {
722718}
723719
724720bool Debugger::hasAnyLiveHooks (JSRuntime* rt) const {
725- if (!enabled) {
726- return false ;
727- }
728-
729721 // A onNewGlobalObject hook does not hold its Debugger live, so its behavior
730722 // is nondeterministic. This behavior is not satisfying, but it is at least
731723 // documented.
@@ -964,7 +956,7 @@ bool DebugAPI::slowPathOnLeaveFrame(JSContext* cx, AbstractFramePtr frame,
964956 Debugger* dbg = Debugger::fromChildJSObject (frameobj);
965957 EnterDebuggeeNoExecute nx (cx, *dbg, adjqi);
966958
967- if (dbg-> enabled && frameobj->isLive () && frameobj->onPopHandler ()) {
959+ if (frameobj->isLive () && frameobj->onPopHandler ()) {
968960 OnPopHandler* handler = frameobj->onPopHandler ();
969961
970962 Maybe<AutoRealm> ar;
@@ -2237,7 +2229,7 @@ ResumeMode Debugger::dispatchHook(JSContext* cx, HookIsEnabledFun hookIsEnabled,
22372229 if (GlobalObject::DebuggerVector* debuggers = global->getDebuggers ()) {
22382230 for (auto p = debuggers->begin (); p != debuggers->end (); p++) {
22392231 Debugger* dbg = *p;
2240- if (dbg-> enabled && hookIsEnabled (dbg)) {
2232+ if (hookIsEnabled (dbg)) {
22412233 if (!triggered.append (ObjectValue (*dbg->toJSObject ()))) {
22422234 return ResumeMode::Terminate;
22432235 }
@@ -2258,7 +2250,7 @@ ResumeMode Debugger::dispatchHook(JSContext* cx, HookIsEnabledFun hookIsEnabled,
22582250 for (Value* p = triggered.begin (); p != triggered.end (); p++) {
22592251 Debugger* dbg = Debugger::fromJSObject (&p->toObject ());
22602252 EnterDebuggeeNoExecute nx (cx, *dbg, adjqi);
2261- if (dbg->debuggees .has (global) && dbg-> enabled && hookIsEnabled (dbg)) {
2253+ if (dbg->debuggees .has (global) && hookIsEnabled (dbg)) {
22622254 ResumeMode resumeMode = fireHook (dbg);
22632255 adjqi.runJobs ();
22642256 if (resumeMode != ResumeMode::Continue) {
@@ -2370,8 +2362,8 @@ ResumeMode DebugAPI::onTrap(JSContext* cx, MutableHandleValue vp) {
23702362 continue ;
23712363 }
23722364
2373- // There are two reasons we have to check whether dbg is enabled and
2374- // debugging global.
2365+ // There are two reasons we have to check whether dbg is debugging
2366+ // global.
23752367 //
23762368 // One is just that one breakpoint handler can disable other Debuggers
23772369 // or remove debuggees.
@@ -2380,8 +2372,7 @@ ResumeMode DebugAPI::onTrap(JSContext* cx, MutableHandleValue vp) {
23802372 // specific global--until they are executed. Only now do we know which
23812373 // global the script is running against.
23822374 Debugger* dbg = bp->debugger ;
2383- bool hasDebuggee = dbg->enabled && dbg->debuggees .has (global);
2384- if (hasDebuggee) {
2375+ if (dbg->debuggees .has (global)) {
23852376 Maybe<AutoRealm> ar;
23862377 ar.emplace (cx, dbg->object );
23872378 EnterDebuggeeNoExecute nx (cx, *dbg, adjqi);
@@ -2676,7 +2667,7 @@ Maybe<double> DebugAPI::allocationSamplingProbability(GlobalObject* global) {
26762667 // this is safe as long as dbgp does not escape.
26772668 Debugger* dbgp = p->unbarrieredGet ();
26782669
2679- if (dbgp->trackingAllocationSites && dbgp-> enabled ) {
2670+ if (dbgp->trackingAllocationSites ) {
26802671 foundAnyDebuggers = true ;
26812672 probability = std::max (dbgp->allocationSamplingProbability , probability);
26822673 }
@@ -2712,7 +2703,7 @@ bool DebugAPI::slowPathOnLogAllocationSite(JSContext* cx, HandleObject obj,
27122703 // such that the vector gets reallocated.
27132704 MOZ_ASSERT (dbgs.begin () == begin);
27142705
2715- if ((*dbgp)->trackingAllocationSites && (*dbgp)-> enabled &&
2706+ if ((*dbgp)->trackingAllocationSites &&
27162707 !(*dbgp)->appendAllocationSite (cx, obj, frame, when)) {
27172708 return false ;
27182709 }
@@ -2730,7 +2721,7 @@ bool Debugger::isDebuggeeUnbarriered(const Realm* realm) const {
27302721bool Debugger::appendAllocationSite (JSContext* cx, HandleObject obj,
27312722 HandleSavedFrame frame,
27322723 mozilla::TimeStamp when) {
2733- MOZ_ASSERT (trackingAllocationSites && enabled );
2724+ MOZ_ASSERT (trackingAllocationSites);
27342725
27352726 AutoRealm ar (cx, object);
27362727 RootedObject wrappedFrame (cx, frame);
@@ -3257,21 +3248,21 @@ bool Debugger::hookObservesAllExecution(Hook which) {
32573248}
32583249
32593250Debugger::IsObserving Debugger::observesAllExecution () const {
3260- if (enabled && !!getHook (OnEnterFrame)) {
3251+ if (!!getHook (OnEnterFrame)) {
32613252 return Observing;
32623253 }
32633254 return NotObserving;
32643255}
32653256
32663257Debugger::IsObserving Debugger::observesAsmJS () const {
3267- if (enabled && !allowUnobservedAsmJS) {
3258+ if (!allowUnobservedAsmJS) {
32683259 return Observing;
32693260 }
32703261 return NotObserving;
32713262}
32723263
32733264Debugger::IsObserving Debugger::observesCoverage () const {
3274- if (enabled && collectCoverageInfo) {
3265+ if (collectCoverageInfo) {
32753266 return Observing;
32763267 }
32773268 return NotObserving;
@@ -3388,7 +3379,7 @@ bool DebugAPI::isObservedByDebuggerTrackingAllocations(
33883379 // Use unbarrieredGet() to prevent triggering read barrier while
33893380 // collecting, this is safe as long as dbg does not escape.
33903381 Debugger* dbg = p->unbarrieredGet ();
3391- if (dbg->trackingAllocationSites && dbg-> enabled ) {
3382+ if (dbg->trackingAllocationSites ) {
33923383 return true ;
33933384 }
33943385 }
@@ -3900,71 +3891,6 @@ static Debugger* Debugger_fromThisValue(JSContext* cx, const CallArgs& args,
39003891 Debugger* dbg = Debugger_fromThisValue(cx, args, fnname); \
39013892 if (!dbg) return false
39023893
3903- /* static */
3904- bool Debugger::getEnabled (JSContext* cx, unsigned argc, Value* vp) {
3905- THIS_DEBUGGER (cx, argc, vp, " get enabled" , args, dbg);
3906- args.rval ().setBoolean (dbg->enabled );
3907- return true ;
3908- }
3909-
3910- /* static */
3911- bool Debugger::setEnabled (JSContext* cx, unsigned argc, Value* vp) {
3912- THIS_DEBUGGER (cx, argc, vp, " set enabled" , args, dbg);
3913- if (!args.requireAtLeast (cx, " Debugger.set enabled" , 1 )) {
3914- return false ;
3915- }
3916-
3917- bool wasEnabled = dbg->enabled ;
3918- dbg->enabled = ToBoolean (args[0 ]);
3919-
3920- if (wasEnabled != dbg->enabled ) {
3921- if (dbg->trackingAllocationSites ) {
3922- if (wasEnabled) {
3923- dbg->removeAllocationsTrackingForAllDebuggees ();
3924- } else {
3925- if (!dbg->addAllocationsTrackingForAllDebuggees (cx)) {
3926- dbg->enabled = false ;
3927- return false ;
3928- }
3929- }
3930- }
3931-
3932- for (Breakpoint* bp = dbg->firstBreakpoint (); bp;
3933- bp = bp->nextInDebugger ()) {
3934- if (!wasEnabled) {
3935- bp->site ->inc (cx->runtime ()->defaultFreeOp ());
3936- } else {
3937- bp->site ->dec (cx->runtime ()->defaultFreeOp ());
3938- }
3939- }
3940-
3941- // Add or remove ourselves from the runtime's list of Debuggers
3942- // that care about new globals.
3943- if (dbg->getHook (OnNewGlobalObject)) {
3944- if (!wasEnabled) {
3945- cx->runtime ()->onNewGlobalObjectWatchers ().pushBack (dbg);
3946- } else {
3947- cx->runtime ()->onNewGlobalObjectWatchers ().remove (dbg);
3948- }
3949- }
3950-
3951- // Ensure the compartment is observable if we are re-enabling a
3952- // Debugger with hooks that observe all execution.
3953- if (!dbg->updateObservesAllExecutionOnDebuggees (
3954- cx, dbg->observesAllExecution ())) {
3955- return false ;
3956- }
3957-
3958- // Note: To toogle code coverage, we currently need to have no live
3959- // stack frame, thus the coverage does not depend on the enabled flag.
3960-
3961- dbg->updateObservesAsmJSOnDebuggees (dbg->observesAsmJS ());
3962- }
3963-
3964- args.rval ().setUndefined ();
3965- return true ;
3966- }
3967-
39683894/* static */
39693895bool Debugger::getHookImpl (JSContext* cx, CallArgs& args, Debugger& dbg,
39703896 Hook which) {
@@ -4092,13 +4018,11 @@ bool Debugger::setOnNewGlobalObject(JSContext* cx, unsigned argc, Value* vp) {
40924018
40934019 // Add or remove ourselves from the runtime's list of Debuggers that care
40944020 // about new globals.
4095- if (dbg->enabled ) {
4096- JSObject* newHook = dbg->getHook (OnNewGlobalObject);
4097- if (!oldHook && newHook) {
4098- cx->runtime ()->onNewGlobalObjectWatchers ().pushBack (dbg);
4099- } else if (oldHook && !newHook) {
4100- cx->runtime ()->onNewGlobalObjectWatchers ().remove (dbg);
4101- }
4021+ JSObject* newHook = dbg->getHook (OnNewGlobalObject);
4022+ if (!oldHook && newHook) {
4023+ cx->runtime ()->onNewGlobalObjectWatchers ().pushBack (dbg);
4024+ } else if (oldHook && !newHook) {
4025+ cx->runtime ()->onNewGlobalObjectWatchers ().remove (dbg);
41024026 }
41034027
41044028 return true ;
@@ -4626,13 +4550,13 @@ bool Debugger::addDebuggeeGlobal(JSContext* cx, Handle<GlobalObject*> global) {
46264550 });
46274551
46284552 // (5)
4629- if (trackingAllocationSites && enabled &&
4553+ if (trackingAllocationSites &&
46304554 !Debugger::addAllocationsTracking (cx, global)) {
46314555 return false ;
46324556 }
46334557
46344558 auto allocationsTrackingGuard = MakeScopeExit ([&] {
4635- if (trackingAllocationSites && enabled ) {
4559+ if (trackingAllocationSites) {
46364560 Debugger::removeAllocationsTracking (*global);
46374561 }
46384562 });
@@ -6055,7 +5979,6 @@ bool Debugger::adoptSource(JSContext* cx, unsigned argc, Value* vp) {
60555979}
60565980
60575981const JSPropertySpec Debugger::properties[] = {
6058- JS_PSGS (" enabled" , Debugger::getEnabled, Debugger::setEnabled, 0 ),
60595982 JS_PSGS (" onDebuggerStatement" , Debugger::getOnDebuggerStatement,
60605983 Debugger::setOnDebuggerStatement, 0 ),
60615984 JS_PSGS (" onExceptionUnwind" , Debugger::getOnExceptionUnwind,
@@ -6270,16 +6193,13 @@ bool Debugger::observesFrame(const FrameIter& iter) const {
62706193}
62716194
62726195bool Debugger::observesScript (JSScript* script) const {
6273- if (!enabled) {
6274- return false ;
6275- }
62766196 // Don't ever observe self-hosted scripts: the Debugger API can break
62776197 // self-hosted invariants.
62786198 return observesGlobal (&script->global ()) && !script->selfHosted ();
62796199}
62806200
62816201bool Debugger::observesWasm (wasm::Instance* instance) const {
6282- if (!enabled || ! instance->debugEnabled ()) {
6202+ if (!instance->debugEnabled ()) {
62836203 return false ;
62846204 }
62856205 return observesGlobal (&instance->object ()->global ());
@@ -6792,7 +6712,7 @@ JS_PUBLIC_API bool FireOnGarbageCollectionHookRequired(JSContext* cx) {
67926712 AutoCheckCannotGC noGC;
67936713
67946714 for (Debugger* dbg : cx->runtime ()->debuggerList ()) {
6795- if (dbg->enabled && dbg-> observedGC (cx->runtime ()->gc .majorGCCount ()) &&
6715+ if (dbg->observedGC (cx->runtime ()->gc .majorGCCount ()) &&
67966716 dbg->getHook (Debugger::OnGarbageCollection)) {
67976717 return true ;
67986718 }
@@ -6812,7 +6732,7 @@ JS_PUBLIC_API bool FireOnGarbageCollectionHook(
68126732 AutoCheckCannotGC noGC;
68136733
68146734 for (Debugger* dbg : cx->runtime ()->debuggerList ()) {
6815- if (dbg->enabled && dbg-> observedGC (data->majorGCNumber ()) &&
6735+ if (dbg->observedGC (data->majorGCNumber ()) &&
68166736 dbg->getHook (Debugger::OnGarbageCollection)) {
68176737 if (!triggered.append (dbg->object )) {
68186738 JS_ReportOutOfMemory (cx);
0 commit comments