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));
    }


Review comment (bug):
Maybe worth mentioning the scope `$id` (or even whether it was being `$emit`ed/`$broadcast`ed) to aid in debugging).

Also, we need an error page for `$rootScope:inevt`.


Code after:
              current = current.$parent;
            }
          }
        }

        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;
    }