Repository: angular/angular.js
File: src/ng/rootScope.js (JavaScript)

Code before:
    };

    var $rootScope = new Scope();

    //The internal queues. Expose them on the $rootScope for debugging/testing purposes.
    var asyncQueue = $rootScope.$$asyncQueue = [];
    var postDigestQueue = $rootScope.$$postDigestQueue = [];
    var applyAsyncQueue = $rootScope.$$applyAsyncQueue = [];

    var postDigestQueuePosition = 0;

    return $rootScope;

    function invokeListeners(scope, event, listenerArgs, name) {
      var listeners = scope.$$listeners[name];
      if (listeners) {
        if (listeners.$$index !== -1) {
          throw $rootScopeMinErr('inevt', '{0} already $emit/$broadcast-ing', name);
        }
        event.currentScope = scope;
        for (listeners.$$index = 0; listeners.$$index < listeners.length; listeners.$$index++) {
          try {
            //allow all listeners attached to the current scope to run
            listeners[listeners.$$index].apply(null, listenerArgs);
          } catch (e) {
            $exceptionHandler(e);
          }
        }
        listeners.$$index = -1;
      }
    }

    function beginPhase(phase) {
      if ($rootScope.$$phase) {
        throw $rootScopeMinErr('inprog', '{0} already in progress', $rootScope.$$phase);
      }

      $rootScope.$$phase = phase;
    }

    function clearPhase() {
      $rootScope.$$phase = null;
    }

    function incrementWatchersCount(current, count) {
      do {
        current.$$watchersCount += count;
      } while ((current = current.$parent));
    }

    function decrementListenerCount(current, count, name) {

Review comment (suggestion):
If `$exceptionHandler` throws, `listeners.$$index` will be never reset and the event will be never allowed to be emitted/broadcasted any more. I wonder if that would break some usecase unnecessarily.

Code after:
            }
          }
        }

        event.currentScope = null;
        return event;
      }
    };

    var $rootScope = new Scope();

    //The internal queues. Expose them on the $rootScope for debugging/testing purposes.
    var asyncQueue = $rootScope.$$asyncQueue = [];
    var postDigestQueue = $rootScope.$$postDigestQueue = [];
    var applyAsyncQueue = $rootScope.$$applyAsyncQueue = [];

    var postDigestQueuePosition = 0;

    return $rootScope;

    function invokeListeners(scope, event, listenerArgs, name) {
      var listeners = scope.$$listeners[name];
      if (listeners) {
        if (listeners.$$index !== undefined) {
          throw $rootScopeMinErr('inevt', '{0} already $emit/$broadcast-ing on scope ({1})', name, scope.$id);
        }
        event.currentScope = scope;
        try {
          for (listeners.$$index = 0; listeners.$$index < listeners.length; listeners.$$index++) {
            try {
              //allow all listeners attached to the current scope to run
              listeners[listeners.$$index].apply(null, listenerArgs);
            } catch (e) {
              $exceptionHandler(e);
            }
          }
        } finally {
          listeners.$$index = undefined;
        }
      }
    }

    function beginPhase(phase) {
      if ($rootScope.$$phase) {
        throw $rootScopeMinErr('inprog', '{0} already in progress', $rootScope.$$phase);
      }

      $rootScope.$$phase = phase;
    }

    function clearPhase() {