# Global Metrics

path: .metrics.cognitive.sum
old: 120.0
new: 0.0
path: .metrics.cognitive.average
old: 3.1578947368421053
new: 0.0
path: .metrics.nargs.average
old: 1.0
new: 0.14285714285714285
path: .metrics.nargs.sum
old: 38.0
new: 1.0
path: .metrics.cyclomatic.average
old: 4.333333333333333
new: 1.0
path: .metrics.cyclomatic.sum
old: 169.0
new: 14.0
path: .metrics.mi.mi_original
old: -28.349308259643426
new: 50.046447030757605
path: .metrics.mi.mi_visual_studio
old: 0.0
new: 29.266928088162345
path: .metrics.mi.mi_sei
old: -70.13760114468748
new: 39.79639446083858
path: .metrics.halstead.n1
old: 28.0
new: 16.0
path: .metrics.halstead.purity_ratio
old: 0.73447436514
new: 1.7277201379627245
path: .metrics.halstead.level
old: 0.016979591836734694
new: 0.07224770642201835
path: .metrics.halstead.estimated_program_length
old: 1736.2973991909598
new: 440.5686351804948
path: .metrics.halstead.n2
old: 208.0
new: 63.0
path: .metrics.halstead.time
old: 60970.475445104035
new: 1236.074680039383
path: .metrics.halstead.vocabulary
old: 236.0
new: 79.0
path: .metrics.halstead.effort
old: 1097468.5580118727
new: 22249.3442407089
path: .metrics.halstead.volume
old: 18634.568168691392
new: 1607.4640907851613
path: .metrics.halstead.bugs
old: 3.5465558479303168
new: 0.2636879125839582
path: .metrics.halstead.N2
old: 875.0
new: 109.0
path: .metrics.halstead.length
old: 2364.0
new: 255.0
path: .metrics.halstead.N1
old: 1489.0
new: 146.0
path: .metrics.halstead.difficulty
old: 58.89423076923077
new: 13.841269841269842
path: .metrics.nexits.average
old: 2.526315789473684
new: 0.5714285714285714
path: .metrics.nexits.sum
old: 96.0
new: 4.0
path: .metrics.loc.blank
old: 121.0
new: 26.0
path: .metrics.loc.cloc
old: 139.0
new: 55.0
path: .metrics.loc.ploc
old: 594.0
new: 53.0
path: .metrics.loc.lloc
old: 300.0
new: 5.0
path: .metrics.loc.sloc
old: 854.0
new: 134.0
path: .metrics.nom.functions
old: 38.0
new: 7.0
path: .metrics.nom.total
old: 38.0
new: 7.0

# Spaces Data

## Minimal test - lines (18, 18)

path: .spaces[2].metrics.nargs.average
old: 0.0
new: null
path: .spaces[2].metrics.nexits.sum
old: 2.0
new: 0.0
path: .spaces[2].metrics.nexits.average
old: 2.0
new: null
path: .spaces[2].metrics.loc.blank
old: 3.0
new: 0.0
path: .spaces[2].metrics.loc.lloc
old: 5.0
new: 0.0
path: .spaces[2].metrics.loc.ploc
old: 10.0
new: 1.0
path: .spaces[2].metrics.loc.cloc
old: 2.0
new: 0.0
path: .spaces[2].metrics.loc.sloc
old: 15.0
new: 1.0
path: .spaces[2].metrics.nom.functions
old: 1.0
new: 0.0
path: .spaces[2].metrics.nom.total
old: 1.0
new: 0.0
path: .spaces[2].metrics.mi.mi_original
old: 100.5584011597944
new: null
path: .spaces[2].metrics.mi.mi_visual_studio
old: 58.80608254958737
new: null
path: .spaces[2].metrics.mi.mi_sei
old: 96.37762401441884
new: null
path: .spaces[2].metrics.halstead.bugs
old: 0.03129573791184525
new: 0.0
path: .spaces[2].metrics.halstead.n1
old: 11.0
new: 0.0
path: .spaces[2].metrics.halstead.N1
old: 22.0
new: 0.0
path: .spaces[2].metrics.halstead.n2
old: 11.0
new: 1.0
path: .spaces[2].metrics.halstead.level
old: 0.16666666666666666
new: null
path: .spaces[2].metrics.halstead.time
old: 50.5402250112227
new: 0.0
path: .spaces[2].metrics.halstead.length
old: 34.0
new: 1.0
path: .spaces[2].metrics.halstead.volume
old: 151.6206750336681
new: 0.0
path: .spaces[2].metrics.halstead.N2
old: 12.0
new: 1.0
path: .spaces[2].metrics.halstead.difficulty
old: 6.0
new: 0.0
path: .spaces[2].metrics.halstead.effort
old: 909.7240502020086
new: 0.0
path: .spaces[2].metrics.halstead.purity_ratio
old: 2.238455753235898
new: null
path: .spaces[2].metrics.halstead.estimated_program_length
old: 76.10749561002054
new: null
path: .spaces[2].metrics.halstead.vocabulary
old: 22.0
new: 1.0
path: .spaces[2].metrics.cyclomatic.average
old: 2.0
new: 1.0
path: .spaces[2].metrics.cyclomatic.sum
old: 2.0
new: 1.0
path: .spaces[2].metrics.cognitive.sum
old: 1.0
new: 0.0
path: .spaces[2].metrics.cognitive.average
old: 1.0
new: null

### Code

    class nsIThread;

## Minimal test - lines (17, 17)

path: .spaces[1].metrics.mi.mi_visual_studio
old: 55.97967198826951
new: null
path: .spaces[1].metrics.mi.mi_sei
old: 81.15655305879856
new: null
path: .spaces[1].metrics.mi.mi_original
old: 95.72523909994086
new: null
path: .spaces[1].metrics.nargs.average
old: 1.0
new: null
path: .spaces[1].metrics.nargs.sum
old: 1.0
new: 0.0
path: .spaces[1].metrics.cyclomatic.sum
old: 4.0
new: 1.0
path: .spaces[1].metrics.cyclomatic.average
old: 4.0
new: 1.0
path: .spaces[1].metrics.loc.lloc
old: 6.0
new: 0.0
path: .spaces[1].metrics.loc.blank
old: 3.0
new: 0.0
path: .spaces[1].metrics.loc.ploc
old: 13.0
new: 1.0
path: .spaces[1].metrics.loc.sloc
old: 17.0
new: 1.0
path: .spaces[1].metrics.loc.cloc
old: 1.0
new: 0.0
path: .spaces[1].metrics.halstead.n1
old: 16.0
new: 0.0
path: .spaces[1].metrics.halstead.bugs
old: 0.061241202589591495
new: 0.0
path: .spaces[1].metrics.halstead.level
old: 0.09558823529411764
new: null
path: .spaces[1].metrics.halstead.difficulty
old: 10.461538461538462
new: 0.0
path: .spaces[1].metrics.halstead.length
old: 49.0
new: 1.0
path: .spaces[1].metrics.halstead.vocabulary
old: 29.0
new: 1.0
path: .spaces[1].metrics.halstead.n2
old: 13.0
new: 1.0
path: .spaces[1].metrics.halstead.N1
old: 32.0
new: 0.0
path: .spaces[1].metrics.halstead.estimated_program_length
old: 112.1057163358342
new: null
path: .spaces[1].metrics.halstead.purity_ratio
old: 2.2878717619558
new: null
path: .spaces[1].metrics.halstead.volume
old: 238.041068761251
new: 0.0
path: .spaces[1].metrics.halstead.N2
old: 17.0
new: 1.0
path: .spaces[1].metrics.halstead.time
old: 138.34865534841938
new: 0.0
path: .spaces[1].metrics.halstead.effort
old: 2490.275796271549
new: 0.0
path: .spaces[1].metrics.nexits.average
old: 2.0
new: null
path: .spaces[1].metrics.nexits.sum
old: 2.0
new: 0.0
path: .spaces[1].metrics.nom.functions
old: 1.0
new: 0.0
path: .spaces[1].metrics.nom.total
old: 1.0
new: 0.0
path: .spaces[1].metrics.cognitive.average
old: 4.0
new: null
path: .spaces[1].metrics.cognitive.sum
old: 4.0
new: 0.0

### Code

    class nsIRunnable;

## Minimal test - lines (16, 16)

path: .spaces[0].metrics.halstead.volume
old: 34.86917501586544
new: 0.0
path: .spaces[0].metrics.halstead.time
old: 6.053676218032194
new: 0.0
path: .spaces[0].metrics.halstead.estimated_program_length
old: 19.60964047443681
new: null
path: .spaces[0].metrics.halstead.effort
old: 108.9661719245795
new: 0.0
path: .spaces[0].metrics.halstead.difficulty
old: 3.125
new: 0.0
path: .spaces[0].metrics.halstead.level
old: 0.32
new: null
path: .spaces[0].metrics.halstead.N2
old: 5.0
new: 1.0
path: .spaces[0].metrics.halstead.N1
old: 6.0
new: 0.0
path: .spaces[0].metrics.halstead.n2
old: 4.0
new: 1.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.7826945885851644
new: null
path: .spaces[0].metrics.halstead.bugs
old: 0.007604544540941429
new: 0.0
path: .spaces[0].metrics.halstead.length
old: 11.0
new: 1.0
path: .spaces[0].metrics.halstead.n1
old: 5.0
new: 0.0
path: .spaces[0].metrics.halstead.vocabulary
old: 9.0
new: 1.0
path: .spaces[0].metrics.nom.functions
old: 1.0
new: 0.0
path: .spaces[0].metrics.nom.total
old: 1.0
new: 0.0
path: .spaces[0].metrics.cognitive.average
old: 0.0
new: null
path: .spaces[0].metrics.mi.mi_original
old: 152.30166335190526
new: null
path: .spaces[0].metrics.mi.mi_sei
old: 144.12582230432585
new: null
path: .spaces[0].metrics.mi.mi_visual_studio
old: 89.06530020579255
new: null
path: .spaces[0].metrics.nargs.sum
old: 1.0
new: 0.0
path: .spaces[0].metrics.nargs.average
old: 1.0
new: null
path: .spaces[0].metrics.nexits.average
old: 0.0
new: null

### Code

    class nsIEventTarget;

## Minimal test - lines (20, 132)

path: .spaces[3].metrics.nom.total
old: 1.0
new: 7.0
path: .spaces[3].metrics.nom.functions
old: 1.0
new: 7.0
path: .spaces[3].metrics.nexits.average
old: 3.0
new: 0.5714285714285714
path: .spaces[3].metrics.nexits.sum
old: 3.0
new: 4.0
path: .spaces[3].metrics.cognitive.average
old: 5.0
new: 0.0
path: .spaces[3].metrics.cognitive.sum
old: 5.0
new: 0.0
path: .spaces[3].metrics.nargs.average
old: 1.0
new: 0.14285714285714285
path: .spaces[3].metrics.halstead.bugs
old: 0.075962752756843
new: 0.2397473955335632
path: .spaces[3].metrics.halstead.estimated_program_length
old: 122.60335893412778
new: 391.07808974151806
path: .spaces[3].metrics.halstead.n1
old: 16.0
new: 15.0
path: .spaces[3].metrics.halstead.level
old: 0.08928571428571429
new: 0.07676767676767676
path: .spaces[3].metrics.halstead.vocabulary
old: 31.0
new: 72.0
path: .spaces[3].metrics.halstead.N2
old: 21.0
new: 99.0
path: .spaces[3].metrics.halstead.n2
old: 15.0
new: 57.0
path: .spaces[3].metrics.halstead.purity_ratio
old: 1.977473531195609
new: 1.6294920405896585
path: .spaces[3].metrics.halstead.N1
old: 41.0
new: 141.0
path: .spaces[3].metrics.halstead.difficulty
old: 11.2
new: 13.026315789473683
path: .spaces[3].metrics.halstead.effort
old: 3440.193917932646
new: 19289.133951877546
path: .spaces[3].metrics.halstead.volume
old: 307.16017124398627
new: 1480.782000346155
path: .spaces[3].metrics.halstead.length
old: 62.0
new: 240.0
path: .spaces[3].metrics.halstead.time
old: 191.12188432959144
new: 1071.618552882086
path: .spaces[3].metrics.loc.cloc
old: 2.0
new: 49.0
path: .spaces[3].metrics.loc.blank
old: 3.0
new: 22.0
path: .spaces[3].metrics.loc.ploc
old: 17.0
new: 42.0
path: .spaces[3].metrics.loc.lloc
old: 8.0
new: 5.0
path: .spaces[3].metrics.loc.sloc
old: 22.0
new: 113.0
path: .spaces[3].metrics.cyclomatic.average
old: 5.0
new: 1.0
path: .spaces[3].metrics.cyclomatic.sum
old: 5.0
new: 10.0
path: .spaces[3].metrics.mi.mi_visual_studio
old: 52.62736355400771
new: 31.669370869331313
path: .spaces[3].metrics.mi.mi_original
old: 89.99279167735318
new: 54.154624186556546
path: .spaces[3].metrics.mi.mi_sei
old: 77.15531512072465
new: 46.05530512268063

### Code

    namespace mozilla {

    class TaskDispatcher;

    /*
     * We often want to run tasks on a target that guarantees that events will never
     * run in parallel. There are various target types that achieve this - namely
     * nsIThread and TaskQueue. Note that nsIThreadPool (which implements
     * nsIEventTarget) does not have this property, so we do not want to use
     * nsIEventTarget for this purpose. This class encapsulates the specifics of
     * the structures we might use here and provides a consistent interface.
     *
     * At present, the supported AbstractThread implementations are TaskQueue,
     * AbstractThread::MainThread() and XPCOMThreadWrapper which can wrap any
     * nsThread.
     *
     * The primary use of XPCOMThreadWrapper is to allow any threads to provide
     * Direct Task dispatching which is similar (but not identical to) the microtask
     * semantics of JS promises. Instantiating a XPCOMThreadWrapper on the current
     * nsThread is sufficient to enable direct task dispatching.
     *
     * You shouldn't use pointers when comparing AbstractThread or nsIThread to
     * determine if you are currently on the thread, but instead use the
     * nsISerialEventTarget::IsOnCurrentThread() method.
     */
    class AbstractThread : public nsISerialEventTarget {
     public:
      // Returns the AbstractThread that the caller is currently running in, or null
      // if the caller is not running in an AbstractThread.
      static AbstractThread* GetCurrent() { return sCurrentThreadTLS.get(); }

      AbstractThread(bool aSupportsTailDispatch)
          : mSupportsTailDispatch(aSupportsTailDispatch) {}

      // Returns an AbstractThread wrapper of a nsIThread.
      static already_AddRefed CreateXPCOMThreadWrapper(
          nsIThread* aThread, bool aRequireTailDispatch, bool aOnThread = false);

      NS_DECL_THREADSAFE_ISUPPORTS

      // We don't use NS_DECL_NSIEVENTTARGET so that we can remove the default
      // |flags| parameter from Dispatch. Otherwise, a single-argument Dispatch call
      // would be ambiguous.
      NS_IMETHOD_(bool) IsOnCurrentThreadInfallible(void) override;
      NS_IMETHOD IsOnCurrentThread(bool* _retval) override;
      NS_IMETHOD Dispatch(already_AddRefed event,
                          uint32_t flags) override;
      NS_IMETHOD DispatchFromScript(nsIRunnable* event, uint32_t flags) override;
      NS_IMETHOD DelayedDispatch(already_AddRefed event,
                                 uint32_t delay) override;

      enum DispatchReason { NormalDispatch, TailDispatch };
      virtual nsresult Dispatch(already_AddRefed aRunnable,
                                DispatchReason aReason = NormalDispatch) = 0;

      virtual bool IsCurrentThreadIn() const = 0;

      // Returns a TaskDispatcher that will dispatch its tasks when the currently-
      // running tasks pops off the stack.
      //
      // May only be called when running within the it is invoked up, and only on
      // threads which support it.
      virtual TaskDispatcher& TailDispatcher() = 0;

      // Returns true if we have tail tasks scheduled, or if this isn't known.
      // Returns false if we definitely don't have any tail tasks.
      virtual bool MightHaveTailTasks() { return true; }

      // Returns true if the tail dispatcher is available. In certain edge cases
      // like shutdown, it might not be.
      virtual bool IsTailDispatcherAvailable() { return true; }

      // Helper functions for methods on the tail TasklDispatcher. These check
      // HasTailTasks to avoid allocating a TailDispatcher if it isn't
      // needed.
      nsresult TailDispatchTasksFor(AbstractThread* aThread);
      bool HasTailTasksFor(AbstractThread* aThread);

      // Returns true if this supports the tail dispatcher.
      bool SupportsTailDispatch() const { return mSupportsTailDispatch; }

      // Returns true if this thread requires all dispatches originating from
      // aThread go through the tail dispatcher.
      bool RequiresTailDispatch(AbstractThread* aThread) const;
      bool RequiresTailDispatchFromCurrentThread() const;

      virtual nsIEventTarget* AsEventTarget() { MOZ_CRASH("Not an event target!"); }

      // Returns the non-DocGroup version of AbstractThread on the main thread.
      // A DocGroup-versioned one is available in
      // DispatcherTrait::AbstractThreadFor(). Note:
      // DispatcherTrait::AbstractThreadFor() SHALL be used when possible.
      static AbstractThread* MainThread();

      // Must be called exactly once during startup.
      static void InitTLS();
      static void InitMainThread();
      static void ShutdownMainThread();

      void DispatchStateChange(already_AddRefed aRunnable);

      static void DispatchDirectTask(already_AddRefed aRunnable);

     protected:
      virtual ~AbstractThread() = default;
      static MOZ_THREAD_LOCAL(AbstractThread*) sCurrentThreadTLS;

      // True if we want to require that every task dispatched from tasks running in
      // this queue go through our queue's tail dispatcher.
      const bool mSupportsTailDispatch;
    };

    }  // namespace mozilla