[Pkg-javascript-commits] [leaflet] 165/301: Work around iOS7 memory trouble by not applying the contextId performance optimization when context==this. The optimization does nothing in this case anyway. Fixes #2122

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:48 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit 9fce6979825e78100621495686041dd9d2459bfe
Author: danzel <danzel at localhost.geek.nz>
Date:   Mon Nov 4 09:47:55 2013 +1300

    Work around iOS7 memory trouble by not applying the contextId performance optimization when context==this. The optimization does nothing in this case anyway. Fixes #2122
---
 spec/suites/core/EventsSpec.js | 18 ++++++++++++++++++
 src/core/Events.js             |  4 ++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/spec/suites/core/EventsSpec.js b/spec/suites/core/EventsSpec.js
index 400f424..b16429d 100644
--- a/spec/suites/core/EventsSpec.js
+++ b/spec/suites/core/EventsSpec.js
@@ -190,6 +190,24 @@ describe('Events', function() {
 			expect(spy2.called).to.be(false);
 		});
 
+		it('removes listeners with context == this and a stamp originally added without one', function () {
+			var obj = new Klass(),
+				spy1 = sinon.spy(),
+				spy2 = sinon.spy();
+
+			obj.addEventListener('test', spy1, obj);
+			L.Util.stamp(obj);
+			obj.addEventListener('test', spy2, obj);
+
+			obj.removeEventListener('test', spy1, obj);
+			obj.removeEventListener('test', spy2, obj);
+
+			obj.fireEvent('test');
+
+			expect(spy1.called).to.be(false);
+			expect(spy2.called).to.be(false);
+		});
+
 		it('doesnt lose track of listeners when removing non existent ones', function () {
 			var obj = new Klass(),
 			    spy = sinon.spy(),
diff --git a/src/core/Events.js b/src/core/Events.js
index 5c1efb1..f9cb92b 100644
--- a/src/core/Events.js
+++ b/src/core/Events.js
@@ -14,7 +14,7 @@ L.Mixin.Events = {
 		if (L.Util.invokeEach(types, this.addEventListener, this, fn, context)) { return this; }
 
 		var events = this[eventsKey] = this[eventsKey] || {},
-		    contextId = context && L.stamp(context),
+		    contextId = context && context !== this && L.stamp(context),
 		    i, len, event, type, indexKey, indexLenKey, typeIndex;
 
 		// types can be a string of space-separated words
@@ -27,7 +27,7 @@ L.Mixin.Events = {
 			};
 			type = types[i];
 
-			if (context) {
+			if (contextId) {
 				// store listeners of a particular context in a separate hash (if it has an id)
 				// gives a major performance boost when removing thousands of map layers
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list