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