|
44 | 44 | _.extend(AV.Promise, /** @lends AV.Promise */ { |
45 | 45 |
|
46 | 46 | _isPromisesAPlusCompliant: true, |
| 47 | + _debugError: false, |
47 | 48 |
|
48 | 49 | /** |
49 | 50 | * Returns true iff the given object fulfils the Promise interface. |
|
361 | 362 | try { |
362 | 363 | result = [resolvedCallback.apply(this, result)]; |
363 | 364 | } catch (e) { |
| 365 | + if(AV.Promise._debugError && e) { |
| 366 | + console.error('Error occurred in promise resolve callback', e); |
| 367 | + } |
364 | 368 | result = [AV.Promise.error(e)]; |
365 | 369 | } |
366 | 370 | } else { |
|
385 | 389 | try { |
386 | 390 | result = [rejectedCallback(error)]; |
387 | 391 | } catch (e) { |
| 392 | + if(AV.Promise._debugError && e) { |
| 393 | + console.error('Error occurred in promise reject callback', e); |
| 394 | + } |
388 | 395 | result = [AV.Promise.error(e)]; |
389 | 396 | } |
390 | 397 | } else { |
|
412 | 419 | func.call(); |
413 | 420 | }; |
414 | 421 | if (AV.Promise._isPromisesAPlusCompliant) { |
415 | | - if (typeof(setImmediate) !== 'undefined' && _.isFunction(setImmediate)) { |
416 | | - runLater = setImmediate; |
| 422 | + if (typeof(window) !== 'undefined' && _.isFunction(window.setImmediate)) { |
| 423 | + runLater = function(func) { |
| 424 | + window.setImmediate(func); |
| 425 | + }; |
| 426 | + } else if (typeof(process) !== 'undefined' && process.nextTick) { |
| 427 | + runLater = function(func) { |
| 428 | + process.nextTick(func); |
| 429 | + }; |
417 | 430 | } else if (typeof(setTimeout) !== 'undefined' && _.isFunction(setTimeout)) { |
418 | 431 | runLater = function(func) { |
419 | 432 | setTimeout(func, 0); |
|
428 | 441 | }); |
429 | 442 | } else if (this._rejected) { |
430 | 443 | runLater(function() { |
431 | | - wrappedRejectedCallback(self._error); |
| 444 | + wrappedRejectedCallback.apply(self, [self._error]); |
432 | 445 | }); |
433 | 446 | } else { |
434 | 447 | this._resolvedCallbacks.push(wrappedResolvedCallback); |
|
0 commit comments