@@ -132,8 +132,7 @@ function $RootScopeProvider(){
132
132
this . $$destroyed = false ;
133
133
this . $$asyncQueue = [ ] ;
134
134
this . $$postDigestQueue = [ ] ;
135
- this . $$listeners = { } ;
136
- this . $$listenerCount = { } ;
135
+ this . $$listeners = this . $$listenerCount = null ;
137
136
this . $$isolateBindings = null ;
138
137
this . $$applyAsyncQueue = [ ] ;
139
138
}
@@ -203,8 +202,7 @@ function $RootScopeProvider(){
203
202
this . $$ChildScope = function ChildScope ( ) {
204
203
this . $$watchers = this . $$nextSibling =
205
204
this . $$childHead = this . $$childTail = null ;
206
- this . $$listeners = { } ;
207
- this . $$listenerCount = { } ;
205
+ this . $$listeners = this . $$listenerCount = null ;
208
206
this . $id = nextUid ( ) ;
209
207
this . $$ChildScope = null ;
210
208
} ;
@@ -870,11 +868,10 @@ function $RootScopeProvider(){
870
868
// - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451
871
869
872
870
this . $parent = this . $$nextSibling = this . $$prevSibling = this . $$childHead =
873
- this . $$childTail = this . $root = null ;
871
+ this . $$childTail = this . $root = this . $$watchers = this . $$listeners = null ;
874
872
875
873
// don't reset these to null in case some async task tries to register a listener/watch/task
876
- this . $$listeners = { } ;
877
- this . $$watchers = this . $$asyncQueue = this . $$postDigestQueue = [ ] ;
874
+ this . $$asyncQueue = this . $$postDigestQueue = [ ] ;
878
875
879
876
// prevent NPEs since these methods have references to properties we nulled out
880
877
this . $destroy = this . $digest = this . $apply = noop ;
@@ -1077,14 +1074,17 @@ function $RootScopeProvider(){
1077
1074
* @returns {function() } Returns a deregistration function for this listener.
1078
1075
*/
1079
1076
$on : function ( name , listener ) {
1080
- var namedListeners = this . $$listeners [ name ] ;
1077
+ var namedListeners = ( this . $$listeners || ( this . $$listeners = { } ) ) [ name ] ;
1081
1078
if ( ! namedListeners ) {
1082
1079
this . $$listeners [ name ] = namedListeners = [ ] ;
1083
1080
}
1084
1081
namedListeners . push ( listener ) ;
1085
1082
1086
1083
var current = this ;
1087
1084
do {
1085
+ if ( ! current . $$listenerCount ) {
1086
+ current . $$listenerCount = { } ;
1087
+ }
1088
1088
if ( ! current . $$listenerCount [ name ] ) {
1089
1089
current . $$listenerCount [ name ] = 0 ;
1090
1090
}
@@ -1139,7 +1139,7 @@ function $RootScopeProvider(){
1139
1139
i , length ;
1140
1140
1141
1141
do {
1142
- namedListeners = scope . $$listeners [ name ] || empty ;
1142
+ namedListeners = scope . $$listeners && scope . $$listeners [ name ] || empty ;
1143
1143
event . currentScope = scope ;
1144
1144
for ( i = 0 , length = namedListeners . length ; i < length ; i ++ ) {
1145
1145
@@ -1206,15 +1206,15 @@ function $RootScopeProvider(){
1206
1206
defaultPrevented : false
1207
1207
} ;
1208
1208
1209
- if ( ! target . $$listenerCount [ name ] ) return event ;
1209
+ if ( ! ( target . $$listenerCount && target . $$listenerCount [ name ] ) ) return event ;
1210
1210
1211
1211
var listenerArgs = concat ( [ event ] , arguments , 1 ) ,
1212
1212
listeners , i , length ;
1213
1213
1214
1214
//down while you can, then up and next sibling or up and next sibling until back at root
1215
1215
while ( ( current = next ) ) {
1216
1216
event . currentScope = current ;
1217
- listeners = current . $$listeners [ name ] || [ ] ;
1217
+ listeners = current . $$listeners && current . $$listeners [ name ] || [ ] ;
1218
1218
for ( i = 0 , length = listeners . length ; i < length ; i ++ ) {
1219
1219
// if listeners were deregistered, defragment the array
1220
1220
if ( ! listeners [ i ] ) {
@@ -1235,7 +1235,7 @@ function $RootScopeProvider(){
1235
1235
// yes, this code is a bit crazy, but it works and we have tests to prove it!
1236
1236
// this piece should be kept in sync with the traversal in $digest
1237
1237
// (though it differs due to having the extra check for $$listenerCount)
1238
- if ( ! ( next = ( ( current . $$listenerCount [ name ] && current . $$childHead ) ||
1238
+ if ( ! ( next = ( ( current . $$listenerCount && current . $$listenerCount [ name ] && current . $$childHead ) ||
1239
1239
( current !== target && current . $$nextSibling ) ) ) ) {
1240
1240
while ( current !== target && ! ( next = current . $$nextSibling ) ) {
1241
1241
current = current . $parent ;
0 commit comments