Skip to content

Commit 811f766

Browse files
committed
Remove closures holding element references after mouseup/touchend
With tests Fixes #3083
1 parent bba4c2d commit 811f766

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

src/standard/gestures.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@
168168
function untrackDocument(stateObj) {
169169
document.removeEventListener('mousemove', stateObj.movefn);
170170
document.removeEventListener('mouseup', stateObj.upfn);
171+
stateObj.movefn = null;
172+
stateObj.upfn = null;
171173
}
172174

173175
var Gestures = {
@@ -416,8 +418,8 @@
416418
emits: ['down', 'up'],
417419

418420
info: {
419-
movefn: function(){},
420-
upfn: function(){}
421+
movefn: null,
422+
upfn: null
421423
},
422424

423425
reset: function() {
@@ -486,8 +488,8 @@
486488
}
487489
this.moves.push(move);
488490
},
489-
movefn: function(){},
490-
upfn: function(){},
491+
movefn: null,
492+
upfn: null,
491493
prevent: false
492494
},
493495

test/unit/gestures-elements.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
stream: {
149149
type: Array,
150150
value: function() {
151-
return [];
151+
return [];
152152
}
153153
}
154154
},

test/unit/gestures.html

+39
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,45 @@
406406
assert.equal(el.stream.length, 1);
407407
});
408408
});
409+
410+
suite('Reference Cleanup', function() {
411+
var el;
412+
413+
setup(function() {
414+
el = document.createElement('x-buttons');
415+
document.body.appendChild(el);
416+
});
417+
418+
teardown(function() {
419+
document.body.removeChild(el);
420+
});
421+
422+
test('down and up clear document tracking', function() {
423+
var ev = new CustomEvent('mousedown', {bubbles: true});
424+
el.dispatchEvent(ev);
425+
426+
// some recognizers do not track the document, like tap
427+
var recognizers = Polymer.Gestures.recognizers.filter(function(r) {
428+
return r.info.hasOwnProperty('movefn') &&
429+
r.info.hasOwnProperty('upfn');
430+
});
431+
432+
assert.isAbove(recognizers.length, 0, 'some recognizers track the document');
433+
434+
recognizers.forEach(function(r) {
435+
assert.isFunction(r.info.movefn, r.name + ' movefn');
436+
assert.isFunction(r.info.upfn, r.name + ' upfn');
437+
});
438+
439+
ev = new CustomEvent('mouseup', {bubbles: true});
440+
el.dispatchEvent(ev);
441+
442+
recognizers.forEach(function(r) {
443+
assert.isNull(r.info.movefn, r.name + ' movefn');
444+
assert.isNull(r.info.upfn, r.name + ' upfn');
445+
});
446+
});
447+
});
409448
</script>
410449

411450
</body>

0 commit comments

Comments
 (0)