PHP WebShell
Текущая директория: /opt/BitGoJS/node_modules/supertest-as-promised/node_modules/bluebird/js/zalgo
Просмотр файла: map.js
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise, PromiseArray, INTERNAL, apiRejection) {
var all = Promise.all;
var util = require("./util.js");
var canAttach = require("./errors.js").canAttach;
var isArray = util.isArray;
var _cast = Promise._cast;
function unpack(values) {
return Promise$_Map(values, this[0], this[1], this[2]);
}
function Promise$_Map(promises, fn, useBound, ref) {
if (typeof fn !== "function") {
return apiRejection("fn must be a function");
}
var receiver = void 0;
if (useBound === true) {
if (promises._isBound()) {
receiver = promises._boundTo;
}
}
else if (useBound !== false) {
receiver = useBound;
}
var shouldUnwrapItems = ref !== void 0;
if (shouldUnwrapItems) ref.ref = promises;
if (promises instanceof Promise) {
var pack = [fn, receiver, ref];
return promises._then(unpack, void 0, void 0, pack, void 0);
}
else if (!isArray(promises)) {
return apiRejection("expecting an array, a promise or a thenable");
}
var promise = new Promise(INTERNAL);
if (receiver !== void 0) promise._setBoundTo(receiver);
promise._setTrace(void 0);
var mapping = new Mapping(promise,
fn,
promises,
receiver,
shouldUnwrapItems);
mapping.init();
return promise;
}
var pending = {};
function Mapping(promise, callback, items, receiver, shouldUnwrapItems) {
this.shouldUnwrapItems = shouldUnwrapItems;
this.index = 0;
this.items = items;
this.callback = callback;
this.receiver = receiver;
this.promise = promise;
this.result = new Array(items.length);
}
util.inherits(Mapping, PromiseArray);
Mapping.prototype.init = function Mapping$init() {
var items = this.items;
var len = items.length;
var result = this.result;
var isRejected = false;
for (var i = 0; i < len; ++i) {
var maybePromise = _cast(items[i], void 0);
if (maybePromise instanceof Promise) {
if (maybePromise.isPending()) {
result[i] = pending;
maybePromise._proxyPromiseArray(this, i);
}
else if (maybePromise.isFulfilled()) {
result[i] = maybePromise.value();
}
else {
maybePromise._unsetRejectionIsUnhandled();
if (!isRejected) {
this.reject(maybePromise.reason());
isRejected = true;
}
}
}
else {
result[i] = maybePromise;
}
}
if (!isRejected) this.iterate();
};
Mapping.prototype.isResolved = function Mapping$isResolved() {
return this.promise === null;
};
Mapping.prototype._promiseProgressed =
function Mapping$_promiseProgressed(value) {
if (this.isResolved()) return;
this.promise._progress(value);
};
Mapping.prototype._promiseFulfilled =
function Mapping$_promiseFulfilled(value, index) {
if (this.isResolved()) return;
this.result[index] = value;
if (this.shouldUnwrapItems) this.items[index] = value;
if (this.index === index) this.iterate();
};
Mapping.prototype._promiseRejected =
function Mapping$_promiseRejected(reason) {
this.reject(reason);
};
Mapping.prototype.reject = function Mapping$reject(reason) {
if (this.isResolved()) return;
var trace = canAttach(reason) ? reason : new Error(reason + "");
this.promise._attachExtraTrace(trace);
this.promise._reject(reason, trace);
};
Mapping.prototype.iterate = function Mapping$iterate() {
var i = this.index;
var items = this.items;
var result = this.result;
var len = items.length;
var result = this.result;
var receiver = this.receiver;
var callback = this.callback;
for (; i < len; ++i) {
var value = result[i];
if (value === pending) {
this.index = i;
return;
}
try { result[i] = callback.call(receiver, value, i, len); }
catch (e) { return this.reject(e); }
}
this.promise._follow(all(result));
this.items = this.result = this.callback = this.promise = null;
};
Promise.prototype.map = function Promise$map(fn, ref) {
return Promise$_Map(this, fn, true, ref);
};
Promise.map = function Promise$Map(promises, fn, ref) {
return Promise$_Map(promises, fn, false, ref);
};
};
Выполнить команду
Для локальной разработки. Не используйте в интернете!