aboutsummaryrefslogtreecommitdiff
path: root/node_modules/promise/setimmediate
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-03-27 21:01:33 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-03-27 21:01:33 +0100
commitcc97a4dd2a967e1c2273bd5f4c5f49a5bf2e2585 (patch)
tree92c5d88706a6ffc654d1b133618d357890e7096b /node_modules/promise/setimmediate
parent3771b4d6b67b34c130f3a9a1a15f42deefdb2eda (diff)
remove node_modules
Diffstat (limited to 'node_modules/promise/setimmediate')
-rw-r--r--node_modules/promise/setimmediate/core.js213
-rw-r--r--node_modules/promise/setimmediate/done.js13
-rw-r--r--node_modules/promise/setimmediate/es6-extensions.js107
-rw-r--r--node_modules/promise/setimmediate/finally.js16
-rw-r--r--node_modules/promise/setimmediate/index.js8
-rw-r--r--node_modules/promise/setimmediate/node-extensions.js130
-rw-r--r--node_modules/promise/setimmediate/rejection-tracking.js113
-rw-r--r--node_modules/promise/setimmediate/synchronous.js62
8 files changed, 0 insertions, 662 deletions
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;
-};