From 245d2332d7dd73989e3c889f8011410da29700c6 Mon Sep 17 00:00:00 2001 From: Brian Cavalier Date: Sun, 14 Aug 2016 20:59:51 -0400 Subject: [PATCH] Bump version, rebuild --- dist/creed.es.js | 317 ++++++++++++++++++++++++++++------------------ dist/creed.js | 317 ++++++++++++++++++++++++++++------------------ dist/creed.min.js | 2 +- package.json | 2 +- 4 files changed, 386 insertions(+), 252 deletions(-) diff --git a/dist/creed.es.js b/dist/creed.es.js index 31f1957..47fa023 100644 --- a/dist/creed.es.js +++ b/dist/creed.es.js @@ -54,6 +54,7 @@ function silenceError (p) { p._runAction(silencer) } +// implements Action var silencer = { fulfilled: function fulfilled () {}, rejected: setHandled @@ -216,96 +217,129 @@ function maybeThenable (x) { return (typeof x === 'object' || typeof x === 'function') && x !== null } -function then (f, r, p, promise) { - p._when(new Then(f, r, promise)) - return promise -} - -var Then = function Then (f, r, promise) { - this.f = f - this.r = r +var Action = function Action (promise) { this.promise = promise }; -Then.prototype.fulfilled = function fulfilled (p) { - runThen(this.f, p, this.promise) +// default onFulfilled action +/* istanbul ignore next */ +Action.prototype.fulfilled = function fulfilled (p) { + this.promise._become(p) }; -Then.prototype.rejected = function rejected (p) { - return runThen(this.r, p, this.promise) +// default onRejected action +Action.prototype.rejected = function rejected (p) { + this.promise._become(p) + return false }; -function runThen (f, p, promise) { - if (typeof f !== 'function') { - promise._become(p) - return false - } +Action.prototype.tryCall = function tryCall (f, x) { + var result + // test if `f` (and only it) throws + try { + result = f(x) + } catch (e) { + this.promise._reject(e) + return + } // else + this.handle(result) +}; - tryMapNext(f, p.value, promise) - return true +function then (f, r, p, promise) { + p._when(new Then(f, r, promise)) + return promise } -function tryMapNext (f, x, promise) { - try { - promise._resolve(f(x)) - } catch (e) { - promise._reject(e) +var Then = (function (Action) { + function Then (f, r, promise) { + Action.call(this, promise) + this.f = f + this.r = r } -} + + if ( Action ) Then.__proto__ = Action; + Then.prototype = Object.create( Action && Action.prototype ); + Then.prototype.constructor = Then; + + Then.prototype.fulfilled = function fulfilled (p) { + this.runThen(this.f, p) + }; + + Then.prototype.rejected = function rejected (p) { + return this.runThen(this.r, p) + }; + + Then.prototype.runThen = function runThen (f, p) { + if (typeof f !== 'function') { + this.promise._become(p) + return false + } + this.tryCall(f, p.value) + return true + }; + + Then.prototype.handle = function handle (result) { + this.promise._resolve(result) + }; + + return Then; +}(Action)); function map (f, p, promise) { p._when(new Map(f, promise)) return promise } -var Map = function Map (f, promise) { - this.f = f - this.promise = promise -}; - -Map.prototype.fulfilled = function fulfilled (p) { - try { - var f = this.f - this.promise._fulfill(f(p.value)) - } catch (e) { - this.promise._reject(e) +var Map = (function (Action) { + function Map (f, promise) { + Action.call(this, promise) + this.f = f } -}; -Map.prototype.rejected = function rejected (p) { - this.promise._become(p) -}; + if ( Action ) Map.__proto__ = Action; + Map.prototype = Object.create( Action && Action.prototype ); + Map.prototype.constructor = Map; + + Map.prototype.fulfilled = function fulfilled (p) { + this.tryCall(this.f, p.value) + }; + + Map.prototype.handle = function handle (result) { + this.promise._fulfill(result) + }; + + return Map; +}(Action)); function chain (f, p, promise) { p._when(new Chain(f, promise)) return promise } -var Chain = function Chain (f, promise) { - this.f = f - this.promise = promise -}; - -Chain.prototype.fulfilled = function fulfilled (p) { - try { - runChain(this.f, p.value, this.promise) - } catch (e) { - this.promise._reject(e) +var Chain = (function (Action) { + function Chain (f, promise) { + Action.call(this, promise) + this.f = f } -}; -Chain.prototype.rejected = function rejected (p) { - this.promise._become(p) -}; + if ( Action ) Chain.__proto__ = Action; + Chain.prototype = Object.create( Action && Action.prototype ); + Chain.prototype.constructor = Chain; -function runChain (f, x, p) { - var y = f(x) - if (!(maybeThenable(y) && typeof y.then === 'function')) { - throw new TypeError('f must return a promise') - } + Chain.prototype.fulfilled = function fulfilled (p) { + this.tryCall(this.f, p.value) + }; - p._resolve(y) -} + Chain.prototype.handle = function handle (y) { + if (!(maybeThenable(y) && typeof y.then === 'function')) { + this.promise._reject(new TypeError('f must return a promise')) + } + + this.promise._resolve(y) + }; + + return Chain; +}(Action)); var Race = function Race (never) { this.never = never @@ -416,21 +450,31 @@ function handleItem (resolve, handler, x, i, promise) { } else if (isRejected(p)) { handler.rejectAt(p, i, promise) } else { - settleAt(p, handler, i, promise) + p._runAction(new Indexed(handler, i, promise)) } } -function settleAt (p, handler, i, promise) { - p._runAction({handler: handler, i: i, promise: promise, fulfilled: fulfilled, rejected: rejected}) -} +var Indexed = (function (Action) { + function Indexed (handler, i, promise) { + Action.call(this, promise) + this.i = i + this.handler = handler + } -function fulfilled (p) { - this.handler.fulfillAt(p, this.i, this.promise) -} + if ( Action ) Indexed.__proto__ = Action; + Indexed.prototype = Object.create( Action && Action.prototype ); + Indexed.prototype.constructor = Indexed; -function rejected (p) { - return this.handler.rejectAt(p, this.i, this.promise) -} + Indexed.prototype.fulfilled = function fulfilled (p) { + this.handler.fulfillAt(p, this.i, this.promise) + }; + + Indexed.prototype.rejected = function rejected (p) { + return this.handler.rejectAt(p, this.i, this.promise) + }; + + return Indexed; +}(Action)); var taskQueue = new TaskQueue() /* istanbul ignore next */ @@ -923,19 +967,23 @@ function _delay (ms, p, promise) { return promise } -var Delay = function Delay (time, promise) { - this.time = time - this.promise = promise -}; +var Delay = (function (Action) { + function Delay (time, promise) { + Action.call(this, promise) + this.time = time + } -Delay.prototype.fulfilled = function fulfilled (p) { - /*global setTimeout*/ - setTimeout(become, this.time, p, this.promise) -}; + if ( Action ) Delay.__proto__ = Action; + Delay.prototype = Object.create( Action && Action.prototype ); + Delay.prototype.constructor = Delay; -Delay.prototype.rejected = function rejected (p) { - this.promise._become(p) -}; + Delay.prototype.fulfilled = function fulfilled (p) { + /*global setTimeout*/ + setTimeout(become, this.time, p, this.promise) + }; + + return Delay; +}(Action)); function become (p, promise) { promise._become(p) @@ -965,21 +1013,28 @@ function _timeout (ms, p, promise) { return promise } -var Timeout = function Timeout (timer, promise) { - this.timer = timer - this.promise = promise -}; +var Timeout = (function (Action) { + function Timeout (timer, promise) { + Action.call(this, promise) + this.timer = timer + } -Timeout.prototype.fulfilled = function fulfilled (p) { - clearTimeout(this.timer) - this.promise._become(p) -}; + if ( Action ) Timeout.__proto__ = Action; + Timeout.prototype = Object.create( Action && Action.prototype ); + Timeout.prototype.constructor = Timeout; -Timeout.prototype.rejected = function rejected (p) { - clearTimeout(this.timer) - this.promise._become(p) - return false -}; + Timeout.prototype.fulfilled = function fulfilled (p) { + clearTimeout(this.timer) + this.promise._become(p) + }; + + Timeout.prototype.rejected = function rejected (p) { + clearTimeout(this.timer) + return Action.prototype.rejected.call(this, p) + }; + + return Timeout; +}(Action)); function rejectOnTimeout (promise) { promise._reject(new TimeoutError('promise timeout')) @@ -1115,40 +1170,52 @@ function _runCoroutine (resolve, iterator, promise) { return promise } -var Coroutine = function Coroutine (resolve, iterator, promise) { - this.resolve = resolve - this.iterator = iterator - this.promise = promise -}; +var Coroutine = (function (Action) { + function Coroutine (resolve, iterator, promise) { + Action.call(this, promise) + this.resolve = resolve + this.generator = iterator + } -Coroutine.prototype.run = function run () { - this.step(this.iterator.next, void 0) -}; + if ( Action ) Coroutine.__proto__ = Action; + Coroutine.prototype = Object.create( Action && Action.prototype ); + Coroutine.prototype.constructor = Coroutine; -Coroutine.prototype.step = function step (continuation, x) { - try { - this.handle(continuation.call(this.iterator, x)) - } catch (e) { - this.promise._reject(e) - } -}; + Coroutine.prototype.run = function run () { + this.tryStep(this.generator.next, void 0) + }; -Coroutine.prototype.handle = function handle (result) { - if (result.done) { - return this.promise._resolve(result.value) - } + Coroutine.prototype.tryStep = function tryStep (resume, x) { + var result + // test if `resume` (and only it) throws + try { + result = resume.call(this.generator, x) + } catch (e) { + this.promise._reject(e) + return + } // else + this.handle(result) + }; - this.resolve(result.value)._runAction(this) -}; + Coroutine.prototype.handle = function handle (result) { + if (result.done) { + return this.promise._resolve(result.value) + } -Coroutine.prototype.fulfilled = function fulfilled (ref) { - this.step(this.iterator.next, ref.value) -}; + this.resolve(result.value)._when(this) + }; -Coroutine.prototype.rejected = function rejected (ref) { - this.step(this.iterator.throw, ref.value) - return true -}; + Coroutine.prototype.fulfilled = function fulfilled (ref) { + this.tryStep(this.generator.next, ref.value) + }; + + Coroutine.prototype.rejected = function rejected (ref) { + this.tryStep(this.generator.throw, ref.value) + return true + }; + + return Coroutine; +}(Action)); // ------------------------------------------------------------- // ## Coroutine @@ -1157,7 +1224,7 @@ Coroutine.prototype.rejected = function rejected (ref) { // coroutine :: Generator e a -> (...* -> Promise e a) // Make a coroutine from a promise-yielding generator function coroutine (generator) { - return function () { + return function coroutinified () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; @@ -1180,7 +1247,7 @@ function runGenerator (generator, thisArg, args) { // fromNode :: NodeApi e a -> (...args -> Promise e a) // Turn a Node API into a promise API function fromNode (f) { - return function () { + return function promisified () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; diff --git a/dist/creed.js b/dist/creed.js index 1299d03..ac9bec0 100644 --- a/dist/creed.js +++ b/dist/creed.js @@ -60,6 +60,7 @@ p._runAction(silencer) } + // implements Action var silencer = { fulfilled: function fulfilled () {}, rejected: setHandled @@ -222,96 +223,129 @@ return (typeof x === 'object' || typeof x === 'function') && x !== null } - function then (f, r, p, promise) { - p._when(new Then(f, r, promise)) - return promise - } - - var Then = function Then (f, r, promise) { - this.f = f - this.r = r + var Action = function Action (promise) { this.promise = promise }; - Then.prototype.fulfilled = function fulfilled (p) { - runThen(this.f, p, this.promise) + // default onFulfilled action + /* istanbul ignore next */ + Action.prototype.fulfilled = function fulfilled (p) { + this.promise._become(p) }; - Then.prototype.rejected = function rejected (p) { - return runThen(this.r, p, this.promise) + // default onRejected action + Action.prototype.rejected = function rejected (p) { + this.promise._become(p) + return false }; - function runThen (f, p, promise) { - if (typeof f !== 'function') { - promise._become(p) - return false - } + Action.prototype.tryCall = function tryCall (f, x) { + var result + // test if `f` (and only it) throws + try { + result = f(x) + } catch (e) { + this.promise._reject(e) + return + } // else + this.handle(result) + }; - tryMapNext(f, p.value, promise) - return true + function then (f, r, p, promise) { + p._when(new Then(f, r, promise)) + return promise } - function tryMapNext (f, x, promise) { - try { - promise._resolve(f(x)) - } catch (e) { - promise._reject(e) + var Then = (function (Action) { + function Then (f, r, promise) { + Action.call(this, promise) + this.f = f + this.r = r } - } + + if ( Action ) Then.__proto__ = Action; + Then.prototype = Object.create( Action && Action.prototype ); + Then.prototype.constructor = Then; + + Then.prototype.fulfilled = function fulfilled (p) { + this.runThen(this.f, p) + }; + + Then.prototype.rejected = function rejected (p) { + return this.runThen(this.r, p) + }; + + Then.prototype.runThen = function runThen (f, p) { + if (typeof f !== 'function') { + this.promise._become(p) + return false + } + this.tryCall(f, p.value) + return true + }; + + Then.prototype.handle = function handle (result) { + this.promise._resolve(result) + }; + + return Then; + }(Action)); function map (f, p, promise) { p._when(new Map(f, promise)) return promise } - var Map = function Map (f, promise) { - this.f = f - this.promise = promise - }; - - Map.prototype.fulfilled = function fulfilled (p) { - try { - var f = this.f - this.promise._fulfill(f(p.value)) - } catch (e) { - this.promise._reject(e) + var Map = (function (Action) { + function Map (f, promise) { + Action.call(this, promise) + this.f = f } - }; - Map.prototype.rejected = function rejected (p) { - this.promise._become(p) - }; + if ( Action ) Map.__proto__ = Action; + Map.prototype = Object.create( Action && Action.prototype ); + Map.prototype.constructor = Map; + + Map.prototype.fulfilled = function fulfilled (p) { + this.tryCall(this.f, p.value) + }; + + Map.prototype.handle = function handle (result) { + this.promise._fulfill(result) + }; + + return Map; + }(Action)); function chain (f, p, promise) { p._when(new Chain(f, promise)) return promise } - var Chain = function Chain (f, promise) { - this.f = f - this.promise = promise - }; - - Chain.prototype.fulfilled = function fulfilled (p) { - try { - runChain(this.f, p.value, this.promise) - } catch (e) { - this.promise._reject(e) + var Chain = (function (Action) { + function Chain (f, promise) { + Action.call(this, promise) + this.f = f } - }; - Chain.prototype.rejected = function rejected (p) { - this.promise._become(p) - }; + if ( Action ) Chain.__proto__ = Action; + Chain.prototype = Object.create( Action && Action.prototype ); + Chain.prototype.constructor = Chain; - function runChain (f, x, p) { - var y = f(x) - if (!(maybeThenable(y) && typeof y.then === 'function')) { - throw new TypeError('f must return a promise') - } + Chain.prototype.fulfilled = function fulfilled (p) { + this.tryCall(this.f, p.value) + }; - p._resolve(y) - } + Chain.prototype.handle = function handle (y) { + if (!(maybeThenable(y) && typeof y.then === 'function')) { + this.promise._reject(new TypeError('f must return a promise')) + } + + this.promise._resolve(y) + }; + + return Chain; + }(Action)); var Race = function Race (never) { this.never = never @@ -422,21 +456,31 @@ } else if (isRejected(p)) { handler.rejectAt(p, i, promise) } else { - settleAt(p, handler, i, promise) + p._runAction(new Indexed(handler, i, promise)) } } - function settleAt (p, handler, i, promise) { - p._runAction({handler: handler, i: i, promise: promise, fulfilled: fulfilled, rejected: rejected}) - } + var Indexed = (function (Action) { + function Indexed (handler, i, promise) { + Action.call(this, promise) + this.i = i + this.handler = handler + } - function fulfilled (p) { - this.handler.fulfillAt(p, this.i, this.promise) - } + if ( Action ) Indexed.__proto__ = Action; + Indexed.prototype = Object.create( Action && Action.prototype ); + Indexed.prototype.constructor = Indexed; - function rejected (p) { - return this.handler.rejectAt(p, this.i, this.promise) - } + Indexed.prototype.fulfilled = function fulfilled (p) { + this.handler.fulfillAt(p, this.i, this.promise) + }; + + Indexed.prototype.rejected = function rejected (p) { + return this.handler.rejectAt(p, this.i, this.promise) + }; + + return Indexed; + }(Action)); var taskQueue = new TaskQueue() /* istanbul ignore next */ @@ -929,19 +973,23 @@ return promise } - var Delay = function Delay (time, promise) { - this.time = time - this.promise = promise - }; + var Delay = (function (Action) { + function Delay (time, promise) { + Action.call(this, promise) + this.time = time + } - Delay.prototype.fulfilled = function fulfilled (p) { - /*global setTimeout*/ - setTimeout(become, this.time, p, this.promise) - }; + if ( Action ) Delay.__proto__ = Action; + Delay.prototype = Object.create( Action && Action.prototype ); + Delay.prototype.constructor = Delay; - Delay.prototype.rejected = function rejected (p) { - this.promise._become(p) - }; + Delay.prototype.fulfilled = function fulfilled (p) { + /*global setTimeout*/ + setTimeout(become, this.time, p, this.promise) + }; + + return Delay; + }(Action)); function become (p, promise) { promise._become(p) @@ -971,21 +1019,28 @@ return promise } - var Timeout = function Timeout (timer, promise) { - this.timer = timer - this.promise = promise - }; + var Timeout = (function (Action) { + function Timeout (timer, promise) { + Action.call(this, promise) + this.timer = timer + } - Timeout.prototype.fulfilled = function fulfilled (p) { - clearTimeout(this.timer) - this.promise._become(p) - }; + if ( Action ) Timeout.__proto__ = Action; + Timeout.prototype = Object.create( Action && Action.prototype ); + Timeout.prototype.constructor = Timeout; - Timeout.prototype.rejected = function rejected (p) { - clearTimeout(this.timer) - this.promise._become(p) - return false - }; + Timeout.prototype.fulfilled = function fulfilled (p) { + clearTimeout(this.timer) + this.promise._become(p) + }; + + Timeout.prototype.rejected = function rejected (p) { + clearTimeout(this.timer) + return Action.prototype.rejected.call(this, p) + }; + + return Timeout; + }(Action)); function rejectOnTimeout (promise) { promise._reject(new TimeoutError('promise timeout')) @@ -1121,40 +1176,52 @@ return promise } - var Coroutine = function Coroutine (resolve, iterator, promise) { - this.resolve = resolve - this.iterator = iterator - this.promise = promise - }; + var Coroutine = (function (Action) { + function Coroutine (resolve, iterator, promise) { + Action.call(this, promise) + this.resolve = resolve + this.generator = iterator + } - Coroutine.prototype.run = function run () { - this.step(this.iterator.next, void 0) - }; + if ( Action ) Coroutine.__proto__ = Action; + Coroutine.prototype = Object.create( Action && Action.prototype ); + Coroutine.prototype.constructor = Coroutine; - Coroutine.prototype.step = function step (continuation, x) { - try { - this.handle(continuation.call(this.iterator, x)) - } catch (e) { - this.promise._reject(e) - } - }; + Coroutine.prototype.run = function run () { + this.tryStep(this.generator.next, void 0) + }; - Coroutine.prototype.handle = function handle (result) { - if (result.done) { - return this.promise._resolve(result.value) - } + Coroutine.prototype.tryStep = function tryStep (resume, x) { + var result + // test if `resume` (and only it) throws + try { + result = resume.call(this.generator, x) + } catch (e) { + this.promise._reject(e) + return + } // else + this.handle(result) + }; - this.resolve(result.value)._runAction(this) - }; + Coroutine.prototype.handle = function handle (result) { + if (result.done) { + return this.promise._resolve(result.value) + } - Coroutine.prototype.fulfilled = function fulfilled (ref) { - this.step(this.iterator.next, ref.value) - }; + this.resolve(result.value)._when(this) + }; - Coroutine.prototype.rejected = function rejected (ref) { - this.step(this.iterator.throw, ref.value) - return true - }; + Coroutine.prototype.fulfilled = function fulfilled (ref) { + this.tryStep(this.generator.next, ref.value) + }; + + Coroutine.prototype.rejected = function rejected (ref) { + this.tryStep(this.generator.throw, ref.value) + return true + }; + + return Coroutine; + }(Action)); // ------------------------------------------------------------- // ## Coroutine @@ -1163,7 +1230,7 @@ // coroutine :: Generator e a -> (...* -> Promise e a) // Make a coroutine from a promise-yielding generator function coroutine (generator) { - return function () { + return function coroutinified () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; @@ -1186,7 +1253,7 @@ // fromNode :: NodeApi e a -> (...args -> Promise e a) // Turn a Node API into a promise API function fromNode (f) { - return function () { + return function promisified () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; diff --git a/dist/creed.min.js b/dist/creed.min.js index 5661e18..3d0d774 100644 --- a/dist/creed.min.js +++ b/dist/creed.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.creed=t.creed||{})}(this,function(t){"use strict";function e(t){return(t.state()&vt)>0}function n(t){return(t.state()&dt)>0}function r(t){return(t.state()&mt)>0}function o(t){return(t.state()&_t)>0}function i(t){return(t.state()&wt)>0}function c(t){return(t.state()&bt)>0}function u(t){var e=t.near();if(!n(e))throw new TypeError("getValue called on "+t);return e.value}function s(t){var e=t.near();if(!r(e))throw new TypeError("getReason called on "+t);return p(e),e.value}function p(t){t._runAction(gt)}function f(t){t._state|=bt}function h(t){return jt?l(t):At?y(t):a(t)}function a(t){return function(){return setTimeout(t,0)}}function l(t){return function(){return process.nextTick(t)}}function y(t){var e=document.createTextNode("");new At(t).observe(e,{characterData:!0});var n=0;return function(){e.data=n^=1}}function v(t,e){try{d(e,t)}finally{e.length=0}}function d(t,e){for(var n=0;n0;)e[n]=arguments[n+1];return ct($,t,this,e,new Vt)}function it(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return ct(Z,t,this,e,new Vt)}function ct(t,e,n,r,o){lt(e);try{t(e,n,r,o)}catch(t){o._reject(t)}return o}function ut(t,e){var n=H(e);return t<=0||r(n)||i(n)?n:Q(t,n,new Vt)}function st(t,e){var n=H(e);return o(n)?n:X(t,n,new Vt)}function pt(t){return z(new Jt,t)}function ft(t){var e=new Lt(H,E(t));return z(e,t)}function ht(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return at(t,this,e)}function at(t,e,n){var r=new Nt(new Ut(t,e),E(n));return z(r,n)}function lt(t){if("function"!=typeof t)throw new TypeError("must provide a resolver function")}function yt(){var t="function"==typeof Promise&&Promise;return"undefined"!=typeof self?self.Promise=Yt:"undefined"!=typeof global&&(global.Promise=Yt),t}var vt=1,dt=2,mt=4,_t=dt|mt,wt=8,bt=16,gt={fulfilled:function(){},rejected:f},jt="undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process),At="function"==typeof MutationObserver&&MutationObserver||"function"==typeof WebKitMutationObserver&&WebKitMutationObserver,kt=function(){var t=this;this.tasks=new Array(65536),this.length=0,this.drain=h(function(){return t._drain()})};kt.prototype.add=function(t){0===this.length&&this.drain(),this.tasks[this.length++]=t},kt.prototype._drain=function(){for(var t=this.tasks,e=0;e0}function n(t){return(t.state()&ft)>0}function r(t){return(t.state()&at)>0}function o(t){return(t.state()&ht)>0}function i(t){return(t.state()<)>0}function c(t){return(t.state()&yt)>0}function u(t){var e=t.near();if(!n(e))throw new TypeError("getValue called on "+t);return e.value}function p(t){var e=t.near();if(!r(e))throw new TypeError("getReason called on "+t);return s(e),e.value}function s(t){t._runAction(vt)}function f(t){t._state|=yt}function a(t){return _t?l(t):dt?y(t):h(t)}function h(t){return function(){return setTimeout(t,0)}}function l(t){return function(){return process.nextTick(t)}}function y(t){var e=document.createTextNode("");new dt(t).observe(e,{characterData:!0});var n=0;return function(){e.data=n^=1}}function v(t,e){try{_(e,t)}finally{e.length=0}}function _(t,e){for(var n=0;n0;)e[n]=arguments[n+1];return tt(L,t,this,e,new Mt)}function $(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return tt(J,t,this,e,new Mt)}function tt(t,e,n,r,o){ut(e);try{t(e,n,r,o)}catch(t){o._reject(t)}return o}function et(t,e){var n=P(e);return t<=0||r(n)||i(n)?n:z(t,n,new Mt)}function nt(t,e){var n=P(e);return o(n)?n:G(t,n,new Mt)}function rt(t){return K(new zt,t)}function ot(t){var e=new Bt(P,A(t));return K(e,t)}function it(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return ct(t,this,e)}function ct(t,e,n){var r=new Pt(new It(t,e),A(n));return K(r,n)}function ut(t){if("function"!=typeof t)throw new TypeError("must provide a resolver function")}function pt(){var t="function"==typeof Promise&&Promise;return"undefined"!=typeof self?self.Promise=Lt:"undefined"!=typeof global&&(global.Promise=Lt),t}var st=1,ft=2,at=4,ht=ft|at,lt=8,yt=16,vt={fulfilled:function(){},rejected:f},_t="undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process),dt="function"==typeof MutationObserver&&MutationObserver||"function"==typeof WebKitMutationObserver&&WebKitMutationObserver,mt=function(){var t=this;this.tasks=new Array(65536),this.length=0,this.drain=a(function(){return t._drain()})};mt.prototype.add=function(t){0===this.length&&this.drain(),this.tasks[this.length++]=t},mt.prototype._drain=function(){for(var t=this.tasks,e=0;e