Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 58cc8a5

Browse files
committed
fixup! fix($q): treat thrown errors as regular rejections
1 parent e3b3815 commit 58cc8a5

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

lib/promises-aplus/promises-aplus-test-adapter.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
minErr,
1010
extend
1111
*/
12-
/* eslint-disable no-unused-vars */
1312

14-
var isFunction = function isFunction(value) {return typeof value === 'function';};
15-
var isPromiseLike = function isPromiseLike(obj) {return obj && isFunction(obj.then);};
16-
var isObject = function isObject(value) {return value != null && typeof value === 'object';};
17-
var isUndefined = function isUndefined(value) {return typeof value === 'undefined';};
13+
/* eslint-disable no-unused-vars */
14+
function isFunction(value) { return typeof value === 'function'; }
15+
function isPromiseLike(obj) { return obj && isFunction(obj.then); }
16+
function isObject(value) { return value !== null && typeof value === 'object'; }
17+
function isUndefined(value) { return typeof value === 'undefined'; }
1818

19-
var minErr = function minErr(module, constructor) {
19+
function minErr(module, constructor) {
2020
return function() {
2121
var ErrorConstructor = constructor || Error;
2222
throw new ErrorConstructor(module + arguments[0] + arguments[1]);
2323
};
24-
};
24+
}
2525

26-
var extend = function extend(dst) {
26+
function extend(dst) {
2727
for (var i = 1, ii = arguments.length; i < ii; i++) {
2828
var obj = arguments[i];
2929
if (obj) {
@@ -35,18 +35,11 @@ var extend = function extend(dst) {
3535
}
3636
}
3737
return dst;
38-
};
38+
}
39+
/* eslint-enable */
3940

4041
var $q = qFactory(process.nextTick, function noopExceptionHandler() {});
4142

4243
exports.resolved = $q.resolve;
4344
exports.rejected = $q.reject;
44-
exports.deferred = function() {
45-
var deferred = $q.defer();
46-
47-
return {
48-
promise: deferred.promise,
49-
resolve: deferred.resolve,
50-
reject: deferred.reject
51-
};
52-
};
45+
exports.deferred = $q.defer;

src/ng/q.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,14 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
419419
},
420420

421421
$$resolve: function(val) {
422+
var then;
422423
var that = this;
423424
var done = false;
424425
try {
425-
if ((isObject(val) || isFunction(val)) && isFunction(val.then)) {
426+
if (isObject(val) || isFunction(val)) then = val.then;
427+
if (isFunction(then)) {
426428
this.promise.$$state.status = -1;
427-
val.then(resolvePromise, rejectPromise, simpleBind(this, this.notify));
429+
then.call(val, resolvePromise, rejectPromise, simpleBind(this, this.notify));
428430
} else {
429431
this.promise.$$state.value = val;
430432
this.promise.$$state.status = 1;

0 commit comments

Comments
 (0)