You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
12 KiB
1 line
12 KiB
1 year ago
|
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.ES6Promise = factory()) }(this, (function () { 'use strict'; function objectOrFunction(x) { return typeof x === 'function' || typeof x === 'object' && x !== null } function isFunction(x) { return typeof x === 'function' } var _isArray = undefined; if (!Array.isArray) { _isArray = function (x) { return Object.prototype.toString.call(x) === '[object Array]' } } else { _isArray = Array.isArray } var isArray = _isArray; var len = 0; var vertxNext = undefined; var customSchedulerFn = undefined; var asap = function asap(callback, arg) { queue[len] = callback; queue[len + 1] = arg; len += 2; if (len === 2) { if (customSchedulerFn) { customSchedulerFn(flush) } else { scheduleFlush() } } }; function setScheduler(scheduleFn) { customSchedulerFn = scheduleFn } function setAsap(asapFn) { asap = asapFn } var browserWindow = typeof window !== 'undefined' ? window : undefined; var browserGlobal = browserWindow || {}; var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]'; var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; function useNextTick() { return function () { return process.nextTick(flush) } } function useVertxTimer() { if (typeof vertxNext !== 'undefined') { return function () { vertxNext(flush) } } return useSetTimeout() } function useMutationObserver() { var iterations = 0; var observer = new BrowserMutationObserver(flush); var node = document.createTextNode(''); observer.observe(node, { characterData: true }); return function () { node.data = iterations = ++iterations % 2 } } function useMessageChannel() { var channel = new MessageChannel(); channel.port1.onmessage = flush; return function () { return channel.port2.postMessage(0) } } function useSetTimeout() { var globalSetTimeout = setTimeout; return function () { return globalSetTimeout(flush, 1) } } var queue = new Array(1000); function flush() { for (var i = 0; i < len; i += 2) { var callback = queue[i]; var arg = queue[i + 1]; callback(arg); queue[i] = undefined; queue[i + 1] = undefined } len = 0 } function attemptVertx() { try { var r = require; var vertx = r('vertx'); vertxNext = vertx.runOnLoop || vertx.runOnContext; return useVertxTimer() } catch (e) { return useSetTimeout() } } var scheduleFlush = undefined; if (isNode) { scheduleFlush = useNextTick() } else if (BrowserMutationObserver) { scheduleFlush = useMutationObserver() } else if (isWorker) { scheduleFlush = useMessageChannel() } else if (browserWindow === undefined && typeof require === 'function') { scheduleFlush = attemptVertx() } else { scheduleFlush = useSetTimeout() } function then(onFulfillment, onRejection) { var _arguments = arguments; var parent = this; var child = new this.constructor(noop); if (child[PROMISE_ID] === undefined) { makePromise(child) } var _state = parent._state; if (_state) { (function () { var callback = _arguments[_state - 1]; asap(function () { return invokeCallback(_state, child, callback, parent._result) }) })() } else { subscribe(parent, child, onFulfillment, onRejection) } return child } function resolve(object) { var Constructor = this; if (object && typeof object === 'object' && object.constructor === Constructor) { return object } var promise = new Constructor(noop); _resolve(promise, object); return promise } var PROMISE_ID = Math.random().toString(36).substring(16); function noop() { } var PENDING = void 0; var FULFILLED = 1; var REJECTED = 2; var GET_THEN_ERROR = new ErrorObject(); function selfFulfillment() { return new TypeError("You cannot resolve a promise with itself") } function cannotReturnOwn() { return new TypeError('A promises callback cannot return that same promise.') } function getThen(promise) { try { retu
|