From 364eafe511cdc4f162d48bb4594be9b9b45cd315 Mon Sep 17 00:00:00 2001 From: Brian Cavalier Date: Fri, 9 Mar 2012 14:28:35 -0500 Subject: [PATCH] Fix #23 - incorrect check for callback allowed passing null as a callback to clobber the resolution value. --- test/cancelable.js | 16 ++++++++++++++++ when.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/cancelable.js b/test/cancelable.js index 9afe9cfc..142cdbe2 100644 --- a/test/cancelable.js +++ b/test/cancelable.js @@ -38,6 +38,22 @@ buster.testCase('when/cancelable', { done(); } ); + }, + + 'should propagate the unaltered resolution value': function(done) { + var c = cancelable(when.defer(), function() { return false; }); + c.resolve(true); + + c.then( + function(val) { + assert(val); + done(); + }, + function() { + buster.fail(); + done(); + } + ); } }); diff --git a/when.js b/when.js index 37b5b78f..d2141224 100644 --- a/when.js +++ b/when.js @@ -110,7 +110,7 @@ define(function() { var nextValue; try { - nextValue = callback && callback(value); + if(callback) nextValue = callback(value); return promise(nextValue === undef ? value : nextValue); } catch(e) { return rejected(e);