summaryrefslogtreecommitdiff
path: root/js/src/vm/Debugger-inl.h
blob: 83b4f5c4054d8a3c051b1e3c118b86db0062a519 (plain)
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
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * 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 vm_Debugger_inl_h
#define vm_Debugger_inl_h

#include "vm/Debugger.h"

#include "vm/Stack-inl.h"

/* static */ inline bool
js::Debugger::onLeaveFrame(JSContext* cx, AbstractFramePtr frame, jsbytecode* pc, bool ok)
{
    MOZ_ASSERT_IF(frame.isInterpreterFrame(), frame.asInterpreterFrame() == cx->interpreterFrame());
    MOZ_ASSERT_IF(frame.script()->isDebuggee(), frame.isDebuggee());
    /* Traps must be cleared from eval frames, see slowPathOnLeaveFrame. */
    mozilla::DebugOnly<bool> evalTraps = frame.isEvalFrame() &&
                                         frame.script()->hasAnyBreakpointsOrStepMode();
    MOZ_ASSERT_IF(evalTraps, frame.isDebuggee());
    if (frame.isDebuggee())
        ok = slowPathOnLeaveFrame(cx, frame, pc, ok);
    MOZ_ASSERT(!inFrameMaps(frame));
    return ok;
}

/* static */ inline js::Debugger*
js::Debugger::fromJSObject(const JSObject* obj)
{
    MOZ_ASSERT(js::GetObjectClass(obj) == &class_);
    return (Debugger*) obj->as<NativeObject>().getPrivate();
}

/* static */ inline bool
js::Debugger::checkNoExecute(JSContext* cx, HandleScript script)
{
    if (!cx->compartment()->isDebuggee() || !cx->runtime()->noExecuteDebuggerTop)
        return true;
    return slowPathCheckNoExecute(cx, script);
}

/* static */ JSTrapStatus
js::Debugger::onEnterFrame(JSContext* cx, AbstractFramePtr frame)
{
    MOZ_ASSERT_IF(frame.script()->isDebuggee(), frame.isDebuggee());
    if (!frame.isDebuggee())
        return JSTRAP_CONTINUE;
    return slowPathOnEnterFrame(cx, frame);
}

/* static */ JSTrapStatus
js::Debugger::onDebuggerStatement(JSContext* cx, AbstractFramePtr frame)
{
    if (!cx->compartment()->isDebuggee())
        return JSTRAP_CONTINUE;
    return slowPathOnDebuggerStatement(cx, frame);
}

/* static */ JSTrapStatus
js::Debugger::onExceptionUnwind(JSContext* cx, AbstractFramePtr frame)
{
    if (!cx->compartment()->isDebuggee())
        return JSTRAP_CONTINUE;
    return slowPathOnExceptionUnwind(cx, frame);
}

/* static */ void
js::Debugger::onNewWasmInstance(JSContext* cx, Handle<WasmInstanceObject*> wasmInstance)
{
    if (cx->compartment()->isDebuggee())
        slowPathOnNewWasmInstance(cx, wasmInstance);
}

inline bool
js::Debugger::getScriptFrame(JSContext* cx, const ScriptFrameIter& iter,
                             MutableHandle<DebuggerFrame*> result)
{
    return getScriptFrameWithIter(cx, iter.abstractFramePtr(), &iter, result);
}

inline js::Debugger*
js::DebuggerEnvironment::owner() const
{
    JSObject* dbgobj = &getReservedSlot(OWNER_SLOT).toObject();
    return Debugger::fromJSObject(dbgobj);
}

inline js::Debugger*
js::DebuggerFrame::owner() const
{
    JSObject* dbgobj = &getReservedSlot(OWNER_SLOT).toObject();
    return Debugger::fromJSObject(dbgobj);
}

inline js::Debugger*
js::DebuggerObject::owner() const
{
    JSObject* dbgobj = &getReservedSlot(OWNER_SLOT).toObject();
    return Debugger::fromJSObject(dbgobj);
}

inline js::PromiseObject*
js::DebuggerObject::promise() const
{
    MOZ_ASSERT(isPromise());

    JSObject* referent = this->referent();
    if (IsCrossCompartmentWrapper(referent)) {
        referent = CheckedUnwrap(referent);
        MOZ_ASSERT(referent);
    }

    return &referent->as<PromiseObject>();
}

#endif /* vm_Debugger_inl_h */