Skip to content

Commit

Permalink
Merge branch 'v0.8'
Browse files Browse the repository at this point in the history
Conflicts:
	q.js
  • Loading branch information
domenic committed Dec 29, 2012
2 parents 8512628 + 76afd7b commit 1ff6855
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
"jshint": ">=0.9.1",
"cover": "*",
"jasmine-node": "*",
"opener": "*"
"opener": "*",
"promises-aplus-tests": "~1.0"
},
"scripts": {
"test": "jasmine-node spec",
"test": "jasmine-node spec && promises-aplus-tests spec/aplus-adapter",
"test-browser": "opener spec/q-spec.html",
"lint": "jshint q.js",
"cover": "cover run node_modules/jasmine-node/bin/jasmine-node spec && cover report html && opener cover_html/index.html"
Expand Down
13 changes: 5 additions & 8 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ function displayErrors() {
*/
Q.reject = reject;
function reject(exception) {
exception = exception || new Error();
var rejection = makePromise({
"when": function (rejected) {
// note that the error has been handled
Expand Down Expand Up @@ -784,14 +783,14 @@ function when(value, fulfilled, rejected, progressed) {

function _fulfilled(value) {
try {
return fulfilled ? fulfilled(value) : value;
return typeof fulfilled === "function" ? fulfilled(value) : value;
} catch (exception) {
return reject(exception);
}
}

function _rejected(exception) {
if (rejected) {
if (typeof rejected === "function") {
makeStackTraceLong(exception, resolvedValue);
try {
return rejected(exception);
Expand All @@ -803,7 +802,7 @@ function when(value, fulfilled, rejected, progressed) {
}

function _progressed(value) {
return progressed ? progressed(value) : value;
return typeof progressed === "function" ? progressed(value) : value;
}

var resolvedValue = resolve(value);
Expand Down Expand Up @@ -1289,8 +1288,7 @@ function delay(promise, timeout) {
* Passes a continuation to a Node function, which is called with the given
* arguments provided as an array, and returns a promise.
*
* var readFile = require("fs").readFile;
* Q.nfapply(readFile, [__filename])
* Q.nfapply(FS.readFile, [__filename])
* .then(function (content) {
* })
*
Expand All @@ -1309,8 +1307,7 @@ function nfapply(callback, args) {
* Passes a continuation to a Node function, which is called with the given
* arguments provided individually, and returns a promise.
*
* var readFile = require("fs").readFile;
* Q.nfcall(readFile, __filename)
* Q.nfcall(FS.readFile, __filename)
* .then(function (content) {
* })
*
Expand Down
15 changes: 15 additions & 0 deletions spec/aplus-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";

var Q = require("../q");

exports.fulfilled = Q.resolve;
exports.rejected = Q.reject;
exports.pending = function () {
var deferred = Q.defer();

return {
promise: deferred.promise,
fulfill: deferred.resolve,
reject: deferred.reject
};
};
10 changes: 10 additions & 0 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,16 @@ describe("all", function () {
.timeout(1000);
});

it("resolves foreign promises", function () {
var normal = Q.resolve(1);
var foreign = { then: function (f) { f(2); } };

return Q.all([normal, foreign])
.then(function (result) {
expect(result).toEqual([1, 2]);
});
});

});

describe("allResolved", function () {
Expand Down

0 comments on commit 1ff6855

Please sign in to comment.