1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef debugger_DebugAPI_inl_h
#define debugger_DebugAPI_inl_h
#include "debugger/DebugAPI.h"
#include "gc/GC.h"
#include "vm/GeneratorObject.h"
#include "vm/PromiseObject.h" // js::PromiseObject
#include "vm/Stack-inl.h"
namespace js {
/* static */
bool DebugAPI::stepModeEnabled(JSScript* script) {
return script->hasDebugScript() && stepModeEnabledSlow(script);
}
/* static */
bool DebugAPI::hasBreakpointsAt(JSScript* script, jsbytecode* pc) {
return script->hasDebugScript() && hasBreakpointsAtSlow(script, pc);
}
/* static */
bool DebugAPI::hasAnyBreakpointsOrStepMode(JSScript* script) {
return script->hasDebugScript();
}
/* static */
void DebugAPI::onNewGlobalObject(JSContext* cx, Handle<GlobalObject*> global) {
MOZ_ASSERT(!global->realm()->firedOnNewGlobalObject);
#ifdef DEBUG
global->realm()->firedOnNewGlobalObject = true;
#endif
if (!cx->runtime()->onNewGlobalObjectWatchers().isEmpty()) {
slowPathOnNewGlobalObject(cx, global);
}
}
/* static */
void DebugAPI::notifyParticipatesInGC(GlobalObject* global,
uint64_t majorGCNumber) {
JS::AutoAssertNoGC nogc;
Realm::DebuggerVector& dbgs = global->getDebuggers(nogc);
if (!dbgs.empty()) {
slowPathNotifyParticipatesInGC(majorGCNumber, dbgs, nogc);
}
}
/* static */
bool DebugAPI::onLogAllocationSite(JSContext* cx, JSObject* obj,
Handle<SavedFrame*> frame,
mozilla::TimeStamp when) {
// slowPathOnLogAllocationSite creates GC things so we must suppress GC here.
gc::AutoSuppressGC nogc(cx);
Realm::DebuggerVector& dbgs = cx->global()->getDebuggers(nogc);
if (dbgs.empty()) {
return true;
}
RootedObject hobj(cx, obj);
return slowPathOnLogAllocationSite(cx, hobj, frame, when, dbgs, nogc);
}
/* static */
bool DebugAPI::onLeaveFrame(JSContext* cx, AbstractFramePtr frame,
const jsbytecode* pc, bool ok) {
MOZ_ASSERT_IF(frame.isInterpreterFrame(),
frame.asInterpreterFrame() == cx->interpreterFrame());
MOZ_ASSERT_IF(frame.hasScript() && frame.script()->isDebuggee(),
frame.isDebuggee());
/* Traps must be cleared from eval frames, see slowPathOnLeaveFrame. */
mozilla::DebugOnly<bool> evalTraps =
frame.isEvalFrame() && frame.script()->hasDebugScript();
MOZ_ASSERT_IF(evalTraps, frame.isDebuggee());
if (frame.isDebuggee()) {
ok = slowPathOnLeaveFrame(cx, frame, pc, ok);
}
MOZ_ASSERT(!inFrameMaps(frame));
return ok;
}
/* static */
bool DebugAPI::onNewGenerator(JSContext* cx, AbstractFramePtr frame,
Handle<AbstractGeneratorObject*> genObj) {
if (frame.isDebuggee()) {
return slowPathOnNewGenerator(cx, frame, genObj);
}
return true;
}
/* static */
bool DebugAPI::checkNoExecute(JSContext* cx, HandleScript script) {
if (!cx->realm()->isDebuggee() || !cx->noExecuteDebuggerTop) {
return true;
}
return slowPathCheckNoExecute(cx, script);
}
/* static */
bool DebugAPI::onEnterFrame(JSContext* cx, AbstractFramePtr frame) {
MOZ_ASSERT_IF(frame.hasScript() && frame.script()->isDebuggee(),
frame.isDebuggee());
if (MOZ_UNLIKELY(frame.isDebuggee())) {
return slowPathOnEnterFrame(cx, frame);
}
return true;
}
/* static */
bool DebugAPI::onResumeFrame(JSContext* cx, AbstractFramePtr frame) {
MOZ_ASSERT_IF(frame.hasScript() && frame.script()->isDebuggee(),
frame.isDebuggee());
if (MOZ_UNLIKELY(frame.isDebuggee())) {
return slowPathOnResumeFrame(cx, frame);
}
return true;
}
/* static */
NativeResumeMode DebugAPI::onNativeCall(JSContext* cx, const CallArgs& args,
CallReason reason) {
if (MOZ_UNLIKELY(cx->realm()->isDebuggee())) {
return slowPathOnNativeCall(cx, args, reason);
}
return NativeResumeMode::Continue;
}
/* static */
bool DebugAPI::onDebuggerStatement(JSContext* cx, AbstractFramePtr frame) {
if (MOZ_UNLIKELY(cx->realm()->isDebuggee())) {
return slowPathOnDebuggerStatement(cx, frame);
}
return true;
}
/* static */
bool DebugAPI::onExceptionUnwind(JSContext* cx, AbstractFramePtr frame) {
if (MOZ_UNLIKELY(cx->realm()->isDebuggee())) {
return slowPathOnExceptionUnwind(cx, frame);
}
return true;
}
/* static */
void DebugAPI::onNewWasmInstance(JSContext* cx,
Handle<WasmInstanceObject*> wasmInstance) {
if (cx->realm()->isDebuggee()) {
slowPathOnNewWasmInstance(cx, wasmInstance);
}
}
/* static */
void DebugAPI::onNewPromise(JSContext* cx, Handle<PromiseObject*> promise) {
if (MOZ_UNLIKELY(cx->realm()->isDebuggee())) {
slowPathOnNewPromise(cx, promise);
}
}
/* static */
void DebugAPI::onPromiseSettled(JSContext* cx, Handle<PromiseObject*> promise) {
if (MOZ_UNLIKELY(promise->realm()->isDebuggee())) {
slowPathOnPromiseSettled(cx, promise);
}
}
/* static */
void DebugAPI::traceGeneratorFrame(JSTracer* tracer,
AbstractGeneratorObject* generator) {
if (MOZ_UNLIKELY(generator->realm()->isDebuggee())) {
slowPathTraceGeneratorFrame(tracer, generator);
}
}
} // namespace js
#endif /* debugger_DebugAPI_inl_h */
|