2 module.exports = function(
3 Promise, PromiseArray, tryConvertToPromise, apiRejection) {
4 var util = require("./util.js");
5 var isObject = util.isObject;
6 var es5 = require("./es5.js");
8 function PropertiesPromiseArray(obj) {
9 var keys = es5.keys(obj);
10 var len = keys.length;
11 var values = new Array(len * 2);
12 for (var i = 0; i < len; ++i) {
15 values[i + len] = key;
17 this.constructor$(values);
19 util.inherits(PropertiesPromiseArray, PromiseArray);
21 PropertiesPromiseArray.prototype._init = function () {
22 this._init$(undefined, -3) ;
25 PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
26 this._values[index] = value;
27 var totalResolved = ++this._totalResolved;
28 if (totalResolved >= this._length) {
30 var keyOffset = this.length();
31 for (var i = 0, len = this.length(); i < len; ++i) {
32 val[this._values[i + keyOffset]] = this._values[i];
38 PropertiesPromiseArray.prototype._promiseProgressed = function (value, index) {
39 this._promise._progress({
40 key: this._values[index + this.length()],
45 PropertiesPromiseArray.prototype.shouldCopyValues = function () {
49 PropertiesPromiseArray.prototype.getActualLength = function (len) {
53 function props(promises) {
55 var castValue = tryConvertToPromise(promises);
57 if (!isObject(castValue)) {
58 return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/OsFKC8\u000a");
59 } else if (castValue instanceof Promise) {
60 ret = castValue._then(
61 Promise.props, undefined, undefined, undefined, undefined);
63 ret = new PropertiesPromiseArray(castValue).promise();
66 if (castValue instanceof Promise) {
67 ret._propagateFrom(castValue, 4);
72 Promise.prototype.props = function () {
76 Promise.props = function (promises) {
77 return props(promises);