Bug 1546727: Move JSSLOT_DEBUGFRAME_ enum into DebuggerFrame class. r=jorendorff
authorJim Blandy <jimb@mozilla.com>
Wed, 08 May 2019 07:06:36 +0000
changeset 535000 054f6ef6e447b028fd3c5f58de93607f3f37e1c1
parent 534999 a0ab4288cda4246470aae59f9f1be2c1be65dcd8
child 535001 6dd8d9bf3e308e62c4a6f2eacd7b7379d1ad3484
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1546727
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1546727: Move JSSLOT_DEBUGFRAME_ enum into DebuggerFrame class. r=jorendorff This is standard SpiderMonkey practice for NativeObject subclasses, and makes slot access in DebuggerFrame methods a bit cleaner. Differential Revision: https://phabricator.services.mozilla.com/D28782
js/src/vm/Debugger.cpp
js/src/vm/Debugger.h
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -82,26 +82,18 @@ using mozilla::TimeStamp;
 
 static void DebuggerFrame_finalize(FreeOp* fop, JSObject* obj);
 static void DebuggerFrame_trace(JSTracer* trc, JSObject* obj);
 static void DebuggerEnv_trace(JSTracer* trc, JSObject* obj);
 static void DebuggerObject_trace(JSTracer* trc, JSObject* obj);
 static void DebuggerScript_trace(JSTracer* trc, JSObject* obj);
 static void DebuggerSource_trace(JSTracer* trc, JSObject* obj);
 
-enum {
-  JSSLOT_DEBUGFRAME_OWNER,
-  JSSLOT_DEBUGFRAME_ARGUMENTS,
-  JSSLOT_DEBUGFRAME_ONSTEP_HANDLER,
-  JSSLOT_DEBUGFRAME_ONPOP_HANDLER,
-  JSSLOT_DEBUGFRAME_COUNT
-};
-
 inline js::Debugger* js::DebuggerFrame::owner() const {
-  JSObject* dbgobj = &getReservedSlot(JSSLOT_DEBUGFRAME_OWNER).toObject();
+  JSObject* dbgobj = &getReservedSlot(OWNER_SLOT).toObject();
   return Debugger::fromJSObject(dbgobj);
 }
 
 const ClassOps DebuggerFrame::classOps_ = {nullptr, /* addProperty */
                                            nullptr, /* delProperty */
                                            nullptr, /* enumerate   */
                                            nullptr, /* newEnumerate */
                                            nullptr, /* resolve     */
@@ -109,17 +101,17 @@ const ClassOps DebuggerFrame::classOps_ 
                                            DebuggerFrame_finalize,
                                            nullptr, /* call        */
                                            nullptr, /* hasInstance */
                                            nullptr, /* construct   */
                                            DebuggerFrame_trace};
 
 const Class DebuggerFrame::class_ = {
     "Frame",
-    JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(JSSLOT_DEBUGFRAME_COUNT) |
+    JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(RESERVED_SLOTS) |
         JSCLASS_BACKGROUND_FINALIZE,
     &DebuggerFrame::classOps_};
 
 enum { JSSLOT_DEBUGARGUMENTS_FRAME, JSSLOT_DEBUGARGUMENTS_COUNT };
 
 const Class DebuggerArguments::class_ = {
     "Arguments", JSCLASS_HAS_RESERVED_SLOTS(JSSLOT_DEBUGARGUMENTS_COUNT)};
 
@@ -646,23 +638,23 @@ Debugger::~Debugger() {
   if (onNewGlobalObjectWatchersLink.mPrev ||
       onNewGlobalObjectWatchersLink.mNext ||
       cx->runtime()->onNewGlobalObjectWatchers().begin() ==
           JSRuntime::WatchersList::Iterator(this)) {
     cx->runtime()->onNewGlobalObjectWatchers().remove(this);
   }
 }
 
-JS_STATIC_ASSERT(unsigned(JSSLOT_DEBUGFRAME_OWNER) ==
+JS_STATIC_ASSERT(unsigned(DebuggerFrame::OWNER_SLOT) ==
                  unsigned(JSSLOT_DEBUGSCRIPT_OWNER));
-JS_STATIC_ASSERT(unsigned(JSSLOT_DEBUGFRAME_OWNER) ==
+JS_STATIC_ASSERT(unsigned(DebuggerFrame::OWNER_SLOT) ==
                  unsigned(JSSLOT_DEBUGSOURCE_OWNER));
-JS_STATIC_ASSERT(unsigned(JSSLOT_DEBUGFRAME_OWNER) ==
+JS_STATIC_ASSERT(unsigned(DebuggerFrame::OWNER_SLOT) ==
                  unsigned(JSSLOT_DEBUGOBJECT_OWNER));
-JS_STATIC_ASSERT(unsigned(JSSLOT_DEBUGFRAME_OWNER) ==
+JS_STATIC_ASSERT(unsigned(DebuggerFrame::OWNER_SLOT) ==
                  unsigned(DebuggerEnvironment::OWNER_SLOT));
 
 /* static */
 Debugger* Debugger::fromChildJSObject(JSObject* obj) {
   MOZ_ASSERT(obj->getClass() == &DebuggerFrame::class_ ||
              obj->getClass() == &DebuggerScript_class ||
              obj->getClass() == &DebuggerSource_class ||
              obj->getClass() == &DebuggerObject::class_ ||
@@ -2374,17 +2366,17 @@ ResumeMode Debugger::onSingleStep(JSCont
         Debugger* dbg = *p;
         for (FrameMap::Range r = dbg->frames.all(); !r.empty(); r.popFront()) {
           AbstractFramePtr frame = r.front().key();
           NativeObject* frameobj = r.front().value();
           if (frame.isWasmDebugFrame()) {
             continue;
           }
           if (frame.script() == trappingScript &&
-              !frameobj->getReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER)
+              !frameobj->getReservedSlot(DebuggerFrame::ONSTEP_HANDLER_SLOT)
                    .isUndefined()) {
             liveStepperCount++;
           }
         }
 
         // Also count hooks set on suspended generator frames.
         for (GeneratorWeakMap::Range r = dbg->generatorFrames.all(); !r.empty();
              r.popFront()) {
@@ -2418,17 +2410,17 @@ ResumeMode Debugger::onSingleStep(JSCont
           // that the generator is actually suspended before we attribute a step
           // count to it.
           if (!genObj.isSuspended()) {
             continue;
           }
 
           if (!genObj.callee().isInterpretedLazy() &&
               genObj.callee().nonLazyScript() == trappingScript &&
-              !frameObj.getReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER)
+              !frameObj.getReservedSlot(DebuggerFrame::ONSTEP_HANDLER_SLOT)
                    .isUndefined()) {
             suspendedStepperCount++;
           }
         }
       }
     }
 
     MOZ_ASSERT(liveStepperCount + suspendedStepperCount ==
@@ -8961,18 +8953,18 @@ bool DebuggerFrame::resume(const FrameIt
   if (!data) {
     return false;
   }
   setPrivate(data);
   return true;
 }
 
 bool DebuggerFrame::hasAnyLiveHooks() const {
-  return !getReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER).isUndefined() ||
-         !getReservedSlot(JSSLOT_DEBUGFRAME_ONPOP_HANDLER).isUndefined();
+  return !getReservedSlot(ONSTEP_HANDLER_SLOT).isUndefined() ||
+         !getReservedSlot(ONPOP_HANDLER_SLOT).isUndefined();
 }
 
 /* static */
 NativeObject* DebuggerFrame::initClass(JSContext* cx, HandleObject dbgCtor,
                                        Handle<GlobalObject*> global) {
   return InitClass(cx, dbgCtor, nullptr, &class_, construct, 0, properties_,
                    methods_, nullptr, nullptr);
 }
@@ -8987,17 +8979,17 @@ DebuggerFrame* DebuggerFrame::create(JSC
   }
 
   FrameIter::Data* data = iter.copyData();
   if (!data) {
     return nullptr;
   }
   frame->setPrivate(data);
 
-  frame->setReservedSlot(JSSLOT_DEBUGFRAME_OWNER, ObjectValue(*debugger));
+  frame->setReservedSlot(OWNER_SLOT, ObjectValue(*debugger));
 
   return frame;
 }
 
 /* static */
 bool DebuggerFrame::getCallee(JSContext* cx, HandleDebuggerFrame frame,
                               MutableHandleDebuggerObject result) {
   MOZ_ASSERT(frame->isLive());
@@ -9274,25 +9266,25 @@ bool DebuggerFrame::setOnStepHandler(JSC
       }
     } else if (!handler && prior) {
       // Single stepping toggled on->off.
       referent.script()->decrementStepModeCount(cx->runtime()->defaultFreeOp());
     }
   }
 
   // Now that the step mode switch has succeeded, we can install the handler.
-  frame->setReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER,
+  frame->setReservedSlot(ONSTEP_HANDLER_SLOT,
                          handler ? PrivateValue(handler) : UndefinedValue());
   return true;
 }
 
 /* static */
 bool DebuggerFrame::getArguments(JSContext* cx, HandleDebuggerFrame frame,
                                  MutableHandleDebuggerArguments result) {
-  Value argumentsv = frame->getReservedSlot(JSSLOT_DEBUGFRAME_ARGUMENTS);
+  Value argumentsv = frame->getReservedSlot(ARGUMENTS_SLOT);
   if (!argumentsv.isUndefined()) {
     result.set(argumentsv.isObject()
                    ? &argumentsv.toObject().as<DebuggerArguments>()
                    : nullptr);
     return true;
   }
 
   AbstractFramePtr referent = DebuggerFrame::getReferent(frame);
@@ -9308,18 +9300,17 @@ bool DebuggerFrame::getArguments(JSConte
     if (!arguments) {
       return false;
     }
   } else {
     arguments = nullptr;
   }
 
   result.set(arguments);
-  frame->setReservedSlot(JSSLOT_DEBUGFRAME_ARGUMENTS,
-                         ObjectOrNullValue(result));
+  frame->setReservedSlot(ARGUMENTS_SLOT, ObjectOrNullValue(result));
   return true;
 }
 
 /*
  * Evaluate |chars[0..length-1]| in the environment |env|, treating that
  * source as appearing starting at |lineno| in |filename|. Store the return
  * value in |*rval|. Use |thisv| as the 'this' value.
  *
@@ -9501,36 +9492,36 @@ bool DebuggerFrame::eval(JSContext* cx, 
   return DebuggerGenericEval(cx, chars, bindings, options, resumeMode, value,
                              dbg, nullptr, &iter);
 }
 
 /* static */
 bool DebuggerFrame::isLive() const { return !!getPrivate(); }
 
 OnStepHandler* DebuggerFrame::onStepHandler() const {
-  Value value = getReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER);
+  Value value = getReservedSlot(ONSTEP_HANDLER_SLOT);
   return value.isUndefined() ? nullptr
                              : static_cast<OnStepHandler*>(value.toPrivate());
 }
 
 OnPopHandler* DebuggerFrame::onPopHandler() const {
-  Value value = getReservedSlot(JSSLOT_DEBUGFRAME_ONPOP_HANDLER);
+  Value value = getReservedSlot(ONPOP_HANDLER_SLOT);
   return value.isUndefined() ? nullptr
                              : static_cast<OnPopHandler*>(value.toPrivate());
 }
 
 void DebuggerFrame::setOnPopHandler(OnPopHandler* handler) {
   MOZ_ASSERT(isLive());
 
   OnPopHandler* prior = onPopHandler();
   if (prior && prior != handler) {
     prior->drop();
   }
 
-  setReservedSlot(JSSLOT_DEBUGFRAME_ONPOP_HANDLER,
+  setReservedSlot(ONPOP_HANDLER_SLOT,
                   handler ? PrivateValue(handler) : UndefinedValue());
 }
 
 static bool DebuggerFrame_requireLive(JSContext* cx,
                                       HandleDebuggerFrame frame) {
   if (!frame->isLive()) {
     JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                               JSMSG_DEBUG_NOT_LIVE, "Debugger.Frame");
@@ -9575,17 +9566,17 @@ void DebuggerFrame::freeFrameIterData(Fr
     fop->delete_(data);
     setPrivate(nullptr);
   }
 }
 
 static void DebuggerFrame_maybeDecrementFrameScriptStepModeCount(
     FreeOp* fop, AbstractFramePtr frame, NativeObject* frameobj) {
   // If this frame has an onStep handler, decrement the script's count.
-  if (frameobj->getReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER)
+  if (frameobj->getReservedSlot(DebuggerFrame::ONSTEP_HANDLER_SLOT)
           .isUndefined()) {
     return;
   }
   if (frame.isWasmDebugFrame()) {
     wasm::Instance* instance = frame.wasmInstance();
     instance->debug().decrementStepModeCount(
         fop, frame.asWasmDebugFrame()->funcIndex());
   } else {
@@ -9635,17 +9626,17 @@ static DebuggerFrame* DebuggerFrame_chec
 
   RootedDebuggerFrame frame(cx, &thisobj->as<DebuggerFrame>());
 
   // Forbid Debugger.Frame.prototype, which is of class DebuggerFrame::class_
   // but isn't really a working Debugger.Frame object. The prototype object
   // is distinguished by having a nullptr private value. Also, forbid popped
   // frames.
   if (!frame->getPrivate() &&
-      frame->getReservedSlot(JSSLOT_DEBUGFRAME_OWNER).isUndefined()) {
+      frame->getReservedSlot(DebuggerFrame::OWNER_SLOT).isUndefined()) {
     JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                               JSMSG_INCOMPATIBLE_PROTO, "Debugger.Frame",
                               fnname, "prototype object");
     return nullptr;
   }
 
   if (checkLive) {
     if (!DebuggerFrame_requireLive(cx, frame)) {
--- a/js/src/vm/Debugger.h
+++ b/js/src/vm/Debugger.h
@@ -1430,16 +1430,24 @@ class ScriptedOnPopHandler final : publi
 class DebuggerFrame : public NativeObject {
   friend class DebuggerArguments;
   friend class ScriptedOnStepHandler;
   friend class ScriptedOnPopHandler;
 
  public:
   static const Class class_;
 
+  enum {
+    OWNER_SLOT = 0,
+    ARGUMENTS_SLOT,
+    ONSTEP_HANDLER_SLOT,
+    ONPOP_HANDLER_SLOT,
+    RESERVED_SLOTS,
+  };
+
   static NativeObject* initClass(JSContext* cx, HandleObject dbgCtor,
                                  Handle<GlobalObject*> global);
   static DebuggerFrame* create(JSContext* cx, HandleObject proto,
                                const FrameIter& iter,
                                HandleNativeObject debugger);
   void freeFrameIterData(FreeOp* fop);
 
   static MOZ_MUST_USE bool getArguments(JSContext* cx,