Code coverage report for debug\some.js

Statements: 100% (79 / 79)      Branches: 100% (21 / 21)      Functions: 100% (19 / 19)      Lines: 100% (79 / 79)      Ignored: none     

All files » debug\ » some.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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140  8   8 8 8 8 8     8 144 144 144 144   8   8 288 144   144 144 3 3   141 141 141     3       8 144 144     8 63     8 309     8 144   144     8 108   108 108 69 69 33   36         8 63   63 63 24 24 63   24       8 108     8 102     8 63     8 108     8 102     8 9   9     8 6     8 91 10   81 81 81   81   81 81 81     8 76     8 15     8        
(function () { "use strict";
module.exports =
function(Promise, PromiseArray, apiRejection) {
var ASSERT = require("./assert.js");
var util = require("./util.js");
var RangeError = require("./errors.js").RangeError;
var AggregateError = require("./errors.js").AggregateError;
var isArray = util.isArray;
 
 
function SomePromiseArray(values) {
    this.constructor$(values);
    this._howMany = 0;
    this._unwrap = false;
    this._initialized = false;
}
util.inherits(SomePromiseArray, PromiseArray);
 
SomePromiseArray.prototype._init = function () {
    if (!this._initialized) {
        return;
    }
    this._promise._setIsSpreadable();
    if (this._howMany === 0) {
        this._resolve([]);
        return;
    }
    this._init$(undefined, -5);
    var isArrayResolved = isArray(this._values);
    if (!this._isResolved() &&
        isArrayResolved &&
        this._howMany > this._canPossiblyFulfill()) {
        this._reject(this._getRangeError(this.length()));
    }
};
 
SomePromiseArray.prototype.init = function () {
    this._initialized = true;
    this._init();
};
 
SomePromiseArray.prototype.setUnwrap = function () {
    this._unwrap = true;
};
 
SomePromiseArray.prototype.howMany = function () {
    return this._howMany;
};
 
SomePromiseArray.prototype.setHowMany = function (count) {
    ASSERT((! this._isResolved()),
    "!this._isResolved()");
    this._howMany = count;
};
 
SomePromiseArray.prototype._promiseFulfilled = function (value) {
    ASSERT((! this._isResolved()),
    "!this._isResolved()");
    this._addFulfilled(value);
    if (this._fulfilled() === this.howMany()) {
        this._values.length = this.howMany();
        if (this.howMany() === 1 && this._unwrap) {
            this._resolve(this._values[0]);
        } else {
            this._resolve(this._values);
        }
    }
 
};
SomePromiseArray.prototype._promiseRejected = function (reason) {
    ASSERT((! this._isResolved()),
    "!this._isResolved()");
    this._addRejected(reason);
    if (this.howMany() > this._canPossiblyFulfill()) {
        var e = new AggregateError();
        for (var i = this.length(); i < this._values.length; ++i) {
            e.push(this._values[i]);
        }
        this._reject(e);
    }
};
 
SomePromiseArray.prototype._fulfilled = function () {
    return this._totalResolved;
};
 
SomePromiseArray.prototype._rejected = function () {
    return this._values.length - this.length();
};
 
SomePromiseArray.prototype._addRejected = function (reason) {
    this._values.push(reason);
};
 
SomePromiseArray.prototype._addFulfilled = function (value) {
    this._values[this._totalResolved++] = value;
};
 
SomePromiseArray.prototype._canPossiblyFulfill = function () {
    return this.length() - this._rejected();
};
 
SomePromiseArray.prototype._getRangeError = function (count) {
    var message = "Input array must contain at least " +
            this._howMany + " items but contains only " + count + " items";
    return new RangeError(message);
};
 
SomePromiseArray.prototype._resolveEmptyArray = function () {
    this._reject(this._getRangeError(0));
};
 
function some(promises, howMany) {
    if ((howMany | 0) !== howMany || howMany < 0) {
        return apiRejection("expecting a positive integer\u000a\u000a    See http://goo.gl/1wAmHx\u000a");
    }
    var ret = new SomePromiseArray(promises);
    var promise = ret.promise();
    ASSERT(promise.isPending(),
    "promise.isPending()");
    ASSERT((ret instanceof SomePromiseArray),
    "ret instanceof SomePromiseArray");
    ret.setHowMany(howMany);
    ret.init();
    return promise;
}
 
Promise.some = function (promises, howMany) {
    return some(promises, howMany);
};
 
Promise.prototype.some = function (howMany) {
    return some(this, howMany);
};
 
Promise._SomePromiseArray = SomePromiseArray;
};
 
}());