[Pkg-javascript-commits] [sockjs-client] 216/350: Make sure everything gets cleaned up
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:04:23 UTC 2016
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.
commit f8b72d7384c2a90f5aec654ea6af0d595dc0c9fb
Author: Bryce Kahle <bkahle at gmail.com>
Date: Tue Oct 21 16:05:34 2014 -0400
Make sure everything gets cleaned up
---
gulpfile.js | 8 +++++++-
lib/main.js | 1 -
lib/transport/browser/abstract-xhr.js | 2 +-
lib/transport/iframe.js | 5 +++--
lib/transport/lib/ajax-based.js | 5 +++++
lib/transport/lib/buffered-sender.js | 4 ++--
lib/transport/lib/polling.js | 3 ++-
lib/transport/lib/sender-receiver.js | 6 ++----
lib/transport/receiver/eventsource.js | 3 +++
lib/transport/receiver/htmlfile.js | 4 ++--
10 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/gulpfile.js b/gulpfile.js
index 569c85f..b0146ff 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,3 +1,4 @@
+/* eslint camelcase: 0 */
'use strict';
var util = require('util')
@@ -71,7 +72,12 @@ gulp.task('browserify:min', function () {
.bundle()
.pipe(source(libName + '.min.js'))
.pipe(buffer())
- .pipe(uglify())
+ .pipe(uglify({
+ compress: {
+ // remove debug statements from output entirely
+ pure_funcs: ['debug']
+ }
+ }))
.pipe(gulp.dest('./build/'))
;
});
diff --git a/lib/main.js b/lib/main.js
index 3e0c53e..f1aeb0c 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -324,7 +324,6 @@ SockJS.prototype._close = function(code, reason, wasClean) {
this._ir = null;
}
if (this._transport) {
- this._transport.removeAllListeners();
this._transport.close();
this._transport = null;
this.transport = null;
diff --git a/lib/transport/browser/abstract-xhr.js b/lib/transport/browser/abstract-xhr.js
index d8b349c..6eaed8d 100644
--- a/lib/transport/browser/abstract-xhr.js
+++ b/lib/transport/browser/abstract-xhr.js
@@ -53,7 +53,7 @@ AbstractXHRObject.prototype._start = function(method, url, payload, opts) {
debug('exception', e);
// IE raises an exception on wrong port.
this.emit('finish', 0, '');
- this._cleanup();
+ this._cleanup(false);
return;
}
diff --git a/lib/transport/iframe.js b/lib/transport/iframe.js
index 8beb83f..fdf734d 100644
--- a/lib/transport/iframe.js
+++ b/lib/transport/iframe.js
@@ -42,7 +42,7 @@ function IframeTransport(transport, transUrl, baseUrl) {
this.iframeObj = iframeUtils.createIframe(iframeUrl, function(r) {
debug('err callback');
self.emit('close', 1006, 'Unable to load an iframe (' + r + ')');
- self.removeAllListeners();
+ self.close();
});
this.onmessageCallback = this._message.bind(this);
@@ -53,6 +53,7 @@ inherits(IframeTransport, EventEmitter);
IframeTransport.prototype.close = function() {
debug('close');
+ this.removeAllListeners();
if (this.iframeObj) {
eventUtils.detachEvent('message', this.onmessageCallback);
try {
@@ -64,7 +65,6 @@ IframeTransport.prototype.close = function() {
this.iframeObj = null;
this.onmessageCallback = this.iframeObj = null;
}
- this.removeAllListeners();
};
IframeTransport.prototype._message = function(e) {
@@ -110,6 +110,7 @@ IframeTransport.prototype._message = function(e) {
return;
}
this.emit('close', cdata[0], cdata[1]);
+ this.close();
break;
}
};
diff --git a/lib/transport/lib/ajax-based.js b/lib/transport/lib/ajax-based.js
index 1b02787..6477fbc 100644
--- a/lib/transport/lib/ajax-based.js
+++ b/lib/transport/lib/ajax-based.js
@@ -21,6 +21,8 @@ function createAjaxSender(AjaxObject) {
var xo = new AjaxObject('POST', ajaxUrl, payload, opt);
xo.once('finish', function(status) {
debug('finish', status);
+ xo = null;
+
if (status !== 200 && status !== 204) {
return callback(new Error('http status ' + status));
}
@@ -28,6 +30,9 @@ function createAjaxSender(AjaxObject) {
});
return function() {
debug('abort');
+ xo.close();
+ xo = null;
+
var err = new Error('Aborted');
err.code = 1000;
callback(err);
diff --git a/lib/transport/lib/buffered-sender.js b/lib/transport/lib/buffered-sender.js
index 966aafc..cf5cb81 100644
--- a/lib/transport/lib/buffered-sender.js
+++ b/lib/transport/lib/buffered-sender.js
@@ -77,11 +77,11 @@ BufferedSender.prototype._cleanup = function() {
BufferedSender.prototype.stop = function() {
debug('stop');
+ this._cleanup();
if (this.sendStop) {
this.sendStop();
+ this.sendStop = null;
}
- this.sendStop = null;
- this._cleanup();
};
module.exports = BufferedSender;
diff --git a/lib/transport/lib/polling.js b/lib/transport/lib/polling.js
index d544f0b..8108432 100644
--- a/lib/transport/lib/polling.js
+++ b/lib/transport/lib/polling.js
@@ -39,6 +39,7 @@ Polling.prototype._scheduleReceiver = function() {
self._scheduleReceiver();
} else {
self.emit('close', code || 1006, reason);
+ self.removeAllListeners();
}
}
});
@@ -46,11 +47,11 @@ Polling.prototype._scheduleReceiver = function() {
Polling.prototype.abort = function() {
debug('abort');
+ this.removeAllListeners();
this.pollIsClosing = true;
if (this.poll) {
this.poll.abort();
}
- this.removeAllListeners();
};
module.exports = Polling;
diff --git a/lib/transport/lib/sender-receiver.js b/lib/transport/lib/sender-receiver.js
index b81480a..fb0f51a 100644
--- a/lib/transport/lib/sender-receiver.js
+++ b/lib/transport/lib/sender-receiver.js
@@ -25,9 +25,8 @@ function SenderReceiver(transUrl, urlSuffix, senderFunc, Receiver, AjaxObject) {
this.poll.once('close', function(code, reason) {
debug('poll close', code, reason);
self.poll = null;
- self.stop();
self.emit('close', code, reason);
- self.removeAllListeners();
+ self.close();
});
}
@@ -35,13 +34,12 @@ inherits(SenderReceiver, BufferedSender);
SenderReceiver.prototype.close = function() {
debug('close');
+ this.removeAllListeners();
if (this.poll) {
this.poll.abort();
this.poll = null;
}
this.stop();
- this.emit('close', null, 'user');
- this.removeAllListeners();
};
module.exports = SenderReceiver;
diff --git a/lib/transport/receiver/eventsource.js b/lib/transport/receiver/eventsource.js
index df32c67..f9b3cc9 100644
--- a/lib/transport/receiver/eventsource.js
+++ b/lib/transport/receiver/eventsource.js
@@ -51,6 +51,9 @@ EventSourceReceiver.prototype._cleanup = function() {
EventSourceReceiver.prototype._close = function(reason) {
debug('close', reason);
var self = this;
+ // Safari and chrome < 15 crash if we close window before
+ // waiting for ES cleanup. See:
+ // https://code.google.com/p/chromium/issues/detail?id=89155
setTimeout(function() {
self.emit('close', null, reason);
self.removeAllListeners();
diff --git a/lib/transport/receiver/htmlfile.js b/lib/transport/receiver/htmlfile.js
index ad7a4cd..a560c55 100644
--- a/lib/transport/receiver/htmlfile.js
+++ b/lib/transport/receiver/htmlfile.js
@@ -22,7 +22,7 @@ function HtmlfileReceiver(url) {
url = urlUtils.addQuery(url, 'c=' + decodeURIComponent(iframeUtils.WPrefix + '.' + this.id));
debug('using htmlfile', HtmlfileReceiver.htmlfileEnabled);
- var constructor = HtmlfileReceiver.htmlfileEnabled ?
+ var constructFunc = HtmlfileReceiver.htmlfileEnabled ?
iframeUtils.createHtmlfile : iframeUtils.createIframe;
global[iframeUtils.WPrefix][this.id] = {
@@ -40,7 +40,7 @@ function HtmlfileReceiver(url) {
self._close('network');
}
};
- this.iframeObj = constructor(url, function() {
+ this.iframeObj = constructFunc(url, function() {
debug('callback');
self._cleanup();
self._close('permanent');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list