DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (6863f516ba38)

VCS Links

Line Code
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
/* -*- 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 vm_Debugger_inl_h
#define vm_Debugger_inl_h

#include "vm/Debugger.h"

#include "builtin/Promise.h"
#include "vm/GeneratorObject.h"

#include "gc/WeakMap-inl.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.hasScript() && 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 bool js::Debugger::onNewGenerator(
    JSContext* cx, AbstractFramePtr frame,
    Handle<AbstractGeneratorObject*> genObj) {
  if (frame.isDebuggee()) {
    return slowPathOnNewGenerator(cx, frame, genObj);
  }
  return true;
}

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

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

/* static */ inline js::ResumeMode js::Debugger::onEnterFrame(JSContext* cx,
                                                       AbstractFramePtr frame) {
  MOZ_ASSERT_IF(frame.hasScript() && frame.script()->isDebuggee(),
                frame.isDebuggee());
  if (!frame.isDebuggee()) {
    return ResumeMode::Continue;
  }
  return slowPathOnEnterFrame(cx, frame);
}

/* static */ inline js::ResumeMode js::Debugger::onResumeFrame(
    JSContext* cx, AbstractFramePtr frame) {
  MOZ_ASSERT_IF(frame.hasScript() && frame.script()->isDebuggee(),
                frame.isDebuggee());
  if (!frame.isDebuggee()) {
    return ResumeMode::Continue;
  }
  return slowPathOnResumeFrame(cx, frame);
}

/* static */ inline js::ResumeMode js::Debugger::onDebuggerStatement(
    JSContext* cx, AbstractFramePtr frame) {
  if (!cx->realm()->isDebuggee()) {
    return ResumeMode::Continue;
  }
  return slowPathOnDebuggerStatement(cx, frame);
}

/* static */ inline js::ResumeMode js::Debugger::onExceptionUnwind(
    JSContext* cx, AbstractFramePtr frame) {
  if (!cx->realm()->isDebuggee()) {
    return ResumeMode::Continue;
  }
  return slowPathOnExceptionUnwind(cx, frame);
}

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

/* static */ inline void js::Debugger::onNewPromise(JSContext* cx,
                                             Handle<PromiseObject*> promise) {
  if (MOZ_UNLIKELY(cx->realm()->isDebuggee())) {
    slowPathPromiseHook(cx, Debugger::OnNewPromise, promise);
  }
}

/* static */ inline void js::Debugger::onPromiseSettled(
    JSContext* cx, Handle<PromiseObject*> promise) {
  if (MOZ_UNLIKELY(promise->realm()->isDebuggee())) {
    slowPathPromiseHook(cx, Debugger::OnPromiseSettled, promise);
  }
}

inline js::Debugger* js::DebuggerEnvironment::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)) {
    // We know we have a Promise here, so CheckedUnwrapStatic is fine.
    referent = CheckedUnwrapStatic(referent);
    MOZ_ASSERT(referent);
  }

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

#endif /* vm_Debugger_inl_h */