"use strict"; module.exports = function( Promise, PromiseArray, tryConvertToPromise, apiRejection) { var util = require("./util"); var isObject = util.isObject; var es5 = require("./es5"); var Es6Map; if (typeof Map === "function") Es6Map = Map; var mapToEntries = (function() { var index = 0; var size = 0; function extractEntry(value, key) { this[index] = value; this[index + size] = key; index++; } return function mapToEntries(map) { size = map.size; index = 0; var ret = new Array(map.size * 2); map.forEach(extractEntry, ret); return ret; }; })(); var entriesToMap = function(entries) { var ret = new Es6Map(); var length = entries.length / 2 | 0; for (var i = 0; i < length; ++i) { var key = entries[length + i]; var value = entries[i]; ret.set(key, value); } return ret; }; function PropertiesPromiseArray(obj) { var isMap = false; var entries; if (Es6Map !== undefined && obj instanceof Es6Map) { entries = mapToEntries(obj); isMap = true; } else { var keys = es5.keys(obj); var len = keys.length; entries = new Array(len * 2); for (var i = 0; i < len; ++i) { var key = keys[i]; entries[i] = obj[key]; entries[i + len] = key; } } this.constructor$(entries); this._isMap = isMap; this._init$(undefined, isMap ? -6 : -3); } util.inherits(PropertiesPromiseArray, PromiseArray); PropertiesPromiseArray.prototype._init = function () {}; PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) { this._values[index] = value; var totalResolved = ++this._totalResolved; if (totalResolved >= this._length) { var val; if (this._isMap) { val = entriesToMap(this._values); } else { val = {}; var keyOffset = this.length(); for (var i = 0, len = this.length(); i < len; ++i) { val[this._values[i + keyOffset]] = this._values[i]; } } this._resolve(val); return true; } return false; }; PropertiesPromiseArray.prototype.shouldCopyValues = function () { return false; }; PropertiesPromiseArray.prototype.getActualLength = function (len) { return len >> 1; }; function props(promises) { var ret; var castValue = tryConvertToPromise(promises); if (!isObject(castValue)) { return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a"); } else if (castValue instanceof Promise) { ret = castValue._then( Promise.props, undefined, undefined, undefined, undefined); } else { ret = new PropertiesPromiseArray(castValue).promise(); } if (castValue instanceof Promise) { ret._propagateFrom(castValue, 2); } return ret; } Promise.prototype.props = function () { return props(this); }; Promise.props = function (promises) { return props(promises); }; };
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
any.js | File | 421 B | 0644 |
|
assert.js | File | 1.61 KB | 0644 |
|
async.js | File | 4.05 KB | 0644 |
|
bind.js | File | 1.92 KB | 0644 |
|
bluebird.js | File | 291 B | 0644 |
|
call_get.js | File | 4.25 KB | 0644 |
|
cancel.js | File | 3.62 KB | 0644 |
|
catch_filter.js | File | 1.39 KB | 0644 |
|
context.js | File | 2.33 KB | 0644 |
|
debuggability.js | File | 29.63 KB | 0644 |
|
direct_resolve.js | File | 1.36 KB | 0644 |
|
each.js | File | 789 B | 0644 |
|
errors.js | File | 3.63 KB | 0644 |
|
es5.js | File | 1.93 KB | 0644 |
|
filter.js | File | 314 B | 0644 |
|
finally.js | File | 4.5 KB | 0644 |
|
generators.js | File | 7.58 KB | 0644 |
|
join.js | File | 8.03 KB | 0644 |
|
map.js | File | 5.25 KB | 0644 |
|
method.js | File | 1.73 KB | 0644 |
|
nodeback.js | File | 1.52 KB | 0644 |
|
nodeify.js | File | 1.61 KB | 0644 |
|
promise.js | File | 25.59 KB | 0644 |
|
promise_array.js | File | 5.08 KB | 0644 |
|
promisify.js | File | 11.9 KB | 0644 |
|
props.js | File | 3.04 KB | 0644 |
|
queue.js | File | 1.83 KB | 0644 |
|
race.js | File | 1.22 KB | 0644 |
|
reduce.js | File | 5.01 KB | 0644 |
|
schedule.js | File | 2.1 KB | 0644 |
|
settle.js | File | 1.23 KB | 0644 |
|
some.js | File | 3.87 KB | 0644 |
|
synchronous_inspection.js | File | 2.75 KB | 0644 |
|
thenables.js | File | 2.08 KB | 0644 |
|
timers.js | File | 2.34 KB | 0644 |
|
using.js | File | 7.35 KB | 0644 |
|
util.js | File | 10.28 KB | 0644 |
|