File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1
1
var _ = require ( './util' )
2
+ var MAX_UPDATE_COUNT = 10
2
3
3
4
// we have two separate queues: one for directive updates
4
5
// and one for user watcher registered via $watch().
@@ -61,7 +62,21 @@ function run (queue) {
61
62
*/
62
63
63
64
exports . push = function ( job ) {
64
- if ( ! job . id || ! has [ job . id ] || flushing ) {
65
+ var id = job . id
66
+ if ( ! id || ! has [ id ] || flushing ) {
67
+ if ( ! has [ id ] ) {
68
+ has [ id ] = 1
69
+ } else {
70
+ has [ id ] ++
71
+ // detect possible infinite update loops
72
+ if ( has [ id ] > MAX_UPDATE_COUNT ) {
73
+ _ . warn (
74
+ 'You may have an infinite update loop for the ' +
75
+ 'watcher with expression: "' + job . expression + '".'
76
+ )
77
+ return
78
+ }
79
+ }
65
80
// A user watcher callback could trigger another
66
81
// directive update during the flushing; at that time
67
82
// the directive queue would already have been run, so
@@ -71,7 +86,6 @@ exports.push = function (job) {
71
86
return
72
87
}
73
88
; ( job . user ? userQueue : queue ) . push ( job )
74
- has [ job . id ] = job
75
89
if ( ! waiting ) {
76
90
waiting = true
77
91
_ . nextTick ( flush )
Original file line number Diff line number Diff line change
1
+ var _ = require ( '../../../src/util' )
1
2
var batcher = require ( '../../../src/batcher' )
2
3
var nextTick = require ( '../../../src/util' ) . nextTick
3
4
@@ -7,6 +8,7 @@ describe('Batcher', function () {
7
8
8
9
beforeEach ( function ( ) {
9
10
spy = jasmine . createSpy ( 'batcher' )
11
+ spyOn ( _ , 'warn' )
10
12
} )
11
13
12
14
it ( 'push' , function ( done ) {
@@ -80,4 +82,21 @@ describe('Batcher', function () {
80
82
} )
81
83
} )
82
84
85
+ it ( 'warn against infinite update loops' , function ( done ) {
86
+ var count = 0
87
+ var job = {
88
+ id : 1 ,
89
+ run : function ( ) {
90
+ count ++
91
+ batcher . push ( job )
92
+ }
93
+ }
94
+ batcher . push ( job )
95
+ nextTick ( function ( ) {
96
+ expect ( count ) . not . toBe ( 0 )
97
+ expect ( _ . warn ) . toHaveBeenCalled ( )
98
+ done ( )
99
+ } )
100
+ } )
101
+
83
102
} )
You can’t perform that action at this time.
0 commit comments