Code coverage report for debug\thenables.js

Statements: 100% (63 / 63)      Branches: 100% (32 / 32)      Functions: 100% (8 / 8)      Lines: 100% (56 / 56)      Ignored: none     

All files » debug\ » thenables.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95  8 8 8 8 8   8 52341 20751 9011   11740 18 18             18   11722 11722 112 112 112 112 11610 4073     39127     8 11722     8 8 11740     8 4073   4073 4073 4073 4073 4073 4073 4073       4073 4073 83 83     8 3657 3429 6     3423   3429     8 601 561 561     8 36 33 30     4073     8        
(function () { "use strict";
module.exports = function(Promise, INTERNAL) {
var ASSERT = require("./assert.js");
var util = require("./util.js");
var errorObj = util.errorObj;
var isObject = util.isObject;
 
function tryConvertToPromise(obj, context) {
    if (isObject(obj)) {
        if (obj instanceof Promise) {
            return obj;
        }
        else if (isAnyBluebirdPromise(obj)) {
            var ret = new Promise(INTERNAL);
            obj._then(
                ret._fulfillUnchecked,
                ret._rejectUncheckedCheckError,
                ret._progressUnchecked,
                ret,
                null
            );
            return ret;
        }
        var then = util.tryCatch(getThen)(obj);
        if (then === errorObj) {
            if (context) context._pushContext();
            var ret = Promise.reject(then.e);
            if (context) context._popContext();
            return ret;
        } else if (typeof then === "function") {
            return doThenable(obj, then, context);
        }
    }
    return obj;
}
 
function getThen(obj) {
    return obj.then;
}
 
var hasProp = {}.hasOwnProperty;
function isAnyBluebirdPromise(obj) {
    return hasProp.call(obj, "_promise0");
}
 
function doThenable(x, then, context) {
    ASSERT(((typeof then) === "function"),
    "typeof then === \u0022function\u0022");
    var promise = new Promise(INTERNAL);
    var ret = promise;
    if (context) context._pushContext();
    promise._captureStackTrace();
    if (context) context._popContext();
    var synchronous = true;
    var result = util.tryCatch(then).call(x,
                                        resolveFromThenable,
                                        rejectFromThenable,
                                        progressFromThenable);
    synchronous = false;
    if (promise && result === errorObj) {
        promise._rejectCallback(result.e, true, true);
        promise = null;
    }
 
    function resolveFromThenable(value) {
        if (!promise) return;
        if (x === value) {
            promise._rejectCallback(
                Promise._makeSelfResolutionError(), false, true);
        } else {
            promise._resolveCallback(value);
        }
        promise = null;
    }
 
    function rejectFromThenable(reason) {
        if (!promise) return;
        promise._rejectCallback(reason, synchronous, true);
        promise = null;
    }
 
    function progressFromThenable(value) {
        if (!promise) return;
        if (typeof promise._progress === "function") {
            promise._progress(value);
        }
    }
    return ret;
}
 
return tryConvertToPromise;
};
 
}());