From 23823048d13e1d70bee26908760381e943f7e483 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Thu, 15 Nov 2007 23:14:36 +0000 Subject: [PATCH] prototype: Prevent memory leaks in Ajax.PeriodicalUpdater. Closes #10049 --- CHANGELOG | 2 ++ src/ajax.js | 10 +++------- test/unit/ajax.html | 14 +++++++++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c3fd9ee..bac2d0c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Make Ajax.Updater clone its options hash before modifying it. Prevents memory leaks in Ajax.PeriodicalUpdater. Closes #10049 [Mislav Marohnić, Tobie Langel]. + * Remove useless variable in Selector.handlers.child. Closes #10006 [kuriyama] * Don't redeclare previously declared variables. Closes #10007 [kuriyama] diff --git a/src/ajax.js b/src/ajax.js index d7790b0..0ecec59 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -306,11 +306,11 @@ Ajax.Updater = Class.create(Ajax.Request, { failure: (container.failure || (container.success ? null : container)) }; - options = options || { }; + options = Object.clone(options); var onComplete = options.onComplete; - options.onComplete = (function(response, param) { + options.onComplete = (function(response, json) { this.updateContent(response.responseText); - if (Object.isFunction(onComplete)) onComplete(response, param); + if (Object.isFunction(onComplete)) onComplete(response, json); }).bind(this); $super(url, options); @@ -332,10 +332,6 @@ Ajax.Updater = Class.create(Ajax.Request, { } else receiver.update(responseText); } - - if (this.success()) { - if (this.onComplete) this.onComplete.bind(this).defer(); - } } }); diff --git a/test/unit/ajax.html b/test/unit/ajax.html index 7e7e98e..0de88a0 100644 --- a/test/unit/ajax.html +++ b/test/unit/ajax.html @@ -161,7 +161,19 @@ }); }); }}, - + + testUpdaterOptions: function() {with(this) { + var options = { + method: 'get', + asynchronous: false, + evalJS: 'force', + onComplete: Prototype.emptyFunction + } + var request = new Ajax.Updater("content", "fixtures/hello.js", options); + request.options.onComplete = function() {}; + assertIdentical(Prototype.emptyFunction, options.onComplete); + }}, + testResponders: function(){with(this) { // check for internal responder assertEqual(1, Ajax.Responders.responders.length);