Commit 52385efd authored by Jim Blandy's avatar Jim Blandy
Browse files

Bug 1551176: JSScript::getOrCreateDebugScript replaces ensureDebugScript. r=jorendorff

All extant calls to JSScript::ensureDebugScript are immediately followed by a
call to JSScript::debugScript. A fallible getOrCreate interface is cleaner for
the callers, and not much more work in the callee.

Differential Revision: https://phabricator.services.mozilla.com/D32267

--HG--
extra : moz-landing-system : lando
parent 34a3c1cf
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -4687,9 +4687,9 @@ void JSScript::destroyDebugScript(FreeOp* fop) {
  }
}

bool JSScript::ensureHasDebugScript(JSContext* cx) {
DebugScript* JSScript::getOrCreateDebugScript(JSContext* cx) {
  if (hasDebugScript()) {
    return true;
    return debugScript();
  }

  size_t nbytes =
@@ -4697,22 +4697,23 @@ bool JSScript::ensureHasDebugScript(JSContext* cx) {
  UniqueDebugScript debug(
      reinterpret_cast<DebugScript*>(cx->pod_calloc<uint8_t>(nbytes)));
  if (!debug) {
    return false;
    return nullptr;
  }

  /* Create realm's debugScriptMap if necessary. */
  if (!realm()->debugScriptMap) {
    auto map = cx->make_unique<DebugScriptMap>();
    if (!map) {
      return false;
      return nullptr;
    }

    realm()->debugScriptMap = std::move(map);
  }

  DebugScript* borrowed = debug.get();
  if (!realm()->debugScriptMap->putNew(this, std::move(debug))) {
    ReportOutOfMemory(cx);
    return false;
    return nullptr;
  }

  setFlag(MutableFlags::HasDebugScript);  // safe to set this;  we can't fail
@@ -4729,7 +4730,7 @@ bool JSScript::ensureHasDebugScript(JSContext* cx) {
    }
  }

  return true;
  return borrowed;
}

void JSScript::setNewStepMode(FreeOp* fop, uint32_t newValue) {
@@ -4754,11 +4755,11 @@ bool JSScript::incrementStepModeCount(JSContext* cx) {

  AutoRealm ar(cx, this);

  if (!ensureHasDebugScript(cx)) {
  DebugScript* debug = getOrCreateDebugScript(cx);
  if (!debug) {
    return false;
  }

  DebugScript* debug = debugScript();
  uint32_t count = debug->stepMode;
  setNewStepMode(cx->runtime()->defaultFreeOp(), count + 1);
  return true;
@@ -4775,11 +4776,11 @@ BreakpointSite* JSScript::getOrCreateBreakpointSite(JSContext* cx,
                                                    jsbytecode* pc) {
  AutoRealm ar(cx, this);

  if (!ensureHasDebugScript(cx)) {
  DebugScript* debug = getOrCreateDebugScript(cx);
  if (!debug) {
    return nullptr;
  }

  DebugScript* debug = debugScript();
  BreakpointSite*& site = debug->breakpoints[pcToOffset(pc)];

  if (!site) {
+1 −1
Original line number Diff line number Diff line
@@ -2886,7 +2886,7 @@ class JSScript : public js::gc::TenuredCell {
  /* Change this->stepMode to |newValue|. */
  void setNewStepMode(js::FreeOp* fop, uint32_t newValue);

  bool ensureHasDebugScript(JSContext* cx);
  js::DebugScript* getOrCreateDebugScript(JSContext* cx);
  js::DebugScript* debugScript();
  js::DebugScript* releaseDebugScript();
  void destroyDebugScript(js::FreeOp* fop);