Simulator first commit
This commit is contained in:
5
node_modules/promise/.jshintrc
generated
vendored
Normal file
5
node_modules/promise/.jshintrc
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"asi": true,
|
||||
"node": true,
|
||||
"strict": true
|
||||
}
|
7
node_modules/promise/.npmignore
generated
vendored
Normal file
7
node_modules/promise/.npmignore
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
components
|
||||
node_modules
|
||||
test
|
||||
.gitignore
|
||||
.travis.yml
|
||||
component.json
|
||||
coverage
|
19
node_modules/promise/LICENSE
generated
vendored
Normal file
19
node_modules/promise/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2014 Forbes Lindesay
|
||||
|
||||
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:
|
||||
|
||||
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.
|
231
node_modules/promise/Readme.md
generated
vendored
Normal file
231
node_modules/promise/Readme.md
generated
vendored
Normal file
@ -0,0 +1,231 @@
|
||||
<a href="https://promisesaplus.com/"><img src="https://promisesaplus.com/assets/logo-small.png" align="right" /></a>
|
||||
# promise
|
||||
|
||||
This is a simple implementation of Promises. It is a super set of ES6 Promises designed to have readable, performant code and to provide just the extensions that are absolutely necessary for using promises today.
|
||||
|
||||
For detailed tutorials on its use, see www.promisejs.org
|
||||
|
||||
**N.B.** This promise exposes internals via underscore (`_`) prefixed properties. If you use these, your code will break with each new release.
|
||||
|
||||
[![travis][travis-image]][travis-url]
|
||||
[![dep][dep-image]][dep-url]
|
||||
[![npm][npm-image]][npm-url]
|
||||
[![downloads][downloads-image]][downloads-url]
|
||||
|
||||
[travis-image]: https://img.shields.io/travis/then/promise.svg?style=flat
|
||||
[travis-url]: https://travis-ci.org/then/promise
|
||||
[dep-image]: https://img.shields.io/david/then/promise.svg?style=flat
|
||||
[dep-url]: https://david-dm.org/then/promise
|
||||
[npm-image]: https://img.shields.io/npm/v/promise.svg?style=flat
|
||||
[npm-url]: https://npmjs.org/package/promise
|
||||
[downloads-image]: https://img.shields.io/npm/dm/promise.svg?style=flat
|
||||
[downloads-url]: https://npmjs.org/package/promise
|
||||
|
||||
## Installation
|
||||
|
||||
**Server:**
|
||||
|
||||
$ npm install promise
|
||||
|
||||
**Client:**
|
||||
|
||||
You can use browserify on the client, or use the pre-compiled script that acts as a polyfill.
|
||||
|
||||
```html
|
||||
<script src="https://www.promisejs.org/polyfills/promise-6.1.0.js"></script>
|
||||
```
|
||||
|
||||
Note that the [es5-shim](https://github.com/es-shims/es5-shim) must be loaded before this library to support browsers pre IE9.
|
||||
|
||||
```html
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/3.4.0/es5-shim.min.js"></script>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The example below shows how you can load the promise library (in a way that works on both client and server using node or browserify). It then demonstrates creating a promise from scratch. You simply call `new Promise(fn)`. There is a complete specification for what is returned by this method in [Promises/A+](http://promises-aplus.github.com/promises-spec/).
|
||||
|
||||
```javascript
|
||||
var Promise = require('promise');
|
||||
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
get('http://www.google.com', function (err, res) {
|
||||
if (err) reject(err);
|
||||
else resolve(res);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
If you need [domains](https://iojs.org/api/domain.html) support, you should instead use:
|
||||
|
||||
```js
|
||||
var Promise = require('promise/domains');
|
||||
```
|
||||
|
||||
If you are in an environment that implements `setImmediate` and don't want the optimisations provided by asap, you can use:
|
||||
|
||||
```js
|
||||
var Promise = require('promise/setimmediate');
|
||||
```
|
||||
|
||||
If you only want part of the features, e.g. just a pure ES6 polyfill:
|
||||
|
||||
```js
|
||||
var Promise = require('promise/lib/es6-extensions');
|
||||
// or require('promise/domains/es6-extensions');
|
||||
// or require('promise/setimmediate/es6-extensions');
|
||||
```
|
||||
|
||||
## Unhandled Rejections
|
||||
|
||||
By default, promises silence any unhandled rejections.
|
||||
|
||||
You can enable logging of unhandled ReferenceErrors and TypeErrors via:
|
||||
|
||||
```js
|
||||
require('promise/lib/rejection-tracking').enable();
|
||||
```
|
||||
|
||||
Due to the performance cost, you should only do this during development.
|
||||
|
||||
You can enable logging of all unhandled rejections if you need to debug an exception you think is being swallowed by promises:
|
||||
|
||||
```js
|
||||
require('promise/lib/rejection-tracking').enable(
|
||||
{allRejections: true}
|
||||
);
|
||||
```
|
||||
|
||||
Due to the high probability of false positives, I only recommend using this when debugging specific issues that you think may be being swallowed. For the preferred debugging method, see `Promise#done(onFulfilled, onRejected)`.
|
||||
|
||||
`rejection-tracking.enable(options)` takes the following options:
|
||||
|
||||
- allRejections (`boolean`) - track all exceptions, not just reference errors and type errors. Note that this has a high probability of resulting in false positives if your code loads data optimisticly
|
||||
- whitelist (`Array<ErrorConstructor>`) - this defaults to `[ReferenceError, TypeError]` but you can override it with your own list of error constructors to track.
|
||||
- `onUnhandled(id, error)` and `onHandled(id, error)` - you can use these to provide your own customised display for errors. Note that if possible you should indicate that the error was a false positive if `onHandled` is called. `onHandled` is only called if `onUnhandled` has already been called.
|
||||
|
||||
To reduce the chance of false-positives there is a delay of up to 2 seconds before errors are logged. This means that if you attach an error handler within 2 seconds, it won't be logged as a false positive. ReferenceErrors and TypeErrors are only subject to a 100ms delay due to the higher likelihood that the error is due to programmer error.
|
||||
|
||||
## API
|
||||
|
||||
Before all examples, you will need:
|
||||
|
||||
```js
|
||||
var Promise = require('promise');
|
||||
```
|
||||
|
||||
### new Promise(resolver)
|
||||
|
||||
This creates and returns a new promise. `resolver` must be a function. The `resolver` function is passed two arguments:
|
||||
|
||||
1. `resolve` should be called with a single argument. If it is called with a non-promise value then the promise is fulfilled with that value. If it is called with a promise (A) then the returned promise takes on the state of that new promise (A).
|
||||
2. `reject` should be called with a single argument. The returned promise will be rejected with that argument.
|
||||
|
||||
### Static Functions
|
||||
|
||||
These methods are invoked by calling `Promise.methodName`.
|
||||
|
||||
#### Promise.resolve(value)
|
||||
|
||||
(deprecated aliases: `Promise.from(value)`, `Promise.cast(value)`)
|
||||
|
||||
Converts values and foreign promises into Promises/A+ promises. If you pass it a value then it returns a Promise for that value. If you pass it something that is close to a promise (such as a jQuery attempt at a promise) it returns a Promise that takes on the state of `value` (rejected or fulfilled).
|
||||
|
||||
#### Promise.reject(value)
|
||||
|
||||
Returns a rejected promise with the given value.
|
||||
|
||||
#### Promise.all(array)
|
||||
|
||||
Returns a promise for an array. If it is called with a single argument that `Array.isArray` then this returns a promise for a copy of that array with any promises replaced by their fulfilled values. e.g.
|
||||
|
||||
```js
|
||||
Promise.all([Promise.resolve('a'), 'b', Promise.resolve('c')])
|
||||
.then(function (res) {
|
||||
assert(res[0] === 'a')
|
||||
assert(res[1] === 'b')
|
||||
assert(res[2] === 'c')
|
||||
})
|
||||
```
|
||||
|
||||
#### Promise.denodeify(fn)
|
||||
|
||||
_Non Standard_
|
||||
|
||||
Takes a function which accepts a node style callback and returns a new function that returns a promise instead.
|
||||
|
||||
e.g.
|
||||
|
||||
```javascript
|
||||
var fs = require('fs')
|
||||
|
||||
var read = Promise.denodeify(fs.readFile)
|
||||
var write = Promise.denodeify(fs.writeFile)
|
||||
|
||||
var p = read('foo.json', 'utf8')
|
||||
.then(function (str) {
|
||||
return write('foo.json', JSON.stringify(JSON.parse(str), null, ' '), 'utf8')
|
||||
})
|
||||
```
|
||||
|
||||
#### Promise.nodeify(fn)
|
||||
|
||||
_Non Standard_
|
||||
|
||||
The twin to `denodeify` is useful when you want to export an API that can be used by people who haven't learnt about the brilliance of promises yet.
|
||||
|
||||
```javascript
|
||||
module.exports = Promise.nodeify(awesomeAPI)
|
||||
function awesomeAPI(a, b) {
|
||||
return download(a, b)
|
||||
}
|
||||
```
|
||||
|
||||
If the last argument passed to `module.exports` is a function, then it will be treated like a node.js callback and not parsed on to the child function, otherwise the API will just return a promise.
|
||||
|
||||
### Prototype Methods
|
||||
|
||||
These methods are invoked on a promise instance by calling `myPromise.methodName`
|
||||
|
||||
### Promise#then(onFulfilled, onRejected)
|
||||
|
||||
This method follows the [Promises/A+ spec](http://promises-aplus.github.io/promises-spec/). It explains things very clearly so I recommend you read it.
|
||||
|
||||
Either `onFulfilled` or `onRejected` will be called and they will not be called more than once. They will be passed a single argument and will always be called asynchronously (in the next turn of the event loop).
|
||||
|
||||
If the promise is fulfilled then `onFulfilled` is called. If the promise is rejected then `onRejected` is called.
|
||||
|
||||
The call to `.then` also returns a promise. If the handler that is called returns a promise, the promise returned by `.then` takes on the state of that returned promise. If the handler that is called returns a value that is not a promise, the promise returned by `.then` will be fulfilled with that value. If the handler that is called throws an exception then the promise returned by `.then` is rejected with that exception.
|
||||
|
||||
#### Promise#catch(onRejected)
|
||||
|
||||
Sugar for `Promise#then(null, onRejected)`, to mirror `catch` in synchronous code.
|
||||
|
||||
#### Promise#done(onFulfilled, onRejected)
|
||||
|
||||
_Non Standard_
|
||||
|
||||
The same semantics as `.then` except that it does not return a promise and any exceptions are re-thrown so that they can be logged (crashing the application in non-browser environments)
|
||||
|
||||
#### Promise#nodeify(callback)
|
||||
|
||||
_Non Standard_
|
||||
|
||||
If `callback` is `null` or `undefined` it just returns `this`. If `callback` is a function it is called with rejection reason as the first argument and result as the second argument (as per the node.js convention).
|
||||
|
||||
This lets you write API functions that look like:
|
||||
|
||||
```javascript
|
||||
function awesomeAPI(foo, bar, callback) {
|
||||
return internalAPI(foo, bar)
|
||||
.then(parseResult)
|
||||
.then(null, retryErrors)
|
||||
.nodeify(callback)
|
||||
}
|
||||
```
|
||||
|
||||
People who use typical node.js style callbacks will be able to just pass a callback and get the expected behavior. The enlightened people can not pass a callback and will get awesome promises.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
69
node_modules/promise/build.js
generated
vendored
Normal file
69
node_modules/promise/build.js
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var rimraf = require('rimraf');
|
||||
var acorn = require('acorn');
|
||||
var walk = require('acorn/dist/walk');
|
||||
|
||||
var ids = [];
|
||||
var names = {};
|
||||
|
||||
function getIdFor(name) {
|
||||
if (name in names) return names[name];
|
||||
var id;
|
||||
do {
|
||||
id = '_' + Math.floor(Math.random() * 100);
|
||||
} while (ids.indexOf(id) !== -1)
|
||||
ids.push(id);
|
||||
names[name] = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
function fixup(src) {
|
||||
var ast = acorn.parse(src);
|
||||
src = src.split('');
|
||||
walk.simple(ast, {
|
||||
MemberExpression: function (node) {
|
||||
if (node.computed) return;
|
||||
if (node.property.type !== 'Identifier') return;
|
||||
if (node.property.name[0] !== '_') return;
|
||||
replace(node.property, getIdFor(node.property.name));
|
||||
}
|
||||
});
|
||||
function source(node) {
|
||||
return src.slice(node.start, node.end).join('');
|
||||
}
|
||||
function replace(node, str) {
|
||||
for (var i = node.start; i < node.end; i++) {
|
||||
src[i] = '';
|
||||
}
|
||||
src[node.start] = str;
|
||||
}
|
||||
return src.join('');
|
||||
}
|
||||
rimraf.sync(__dirname + '/lib/');
|
||||
fs.mkdirSync(__dirname + '/lib/');
|
||||
fs.readdirSync(__dirname + '/src').forEach(function (filename) {
|
||||
var src = fs.readFileSync(__dirname + '/src/' + filename, 'utf8');
|
||||
var out = fixup(src);
|
||||
fs.writeFileSync(__dirname + '/lib/' + filename, out);
|
||||
});
|
||||
|
||||
rimraf.sync(__dirname + '/domains/');
|
||||
fs.mkdirSync(__dirname + '/domains/');
|
||||
fs.readdirSync(__dirname + '/src').forEach(function (filename) {
|
||||
var src = fs.readFileSync(__dirname + '/src/' + filename, 'utf8');
|
||||
var out = fixup(src);
|
||||
out = out.replace(/require\(\'asap\/raw\'\)/g, "require('asap')");
|
||||
fs.writeFileSync(__dirname + '/domains/' + filename, out);
|
||||
});
|
||||
|
||||
rimraf.sync(__dirname + '/setimmediate/');
|
||||
fs.mkdirSync(__dirname + '/setimmediate/');
|
||||
fs.readdirSync(__dirname + '/src').forEach(function (filename) {
|
||||
var src = fs.readFileSync(__dirname + '/src/' + filename, 'utf8');
|
||||
var out = fixup(src);
|
||||
out = out.replace(/var asap \= require\(\'([a-z\/]+)\'\);/g, '');
|
||||
out = out.replace(/asap/g, "setImmediate");
|
||||
fs.writeFileSync(__dirname + '/setimmediate/' + filename, out);
|
||||
});
|
5
node_modules/promise/core.js
generated
vendored
Normal file
5
node_modules/promise/core.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./lib/core.js');
|
||||
|
||||
console.error('require("promise/core") is deprecated, use require("promise/lib/core") instead.');
|
213
node_modules/promise/domains/core.js
generated
vendored
Normal file
213
node_modules/promise/domains/core.js
generated
vendored
Normal file
@ -0,0 +1,213 @@
|
||||
'use strict';
|
||||
|
||||
var asap = require('asap');
|
||||
|
||||
function noop() {}
|
||||
|
||||
// States:
|
||||
//
|
||||
// 0 - pending
|
||||
// 1 - fulfilled with _value
|
||||
// 2 - rejected with _value
|
||||
// 3 - adopted the state of another promise, _value
|
||||
//
|
||||
// once the state is no longer pending (0) it is immutable
|
||||
|
||||
// All `_` prefixed properties will be reduced to `_{random number}`
|
||||
// at build time to obfuscate them and discourage their use.
|
||||
// We don't use symbols or Object.defineProperty to fully hide them
|
||||
// because the performance isn't good enough.
|
||||
|
||||
|
||||
// to avoid using try/catch inside critical functions, we
|
||||
// extract them to here.
|
||||
var LAST_ERROR = null;
|
||||
var IS_ERROR = {};
|
||||
function getThen(obj) {
|
||||
try {
|
||||
return obj.then;
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function tryCallOne(fn, a) {
|
||||
try {
|
||||
return fn(a);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
function tryCallTwo(fn, a, b) {
|
||||
try {
|
||||
fn(a, b);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
function Promise(fn) {
|
||||
if (typeof this !== 'object') {
|
||||
throw new TypeError('Promises must be constructed via new');
|
||||
}
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Promise constructor\'s argument is not a function');
|
||||
}
|
||||
this._40 = 0;
|
||||
this._65 = 0;
|
||||
this._55 = null;
|
||||
this._72 = null;
|
||||
if (fn === noop) return;
|
||||
doResolve(fn, this);
|
||||
}
|
||||
Promise._37 = null;
|
||||
Promise._87 = null;
|
||||
Promise._61 = noop;
|
||||
|
||||
Promise.prototype.then = function(onFulfilled, onRejected) {
|
||||
if (this.constructor !== Promise) {
|
||||
return safeThen(this, onFulfilled, onRejected);
|
||||
}
|
||||
var res = new Promise(noop);
|
||||
handle(this, new Handler(onFulfilled, onRejected, res));
|
||||
return res;
|
||||
};
|
||||
|
||||
function safeThen(self, onFulfilled, onRejected) {
|
||||
return new self.constructor(function (resolve, reject) {
|
||||
var res = new Promise(noop);
|
||||
res.then(resolve, reject);
|
||||
handle(self, new Handler(onFulfilled, onRejected, res));
|
||||
});
|
||||
}
|
||||
function handle(self, deferred) {
|
||||
while (self._65 === 3) {
|
||||
self = self._55;
|
||||
}
|
||||
if (Promise._37) {
|
||||
Promise._37(self);
|
||||
}
|
||||
if (self._65 === 0) {
|
||||
if (self._40 === 0) {
|
||||
self._40 = 1;
|
||||
self._72 = deferred;
|
||||
return;
|
||||
}
|
||||
if (self._40 === 1) {
|
||||
self._40 = 2;
|
||||
self._72 = [self._72, deferred];
|
||||
return;
|
||||
}
|
||||
self._72.push(deferred);
|
||||
return;
|
||||
}
|
||||
handleResolved(self, deferred);
|
||||
}
|
||||
|
||||
function handleResolved(self, deferred) {
|
||||
asap(function() {
|
||||
var cb = self._65 === 1 ? deferred.onFulfilled : deferred.onRejected;
|
||||
if (cb === null) {
|
||||
if (self._65 === 1) {
|
||||
resolve(deferred.promise, self._55);
|
||||
} else {
|
||||
reject(deferred.promise, self._55);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var ret = tryCallOne(cb, self._55);
|
||||
if (ret === IS_ERROR) {
|
||||
reject(deferred.promise, LAST_ERROR);
|
||||
} else {
|
||||
resolve(deferred.promise, ret);
|
||||
}
|
||||
});
|
||||
}
|
||||
function resolve(self, newValue) {
|
||||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
||||
if (newValue === self) {
|
||||
return reject(
|
||||
self,
|
||||
new TypeError('A promise cannot be resolved with itself.')
|
||||
);
|
||||
}
|
||||
if (
|
||||
newValue &&
|
||||
(typeof newValue === 'object' || typeof newValue === 'function')
|
||||
) {
|
||||
var then = getThen(newValue);
|
||||
if (then === IS_ERROR) {
|
||||
return reject(self, LAST_ERROR);
|
||||
}
|
||||
if (
|
||||
then === self.then &&
|
||||
newValue instanceof Promise
|
||||
) {
|
||||
self._65 = 3;
|
||||
self._55 = newValue;
|
||||
finale(self);
|
||||
return;
|
||||
} else if (typeof then === 'function') {
|
||||
doResolve(then.bind(newValue), self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self._65 = 1;
|
||||
self._55 = newValue;
|
||||
finale(self);
|
||||
}
|
||||
|
||||
function reject(self, newValue) {
|
||||
self._65 = 2;
|
||||
self._55 = newValue;
|
||||
if (Promise._87) {
|
||||
Promise._87(self, newValue);
|
||||
}
|
||||
finale(self);
|
||||
}
|
||||
function finale(self) {
|
||||
if (self._40 === 1) {
|
||||
handle(self, self._72);
|
||||
self._72 = null;
|
||||
}
|
||||
if (self._40 === 2) {
|
||||
for (var i = 0; i < self._72.length; i++) {
|
||||
handle(self, self._72[i]);
|
||||
}
|
||||
self._72 = null;
|
||||
}
|
||||
}
|
||||
|
||||
function Handler(onFulfilled, onRejected, promise){
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a potentially misbehaving resolver function and make sure
|
||||
* onFulfilled and onRejected are only called once.
|
||||
*
|
||||
* Makes no guarantees about asynchrony.
|
||||
*/
|
||||
function doResolve(fn, promise) {
|
||||
var done = false;
|
||||
var res = tryCallTwo(fn, function (value) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
resolve(promise, value);
|
||||
}, function (reason) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(promise, reason);
|
||||
});
|
||||
if (!done && res === IS_ERROR) {
|
||||
done = true;
|
||||
reject(promise, LAST_ERROR);
|
||||
}
|
||||
}
|
13
node_modules/promise/domains/done.js
generated
vendored
Normal file
13
node_modules/promise/domains/done.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype.done = function (onFulfilled, onRejected) {
|
||||
var self = arguments.length ? this.then.apply(this, arguments) : this;
|
||||
self.then(null, function (err) {
|
||||
setTimeout(function () {
|
||||
throw err;
|
||||
}, 0);
|
||||
});
|
||||
};
|
107
node_modules/promise/domains/es6-extensions.js
generated
vendored
Normal file
107
node_modules/promise/domains/es6-extensions.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
//This file contains the ES6 extensions to the core Promises/A+ API
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
var TRUE = valuePromise(true);
|
||||
var FALSE = valuePromise(false);
|
||||
var NULL = valuePromise(null);
|
||||
var UNDEFINED = valuePromise(undefined);
|
||||
var ZERO = valuePromise(0);
|
||||
var EMPTYSTRING = valuePromise('');
|
||||
|
||||
function valuePromise(value) {
|
||||
var p = new Promise(Promise._61);
|
||||
p._65 = 1;
|
||||
p._55 = value;
|
||||
return p;
|
||||
}
|
||||
Promise.resolve = function (value) {
|
||||
if (value instanceof Promise) return value;
|
||||
|
||||
if (value === null) return NULL;
|
||||
if (value === undefined) return UNDEFINED;
|
||||
if (value === true) return TRUE;
|
||||
if (value === false) return FALSE;
|
||||
if (value === 0) return ZERO;
|
||||
if (value === '') return EMPTYSTRING;
|
||||
|
||||
if (typeof value === 'object' || typeof value === 'function') {
|
||||
try {
|
||||
var then = value.then;
|
||||
if (typeof then === 'function') {
|
||||
return new Promise(then.bind(value));
|
||||
}
|
||||
} catch (ex) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
return valuePromise(value);
|
||||
};
|
||||
|
||||
Promise.all = function (arr) {
|
||||
var args = Array.prototype.slice.call(arr);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (args.length === 0) return resolve([]);
|
||||
var remaining = args.length;
|
||||
function res(i, val) {
|
||||
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
||||
if (val instanceof Promise && val.then === Promise.prototype.then) {
|
||||
while (val._65 === 3) {
|
||||
val = val._55;
|
||||
}
|
||||
if (val._65 === 1) return res(i, val._55);
|
||||
if (val._65 === 2) reject(val._55);
|
||||
val.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
} else {
|
||||
var then = val.then;
|
||||
if (typeof then === 'function') {
|
||||
var p = new Promise(then.bind(val));
|
||||
p.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
args[i] = val;
|
||||
if (--remaining === 0) {
|
||||
resolve(args);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
res(i, args[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (value) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
values.forEach(function(value){
|
||||
Promise.resolve(value).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/* Prototype Methods */
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
16
node_modules/promise/domains/finally.js
generated
vendored
Normal file
16
node_modules/promise/domains/finally.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype['finally'] = function (f) {
|
||||
return this.then(function (value) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
return value;
|
||||
});
|
||||
}, function (err) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
};
|
8
node_modules/promise/domains/index.js
generated
vendored
Normal file
8
node_modules/promise/domains/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./core.js');
|
||||
require('./done.js');
|
||||
require('./finally.js');
|
||||
require('./es6-extensions.js');
|
||||
require('./node-extensions.js');
|
||||
require('./synchronous.js');
|
130
node_modules/promise/domains/node-extensions.js
generated
vendored
Normal file
130
node_modules/promise/domains/node-extensions.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
// This file contains then/promise specific extensions that are only useful
|
||||
// for node.js interop
|
||||
|
||||
var Promise = require('./core.js');
|
||||
var asap = require('asap');
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
Promise.denodeify = function (fn, argumentCount) {
|
||||
if (
|
||||
typeof argumentCount === 'number' && argumentCount !== Infinity
|
||||
) {
|
||||
return denodeifyWithCount(fn, argumentCount);
|
||||
} else {
|
||||
return denodeifyWithoutCount(fn);
|
||||
}
|
||||
};
|
||||
|
||||
var callbackFn = (
|
||||
'function (err, res) {' +
|
||||
'if (err) { rj(err); } else { rs(res); }' +
|
||||
'}'
|
||||
);
|
||||
function denodeifyWithCount(fn, argumentCount) {
|
||||
var args = [];
|
||||
for (var i = 0; i < argumentCount; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var res = fn.call(',
|
||||
['self'].concat(args).concat([callbackFn]).join(','),
|
||||
');',
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
return Function(['Promise', 'fn'], body)(Promise, fn);
|
||||
}
|
||||
function denodeifyWithoutCount(fn) {
|
||||
var fnLength = Math.max(fn.length - 1, 3);
|
||||
var args = [];
|
||||
for (var i = 0; i < fnLength; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'var args;',
|
||||
'var argLength = arguments.length;',
|
||||
'if (arguments.length > ' + fnLength + ') {',
|
||||
'args = new Array(arguments.length + 1);',
|
||||
'for (var i = 0; i < arguments.length; i++) {',
|
||||
'args[i] = arguments[i];',
|
||||
'}',
|
||||
'}',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var cb = ' + callbackFn + ';',
|
||||
'var res;',
|
||||
'switch (argLength) {',
|
||||
args.concat(['extra']).map(function (_, index) {
|
||||
return (
|
||||
'case ' + (index) + ':' +
|
||||
'res = fn.call(' + ['self'].concat(args.slice(0, index)).concat('cb').join(',') + ');' +
|
||||
'break;'
|
||||
);
|
||||
}).join(''),
|
||||
'default:',
|
||||
'args[argLength] = cb;',
|
||||
'res = fn.apply(self, args);',
|
||||
'}',
|
||||
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
|
||||
return Function(
|
||||
['Promise', 'fn'],
|
||||
body
|
||||
)(Promise, fn);
|
||||
}
|
||||
|
||||
Promise.nodeify = function (fn) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var callback =
|
||||
typeof args[args.length - 1] === 'function' ? args.pop() : null;
|
||||
var ctx = this;
|
||||
try {
|
||||
return fn.apply(this, arguments).nodeify(callback, ctx);
|
||||
} catch (ex) {
|
||||
if (callback === null || typeof callback == 'undefined') {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
} else {
|
||||
asap(function () {
|
||||
callback.call(ctx, ex);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype.nodeify = function (callback, ctx) {
|
||||
if (typeof callback != 'function') return this;
|
||||
|
||||
this.then(function (value) {
|
||||
asap(function () {
|
||||
callback.call(ctx, null, value);
|
||||
});
|
||||
}, function (err) {
|
||||
asap(function () {
|
||||
callback.call(ctx, err);
|
||||
});
|
||||
});
|
||||
};
|
113
node_modules/promise/domains/rejection-tracking.js
generated
vendored
Normal file
113
node_modules/promise/domains/rejection-tracking.js
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core');
|
||||
|
||||
var DEFAULT_WHITELIST = [
|
||||
ReferenceError,
|
||||
TypeError,
|
||||
RangeError
|
||||
];
|
||||
|
||||
var enabled = false;
|
||||
exports.disable = disable;
|
||||
function disable() {
|
||||
enabled = false;
|
||||
Promise._37 = null;
|
||||
Promise._87 = null;
|
||||
}
|
||||
|
||||
exports.enable = enable;
|
||||
function enable(options) {
|
||||
options = options || {};
|
||||
if (enabled) disable();
|
||||
enabled = true;
|
||||
var id = 0;
|
||||
var displayId = 0;
|
||||
var rejections = {};
|
||||
Promise._37 = function (promise) {
|
||||
if (
|
||||
promise._65 === 2 && // IS REJECTED
|
||||
rejections[promise._51]
|
||||
) {
|
||||
if (rejections[promise._51].logged) {
|
||||
onHandled(promise._51);
|
||||
} else {
|
||||
clearTimeout(rejections[promise._51].timeout);
|
||||
}
|
||||
delete rejections[promise._51];
|
||||
}
|
||||
};
|
||||
Promise._87 = function (promise, err) {
|
||||
if (promise._40 === 0) { // not yet handled
|
||||
promise._51 = id++;
|
||||
rejections[promise._51] = {
|
||||
displayId: null,
|
||||
error: err,
|
||||
timeout: setTimeout(
|
||||
onUnhandled.bind(null, promise._51),
|
||||
// For reference errors and type errors, this almost always
|
||||
// means the programmer made a mistake, so log them after just
|
||||
// 100ms
|
||||
// otherwise, wait 2 seconds to see if they get handled
|
||||
matchWhitelist(err, DEFAULT_WHITELIST)
|
||||
? 100
|
||||
: 2000
|
||||
),
|
||||
logged: false
|
||||
};
|
||||
}
|
||||
};
|
||||
function onUnhandled(id) {
|
||||
if (
|
||||
options.allRejections ||
|
||||
matchWhitelist(
|
||||
rejections[id].error,
|
||||
options.whitelist || DEFAULT_WHITELIST
|
||||
)
|
||||
) {
|
||||
rejections[id].displayId = displayId++;
|
||||
if (options.onUnhandled) {
|
||||
rejections[id].logged = true;
|
||||
options.onUnhandled(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
} else {
|
||||
rejections[id].logged = true;
|
||||
logError(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
function onHandled(id) {
|
||||
if (rejections[id].logged) {
|
||||
if (options.onHandled) {
|
||||
options.onHandled(rejections[id].displayId, rejections[id].error);
|
||||
} else if (!rejections[id].onUnhandled) {
|
||||
console.warn(
|
||||
'Promise Rejection Handled (id: ' + rejections[id].displayId + '):'
|
||||
);
|
||||
console.warn(
|
||||
' This means you can ignore any previous messages of the form "Possible Unhandled Promise Rejection" with id ' +
|
||||
rejections[id].displayId + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logError(id, error) {
|
||||
console.warn('Possible Unhandled Promise Rejection (id: ' + id + '):');
|
||||
var errStr = (error && (error.stack || error)) + '';
|
||||
errStr.split('\n').forEach(function (line) {
|
||||
console.warn(' ' + line);
|
||||
});
|
||||
}
|
||||
|
||||
function matchWhitelist(error, list) {
|
||||
return list.some(function (cls) {
|
||||
return error instanceof cls;
|
||||
});
|
||||
}
|
62
node_modules/promise/domains/synchronous.js
generated
vendored
Normal file
62
node_modules/promise/domains/synchronous.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.enableSynchronous = function () {
|
||||
Promise.prototype.isPending = function() {
|
||||
return this.getState() == 0;
|
||||
};
|
||||
|
||||
Promise.prototype.isFulfilled = function() {
|
||||
return this.getState() == 1;
|
||||
};
|
||||
|
||||
Promise.prototype.isRejected = function() {
|
||||
return this.getState() == 2;
|
||||
};
|
||||
|
||||
Promise.prototype.getValue = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getValue();
|
||||
}
|
||||
|
||||
if (!this.isFulfilled()) {
|
||||
throw new Error('Cannot get a value of an unfulfilled promise.');
|
||||
}
|
||||
|
||||
return this._55;
|
||||
};
|
||||
|
||||
Promise.prototype.getReason = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getReason();
|
||||
}
|
||||
|
||||
if (!this.isRejected()) {
|
||||
throw new Error('Cannot get a rejection reason of a non-rejected promise.');
|
||||
}
|
||||
|
||||
return this._55;
|
||||
};
|
||||
|
||||
Promise.prototype.getState = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getState();
|
||||
}
|
||||
if (this._65 === -1 || this._65 === -2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this._65;
|
||||
};
|
||||
};
|
||||
|
||||
Promise.disableSynchronous = function() {
|
||||
Promise.prototype.isPending = undefined;
|
||||
Promise.prototype.isFulfilled = undefined;
|
||||
Promise.prototype.isRejected = undefined;
|
||||
Promise.prototype.getValue = undefined;
|
||||
Promise.prototype.getReason = undefined;
|
||||
Promise.prototype.getState = undefined;
|
||||
};
|
256
node_modules/promise/index.d.ts
generated
vendored
Normal file
256
node_modules/promise/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,256 @@
|
||||
interface Thenable<T> {
|
||||
/**
|
||||
* Attaches callbacks for the resolution and/or rejection of the ThenPromise.
|
||||
* @param onfulfilled The callback to execute when the ThenPromise is resolved.
|
||||
* @param onrejected The callback to execute when the ThenPromise is rejected.
|
||||
* @returns A ThenPromise for the completion of which ever callback is executed.
|
||||
*/
|
||||
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | Thenable<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | Thenable<TResult2>) | undefined | null): Thenable<TResult1 | TResult2>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the completion of an asynchronous operation
|
||||
*/
|
||||
interface ThenPromise<T> {
|
||||
/**
|
||||
* Attaches callbacks for the resolution and/or rejection of the ThenPromise.
|
||||
* @param onfulfilled The callback to execute when the ThenPromise is resolved.
|
||||
* @param onrejected The callback to execute when the ThenPromise is rejected.
|
||||
* @returns A ThenPromise for the completion of which ever callback is executed.
|
||||
*/
|
||||
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | Thenable<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | Thenable<TResult2>) | undefined | null): ThenPromise<TResult1 | TResult2>;
|
||||
|
||||
/**
|
||||
* Attaches a callback for only the rejection of the ThenPromise.
|
||||
* @param onrejected The callback to execute when the ThenPromise is rejected.
|
||||
* @returns A ThenPromise for the completion of the callback.
|
||||
*/
|
||||
catch<TResult = never>(onrejected?: ((reason: any) => TResult | Thenable<TResult>) | undefined | null): ThenPromise<T | TResult>;
|
||||
|
||||
// Extensions specific to then/promise
|
||||
|
||||
/**
|
||||
* Attaches callbacks for the resolution and/or rejection of the ThenPromise, without returning a new promise.
|
||||
* @param onfulfilled The callback to execute when the ThenPromise is resolved.
|
||||
* @param onrejected The callback to execute when the ThenPromise is rejected.
|
||||
*/
|
||||
done(onfulfilled?: ((value: T) => any) | undefined | null, onrejected?: ((reason: any) => any) | undefined | null): void;
|
||||
|
||||
|
||||
/**
|
||||
* Calls a node.js style callback. If none is provided, the promise is returned.
|
||||
*/
|
||||
nodeify(callback: void | null): ThenPromise<T>;
|
||||
nodeify(callback: (err: Error, value: T) => void): void;
|
||||
}
|
||||
|
||||
interface ThenPromiseConstructor {
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: ThenPromise<any>;
|
||||
|
||||
/**
|
||||
* Creates a new ThenPromise.
|
||||
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
|
||||
* a resolve callback used resolve the promise with a value or the result of another promise,
|
||||
* and a reject callback used to reject the promise with a provided reason or error.
|
||||
*/
|
||||
new <T>(executor: (resolve: (value?: T | Thenable<T>) => void, reject: (reason?: any) => void) => any): ThenPromise<T>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>, T10 | Thenable<T10>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3, T4, T5, T6>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>]): ThenPromise<[T1, T2, T3, T4, T5, T6]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3, T4, T5>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>]): ThenPromise<[T1, T2, T3, T4, T5]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3, T4>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>]): ThenPromise<[T1, T2, T3, T4]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2, T3>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>]): ThenPromise<[T1, T2, T3]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T1, T2>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>]): ThenPromise<[T1, T2]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any ThenPromise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
all<T>(values: (T | Thenable<T>)[]): ThenPromise<T[]>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>, T10 | Thenable<T10>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3, T4, T5, T6>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3, T4, T5>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>]): ThenPromise<T1 | T2 | T3 | T4 | T5>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3, T4>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>]): ThenPromise<T1 | T2 | T3 | T4>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2, T3>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>]): ThenPromise<T1 | T2 | T3>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T1, T2>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>]): ThenPromise<T1 | T2>;
|
||||
|
||||
/**
|
||||
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new ThenPromise.
|
||||
*/
|
||||
race<T>(values: (T | Thenable<T>)[]): ThenPromise<T>;
|
||||
|
||||
/**
|
||||
* Creates a new rejected promise for the provided reason.
|
||||
* @param reason The reason the promise was rejected.
|
||||
* @returns A new rejected ThenPromise.
|
||||
*/
|
||||
reject(reason: any): ThenPromise<never>;
|
||||
|
||||
/**
|
||||
* Creates a new rejected promise for the provided reason.
|
||||
* @param reason The reason the promise was rejected.
|
||||
* @returns A new rejected ThenPromise.
|
||||
*/
|
||||
reject<T>(reason: any): ThenPromise<T>;
|
||||
|
||||
/**
|
||||
* Creates a new resolved promise for the provided value.
|
||||
* @param value A promise.
|
||||
* @returns A promise whose internal state matches the provided promise.
|
||||
*/
|
||||
resolve<T>(value: T | Thenable<T>): ThenPromise<T>;
|
||||
|
||||
/**
|
||||
* Creates a new resolved promise .
|
||||
* @returns A resolved promise.
|
||||
*/
|
||||
resolve(): ThenPromise<void>;
|
||||
|
||||
// Extensions specific to then/promise
|
||||
|
||||
denodeify: (fn: Function) => (...args: any[]) => ThenPromise<any>;
|
||||
nodeify: (fn: Function) => Function;
|
||||
}
|
||||
|
||||
declare var ThenPromise: ThenPromiseConstructor;
|
||||
|
||||
export = ThenPromise;
|
3
node_modules/promise/index.js
generated
vendored
Normal file
3
node_modules/promise/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./lib')
|
213
node_modules/promise/lib/core.js
generated
vendored
Normal file
213
node_modules/promise/lib/core.js
generated
vendored
Normal file
@ -0,0 +1,213 @@
|
||||
'use strict';
|
||||
|
||||
var asap = require('asap/raw');
|
||||
|
||||
function noop() {}
|
||||
|
||||
// States:
|
||||
//
|
||||
// 0 - pending
|
||||
// 1 - fulfilled with _value
|
||||
// 2 - rejected with _value
|
||||
// 3 - adopted the state of another promise, _value
|
||||
//
|
||||
// once the state is no longer pending (0) it is immutable
|
||||
|
||||
// All `_` prefixed properties will be reduced to `_{random number}`
|
||||
// at build time to obfuscate them and discourage their use.
|
||||
// We don't use symbols or Object.defineProperty to fully hide them
|
||||
// because the performance isn't good enough.
|
||||
|
||||
|
||||
// to avoid using try/catch inside critical functions, we
|
||||
// extract them to here.
|
||||
var LAST_ERROR = null;
|
||||
var IS_ERROR = {};
|
||||
function getThen(obj) {
|
||||
try {
|
||||
return obj.then;
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function tryCallOne(fn, a) {
|
||||
try {
|
||||
return fn(a);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
function tryCallTwo(fn, a, b) {
|
||||
try {
|
||||
fn(a, b);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
function Promise(fn) {
|
||||
if (typeof this !== 'object') {
|
||||
throw new TypeError('Promises must be constructed via new');
|
||||
}
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Promise constructor\'s argument is not a function');
|
||||
}
|
||||
this._40 = 0;
|
||||
this._65 = 0;
|
||||
this._55 = null;
|
||||
this._72 = null;
|
||||
if (fn === noop) return;
|
||||
doResolve(fn, this);
|
||||
}
|
||||
Promise._37 = null;
|
||||
Promise._87 = null;
|
||||
Promise._61 = noop;
|
||||
|
||||
Promise.prototype.then = function(onFulfilled, onRejected) {
|
||||
if (this.constructor !== Promise) {
|
||||
return safeThen(this, onFulfilled, onRejected);
|
||||
}
|
||||
var res = new Promise(noop);
|
||||
handle(this, new Handler(onFulfilled, onRejected, res));
|
||||
return res;
|
||||
};
|
||||
|
||||
function safeThen(self, onFulfilled, onRejected) {
|
||||
return new self.constructor(function (resolve, reject) {
|
||||
var res = new Promise(noop);
|
||||
res.then(resolve, reject);
|
||||
handle(self, new Handler(onFulfilled, onRejected, res));
|
||||
});
|
||||
}
|
||||
function handle(self, deferred) {
|
||||
while (self._65 === 3) {
|
||||
self = self._55;
|
||||
}
|
||||
if (Promise._37) {
|
||||
Promise._37(self);
|
||||
}
|
||||
if (self._65 === 0) {
|
||||
if (self._40 === 0) {
|
||||
self._40 = 1;
|
||||
self._72 = deferred;
|
||||
return;
|
||||
}
|
||||
if (self._40 === 1) {
|
||||
self._40 = 2;
|
||||
self._72 = [self._72, deferred];
|
||||
return;
|
||||
}
|
||||
self._72.push(deferred);
|
||||
return;
|
||||
}
|
||||
handleResolved(self, deferred);
|
||||
}
|
||||
|
||||
function handleResolved(self, deferred) {
|
||||
asap(function() {
|
||||
var cb = self._65 === 1 ? deferred.onFulfilled : deferred.onRejected;
|
||||
if (cb === null) {
|
||||
if (self._65 === 1) {
|
||||
resolve(deferred.promise, self._55);
|
||||
} else {
|
||||
reject(deferred.promise, self._55);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var ret = tryCallOne(cb, self._55);
|
||||
if (ret === IS_ERROR) {
|
||||
reject(deferred.promise, LAST_ERROR);
|
||||
} else {
|
||||
resolve(deferred.promise, ret);
|
||||
}
|
||||
});
|
||||
}
|
||||
function resolve(self, newValue) {
|
||||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
||||
if (newValue === self) {
|
||||
return reject(
|
||||
self,
|
||||
new TypeError('A promise cannot be resolved with itself.')
|
||||
);
|
||||
}
|
||||
if (
|
||||
newValue &&
|
||||
(typeof newValue === 'object' || typeof newValue === 'function')
|
||||
) {
|
||||
var then = getThen(newValue);
|
||||
if (then === IS_ERROR) {
|
||||
return reject(self, LAST_ERROR);
|
||||
}
|
||||
if (
|
||||
then === self.then &&
|
||||
newValue instanceof Promise
|
||||
) {
|
||||
self._65 = 3;
|
||||
self._55 = newValue;
|
||||
finale(self);
|
||||
return;
|
||||
} else if (typeof then === 'function') {
|
||||
doResolve(then.bind(newValue), self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self._65 = 1;
|
||||
self._55 = newValue;
|
||||
finale(self);
|
||||
}
|
||||
|
||||
function reject(self, newValue) {
|
||||
self._65 = 2;
|
||||
self._55 = newValue;
|
||||
if (Promise._87) {
|
||||
Promise._87(self, newValue);
|
||||
}
|
||||
finale(self);
|
||||
}
|
||||
function finale(self) {
|
||||
if (self._40 === 1) {
|
||||
handle(self, self._72);
|
||||
self._72 = null;
|
||||
}
|
||||
if (self._40 === 2) {
|
||||
for (var i = 0; i < self._72.length; i++) {
|
||||
handle(self, self._72[i]);
|
||||
}
|
||||
self._72 = null;
|
||||
}
|
||||
}
|
||||
|
||||
function Handler(onFulfilled, onRejected, promise){
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a potentially misbehaving resolver function and make sure
|
||||
* onFulfilled and onRejected are only called once.
|
||||
*
|
||||
* Makes no guarantees about asynchrony.
|
||||
*/
|
||||
function doResolve(fn, promise) {
|
||||
var done = false;
|
||||
var res = tryCallTwo(fn, function (value) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
resolve(promise, value);
|
||||
}, function (reason) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(promise, reason);
|
||||
});
|
||||
if (!done && res === IS_ERROR) {
|
||||
done = true;
|
||||
reject(promise, LAST_ERROR);
|
||||
}
|
||||
}
|
13
node_modules/promise/lib/done.js
generated
vendored
Normal file
13
node_modules/promise/lib/done.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype.done = function (onFulfilled, onRejected) {
|
||||
var self = arguments.length ? this.then.apply(this, arguments) : this;
|
||||
self.then(null, function (err) {
|
||||
setTimeout(function () {
|
||||
throw err;
|
||||
}, 0);
|
||||
});
|
||||
};
|
107
node_modules/promise/lib/es6-extensions.js
generated
vendored
Normal file
107
node_modules/promise/lib/es6-extensions.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
//This file contains the ES6 extensions to the core Promises/A+ API
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
var TRUE = valuePromise(true);
|
||||
var FALSE = valuePromise(false);
|
||||
var NULL = valuePromise(null);
|
||||
var UNDEFINED = valuePromise(undefined);
|
||||
var ZERO = valuePromise(0);
|
||||
var EMPTYSTRING = valuePromise('');
|
||||
|
||||
function valuePromise(value) {
|
||||
var p = new Promise(Promise._61);
|
||||
p._65 = 1;
|
||||
p._55 = value;
|
||||
return p;
|
||||
}
|
||||
Promise.resolve = function (value) {
|
||||
if (value instanceof Promise) return value;
|
||||
|
||||
if (value === null) return NULL;
|
||||
if (value === undefined) return UNDEFINED;
|
||||
if (value === true) return TRUE;
|
||||
if (value === false) return FALSE;
|
||||
if (value === 0) return ZERO;
|
||||
if (value === '') return EMPTYSTRING;
|
||||
|
||||
if (typeof value === 'object' || typeof value === 'function') {
|
||||
try {
|
||||
var then = value.then;
|
||||
if (typeof then === 'function') {
|
||||
return new Promise(then.bind(value));
|
||||
}
|
||||
} catch (ex) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
return valuePromise(value);
|
||||
};
|
||||
|
||||
Promise.all = function (arr) {
|
||||
var args = Array.prototype.slice.call(arr);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (args.length === 0) return resolve([]);
|
||||
var remaining = args.length;
|
||||
function res(i, val) {
|
||||
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
||||
if (val instanceof Promise && val.then === Promise.prototype.then) {
|
||||
while (val._65 === 3) {
|
||||
val = val._55;
|
||||
}
|
||||
if (val._65 === 1) return res(i, val._55);
|
||||
if (val._65 === 2) reject(val._55);
|
||||
val.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
} else {
|
||||
var then = val.then;
|
||||
if (typeof then === 'function') {
|
||||
var p = new Promise(then.bind(val));
|
||||
p.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
args[i] = val;
|
||||
if (--remaining === 0) {
|
||||
resolve(args);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
res(i, args[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (value) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
values.forEach(function(value){
|
||||
Promise.resolve(value).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/* Prototype Methods */
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
16
node_modules/promise/lib/finally.js
generated
vendored
Normal file
16
node_modules/promise/lib/finally.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype['finally'] = function (f) {
|
||||
return this.then(function (value) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
return value;
|
||||
});
|
||||
}, function (err) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
};
|
8
node_modules/promise/lib/index.js
generated
vendored
Normal file
8
node_modules/promise/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./core.js');
|
||||
require('./done.js');
|
||||
require('./finally.js');
|
||||
require('./es6-extensions.js');
|
||||
require('./node-extensions.js');
|
||||
require('./synchronous.js');
|
130
node_modules/promise/lib/node-extensions.js
generated
vendored
Normal file
130
node_modules/promise/lib/node-extensions.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
// This file contains then/promise specific extensions that are only useful
|
||||
// for node.js interop
|
||||
|
||||
var Promise = require('./core.js');
|
||||
var asap = require('asap');
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
Promise.denodeify = function (fn, argumentCount) {
|
||||
if (
|
||||
typeof argumentCount === 'number' && argumentCount !== Infinity
|
||||
) {
|
||||
return denodeifyWithCount(fn, argumentCount);
|
||||
} else {
|
||||
return denodeifyWithoutCount(fn);
|
||||
}
|
||||
};
|
||||
|
||||
var callbackFn = (
|
||||
'function (err, res) {' +
|
||||
'if (err) { rj(err); } else { rs(res); }' +
|
||||
'}'
|
||||
);
|
||||
function denodeifyWithCount(fn, argumentCount) {
|
||||
var args = [];
|
||||
for (var i = 0; i < argumentCount; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var res = fn.call(',
|
||||
['self'].concat(args).concat([callbackFn]).join(','),
|
||||
');',
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
return Function(['Promise', 'fn'], body)(Promise, fn);
|
||||
}
|
||||
function denodeifyWithoutCount(fn) {
|
||||
var fnLength = Math.max(fn.length - 1, 3);
|
||||
var args = [];
|
||||
for (var i = 0; i < fnLength; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'var args;',
|
||||
'var argLength = arguments.length;',
|
||||
'if (arguments.length > ' + fnLength + ') {',
|
||||
'args = new Array(arguments.length + 1);',
|
||||
'for (var i = 0; i < arguments.length; i++) {',
|
||||
'args[i] = arguments[i];',
|
||||
'}',
|
||||
'}',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var cb = ' + callbackFn + ';',
|
||||
'var res;',
|
||||
'switch (argLength) {',
|
||||
args.concat(['extra']).map(function (_, index) {
|
||||
return (
|
||||
'case ' + (index) + ':' +
|
||||
'res = fn.call(' + ['self'].concat(args.slice(0, index)).concat('cb').join(',') + ');' +
|
||||
'break;'
|
||||
);
|
||||
}).join(''),
|
||||
'default:',
|
||||
'args[argLength] = cb;',
|
||||
'res = fn.apply(self, args);',
|
||||
'}',
|
||||
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
|
||||
return Function(
|
||||
['Promise', 'fn'],
|
||||
body
|
||||
)(Promise, fn);
|
||||
}
|
||||
|
||||
Promise.nodeify = function (fn) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var callback =
|
||||
typeof args[args.length - 1] === 'function' ? args.pop() : null;
|
||||
var ctx = this;
|
||||
try {
|
||||
return fn.apply(this, arguments).nodeify(callback, ctx);
|
||||
} catch (ex) {
|
||||
if (callback === null || typeof callback == 'undefined') {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
} else {
|
||||
asap(function () {
|
||||
callback.call(ctx, ex);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype.nodeify = function (callback, ctx) {
|
||||
if (typeof callback != 'function') return this;
|
||||
|
||||
this.then(function (value) {
|
||||
asap(function () {
|
||||
callback.call(ctx, null, value);
|
||||
});
|
||||
}, function (err) {
|
||||
asap(function () {
|
||||
callback.call(ctx, err);
|
||||
});
|
||||
});
|
||||
};
|
113
node_modules/promise/lib/rejection-tracking.js
generated
vendored
Normal file
113
node_modules/promise/lib/rejection-tracking.js
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core');
|
||||
|
||||
var DEFAULT_WHITELIST = [
|
||||
ReferenceError,
|
||||
TypeError,
|
||||
RangeError
|
||||
];
|
||||
|
||||
var enabled = false;
|
||||
exports.disable = disable;
|
||||
function disable() {
|
||||
enabled = false;
|
||||
Promise._37 = null;
|
||||
Promise._87 = null;
|
||||
}
|
||||
|
||||
exports.enable = enable;
|
||||
function enable(options) {
|
||||
options = options || {};
|
||||
if (enabled) disable();
|
||||
enabled = true;
|
||||
var id = 0;
|
||||
var displayId = 0;
|
||||
var rejections = {};
|
||||
Promise._37 = function (promise) {
|
||||
if (
|
||||
promise._65 === 2 && // IS REJECTED
|
||||
rejections[promise._51]
|
||||
) {
|
||||
if (rejections[promise._51].logged) {
|
||||
onHandled(promise._51);
|
||||
} else {
|
||||
clearTimeout(rejections[promise._51].timeout);
|
||||
}
|
||||
delete rejections[promise._51];
|
||||
}
|
||||
};
|
||||
Promise._87 = function (promise, err) {
|
||||
if (promise._40 === 0) { // not yet handled
|
||||
promise._51 = id++;
|
||||
rejections[promise._51] = {
|
||||
displayId: null,
|
||||
error: err,
|
||||
timeout: setTimeout(
|
||||
onUnhandled.bind(null, promise._51),
|
||||
// For reference errors and type errors, this almost always
|
||||
// means the programmer made a mistake, so log them after just
|
||||
// 100ms
|
||||
// otherwise, wait 2 seconds to see if they get handled
|
||||
matchWhitelist(err, DEFAULT_WHITELIST)
|
||||
? 100
|
||||
: 2000
|
||||
),
|
||||
logged: false
|
||||
};
|
||||
}
|
||||
};
|
||||
function onUnhandled(id) {
|
||||
if (
|
||||
options.allRejections ||
|
||||
matchWhitelist(
|
||||
rejections[id].error,
|
||||
options.whitelist || DEFAULT_WHITELIST
|
||||
)
|
||||
) {
|
||||
rejections[id].displayId = displayId++;
|
||||
if (options.onUnhandled) {
|
||||
rejections[id].logged = true;
|
||||
options.onUnhandled(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
} else {
|
||||
rejections[id].logged = true;
|
||||
logError(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
function onHandled(id) {
|
||||
if (rejections[id].logged) {
|
||||
if (options.onHandled) {
|
||||
options.onHandled(rejections[id].displayId, rejections[id].error);
|
||||
} else if (!rejections[id].onUnhandled) {
|
||||
console.warn(
|
||||
'Promise Rejection Handled (id: ' + rejections[id].displayId + '):'
|
||||
);
|
||||
console.warn(
|
||||
' This means you can ignore any previous messages of the form "Possible Unhandled Promise Rejection" with id ' +
|
||||
rejections[id].displayId + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logError(id, error) {
|
||||
console.warn('Possible Unhandled Promise Rejection (id: ' + id + '):');
|
||||
var errStr = (error && (error.stack || error)) + '';
|
||||
errStr.split('\n').forEach(function (line) {
|
||||
console.warn(' ' + line);
|
||||
});
|
||||
}
|
||||
|
||||
function matchWhitelist(error, list) {
|
||||
return list.some(function (cls) {
|
||||
return error instanceof cls;
|
||||
});
|
||||
}
|
62
node_modules/promise/lib/synchronous.js
generated
vendored
Normal file
62
node_modules/promise/lib/synchronous.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.enableSynchronous = function () {
|
||||
Promise.prototype.isPending = function() {
|
||||
return this.getState() == 0;
|
||||
};
|
||||
|
||||
Promise.prototype.isFulfilled = function() {
|
||||
return this.getState() == 1;
|
||||
};
|
||||
|
||||
Promise.prototype.isRejected = function() {
|
||||
return this.getState() == 2;
|
||||
};
|
||||
|
||||
Promise.prototype.getValue = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getValue();
|
||||
}
|
||||
|
||||
if (!this.isFulfilled()) {
|
||||
throw new Error('Cannot get a value of an unfulfilled promise.');
|
||||
}
|
||||
|
||||
return this._55;
|
||||
};
|
||||
|
||||
Promise.prototype.getReason = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getReason();
|
||||
}
|
||||
|
||||
if (!this.isRejected()) {
|
||||
throw new Error('Cannot get a rejection reason of a non-rejected promise.');
|
||||
}
|
||||
|
||||
return this._55;
|
||||
};
|
||||
|
||||
Promise.prototype.getState = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getState();
|
||||
}
|
||||
if (this._65 === -1 || this._65 === -2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this._65;
|
||||
};
|
||||
};
|
||||
|
||||
Promise.disableSynchronous = function() {
|
||||
Promise.prototype.isPending = undefined;
|
||||
Promise.prototype.isFulfilled = undefined;
|
||||
Promise.prototype.isRejected = undefined;
|
||||
Promise.prototype.getValue = undefined;
|
||||
Promise.prototype.getReason = undefined;
|
||||
Promise.prototype.getState = undefined;
|
||||
};
|
66
node_modules/promise/package.json
generated
vendored
Normal file
66
node_modules/promise/package.json
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"_from": "promise@^7.1.1",
|
||||
"_id": "promise@7.3.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
|
||||
"_location": "/promise",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "promise@^7.1.1",
|
||||
"name": "promise",
|
||||
"escapedName": "promise",
|
||||
"rawSpec": "^7.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^7.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mumble-client"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
|
||||
"_shasum": "064b72602b18f90f29192b8b1bc418ffd1ebd3bf",
|
||||
"_spec": "promise@^7.1.1",
|
||||
"_where": "/home/sergiu/linx-audio-simulator/node_modules/mumble-client",
|
||||
"author": {
|
||||
"name": "ForbesLindesay"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/then/promise/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"asap": "~2.0.3"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Bare bones Promises/A+ implementation",
|
||||
"devDependencies": {
|
||||
"acorn": "^1.0.1",
|
||||
"better-assert": "*",
|
||||
"istanbul": "^0.3.13",
|
||||
"mocha": "*",
|
||||
"promises-aplus-tests": "*",
|
||||
"rimraf": "^2.3.2"
|
||||
},
|
||||
"homepage": "https://github.com/then/promise#readme",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "promise",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/then/promise.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --bail --timeout 200 --slow 99999 -R dot",
|
||||
"prepublish": "node build",
|
||||
"pretest": "node build",
|
||||
"pretest-extensions": "node build",
|
||||
"pretest-memory-leak": "node build",
|
||||
"pretest-resolve": "node build",
|
||||
"test": "mocha --bail --timeout 200 --slow 99999 -R dot && npm run test-memory-leak",
|
||||
"test-extensions": "mocha test/extensions-tests.js --timeout 200 --slow 999999",
|
||||
"test-memory-leak": "node --expose-gc test/memory-leak.js",
|
||||
"test-resolve": "mocha test/resolver-tests.js --timeout 200 --slow 999999"
|
||||
},
|
||||
"version": "7.3.1"
|
||||
}
|
12
node_modules/promise/polyfill-done.js
generated
vendored
Normal file
12
node_modules/promise/polyfill-done.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
// should work in any browser without browserify
|
||||
|
||||
if (typeof Promise.prototype.done !== 'function') {
|
||||
Promise.prototype.done = function (onFulfilled, onRejected) {
|
||||
var self = arguments.length ? this.then.apply(this, arguments) : this
|
||||
self.then(null, function (err) {
|
||||
setTimeout(function () {
|
||||
throw err
|
||||
}, 0)
|
||||
})
|
||||
}
|
||||
}
|
10
node_modules/promise/polyfill.js
generated
vendored
Normal file
10
node_modules/promise/polyfill.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// not "use strict" so we can declare global "Promise"
|
||||
|
||||
var asap = require('asap');
|
||||
|
||||
if (typeof Promise === 'undefined') {
|
||||
Promise = require('./lib/core.js')
|
||||
require('./lib/es6-extensions.js')
|
||||
}
|
||||
|
||||
require('./polyfill-done.js');
|
213
node_modules/promise/setimmediate/core.js
generated
vendored
Normal file
213
node_modules/promise/setimmediate/core.js
generated
vendored
Normal file
@ -0,0 +1,213 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
|
||||
function noop() {}
|
||||
|
||||
// States:
|
||||
//
|
||||
// 0 - pending
|
||||
// 1 - fulfilled with _value
|
||||
// 2 - rejected with _value
|
||||
// 3 - adopted the state of another promise, _value
|
||||
//
|
||||
// once the state is no longer pending (0) it is immutable
|
||||
|
||||
// All `_` prefixed properties will be reduced to `_{random number}`
|
||||
// at build time to obfuscate them and discourage their use.
|
||||
// We don't use symbols or Object.defineProperty to fully hide them
|
||||
// because the performance isn't good enough.
|
||||
|
||||
|
||||
// to avoid using try/catch inside critical functions, we
|
||||
// extract them to here.
|
||||
var LAST_ERROR = null;
|
||||
var IS_ERROR = {};
|
||||
function getThen(obj) {
|
||||
try {
|
||||
return obj.then;
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function tryCallOne(fn, a) {
|
||||
try {
|
||||
return fn(a);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
function tryCallTwo(fn, a, b) {
|
||||
try {
|
||||
fn(a, b);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
function Promise(fn) {
|
||||
if (typeof this !== 'object') {
|
||||
throw new TypeError('Promises must be constructed via new');
|
||||
}
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Promise constructor\'s argument is not a function');
|
||||
}
|
||||
this._40 = 0;
|
||||
this._65 = 0;
|
||||
this._55 = null;
|
||||
this._72 = null;
|
||||
if (fn === noop) return;
|
||||
doResolve(fn, this);
|
||||
}
|
||||
Promise._37 = null;
|
||||
Promise._87 = null;
|
||||
Promise._61 = noop;
|
||||
|
||||
Promise.prototype.then = function(onFulfilled, onRejected) {
|
||||
if (this.constructor !== Promise) {
|
||||
return safeThen(this, onFulfilled, onRejected);
|
||||
}
|
||||
var res = new Promise(noop);
|
||||
handle(this, new Handler(onFulfilled, onRejected, res));
|
||||
return res;
|
||||
};
|
||||
|
||||
function safeThen(self, onFulfilled, onRejected) {
|
||||
return new self.constructor(function (resolve, reject) {
|
||||
var res = new Promise(noop);
|
||||
res.then(resolve, reject);
|
||||
handle(self, new Handler(onFulfilled, onRejected, res));
|
||||
});
|
||||
}
|
||||
function handle(self, deferred) {
|
||||
while (self._65 === 3) {
|
||||
self = self._55;
|
||||
}
|
||||
if (Promise._37) {
|
||||
Promise._37(self);
|
||||
}
|
||||
if (self._65 === 0) {
|
||||
if (self._40 === 0) {
|
||||
self._40 = 1;
|
||||
self._72 = deferred;
|
||||
return;
|
||||
}
|
||||
if (self._40 === 1) {
|
||||
self._40 = 2;
|
||||
self._72 = [self._72, deferred];
|
||||
return;
|
||||
}
|
||||
self._72.push(deferred);
|
||||
return;
|
||||
}
|
||||
handleResolved(self, deferred);
|
||||
}
|
||||
|
||||
function handleResolved(self, deferred) {
|
||||
setImmediate(function() {
|
||||
var cb = self._65 === 1 ? deferred.onFulfilled : deferred.onRejected;
|
||||
if (cb === null) {
|
||||
if (self._65 === 1) {
|
||||
resolve(deferred.promise, self._55);
|
||||
} else {
|
||||
reject(deferred.promise, self._55);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var ret = tryCallOne(cb, self._55);
|
||||
if (ret === IS_ERROR) {
|
||||
reject(deferred.promise, LAST_ERROR);
|
||||
} else {
|
||||
resolve(deferred.promise, ret);
|
||||
}
|
||||
});
|
||||
}
|
||||
function resolve(self, newValue) {
|
||||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
||||
if (newValue === self) {
|
||||
return reject(
|
||||
self,
|
||||
new TypeError('A promise cannot be resolved with itself.')
|
||||
);
|
||||
}
|
||||
if (
|
||||
newValue &&
|
||||
(typeof newValue === 'object' || typeof newValue === 'function')
|
||||
) {
|
||||
var then = getThen(newValue);
|
||||
if (then === IS_ERROR) {
|
||||
return reject(self, LAST_ERROR);
|
||||
}
|
||||
if (
|
||||
then === self.then &&
|
||||
newValue instanceof Promise
|
||||
) {
|
||||
self._65 = 3;
|
||||
self._55 = newValue;
|
||||
finale(self);
|
||||
return;
|
||||
} else if (typeof then === 'function') {
|
||||
doResolve(then.bind(newValue), self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self._65 = 1;
|
||||
self._55 = newValue;
|
||||
finale(self);
|
||||
}
|
||||
|
||||
function reject(self, newValue) {
|
||||
self._65 = 2;
|
||||
self._55 = newValue;
|
||||
if (Promise._87) {
|
||||
Promise._87(self, newValue);
|
||||
}
|
||||
finale(self);
|
||||
}
|
||||
function finale(self) {
|
||||
if (self._40 === 1) {
|
||||
handle(self, self._72);
|
||||
self._72 = null;
|
||||
}
|
||||
if (self._40 === 2) {
|
||||
for (var i = 0; i < self._72.length; i++) {
|
||||
handle(self, self._72[i]);
|
||||
}
|
||||
self._72 = null;
|
||||
}
|
||||
}
|
||||
|
||||
function Handler(onFulfilled, onRejected, promise){
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a potentially misbehaving resolver function and make sure
|
||||
* onFulfilled and onRejected are only called once.
|
||||
*
|
||||
* Makes no guarantees about asynchrony.
|
||||
*/
|
||||
function doResolve(fn, promise) {
|
||||
var done = false;
|
||||
var res = tryCallTwo(fn, function (value) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
resolve(promise, value);
|
||||
}, function (reason) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(promise, reason);
|
||||
});
|
||||
if (!done && res === IS_ERROR) {
|
||||
done = true;
|
||||
reject(promise, LAST_ERROR);
|
||||
}
|
||||
}
|
13
node_modules/promise/setimmediate/done.js
generated
vendored
Normal file
13
node_modules/promise/setimmediate/done.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype.done = function (onFulfilled, onRejected) {
|
||||
var self = arguments.length ? this.then.apply(this, arguments) : this;
|
||||
self.then(null, function (err) {
|
||||
setTimeout(function () {
|
||||
throw err;
|
||||
}, 0);
|
||||
});
|
||||
};
|
107
node_modules/promise/setimmediate/es6-extensions.js
generated
vendored
Normal file
107
node_modules/promise/setimmediate/es6-extensions.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
//This file contains the ES6 extensions to the core Promises/A+ API
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
var TRUE = valuePromise(true);
|
||||
var FALSE = valuePromise(false);
|
||||
var NULL = valuePromise(null);
|
||||
var UNDEFINED = valuePromise(undefined);
|
||||
var ZERO = valuePromise(0);
|
||||
var EMPTYSTRING = valuePromise('');
|
||||
|
||||
function valuePromise(value) {
|
||||
var p = new Promise(Promise._61);
|
||||
p._65 = 1;
|
||||
p._55 = value;
|
||||
return p;
|
||||
}
|
||||
Promise.resolve = function (value) {
|
||||
if (value instanceof Promise) return value;
|
||||
|
||||
if (value === null) return NULL;
|
||||
if (value === undefined) return UNDEFINED;
|
||||
if (value === true) return TRUE;
|
||||
if (value === false) return FALSE;
|
||||
if (value === 0) return ZERO;
|
||||
if (value === '') return EMPTYSTRING;
|
||||
|
||||
if (typeof value === 'object' || typeof value === 'function') {
|
||||
try {
|
||||
var then = value.then;
|
||||
if (typeof then === 'function') {
|
||||
return new Promise(then.bind(value));
|
||||
}
|
||||
} catch (ex) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
return valuePromise(value);
|
||||
};
|
||||
|
||||
Promise.all = function (arr) {
|
||||
var args = Array.prototype.slice.call(arr);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (args.length === 0) return resolve([]);
|
||||
var remaining = args.length;
|
||||
function res(i, val) {
|
||||
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
||||
if (val instanceof Promise && val.then === Promise.prototype.then) {
|
||||
while (val._65 === 3) {
|
||||
val = val._55;
|
||||
}
|
||||
if (val._65 === 1) return res(i, val._55);
|
||||
if (val._65 === 2) reject(val._55);
|
||||
val.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
} else {
|
||||
var then = val.then;
|
||||
if (typeof then === 'function') {
|
||||
var p = new Promise(then.bind(val));
|
||||
p.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
args[i] = val;
|
||||
if (--remaining === 0) {
|
||||
resolve(args);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
res(i, args[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (value) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
values.forEach(function(value){
|
||||
Promise.resolve(value).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/* Prototype Methods */
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
16
node_modules/promise/setimmediate/finally.js
generated
vendored
Normal file
16
node_modules/promise/setimmediate/finally.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype['finally'] = function (f) {
|
||||
return this.then(function (value) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
return value;
|
||||
});
|
||||
}, function (err) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
};
|
8
node_modules/promise/setimmediate/index.js
generated
vendored
Normal file
8
node_modules/promise/setimmediate/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./core.js');
|
||||
require('./done.js');
|
||||
require('./finally.js');
|
||||
require('./es6-extensions.js');
|
||||
require('./node-extensions.js');
|
||||
require('./synchronous.js');
|
130
node_modules/promise/setimmediate/node-extensions.js
generated
vendored
Normal file
130
node_modules/promise/setimmediate/node-extensions.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
// This file contains then/promise specific extensions that are only useful
|
||||
// for node.js interop
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
Promise.denodeify = function (fn, argumentCount) {
|
||||
if (
|
||||
typeof argumentCount === 'number' && argumentCount !== Infinity
|
||||
) {
|
||||
return denodeifyWithCount(fn, argumentCount);
|
||||
} else {
|
||||
return denodeifyWithoutCount(fn);
|
||||
}
|
||||
};
|
||||
|
||||
var callbackFn = (
|
||||
'function (err, res) {' +
|
||||
'if (err) { rj(err); } else { rs(res); }' +
|
||||
'}'
|
||||
);
|
||||
function denodeifyWithCount(fn, argumentCount) {
|
||||
var args = [];
|
||||
for (var i = 0; i < argumentCount; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var res = fn.call(',
|
||||
['self'].concat(args).concat([callbackFn]).join(','),
|
||||
');',
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
return Function(['Promise', 'fn'], body)(Promise, fn);
|
||||
}
|
||||
function denodeifyWithoutCount(fn) {
|
||||
var fnLength = Math.max(fn.length - 1, 3);
|
||||
var args = [];
|
||||
for (var i = 0; i < fnLength; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'var args;',
|
||||
'var argLength = arguments.length;',
|
||||
'if (arguments.length > ' + fnLength + ') {',
|
||||
'args = new Array(arguments.length + 1);',
|
||||
'for (var i = 0; i < arguments.length; i++) {',
|
||||
'args[i] = arguments[i];',
|
||||
'}',
|
||||
'}',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var cb = ' + callbackFn + ';',
|
||||
'var res;',
|
||||
'switch (argLength) {',
|
||||
args.concat(['extra']).map(function (_, index) {
|
||||
return (
|
||||
'case ' + (index) + ':' +
|
||||
'res = fn.call(' + ['self'].concat(args.slice(0, index)).concat('cb').join(',') + ');' +
|
||||
'break;'
|
||||
);
|
||||
}).join(''),
|
||||
'default:',
|
||||
'args[argLength] = cb;',
|
||||
'res = fn.apply(self, args);',
|
||||
'}',
|
||||
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
|
||||
return Function(
|
||||
['Promise', 'fn'],
|
||||
body
|
||||
)(Promise, fn);
|
||||
}
|
||||
|
||||
Promise.nodeify = function (fn) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var callback =
|
||||
typeof args[args.length - 1] === 'function' ? args.pop() : null;
|
||||
var ctx = this;
|
||||
try {
|
||||
return fn.apply(this, arguments).nodeify(callback, ctx);
|
||||
} catch (ex) {
|
||||
if (callback === null || typeof callback == 'undefined') {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
} else {
|
||||
setImmediate(function () {
|
||||
callback.call(ctx, ex);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype.nodeify = function (callback, ctx) {
|
||||
if (typeof callback != 'function') return this;
|
||||
|
||||
this.then(function (value) {
|
||||
setImmediate(function () {
|
||||
callback.call(ctx, null, value);
|
||||
});
|
||||
}, function (err) {
|
||||
setImmediate(function () {
|
||||
callback.call(ctx, err);
|
||||
});
|
||||
});
|
||||
};
|
113
node_modules/promise/setimmediate/rejection-tracking.js
generated
vendored
Normal file
113
node_modules/promise/setimmediate/rejection-tracking.js
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core');
|
||||
|
||||
var DEFAULT_WHITELIST = [
|
||||
ReferenceError,
|
||||
TypeError,
|
||||
RangeError
|
||||
];
|
||||
|
||||
var enabled = false;
|
||||
exports.disable = disable;
|
||||
function disable() {
|
||||
enabled = false;
|
||||
Promise._37 = null;
|
||||
Promise._87 = null;
|
||||
}
|
||||
|
||||
exports.enable = enable;
|
||||
function enable(options) {
|
||||
options = options || {};
|
||||
if (enabled) disable();
|
||||
enabled = true;
|
||||
var id = 0;
|
||||
var displayId = 0;
|
||||
var rejections = {};
|
||||
Promise._37 = function (promise) {
|
||||
if (
|
||||
promise._65 === 2 && // IS REJECTED
|
||||
rejections[promise._51]
|
||||
) {
|
||||
if (rejections[promise._51].logged) {
|
||||
onHandled(promise._51);
|
||||
} else {
|
||||
clearTimeout(rejections[promise._51].timeout);
|
||||
}
|
||||
delete rejections[promise._51];
|
||||
}
|
||||
};
|
||||
Promise._87 = function (promise, err) {
|
||||
if (promise._40 === 0) { // not yet handled
|
||||
promise._51 = id++;
|
||||
rejections[promise._51] = {
|
||||
displayId: null,
|
||||
error: err,
|
||||
timeout: setTimeout(
|
||||
onUnhandled.bind(null, promise._51),
|
||||
// For reference errors and type errors, this almost always
|
||||
// means the programmer made a mistake, so log them after just
|
||||
// 100ms
|
||||
// otherwise, wait 2 seconds to see if they get handled
|
||||
matchWhitelist(err, DEFAULT_WHITELIST)
|
||||
? 100
|
||||
: 2000
|
||||
),
|
||||
logged: false
|
||||
};
|
||||
}
|
||||
};
|
||||
function onUnhandled(id) {
|
||||
if (
|
||||
options.allRejections ||
|
||||
matchWhitelist(
|
||||
rejections[id].error,
|
||||
options.whitelist || DEFAULT_WHITELIST
|
||||
)
|
||||
) {
|
||||
rejections[id].displayId = displayId++;
|
||||
if (options.onUnhandled) {
|
||||
rejections[id].logged = true;
|
||||
options.onUnhandled(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
} else {
|
||||
rejections[id].logged = true;
|
||||
logError(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
function onHandled(id) {
|
||||
if (rejections[id].logged) {
|
||||
if (options.onHandled) {
|
||||
options.onHandled(rejections[id].displayId, rejections[id].error);
|
||||
} else if (!rejections[id].onUnhandled) {
|
||||
console.warn(
|
||||
'Promise Rejection Handled (id: ' + rejections[id].displayId + '):'
|
||||
);
|
||||
console.warn(
|
||||
' This means you can ignore any previous messages of the form "Possible Unhandled Promise Rejection" with id ' +
|
||||
rejections[id].displayId + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logError(id, error) {
|
||||
console.warn('Possible Unhandled Promise Rejection (id: ' + id + '):');
|
||||
var errStr = (error && (error.stack || error)) + '';
|
||||
errStr.split('\n').forEach(function (line) {
|
||||
console.warn(' ' + line);
|
||||
});
|
||||
}
|
||||
|
||||
function matchWhitelist(error, list) {
|
||||
return list.some(function (cls) {
|
||||
return error instanceof cls;
|
||||
});
|
||||
}
|
62
node_modules/promise/setimmediate/synchronous.js
generated
vendored
Normal file
62
node_modules/promise/setimmediate/synchronous.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.enableSynchronous = function () {
|
||||
Promise.prototype.isPending = function() {
|
||||
return this.getState() == 0;
|
||||
};
|
||||
|
||||
Promise.prototype.isFulfilled = function() {
|
||||
return this.getState() == 1;
|
||||
};
|
||||
|
||||
Promise.prototype.isRejected = function() {
|
||||
return this.getState() == 2;
|
||||
};
|
||||
|
||||
Promise.prototype.getValue = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getValue();
|
||||
}
|
||||
|
||||
if (!this.isFulfilled()) {
|
||||
throw new Error('Cannot get a value of an unfulfilled promise.');
|
||||
}
|
||||
|
||||
return this._55;
|
||||
};
|
||||
|
||||
Promise.prototype.getReason = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getReason();
|
||||
}
|
||||
|
||||
if (!this.isRejected()) {
|
||||
throw new Error('Cannot get a rejection reason of a non-rejected promise.');
|
||||
}
|
||||
|
||||
return this._55;
|
||||
};
|
||||
|
||||
Promise.prototype.getState = function () {
|
||||
if (this._65 === 3) {
|
||||
return this._55.getState();
|
||||
}
|
||||
if (this._65 === -1 || this._65 === -2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this._65;
|
||||
};
|
||||
};
|
||||
|
||||
Promise.disableSynchronous = function() {
|
||||
Promise.prototype.isPending = undefined;
|
||||
Promise.prototype.isFulfilled = undefined;
|
||||
Promise.prototype.isRejected = undefined;
|
||||
Promise.prototype.getValue = undefined;
|
||||
Promise.prototype.getReason = undefined;
|
||||
Promise.prototype.getState = undefined;
|
||||
};
|
213
node_modules/promise/src/core.js
generated
vendored
Normal file
213
node_modules/promise/src/core.js
generated
vendored
Normal file
@ -0,0 +1,213 @@
|
||||
'use strict';
|
||||
|
||||
var asap = require('asap/raw');
|
||||
|
||||
function noop() {}
|
||||
|
||||
// States:
|
||||
//
|
||||
// 0 - pending
|
||||
// 1 - fulfilled with _value
|
||||
// 2 - rejected with _value
|
||||
// 3 - adopted the state of another promise, _value
|
||||
//
|
||||
// once the state is no longer pending (0) it is immutable
|
||||
|
||||
// All `_` prefixed properties will be reduced to `_{random number}`
|
||||
// at build time to obfuscate them and discourage their use.
|
||||
// We don't use symbols or Object.defineProperty to fully hide them
|
||||
// because the performance isn't good enough.
|
||||
|
||||
|
||||
// to avoid using try/catch inside critical functions, we
|
||||
// extract them to here.
|
||||
var LAST_ERROR = null;
|
||||
var IS_ERROR = {};
|
||||
function getThen(obj) {
|
||||
try {
|
||||
return obj.then;
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
function tryCallOne(fn, a) {
|
||||
try {
|
||||
return fn(a);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
function tryCallTwo(fn, a, b) {
|
||||
try {
|
||||
fn(a, b);
|
||||
} catch (ex) {
|
||||
LAST_ERROR = ex;
|
||||
return IS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
function Promise(fn) {
|
||||
if (typeof this !== 'object') {
|
||||
throw new TypeError('Promises must be constructed via new');
|
||||
}
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Promise constructor\'s argument is not a function');
|
||||
}
|
||||
this._deferredState = 0;
|
||||
this._state = 0;
|
||||
this._value = null;
|
||||
this._deferreds = null;
|
||||
if (fn === noop) return;
|
||||
doResolve(fn, this);
|
||||
}
|
||||
Promise._onHandle = null;
|
||||
Promise._onReject = null;
|
||||
Promise._noop = noop;
|
||||
|
||||
Promise.prototype.then = function(onFulfilled, onRejected) {
|
||||
if (this.constructor !== Promise) {
|
||||
return safeThen(this, onFulfilled, onRejected);
|
||||
}
|
||||
var res = new Promise(noop);
|
||||
handle(this, new Handler(onFulfilled, onRejected, res));
|
||||
return res;
|
||||
};
|
||||
|
||||
function safeThen(self, onFulfilled, onRejected) {
|
||||
return new self.constructor(function (resolve, reject) {
|
||||
var res = new Promise(noop);
|
||||
res.then(resolve, reject);
|
||||
handle(self, new Handler(onFulfilled, onRejected, res));
|
||||
});
|
||||
}
|
||||
function handle(self, deferred) {
|
||||
while (self._state === 3) {
|
||||
self = self._value;
|
||||
}
|
||||
if (Promise._onHandle) {
|
||||
Promise._onHandle(self);
|
||||
}
|
||||
if (self._state === 0) {
|
||||
if (self._deferredState === 0) {
|
||||
self._deferredState = 1;
|
||||
self._deferreds = deferred;
|
||||
return;
|
||||
}
|
||||
if (self._deferredState === 1) {
|
||||
self._deferredState = 2;
|
||||
self._deferreds = [self._deferreds, deferred];
|
||||
return;
|
||||
}
|
||||
self._deferreds.push(deferred);
|
||||
return;
|
||||
}
|
||||
handleResolved(self, deferred);
|
||||
}
|
||||
|
||||
function handleResolved(self, deferred) {
|
||||
asap(function() {
|
||||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
|
||||
if (cb === null) {
|
||||
if (self._state === 1) {
|
||||
resolve(deferred.promise, self._value);
|
||||
} else {
|
||||
reject(deferred.promise, self._value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var ret = tryCallOne(cb, self._value);
|
||||
if (ret === IS_ERROR) {
|
||||
reject(deferred.promise, LAST_ERROR);
|
||||
} else {
|
||||
resolve(deferred.promise, ret);
|
||||
}
|
||||
});
|
||||
}
|
||||
function resolve(self, newValue) {
|
||||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
||||
if (newValue === self) {
|
||||
return reject(
|
||||
self,
|
||||
new TypeError('A promise cannot be resolved with itself.')
|
||||
);
|
||||
}
|
||||
if (
|
||||
newValue &&
|
||||
(typeof newValue === 'object' || typeof newValue === 'function')
|
||||
) {
|
||||
var then = getThen(newValue);
|
||||
if (then === IS_ERROR) {
|
||||
return reject(self, LAST_ERROR);
|
||||
}
|
||||
if (
|
||||
then === self.then &&
|
||||
newValue instanceof Promise
|
||||
) {
|
||||
self._state = 3;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
return;
|
||||
} else if (typeof then === 'function') {
|
||||
doResolve(then.bind(newValue), self);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self._state = 1;
|
||||
self._value = newValue;
|
||||
finale(self);
|
||||
}
|
||||
|
||||
function reject(self, newValue) {
|
||||
self._state = 2;
|
||||
self._value = newValue;
|
||||
if (Promise._onReject) {
|
||||
Promise._onReject(self, newValue);
|
||||
}
|
||||
finale(self);
|
||||
}
|
||||
function finale(self) {
|
||||
if (self._deferredState === 1) {
|
||||
handle(self, self._deferreds);
|
||||
self._deferreds = null;
|
||||
}
|
||||
if (self._deferredState === 2) {
|
||||
for (var i = 0; i < self._deferreds.length; i++) {
|
||||
handle(self, self._deferreds[i]);
|
||||
}
|
||||
self._deferreds = null;
|
||||
}
|
||||
}
|
||||
|
||||
function Handler(onFulfilled, onRejected, promise){
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a potentially misbehaving resolver function and make sure
|
||||
* onFulfilled and onRejected are only called once.
|
||||
*
|
||||
* Makes no guarantees about asynchrony.
|
||||
*/
|
||||
function doResolve(fn, promise) {
|
||||
var done = false;
|
||||
var res = tryCallTwo(fn, function (value) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
resolve(promise, value);
|
||||
}, function (reason) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
reject(promise, reason);
|
||||
});
|
||||
if (!done && res === IS_ERROR) {
|
||||
done = true;
|
||||
reject(promise, LAST_ERROR);
|
||||
}
|
||||
}
|
13
node_modules/promise/src/done.js
generated
vendored
Normal file
13
node_modules/promise/src/done.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype.done = function (onFulfilled, onRejected) {
|
||||
var self = arguments.length ? this.then.apply(this, arguments) : this;
|
||||
self.then(null, function (err) {
|
||||
setTimeout(function () {
|
||||
throw err;
|
||||
}, 0);
|
||||
});
|
||||
};
|
107
node_modules/promise/src/es6-extensions.js
generated
vendored
Normal file
107
node_modules/promise/src/es6-extensions.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
//This file contains the ES6 extensions to the core Promises/A+ API
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
var TRUE = valuePromise(true);
|
||||
var FALSE = valuePromise(false);
|
||||
var NULL = valuePromise(null);
|
||||
var UNDEFINED = valuePromise(undefined);
|
||||
var ZERO = valuePromise(0);
|
||||
var EMPTYSTRING = valuePromise('');
|
||||
|
||||
function valuePromise(value) {
|
||||
var p = new Promise(Promise._noop);
|
||||
p._state = 1;
|
||||
p._value = value;
|
||||
return p;
|
||||
}
|
||||
Promise.resolve = function (value) {
|
||||
if (value instanceof Promise) return value;
|
||||
|
||||
if (value === null) return NULL;
|
||||
if (value === undefined) return UNDEFINED;
|
||||
if (value === true) return TRUE;
|
||||
if (value === false) return FALSE;
|
||||
if (value === 0) return ZERO;
|
||||
if (value === '') return EMPTYSTRING;
|
||||
|
||||
if (typeof value === 'object' || typeof value === 'function') {
|
||||
try {
|
||||
var then = value.then;
|
||||
if (typeof then === 'function') {
|
||||
return new Promise(then.bind(value));
|
||||
}
|
||||
} catch (ex) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
return valuePromise(value);
|
||||
};
|
||||
|
||||
Promise.all = function (arr) {
|
||||
var args = Array.prototype.slice.call(arr);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (args.length === 0) return resolve([]);
|
||||
var remaining = args.length;
|
||||
function res(i, val) {
|
||||
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
||||
if (val instanceof Promise && val.then === Promise.prototype.then) {
|
||||
while (val._state === 3) {
|
||||
val = val._value;
|
||||
}
|
||||
if (val._state === 1) return res(i, val._value);
|
||||
if (val._state === 2) reject(val._value);
|
||||
val.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
} else {
|
||||
var then = val.then;
|
||||
if (typeof then === 'function') {
|
||||
var p = new Promise(then.bind(val));
|
||||
p.then(function (val) {
|
||||
res(i, val);
|
||||
}, reject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
args[i] = val;
|
||||
if (--remaining === 0) {
|
||||
resolve(args);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
res(i, args[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (value) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
values.forEach(function(value){
|
||||
Promise.resolve(value).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/* Prototype Methods */
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
16
node_modules/promise/src/finally.js
generated
vendored
Normal file
16
node_modules/promise/src/finally.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.prototype['finally'] = function (f) {
|
||||
return this.then(function (value) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
return value;
|
||||
});
|
||||
}, function (err) {
|
||||
return Promise.resolve(f()).then(function () {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
};
|
8
node_modules/promise/src/index.js
generated
vendored
Normal file
8
node_modules/promise/src/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./core.js');
|
||||
require('./done.js');
|
||||
require('./finally.js');
|
||||
require('./es6-extensions.js');
|
||||
require('./node-extensions.js');
|
||||
require('./synchronous.js');
|
130
node_modules/promise/src/node-extensions.js
generated
vendored
Normal file
130
node_modules/promise/src/node-extensions.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
// This file contains then/promise specific extensions that are only useful
|
||||
// for node.js interop
|
||||
|
||||
var Promise = require('./core.js');
|
||||
var asap = require('asap');
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
/* Static Functions */
|
||||
|
||||
Promise.denodeify = function (fn, argumentCount) {
|
||||
if (
|
||||
typeof argumentCount === 'number' && argumentCount !== Infinity
|
||||
) {
|
||||
return denodeifyWithCount(fn, argumentCount);
|
||||
} else {
|
||||
return denodeifyWithoutCount(fn);
|
||||
}
|
||||
};
|
||||
|
||||
var callbackFn = (
|
||||
'function (err, res) {' +
|
||||
'if (err) { rj(err); } else { rs(res); }' +
|
||||
'}'
|
||||
);
|
||||
function denodeifyWithCount(fn, argumentCount) {
|
||||
var args = [];
|
||||
for (var i = 0; i < argumentCount; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var res = fn.call(',
|
||||
['self'].concat(args).concat([callbackFn]).join(','),
|
||||
');',
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
return Function(['Promise', 'fn'], body)(Promise, fn);
|
||||
}
|
||||
function denodeifyWithoutCount(fn) {
|
||||
var fnLength = Math.max(fn.length - 1, 3);
|
||||
var args = [];
|
||||
for (var i = 0; i < fnLength; i++) {
|
||||
args.push('a' + i);
|
||||
}
|
||||
var body = [
|
||||
'return function (' + args.join(',') + ') {',
|
||||
'var self = this;',
|
||||
'var args;',
|
||||
'var argLength = arguments.length;',
|
||||
'if (arguments.length > ' + fnLength + ') {',
|
||||
'args = new Array(arguments.length + 1);',
|
||||
'for (var i = 0; i < arguments.length; i++) {',
|
||||
'args[i] = arguments[i];',
|
||||
'}',
|
||||
'}',
|
||||
'return new Promise(function (rs, rj) {',
|
||||
'var cb = ' + callbackFn + ';',
|
||||
'var res;',
|
||||
'switch (argLength) {',
|
||||
args.concat(['extra']).map(function (_, index) {
|
||||
return (
|
||||
'case ' + (index) + ':' +
|
||||
'res = fn.call(' + ['self'].concat(args.slice(0, index)).concat('cb').join(',') + ');' +
|
||||
'break;'
|
||||
);
|
||||
}).join(''),
|
||||
'default:',
|
||||
'args[argLength] = cb;',
|
||||
'res = fn.apply(self, args);',
|
||||
'}',
|
||||
|
||||
'if (res &&',
|
||||
'(typeof res === "object" || typeof res === "function") &&',
|
||||
'typeof res.then === "function"',
|
||||
') {rs(res);}',
|
||||
'});',
|
||||
'};'
|
||||
].join('');
|
||||
|
||||
return Function(
|
||||
['Promise', 'fn'],
|
||||
body
|
||||
)(Promise, fn);
|
||||
}
|
||||
|
||||
Promise.nodeify = function (fn) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var callback =
|
||||
typeof args[args.length - 1] === 'function' ? args.pop() : null;
|
||||
var ctx = this;
|
||||
try {
|
||||
return fn.apply(this, arguments).nodeify(callback, ctx);
|
||||
} catch (ex) {
|
||||
if (callback === null || typeof callback == 'undefined') {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(ex);
|
||||
});
|
||||
} else {
|
||||
asap(function () {
|
||||
callback.call(ctx, ex);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Promise.prototype.nodeify = function (callback, ctx) {
|
||||
if (typeof callback != 'function') return this;
|
||||
|
||||
this.then(function (value) {
|
||||
asap(function () {
|
||||
callback.call(ctx, null, value);
|
||||
});
|
||||
}, function (err) {
|
||||
asap(function () {
|
||||
callback.call(ctx, err);
|
||||
});
|
||||
});
|
||||
};
|
113
node_modules/promise/src/rejection-tracking.js
generated
vendored
Normal file
113
node_modules/promise/src/rejection-tracking.js
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core');
|
||||
|
||||
var DEFAULT_WHITELIST = [
|
||||
ReferenceError,
|
||||
TypeError,
|
||||
RangeError
|
||||
];
|
||||
|
||||
var enabled = false;
|
||||
exports.disable = disable;
|
||||
function disable() {
|
||||
enabled = false;
|
||||
Promise._onHandle = null;
|
||||
Promise._onReject = null;
|
||||
}
|
||||
|
||||
exports.enable = enable;
|
||||
function enable(options) {
|
||||
options = options || {};
|
||||
if (enabled) disable();
|
||||
enabled = true;
|
||||
var id = 0;
|
||||
var displayId = 0;
|
||||
var rejections = {};
|
||||
Promise._onHandle = function (promise) {
|
||||
if (
|
||||
promise._state === 2 && // IS REJECTED
|
||||
rejections[promise._rejectionId]
|
||||
) {
|
||||
if (rejections[promise._rejectionId].logged) {
|
||||
onHandled(promise._rejectionId);
|
||||
} else {
|
||||
clearTimeout(rejections[promise._rejectionId].timeout);
|
||||
}
|
||||
delete rejections[promise._rejectionId];
|
||||
}
|
||||
};
|
||||
Promise._onReject = function (promise, err) {
|
||||
if (promise._deferredState === 0) { // not yet handled
|
||||
promise._rejectionId = id++;
|
||||
rejections[promise._rejectionId] = {
|
||||
displayId: null,
|
||||
error: err,
|
||||
timeout: setTimeout(
|
||||
onUnhandled.bind(null, promise._rejectionId),
|
||||
// For reference errors and type errors, this almost always
|
||||
// means the programmer made a mistake, so log them after just
|
||||
// 100ms
|
||||
// otherwise, wait 2 seconds to see if they get handled
|
||||
matchWhitelist(err, DEFAULT_WHITELIST)
|
||||
? 100
|
||||
: 2000
|
||||
),
|
||||
logged: false
|
||||
};
|
||||
}
|
||||
};
|
||||
function onUnhandled(id) {
|
||||
if (
|
||||
options.allRejections ||
|
||||
matchWhitelist(
|
||||
rejections[id].error,
|
||||
options.whitelist || DEFAULT_WHITELIST
|
||||
)
|
||||
) {
|
||||
rejections[id].displayId = displayId++;
|
||||
if (options.onUnhandled) {
|
||||
rejections[id].logged = true;
|
||||
options.onUnhandled(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
} else {
|
||||
rejections[id].logged = true;
|
||||
logError(
|
||||
rejections[id].displayId,
|
||||
rejections[id].error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
function onHandled(id) {
|
||||
if (rejections[id].logged) {
|
||||
if (options.onHandled) {
|
||||
options.onHandled(rejections[id].displayId, rejections[id].error);
|
||||
} else if (!rejections[id].onUnhandled) {
|
||||
console.warn(
|
||||
'Promise Rejection Handled (id: ' + rejections[id].displayId + '):'
|
||||
);
|
||||
console.warn(
|
||||
' This means you can ignore any previous messages of the form "Possible Unhandled Promise Rejection" with id ' +
|
||||
rejections[id].displayId + '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logError(id, error) {
|
||||
console.warn('Possible Unhandled Promise Rejection (id: ' + id + '):');
|
||||
var errStr = (error && (error.stack || error)) + '';
|
||||
errStr.split('\n').forEach(function (line) {
|
||||
console.warn(' ' + line);
|
||||
});
|
||||
}
|
||||
|
||||
function matchWhitelist(error, list) {
|
||||
return list.some(function (cls) {
|
||||
return error instanceof cls;
|
||||
});
|
||||
}
|
62
node_modules/promise/src/synchronous.js
generated
vendored
Normal file
62
node_modules/promise/src/synchronous.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
var Promise = require('./core.js');
|
||||
|
||||
module.exports = Promise;
|
||||
Promise.enableSynchronous = function () {
|
||||
Promise.prototype.isPending = function() {
|
||||
return this.getState() == 0;
|
||||
};
|
||||
|
||||
Promise.prototype.isFulfilled = function() {
|
||||
return this.getState() == 1;
|
||||
};
|
||||
|
||||
Promise.prototype.isRejected = function() {
|
||||
return this.getState() == 2;
|
||||
};
|
||||
|
||||
Promise.prototype.getValue = function () {
|
||||
if (this._state === 3) {
|
||||
return this._value.getValue();
|
||||
}
|
||||
|
||||
if (!this.isFulfilled()) {
|
||||
throw new Error('Cannot get a value of an unfulfilled promise.');
|
||||
}
|
||||
|
||||
return this._value;
|
||||
};
|
||||
|
||||
Promise.prototype.getReason = function () {
|
||||
if (this._state === 3) {
|
||||
return this._value.getReason();
|
||||
}
|
||||
|
||||
if (!this.isRejected()) {
|
||||
throw new Error('Cannot get a rejection reason of a non-rejected promise.');
|
||||
}
|
||||
|
||||
return this._value;
|
||||
};
|
||||
|
||||
Promise.prototype.getState = function () {
|
||||
if (this._state === 3) {
|
||||
return this._value.getState();
|
||||
}
|
||||
if (this._state === -1 || this._state === -2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this._state;
|
||||
};
|
||||
};
|
||||
|
||||
Promise.disableSynchronous = function() {
|
||||
Promise.prototype.isPending = undefined;
|
||||
Promise.prototype.isFulfilled = undefined;
|
||||
Promise.prototype.isRejected = undefined;
|
||||
Promise.prototype.getValue = undefined;
|
||||
Promise.prototype.getReason = undefined;
|
||||
Promise.prototype.getState = undefined;
|
||||
};
|
Reference in New Issue
Block a user