(record, isReject)
| 2679 | return isObject(it) && typeof (then = it.then) == 'function' ? then : false; |
| 2680 | }; |
| 2681 | var notify = function(record, isReject){ |
| 2682 | if(record.n)return; |
| 2683 | record.n = true; |
| 2684 | var chain = record.c; |
| 2685 | asap(function(){ |
| 2686 | var value = record.v |
| 2687 | , ok = record.s == 1 |
| 2688 | , i = 0; |
| 2689 | var run = function(react){ |
| 2690 | var cb = ok ? react.ok : react.fail |
| 2691 | , ret, then; |
| 2692 | try { |
| 2693 | if(cb){ |
| 2694 | if(!ok)record.h = true; |
| 2695 | ret = cb === true ? value : cb(value); |
| 2696 | if(ret === react.P){ |
| 2697 | react.rej(TypeError('Promise-chain cycle')); |
| 2698 | } else if(then = isThenable(ret)){ |
| 2699 | then.call(ret, react.res, react.rej); |
| 2700 | } else react.res(ret); |
| 2701 | } else react.rej(value); |
| 2702 | } catch(err){ |
| 2703 | react.rej(err); |
| 2704 | } |
| 2705 | }; |
| 2706 | while(chain.length > i)run(chain[i++]); // variable length - can't use forEach |
| 2707 | chain.length = 0; |
| 2708 | record.n = false; |
| 2709 | if(isReject)setTimeout(function(){ |
| 2710 | var promise = record.p |
| 2711 | , handler, console; |
| 2712 | if(isUnhandled(promise)){ |
| 2713 | if(isNode){ |
| 2714 | process.emit('unhandledRejection', value, promise); |
| 2715 | } else if(handler = global.onunhandledrejection){ |
| 2716 | handler({promise: promise, reason: value}); |
| 2717 | } else if((console = global.console) && console.error){ |
| 2718 | console.error('Unhandled promise rejection', value); |
| 2719 | } |
| 2720 | } record.a = undefined; |
| 2721 | }, 1); |
| 2722 | }); |
| 2723 | }; |
| 2724 | var isUnhandled = function(promise){ |
| 2725 | var record = promise[RECORD] |
| 2726 | , chain = record.a || record.c |
no test coverage detected