From 2d54d664ff977652562e3c707d6819888251046c Mon Sep 17 00:00:00 2001 From: Friedemann Altrock Date: Sun, 22 Nov 2009 19:18:24 +0100 Subject: [PATCH] Promises should not be able to be canceled more than once. --- src/node.js | 3 +++ test/mjsunit/test-promise-cancel.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/mjsunit/test-promise-cancel.js diff --git a/src/node.js b/src/node.js index 68821023b2..dcc8e66059 100644 --- a/src/node.js +++ b/src/node.js @@ -257,6 +257,9 @@ process.Promise.prototype.timeout = function(timeout) { }; process.Promise.prototype.cancel = function() { + if(this._cancelled) return; + this._cancelled = true; + this._events['success'] = []; this._events['error'] = []; diff --git a/test/mjsunit/test-promise-cancel.js b/test/mjsunit/test-promise-cancel.js new file mode 100644 index 0000000000..2009875213 --- /dev/null +++ b/test/mjsunit/test-promise-cancel.js @@ -0,0 +1,12 @@ +process.mixin(require('./common')); + +var promise = new process.Promise(); +var cancelled = false; +promise.addCancelback(function(){ + if(cancelled){ + assertUnreachable("promise should not cancel more than once"); + } + cancelled = true; +}); +promise.cancel(); +promise.cancel();