Bug 1564170: Clean up some DebuggerScript referent matchers. r=jorendorff
☠☠ backed out by 221a89193a20 ☠ ☠
authorJim Blandy <jimb@mozilla.com>
Fri, 06 Sep 2019 04:47:09 +0000
changeset 491970 7541e22758ebfdbbb2514184e1bb822bff53ecee
parent 491969 62f5b57b9a03cad3963519d01d00c38e62525d26
child 491971 221a89193a200500d80441f7f32f38912c639f60
push id94638
push userjblandy@mozilla.com
push dateFri, 06 Sep 2019 04:48:28 +0000
treeherderautoland@7541e22758eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1564170
milestone71.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 1564170: Clean up some DebuggerScript referent matchers. r=jorendorff As suggested in patch review, some of the mozilla::Variant matcher classes in Script.cpp could be written more clearly using lambda-based matching. This patch applies that technique in the implementations of DebuggerScript's create, getStartLine, and getFormat methods. Differential Revision: https://phabricator.services.mozilla.com/D38559
js/src/debugger/Script.cpp
js/src/debugger/Script.h
--- a/js/src/debugger/Script.cpp
+++ b/js/src/debugger/Script.cpp
@@ -103,45 +103,30 @@ void DebuggerScript::trace(JSTracer* trc
 /* static */
 NativeObject* DebuggerScript::initClass(JSContext* cx,
                                         Handle<GlobalObject*> global,
                                         HandleObject debugCtor) {
   return InitClass(cx, debugCtor, nullptr, &class_, construct, 0, properties_,
                    methods_, nullptr, nullptr);
 }
 
-class DebuggerScript::SetPrivateMatcher {
-  DebuggerScript* obj_;
-
- public:
-  explicit SetPrivateMatcher(DebuggerScript* obj) : obj_(obj) {}
-  using ReturnType = void;
-  ReturnType match(HandleScript script) { obj_->setPrivateGCThing(script); }
-  ReturnType match(Handle<LazyScript*> lazyScript) {
-    obj_->setPrivateGCThing(lazyScript);
-  }
-  ReturnType match(Handle<WasmInstanceObject*> instance) {
-    obj_->setPrivateGCThing(instance);
-  }
-};
-
 /* static */
 DebuggerScript* DebuggerScript::create(JSContext* cx, HandleObject proto,
                                        Handle<DebuggerScriptReferent> referent,
                                        HandleNativeObject debugger) {
   DebuggerScript* scriptobj =
       NewObjectWithGivenProto<DebuggerScript>(cx, proto, TenuredObject);
   if (!scriptobj) {
     return nullptr;
   }
 
   scriptobj->setReservedSlot(DebuggerScript::OWNER_SLOT,
                              ObjectValue(*debugger));
-  SetPrivateMatcher matcher(scriptobj);
-  referent.match(matcher);
+  referent.get().match(
+      [&](auto& scriptHandle) { scriptobj->setPrivateGCThing(scriptHandle); });
 
   return scriptobj;
 }
 
 static JSScript* DelazifyScript(JSContext* cx, Handle<LazyScript*> lazyScript) {
   if (lazyScript->maybeScript()) {
     return lazyScript->maybeScript();
   }
@@ -351,32 +336,24 @@ bool DebuggerScript::getUrl(JSContext* c
     RootedScript script(cx, obj->getReferent().as<JSScript*>());
     return getUrlImpl<JSScript>(cx, args, script);
   }
 
   Rooted<LazyScript*> lazyScript(cx, obj->getReferent().as<LazyScript*>());
   return getUrlImpl<LazyScript>(cx, args, lazyScript);
 }
 
-struct DebuggerScript::GetStartLineMatcher {
-  using ReturnType = uint32_t;
-
-  ReturnType match(HandleScript script) { return script->lineno(); }
-  ReturnType match(Handle<LazyScript*> lazyScript) {
-    return lazyScript->lineno();
-  }
-  ReturnType match(Handle<WasmInstanceObject*> wasmInstance) { return 1; }
-};
-
 /* static */
 bool DebuggerScript::getStartLine(JSContext* cx, unsigned argc, Value* vp) {
   THIS_DEBUGSCRIPT_REFERENT(cx, argc, vp, "(get startLine)", args, obj,
                             referent);
-  GetStartLineMatcher matcher;
-  args.rval().setNumber(referent.match(matcher));
+  args.rval().setNumber(
+      referent.get().match([](JSScript*& s) { return s->lineno(); },
+                           [](LazyScript*& s) { return s->lineno(); },
+                           [](WasmInstanceObject*&) { return (uint32_t)1; }));
   return true;
 }
 
 struct DebuggerScript::GetStartColumnMatcher {
   using ReturnType = uint32_t;
 
   ReturnType match(HandleScript script) { return script->column(); }
   ReturnType match(Handle<LazyScript*> lazyScript) {
@@ -511,34 +488,23 @@ bool DebuggerScript::getGlobal(JSContext
   RootedValue v(cx, ObjectValue(script->global()));
   if (!dbg->wrapDebuggeeValue(cx, &v)) {
     return false;
   }
   args.rval().set(v);
   return true;
 }
 
-class DebuggerScript::GetFormatMatcher {
-  const JSAtomState& names_;
-
- public:
-  explicit GetFormatMatcher(const JSAtomState& names) : names_(names) {}
-  using ReturnType = JSAtom*;
-  ReturnType match(HandleScript script) { return names_.js; }
-  ReturnType match(Handle<LazyScript*> lazyScript) { return names_.js; }
-  ReturnType match(Handle<WasmInstanceObject*> wasmInstance) {
-    return names_.wasm;
-  }
-};
-
 /* static */
 bool DebuggerScript::getFormat(JSContext* cx, unsigned argc, Value* vp) {
   THIS_DEBUGSCRIPT_REFERENT(cx, argc, vp, "(get format)", args, obj, referent);
-  GetFormatMatcher matcher(cx->names());
-  args.rval().setString(referent.match(matcher));
+  args.rval().setString(referent.get().match(
+      [=](JSScript*&) { return cx->names().js; },
+      [=](LazyScript*&) { return cx->names().js; },
+      [=](WasmInstanceObject*&) { return cx->names().wasm; }));
   return true;
 }
 
 static bool PushFunctionScript(JSContext* cx, Debugger* dbg, HandleFunction fun,
                                HandleObject array) {
   // Ignore asm.js natives.
   if (!IsInterpretedNonSelfHostedFunction(fun)) {
     return true;
--- a/js/src/debugger/Script.h
+++ b/js/src/debugger/Script.h
@@ -105,22 +105,19 @@ class DebuggerScript : public NativeObje
   }
 
  private:
   static const JSClassOps classOps_;
 
   static const JSPropertySpec properties_[];
   static const JSFunctionSpec methods_[];
 
-  class SetPrivateMatcher;
-  struct GetStartLineMatcher;
   struct GetStartColumnMatcher;
   struct GetLineCountMatcher;
   class GetSourceMatcher;
-  class GetFormatMatcher;
   template <bool OnlyOffsets>
   class GetPossibleBreakpointsMatcher;
   class GetOffsetMetadataMatcher;
   class GetOffsetLocationMatcher;
   class GetSuccessorOrPredecessorOffsetsMatcher;
   class GetAllColumnOffsetsMatcher;
   class GetLineOffsetsMatcher;
   struct SetBreakpointMatcher;