react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / har-validator / node_modules / bluebird / js / main / props.js
81160 views"use strict";1module.exports = function(2Promise, PromiseArray, tryConvertToPromise, apiRejection) {3var util = require("./util.js");4var isObject = util.isObject;5var es5 = require("./es5.js");67function PropertiesPromiseArray(obj) {8var keys = es5.keys(obj);9var len = keys.length;10var values = new Array(len * 2);11for (var i = 0; i < len; ++i) {12var key = keys[i];13values[i] = obj[key];14values[i + len] = key;15}16this.constructor$(values);17}18util.inherits(PropertiesPromiseArray, PromiseArray);1920PropertiesPromiseArray.prototype._init = function () {21this._init$(undefined, -3) ;22};2324PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {25this._values[index] = value;26var totalResolved = ++this._totalResolved;27if (totalResolved >= this._length) {28var val = {};29var keyOffset = this.length();30for (var i = 0, len = this.length(); i < len; ++i) {31val[this._values[i + keyOffset]] = this._values[i];32}33this._resolve(val);34}35};3637PropertiesPromiseArray.prototype._promiseProgressed = function (value, index) {38this._promise._progress({39key: this._values[index + this.length()],40value: value41});42};4344PropertiesPromiseArray.prototype.shouldCopyValues = function () {45return false;46};4748PropertiesPromiseArray.prototype.getActualLength = function (len) {49return len >> 1;50};5152function props(promises) {53var ret;54var castValue = tryConvertToPromise(promises);5556if (!isObject(castValue)) {57return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/OsFKC8\u000a");58} else if (castValue instanceof Promise) {59ret = castValue._then(60Promise.props, undefined, undefined, undefined, undefined);61} else {62ret = new PropertiesPromiseArray(castValue).promise();63}6465if (castValue instanceof Promise) {66ret._propagateFrom(castValue, 4);67}68return ret;69}7071Promise.prototype.props = function () {72return props(this);73};7475Promise.props = function (promises) {76return props(promises);77};78};798081