Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-12-29 19:45:54 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-12-29 19:45:54 +0300
commit8518ea886ae0af22f89b62d000dfd9d43e3e9a20 (patch)
treebfe1cd744febeabdd1f26aca9ef44665f23fe007
parent35cb7380e9a108d73d1b79dbd0f0783644044ea4 (diff)
parent5194e8bfc03db491e53df51b993bfd06200a94bc (diff)
Merge pull request #546 from feross/throw-on-use-after-destroy
torrent: throw on use after destroy
-rw-r--r--lib/torrent.js20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index e13ee48..3f41c09 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -449,6 +449,7 @@ Torrent.prototype.destroy = function (cb) {
*/
Torrent.prototype.addPeer = function (peer) {
var self = this
+ if (self.destroyed) throw new Error('torrent is destroyed')
function addPeer () {
self.swarm.addPeer(peer)
@@ -473,9 +474,9 @@ Torrent.prototype.addPeer = function (peer) {
* @param {string} url web seed url
*/
Torrent.prototype.addWebSeed = function (url) {
- var self = this
+ if (this.destroyed) throw new Error('torrent is destroyed')
debug('add web seed %s', url)
- self.swarm.addWebSeed(url, self)
+ this.swarm.addWebSeed(url, this)
}
/**
@@ -488,6 +489,8 @@ Torrent.prototype.addWebSeed = function (url) {
*/
Torrent.prototype.select = function (start, end, priority, notify) {
var self = this
+ if (self.destroyed) throw new Error('torrent is destroyed')
+
if (start > end || start < 0 || end >= self.pieces.length) {
throw new Error('invalid selection ', start, ':', end)
}
@@ -519,6 +522,8 @@ Torrent.prototype.select = function (start, end, priority, notify) {
*/
Torrent.prototype.deselect = function (start, end, priority) {
var self = this
+ if (self.destroyed) throw new Error('torrent is destroyed')
+
priority = Number(priority) || 0
debug('deselect %s-%s (priority %s)', start, end, priority)
@@ -541,6 +546,8 @@ Torrent.prototype.deselect = function (start, end, priority) {
*/
Torrent.prototype.critical = function (start, end) {
var self = this
+ if (self.destroyed) throw new Error('torrent is destroyed')
+
debug('critical %s-%s', start, end)
for (var i = start; i <= end; ++i) {
@@ -1180,6 +1187,8 @@ Torrent.prototype._checkDone = function () {
Torrent.prototype.load = function (streams, cb) {
var self = this
+ if (self.destroyed) throw new Error('torrent is destroyed')
+
if (!Array.isArray(streams)) streams = [ streams ]
if (!cb) cb = noop
@@ -1199,10 +1208,11 @@ Torrent.prototype.load = function (streams, cb) {
}
Torrent.prototype.createServer = function (opts) {
- var self = this
+ if (this.destroyed) throw new Error('torrent is destroyed')
+
if (typeof Server !== 'function') throw new Error('node.js-only method')
- var server = new Server(self, opts)
- self._servers.push(server)
+ var server = new Server(this, opts)
+ this._servers.push(server)
return server
}