diff options
Diffstat (limited to 'node_modules/promise')
43 files changed, 0 insertions, 3324 deletions
diff --git a/node_modules/promise/.jshintrc b/node_modules/promise/.jshintrc deleted file mode 100644 index 47c256f0f..000000000 --- a/node_modules/promise/.jshintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "asi": true, - "node": true, - "strict": true -} diff --git a/node_modules/promise/LICENSE b/node_modules/promise/LICENSE deleted file mode 100644 index 7a1f76364..000000000 --- a/node_modules/promise/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -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. diff --git a/node_modules/promise/Readme.md b/node_modules/promise/Readme.md deleted file mode 100644 index 12a767db0..000000000 --- a/node_modules/promise/Readme.md +++ /dev/null @@ -1,231 +0,0 @@ -<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://nodejs.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 diff --git a/node_modules/promise/build.js b/node_modules/promise/build.js deleted file mode 100644 index 99947d1fe..000000000 --- a/node_modules/promise/build.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var rimraf = require('rimraf'); -var acorn = require('acorn'); -var walk = require('acorn/dist/walk'); -var crypto = require('crypto'); - -var shasum = crypto.createHash('sha512'); -fs.readdirSync(__dirname + '/src').sort().forEach(function (filename) { - shasum.update(fs.readFileSync(__dirname + '/src/' + filename, 'utf8')); -}); - -const names = {}; -const characterSet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; -let i = characterSet.indexOf(shasum.digest('base64').replace(/[^0-9a-zA-Z]/g, '')[0]); -function getIdFor(name) { - if (names[name]) return names[name]; - return names[name] = '_' + characterSet[i++ % characterSet.length] -} - -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 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); -}); diff --git a/node_modules/promise/core.js b/node_modules/promise/core.js deleted file mode 100644 index 5f332a20e..000000000 --- a/node_modules/promise/core.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports = require('./lib/core.js'); - -console.error('require("promise/core") is deprecated, use require("promise/lib/core") instead.'); diff --git a/node_modules/promise/domains/core.js b/node_modules/promise/domains/core.js deleted file mode 100644 index e773536d7..000000000 --- a/node_modules/promise/domains/core.js +++ /dev/null @@ -1,213 +0,0 @@ -'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._h = 0; - this._i = 0; - this._j = null; - this._k = null; - if (fn === noop) return; - doResolve(fn, this); -} -Promise._l = null; -Promise._m = null; -Promise._n = 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._i === 3) { - self = self._j; - } - if (Promise._l) { - Promise._l(self); - } - if (self._i === 0) { - if (self._h === 0) { - self._h = 1; - self._k = deferred; - return; - } - if (self._h === 1) { - self._h = 2; - self._k = [self._k, deferred]; - return; - } - self._k.push(deferred); - return; - } - handleResolved(self, deferred); -} - -function handleResolved(self, deferred) { - asap(function() { - var cb = self._i === 1 ? deferred.onFulfilled : deferred.onRejected; - if (cb === null) { - if (self._i === 1) { - resolve(deferred.promise, self._j); - } else { - reject(deferred.promise, self._j); - } - return; - } - var ret = tryCallOne(cb, self._j); - 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._i = 3; - self._j = newValue; - finale(self); - return; - } else if (typeof then === 'function') { - doResolve(then.bind(newValue), self); - return; - } - } - self._i = 1; - self._j = newValue; - finale(self); -} - -function reject(self, newValue) { - self._i = 2; - self._j = newValue; - if (Promise._m) { - Promise._m(self, newValue); - } - finale(self); -} -function finale(self) { - if (self._h === 1) { - handle(self, self._k); - self._k = null; - } - if (self._h === 2) { - for (var i = 0; i < self._k.length; i++) { - handle(self, self._k[i]); - } - self._k = 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); - } -} diff --git a/node_modules/promise/domains/done.js b/node_modules/promise/domains/done.js deleted file mode 100644 index f879317d0..000000000 --- a/node_modules/promise/domains/done.js +++ /dev/null @@ -1,13 +0,0 @@ -'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); - }); -}; diff --git a/node_modules/promise/domains/es6-extensions.js b/node_modules/promise/domains/es6-extensions.js deleted file mode 100644 index 5046e2367..000000000 --- a/node_modules/promise/domains/es6-extensions.js +++ /dev/null @@ -1,107 +0,0 @@ -'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._n); - p._i = 1; - p._j = 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._i === 3) { - val = val._j; - } - if (val._i === 1) return res(i, val._j); - if (val._i === 2) reject(val._j); - 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); -}; diff --git a/node_modules/promise/domains/finally.js b/node_modules/promise/domains/finally.js deleted file mode 100644 index 3f8a6b7a1..000000000 --- a/node_modules/promise/domains/finally.js +++ /dev/null @@ -1,16 +0,0 @@ -'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; - }); - }); -}; diff --git a/node_modules/promise/domains/index.js b/node_modules/promise/domains/index.js deleted file mode 100644 index 6e674f387..000000000 --- a/node_modules/promise/domains/index.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -module.exports = require('./core.js'); -require('./done.js'); -require('./finally.js'); -require('./es6-extensions.js'); -require('./node-extensions.js'); -require('./synchronous.js'); diff --git a/node_modules/promise/domains/node-extensions.js b/node_modules/promise/domains/node-extensions.js deleted file mode 100644 index 157cddc2b..000000000 --- a/node_modules/promise/domains/node-extensions.js +++ /dev/null @@ -1,130 +0,0 @@ -'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); - }); - }); -}; diff --git a/node_modules/promise/domains/rejection-tracking.js b/node_modules/promise/domains/rejection-tracking.js deleted file mode 100644 index 56e4bd669..000000000 --- a/node_modules/promise/domains/rejection-tracking.js +++ /dev/null @@ -1,113 +0,0 @@ -'use strict'; - -var Promise = require('./core'); - -var DEFAULT_WHITELIST = [ - ReferenceError, - TypeError, - RangeError -]; - -var enabled = false; -exports.disable = disable; -function disable() { - enabled = false; - Promise._l = null; - Promise._m = null; -} - -exports.enable = enable; -function enable(options) { - options = options || {}; - if (enabled) disable(); - enabled = true; - var id = 0; - var displayId = 0; - var rejections = {}; - Promise._l = function (promise) { - if ( - promise._i === 2 && // IS REJECTED - rejections[promise._o] - ) { - if (rejections[promise._o].logged) { - onHandled(promise._o); - } else { - clearTimeout(rejections[promise._o].timeout); - } - delete rejections[promise._o]; - } - }; - Promise._m = function (promise, err) { - if (promise._h === 0) { // not yet handled - promise._o = id++; - rejections[promise._o] = { - displayId: null, - error: err, - timeout: setTimeout( - onUnhandled.bind(null, promise._o), - // 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; - }); -}
\ No newline at end of file diff --git a/node_modules/promise/domains/synchronous.js b/node_modules/promise/domains/synchronous.js deleted file mode 100644 index 79f4eeee9..000000000 --- a/node_modules/promise/domains/synchronous.js +++ /dev/null @@ -1,62 +0,0 @@ -'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._i === 3) { - return this._j.getValue(); - } - - if (!this.isFulfilled()) { - throw new Error('Cannot get a value of an unfulfilled promise.'); - } - - return this._j; - }; - - Promise.prototype.getReason = function () { - if (this._i === 3) { - return this._j.getReason(); - } - - if (!this.isRejected()) { - throw new Error('Cannot get a rejection reason of a non-rejected promise.'); - } - - return this._j; - }; - - Promise.prototype.getState = function () { - if (this._i === 3) { - return this._j.getState(); - } - if (this._i === -1 || this._i === -2) { - return 0; - } - - return this._i; - }; -}; - -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; -}; diff --git a/node_modules/promise/index.d.ts b/node_modules/promise/index.d.ts deleted file mode 100644 index e83d65f3c..000000000 --- a/node_modules/promise/index.d.ts +++ /dev/null @@ -1,246 +0,0 @@ -/** - * Represents the completion of an asynchronous operation - */ -interface ThenPromise<T> extends Promise<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 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<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 | PromiseLike<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 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<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 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<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 | PromiseLike<T1>, T2 | PromiseLike<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 | PromiseLike<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 | PromiseLike<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;
\ No newline at end of file diff --git a/node_modules/promise/index.js b/node_modules/promise/index.js deleted file mode 100644 index 1c38e467c..000000000 --- a/node_modules/promise/index.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -module.exports = require('./lib') diff --git a/node_modules/promise/index.js.flow b/node_modules/promise/index.js.flow deleted file mode 100644 index 78db68ccd..000000000 --- a/node_modules/promise/index.js.flow +++ /dev/null @@ -1,44 +0,0 @@ -// @flow - -declare class ThenPromise<+R> extends Promise<R> { - constructor(callback: ( - resolve: (result: Promise<R> | R) => void, - reject: (error: any) => void - ) => mixed): void; - - then<U>( - onFulfill?: (value: R) => Promise<U> | U, - onReject?: (error: any) => Promise<U> | U - ): ThenPromise<U>; - - catch<U>( - onReject?: (error: any) => Promise<U> | U - ): ThenPromise<R | U>; - - // 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: R) => any, onrejected?: (reason: any) => any): void; - - - /** - * Calls a node.js style callback. If none is provided, the promise is returned. - */ - nodeify(callback: void | null): ThenPromise<R>; - nodeify(callback: (err: Error, value: R) => void): void; - - static resolve<T>(object: Promise<T> | T): ThenPromise<T>; - static reject<T>(error?: any): ThenPromise<T>; - static all<Elem, T:Iterable<Elem>>(promises: T): ThenPromise<$TupleMap<T, typeof $await>>; - static race<T, Elem: Promise<T> | T>(promises: Array<Elem>): ThenPromise<T>; - - // Extensions specific to then/promise - - static denodeify(fn: Function): (...args: any[]) => ThenPromise<any>; - static nodeify(fn: Function): Function; -} -module.exports = ThenPromise; diff --git a/node_modules/promise/lib/core.js b/node_modules/promise/lib/core.js deleted file mode 100644 index 17f724f5f..000000000 --- a/node_modules/promise/lib/core.js +++ /dev/null @@ -1,213 +0,0 @@ -'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._h = 0; - this._i = 0; - this._j = null; - this._k = null; - if (fn === noop) return; - doResolve(fn, this); -} -Promise._l = null; -Promise._m = null; -Promise._n = 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._i === 3) { - self = self._j; - } - if (Promise._l) { - Promise._l(self); - } - if (self._i === 0) { - if (self._h === 0) { - self._h = 1; - self._k = deferred; - return; - } - if (self._h === 1) { - self._h = 2; - self._k = [self._k, deferred]; - return; - } - self._k.push(deferred); - return; - } - handleResolved(self, deferred); -} - -function handleResolved(self, deferred) { - asap(function() { - var cb = self._i === 1 ? deferred.onFulfilled : deferred.onRejected; - if (cb === null) { - if (self._i === 1) { - resolve(deferred.promise, self._j); - } else { - reject(deferred.promise, self._j); - } - return; - } - var ret = tryCallOne(cb, self._j); - 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._i = 3; - self._j = newValue; - finale(self); - return; - } else if (typeof then === 'function') { - doResolve(then.bind(newValue), self); - return; - } - } - self._i = 1; - self._j = newValue; - finale(self); -} - -function reject(self, newValue) { - self._i = 2; - self._j = newValue; - if (Promise._m) { - Promise._m(self, newValue); - } - finale(self); -} -function finale(self) { - if (self._h === 1) { - handle(self, self._k); - self._k = null; - } - if (self._h === 2) { - for (var i = 0; i < self._k.length; i++) { - handle(self, self._k[i]); - } - self._k = 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); - } -} diff --git a/node_modules/promise/lib/done.js b/node_modules/promise/lib/done.js deleted file mode 100644 index f879317d0..000000000 --- a/node_modules/promise/lib/done.js +++ /dev/null @@ -1,13 +0,0 @@ -'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); - }); -}; diff --git a/node_modules/promise/lib/es6-extensions.js b/node_modules/promise/lib/es6-extensions.js deleted file mode 100644 index 5046e2367..000000000 --- a/node_modules/promise/lib/es6-extensions.js +++ /dev/null @@ -1,107 +0,0 @@ -'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._n); - p._i = 1; - p._j = 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._i === 3) { - val = val._j; - } - if (val._i === 1) return res(i, val._j); - if (val._i === 2) reject(val._j); - 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); -}; diff --git a/node_modules/promise/lib/finally.js b/node_modules/promise/lib/finally.js deleted file mode 100644 index 3f8a6b7a1..000000000 --- a/node_modules/promise/lib/finally.js +++ /dev/null @@ -1,16 +0,0 @@ -'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; - }); - }); -}; diff --git a/node_modules/promise/lib/index.js b/node_modules/promise/lib/index.js deleted file mode 100644 index 6e674f387..000000000 --- a/node_modules/promise/lib/index.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -module.exports = require('./core.js'); -require('./done.js'); -require('./finally.js'); -require('./es6-extensions.js'); -require('./node-extensions.js'); -require('./synchronous.js'); diff --git a/node_modules/promise/lib/node-extensions.js b/node_modules/promise/lib/node-extensions.js deleted file mode 100644 index 157cddc2b..000000000 --- a/node_modules/promise/lib/node-extensions.js +++ /dev/null @@ -1,130 +0,0 @@ -'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); - }); - }); -}; diff --git a/node_modules/promise/lib/rejection-tracking.js b/node_modules/promise/lib/rejection-tracking.js deleted file mode 100644 index 56e4bd669..000000000 --- a/node_modules/promise/lib/rejection-tracking.js +++ /dev/null @@ -1,113 +0,0 @@ -'use strict'; - -var Promise = require('./core'); - -var DEFAULT_WHITELIST = [ - ReferenceError, - TypeError, - RangeError -]; - -var enabled = false; -exports.disable = disable; -function disable() { - enabled = false; - Promise._l = null; - Promise._m = null; -} - -exports.enable = enable; -function enable(options) { - options = options || {}; - if (enabled) disable(); - enabled = true; - var id = 0; - var displayId = 0; - var rejections = {}; - Promise._l = function (promise) { - if ( - promise._i === 2 && // IS REJECTED - rejections[promise._o] - ) { - if (rejections[promise._o].logged) { - onHandled(promise._o); - } else { - clearTimeout(rejections[promise._o].timeout); - } - delete rejections[promise._o]; - } - }; - Promise._m = function (promise, err) { - if (promise._h === 0) { // not yet handled - promise._o = id++; - rejections[promise._o] = { - displayId: null, - error: err, - timeout: setTimeout( - onUnhandled.bind(null, promise._o), - // 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; - }); -}
\ No newline at end of file diff --git a/node_modules/promise/lib/synchronous.js b/node_modules/promise/lib/synchronous.js deleted file mode 100644 index 79f4eeee9..000000000 --- a/node_modules/promise/lib/synchronous.js +++ /dev/null @@ -1,62 +0,0 @@ -'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._i === 3) { - return this._j.getValue(); - } - - if (!this.isFulfilled()) { - throw new Error('Cannot get a value of an unfulfilled promise.'); - } - - return this._j; - }; - - Promise.prototype.getReason = function () { - if (this._i === 3) { - return this._j.getReason(); - } - - if (!this.isRejected()) { - throw new Error('Cannot get a rejection reason of a non-rejected promise.'); - } - - return this._j; - }; - - Promise.prototype.getState = function () { - if (this._i === 3) { - return this._j.getState(); - } - if (this._i === -1 || this._i === -2) { - return 0; - } - - return this._i; - }; -}; - -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; -}; diff --git a/node_modules/promise/package.json b/node_modules/promise/package.json deleted file mode 100644 index 3b3d99588..000000000 --- a/node_modules/promise/package.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "promise", - "version": "8.0.2", - "description": "Bare bones Promises/A+ implementation", - "main": "index.js", - "scripts": { - "prepublish": "node build", - "pretest": "node build", - "pretest-resolve": "node build", - "pretest-extensions": "node build", - "pretest-memory-leak": "node build", - "test": "mocha --bail --timeout 200 --slow 99999 -R dot && npm run test-memory-leak", - "test-resolve": "mocha test/resolver-tests.js --timeout 200 --slow 999999", - "test-extensions": "mocha test/extensions-tests.js --timeout 200 --slow 999999", - "test-memory-leak": "node --expose-gc test/memory-leak.js", - "coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --bail --timeout 200 --slow 99999 -R dot" - }, - "repository": { - "type": "git", - "url": "https://github.com/then/promise.git" - }, - "author": "ForbesLindesay", - "license": "MIT", - "devDependencies": { - "acorn": "^1.0.1", - "better-assert": "*", - "istanbul": "^0.3.13", - "mocha": "*", - "promises-aplus-tests": "*", - "rimraf": "^2.3.2" - }, - "dependencies": { - "asap": "~2.0.6" - } -}
\ No newline at end of file diff --git a/node_modules/promise/polyfill-done.js b/node_modules/promise/polyfill-done.js deleted file mode 100644 index e50b4c0e8..000000000 --- a/node_modules/promise/polyfill-done.js +++ /dev/null @@ -1,12 +0,0 @@ -// 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) - }) - } -}
\ No newline at end of file diff --git a/node_modules/promise/polyfill.js b/node_modules/promise/polyfill.js deleted file mode 100644 index db099f8ee..000000000 --- a/node_modules/promise/polyfill.js +++ /dev/null @@ -1,10 +0,0 @@ -// 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'); diff --git a/node_modules/promise/setimmediate/core.js b/node_modules/promise/setimmediate/core.js deleted file mode 100644 index 28b38c881..000000000 --- a/node_modules/promise/setimmediate/core.js +++ /dev/null @@ -1,213 +0,0 @@ -'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._h = 0; - this._i = 0; - this._j = null; - this._k = null; - if (fn === noop) return; - doResolve(fn, this); -} -Promise._l = null; -Promise._m = null; -Promise._n = 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._i === 3) { - self = self._j; - } - if (Promise._l) { - Promise._l(self); - } - if (self._i === 0) { - if (self._h === 0) { - self._h = 1; - self._k = deferred; - return; - } - if (self._h === 1) { - self._h = 2; - self._k = [self._k, deferred]; - return; - } - self._k.push(deferred); - return; - } - handleResolved(self, deferred); -} - -function handleResolved(self, deferred) { - setImmediate(function() { - var cb = self._i === 1 ? deferred.onFulfilled : deferred.onRejected; - if (cb === null) { - if (self._i === 1) { - resolve(deferred.promise, self._j); - } else { - reject(deferred.promise, self._j); - } - return; - } - var ret = tryCallOne(cb, self._j); - 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._i = 3; - self._j = newValue; - finale(self); - return; - } else if (typeof then === 'function') { - doResolve(then.bind(newValue), self); - return; - } - } - self._i = 1; - self._j = newValue; - finale(self); -} - -function reject(self, newValue) { - self._i = 2; - self._j = newValue; - if (Promise._m) { - Promise._m(self, newValue); - } - finale(self); -} -function finale(self) { - if (self._h === 1) { - handle(self, self._k); - self._k = null; - } - if (self._h === 2) { - for (var i = 0; i < self._k.length; i++) { - handle(self, self._k[i]); - } - self._k = 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); - } -} diff --git a/node_modules/promise/setimmediate/done.js b/node_modules/promise/setimmediate/done.js deleted file mode 100644 index f879317d0..000000000 --- a/node_modules/promise/setimmediate/done.js +++ /dev/null @@ -1,13 +0,0 @@ -'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); - }); -}; diff --git a/node_modules/promise/setimmediate/es6-extensions.js b/node_modules/promise/setimmediate/es6-extensions.js deleted file mode 100644 index 5046e2367..000000000 --- a/node_modules/promise/setimmediate/es6-extensions.js +++ /dev/null @@ -1,107 +0,0 @@ -'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._n); - p._i = 1; - p._j = 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._i === 3) { - val = val._j; - } - if (val._i === 1) return res(i, val._j); - if (val._i === 2) reject(val._j); - 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); -}; diff --git a/node_modules/promise/setimmediate/finally.js b/node_modules/promise/setimmediate/finally.js deleted file mode 100644 index 3f8a6b7a1..000000000 --- a/node_modules/promise/setimmediate/finally.js +++ /dev/null @@ -1,16 +0,0 @@ -'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; - }); - }); -}; diff --git a/node_modules/promise/setimmediate/index.js b/node_modules/promise/setimmediate/index.js deleted file mode 100644 index 6e674f387..000000000 --- a/node_modules/promise/setimmediate/index.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -module.exports = require('./core.js'); -require('./done.js'); -require('./finally.js'); -require('./es6-extensions.js'); -require('./node-extensions.js'); -require('./synchronous.js'); diff --git a/node_modules/promise/setimmediate/node-extensions.js b/node_modules/promise/setimmediate/node-extensions.js deleted file mode 100644 index f03e861d8..000000000 --- a/node_modules/promise/setimmediate/node-extensions.js +++ /dev/null @@ -1,130 +0,0 @@ -'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); - }); - }); -}; diff --git a/node_modules/promise/setimmediate/rejection-tracking.js b/node_modules/promise/setimmediate/rejection-tracking.js deleted file mode 100644 index 56e4bd669..000000000 --- a/node_modules/promise/setimmediate/rejection-tracking.js +++ /dev/null @@ -1,113 +0,0 @@ -'use strict'; - -var Promise = require('./core'); - -var DEFAULT_WHITELIST = [ - ReferenceError, - TypeError, - RangeError -]; - -var enabled = false; -exports.disable = disable; -function disable() { - enabled = false; - Promise._l = null; - Promise._m = null; -} - -exports.enable = enable; -function enable(options) { - options = options || {}; - if (enabled) disable(); - enabled = true; - var id = 0; - var displayId = 0; - var rejections = {}; - Promise._l = function (promise) { - if ( - promise._i === 2 && // IS REJECTED - rejections[promise._o] - ) { - if (rejections[promise._o].logged) { - onHandled(promise._o); - } else { - clearTimeout(rejections[promise._o].timeout); - } - delete rejections[promise._o]; - } - }; - Promise._m = function (promise, err) { - if (promise._h === 0) { // not yet handled - promise._o = id++; - rejections[promise._o] = { - displayId: null, - error: err, - timeout: setTimeout( - onUnhandled.bind(null, promise._o), - // 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; - }); -}
\ No newline at end of file diff --git a/node_modules/promise/setimmediate/synchronous.js b/node_modules/promise/setimmediate/synchronous.js deleted file mode 100644 index 79f4eeee9..000000000 --- a/node_modules/promise/setimmediate/synchronous.js +++ /dev/null @@ -1,62 +0,0 @@ -'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._i === 3) { - return this._j.getValue(); - } - - if (!this.isFulfilled()) { - throw new Error('Cannot get a value of an unfulfilled promise.'); - } - - return this._j; - }; - - Promise.prototype.getReason = function () { - if (this._i === 3) { - return this._j.getReason(); - } - - if (!this.isRejected()) { - throw new Error('Cannot get a rejection reason of a non-rejected promise.'); - } - - return this._j; - }; - - Promise.prototype.getState = function () { - if (this._i === 3) { - return this._j.getState(); - } - if (this._i === -1 || this._i === -2) { - return 0; - } - - return this._i; - }; -}; - -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; -}; diff --git a/node_modules/promise/src/core.js b/node_modules/promise/src/core.js deleted file mode 100644 index 312010d92..000000000 --- a/node_modules/promise/src/core.js +++ /dev/null @@ -1,213 +0,0 @@ -'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); - } -} diff --git a/node_modules/promise/src/done.js b/node_modules/promise/src/done.js deleted file mode 100644 index f879317d0..000000000 --- a/node_modules/promise/src/done.js +++ /dev/null @@ -1,13 +0,0 @@ -'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); - }); -}; diff --git a/node_modules/promise/src/es6-extensions.js b/node_modules/promise/src/es6-extensions.js deleted file mode 100644 index 04358131b..000000000 --- a/node_modules/promise/src/es6-extensions.js +++ /dev/null @@ -1,107 +0,0 @@ -'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); -}; diff --git a/node_modules/promise/src/finally.js b/node_modules/promise/src/finally.js deleted file mode 100644 index 3f8a6b7a1..000000000 --- a/node_modules/promise/src/finally.js +++ /dev/null @@ -1,16 +0,0 @@ -'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; - }); - }); -}; diff --git a/node_modules/promise/src/index.js b/node_modules/promise/src/index.js deleted file mode 100644 index 6e674f387..000000000 --- a/node_modules/promise/src/index.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -module.exports = require('./core.js'); -require('./done.js'); -require('./finally.js'); -require('./es6-extensions.js'); -require('./node-extensions.js'); -require('./synchronous.js'); diff --git a/node_modules/promise/src/node-extensions.js b/node_modules/promise/src/node-extensions.js deleted file mode 100644 index 157cddc2b..000000000 --- a/node_modules/promise/src/node-extensions.js +++ /dev/null @@ -1,130 +0,0 @@ -'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); - }); - }); -}; diff --git a/node_modules/promise/src/rejection-tracking.js b/node_modules/promise/src/rejection-tracking.js deleted file mode 100644 index 33a59a196..000000000 --- a/node_modules/promise/src/rejection-tracking.js +++ /dev/null @@ -1,113 +0,0 @@ -'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; - }); -}
\ No newline at end of file diff --git a/node_modules/promise/src/synchronous.js b/node_modules/promise/src/synchronous.js deleted file mode 100644 index 38b228f52..000000000 --- a/node_modules/promise/src/synchronous.js +++ /dev/null @@ -1,62 +0,0 @@ -'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; -}; |