refactor($rootScope): extract scope tree traversal to function

For simpler maintenance, extract algorithm into function, instead of the
current comment: `// this piece should be kept in sync with the traversal in $broadcast`