diff --git a/dist/zone-microtask.js b/dist/zone-microtask.js index b093b75ec..09d03d271 100644 --- a/dist/zone-microtask.js +++ b/dist/zone-microtask.js @@ -1135,12 +1135,13 @@ module.exports = { // TODO(vicb): Create a benchmark for the different methods & the usage of the queue // see https://github.com/angular/zone.js/issues/97 -var hasNativePromise = false; var len = 0; -if (typeof Promise ==! "undefined" && Promise.toString().indexOf("[native code]") !== -1) { - hasNativePromise = true; -} +var hasNativePromise = typeof Promise ==! "undefined" && + Promise.toString().indexOf("[native code]") !== -1; + +var isFirefox = global.navigator && + global.navigator.userAgent.toLowerCase().indexOf('firefox') > -1; function asap(callback) { queue[len] = callback; @@ -1206,7 +1207,9 @@ function flush() { var scheduleFlush; // Decide what async method to use to triggering processing of queued callbacks: -if (hasNativePromise) { +if (hasNativePromise && !isFirefox) { + // TODO(vicb): remove '!isFirefox' when the bug is fixed: + // https://bugzilla.mozilla.org/show_bug.cgi?id=1162013 scheduleFlush = usePromise(); } else if (BrowserMutationObserver) { scheduleFlush = useMutationObserver(); diff --git a/dist/zone-microtask.min.js b/dist/zone-microtask.min.js index 0328e4043..cdd54bc9d 100644 --- a/dist/zone-microtask.min.js +++ b/dist/zone-microtask.min.js @@ -1 +1 @@ -!function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(i)return i(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[u]={exports:{}};t[u][0].call(f.exports,function(e){var n=t[u][1][e];return o(n?n:e)},f,f.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;ue;e+=2){var t=Q[e],n=Q[e+1];t(n),Q[e]=void 0,Q[e+1]=void 0}X=0}function h(){try{var t=e,n=t("vertx");return R=n.runOnLoop||n.runOnContext,c()}catch(r){return l()}}function y(){}function v(){return new TypeError("You cannot resolve a promise with itself")}function g(){return new TypeError("A promises callback cannot return that same promise.")}function m(e){try{return e.then}catch(t){return re.error=t,re}}function b(e,t,n,r){try{e.call(t,n,r)}catch(o){return o}}function w(e,t,n){Y(function(e){var r=!1,o=b(n,t,function(n){r||(r=!0,t!==n?E(e,n):P(e,n))},function(t){r||(r=!0,j(e,t))},"Settle: "+(e._label||" unknown promise"));!r&&o&&(r=!0,j(e,o))},e)}function _(e,t){t._state===te?P(e,t._result):t._state===ne?j(e,t._result):T(t,void 0,function(t){E(e,t)},function(t){j(e,t)})}function k(e,t){if(t.constructor===e.constructor)_(e,t);else{var n=m(t);n===re?j(e,re.error):void 0===n?P(e,t):i(n)?w(e,t,n):P(e,t)}}function E(e,t){e===t?j(e,v()):o(t)?k(e,t):P(e,t)}function O(e){e._onerror&&e._onerror(e._result),x(e)}function P(e,t){e._state===ee&&(e._result=t,e._state=te,0!==e._subscribers.length&&Y(x,e))}function j(e,t){e._state===ee&&(e._state=ne,e._result=t,Y(O,e))}function T(e,t,n,r){var o=e._subscribers,i=o.length;e._onerror=null,o[i]=t,o[i+te]=n,o[i+ne]=r,0===i&&e._state&&Y(x,e)}function x(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var r,o,i=e._result,u=0;uu;u++)T(r.resolve(e[u]),void 0,t,n);return o}function F(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var n=new t(y);return E(n,e),n}function D(e){var t=this,n=new t(y);return j(n,e),n}function W(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function H(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function I(e){this._id=fe++,this._state=void 0,this._result=void 0,this._subscribers=[],y!==e&&(i(e)||W(),this instanceof I||H(),C(this,e))}function N(){var e;if("undefined"!=typeof r)e=r;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=e.Promise;(!n||"[object Promise]"!==Object.prototype.toString.call(n.resolve())||n.cast)&&(e.Promise=pe)}var Z;Z=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var R,U,K=Z,X=0,Y=({}.toString,a),$="undefined"!=typeof window?window:void 0,G=$||{},J=G.MutationObserver||G.WebKitMutationObserver,V="undefined"!=typeof n&&"[object process]"==={}.toString.call(n),B="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Q=new Array(1e3);U=V?s():J?f():B?p():void 0===$&&"function"==typeof e?h():l();var ee=void 0,te=1,ne=2,re=new M,oe=new M;S.prototype._validateInput=function(e){return K(e)},S.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},S.prototype._init=function(){this._result=new Array(this.length)};var ie=S;S.prototype._enumerate=function(){for(var e=this,t=e.length,n=e.promise,r=e._input,o=0;n._state===ee&&t>o;o++)e._eachEntry(r[o],o)},S.prototype._eachEntry=function(e,t){var n=this,r=n._instanceConstructor;u(e)?e.constructor===r&&e._state!==ee?(e._onerror=null,n._settledAt(e._state,t,e._result)):n._willSettleAt(r.resolve(e),t):(n._remaining--,n._result[t]=e)},S.prototype._settledAt=function(e,t,n){var r=this,o=r.promise;o._state===ee&&(r._remaining--,e===ne?j(o,n):r._result[t]=n),0===r._remaining&&P(o,r._result)},S.prototype._willSettleAt=function(e,t){var n=this;T(e,void 0,function(e){n._settledAt(te,t,e)},function(e){n._settledAt(ne,t,e)})};var ue=L,ae=q,se=F,ce=D,fe=0,pe=I;I.all=ue,I.race=ae,I.resolve=se,I.reject=ce,I.prototype={constructor:I,then:function(e,t){var n=this,r=n._state;if(r===te&&!e||r===ne&&!t)return this;var o=new this.constructor(y),i=n._result;if(r){var u=arguments[r-1];Y(function(){z(r,o,u,i)})}else T(n,o,e,t);return o},"catch":function(e){return this.then(null,e)}};var le=N,de={Promise:pe,polyfill:le};"function"==typeof define&&define.amd?define(function(){return de}):"undefined"!=typeof t&&t.exports?t.exports=de:"undefined"!=typeof this&&(this.ES6Promise=de),le()}).call(this)}).call(this,{},"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,n){(function(e){"use strict";function n(e){o(this.bind(e))}function r(e){return e.prototype.scheduleMicrotask=n,e}function o(e){g[p]=e,p+=1,1===p&&l()}function i(){var e=0,t=new y(c),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(){n.data=e=++e%2}}function u(){var e=new MessageChannel;return e.port1.onmessage=c,function(){e.port2.postMessage(0)}}function a(){return function(){setTimeout(c,1)}}function s(){var e=Promise.resolve(void 0);return function(){e.then(c)}}function c(){for(var e=0;p>e;e++){var t=g[e];t(),g[e]=void 0}p=0}t.exports={addMicrotaskSupport:r};var f=!1,p=0;0==typeof Promise&&-1!==Promise.toString().indexOf("[native code]")&&(f=!0);var l,d="undefined"!=typeof e.window?e.window:void 0,h=d||{},y=h.MutationObserver||h.WebKitMutationObserver,v="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,g=new Array(1e3);l=f?s():y?i():v?u():a()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(e,t,n){(function(n){"use strict";function r(){o.patchSetClearFunction(n,["timeout","interval","immediate"]),o.patchSetFunction(n,["requestAnimationFrame","mozRequestAnimationFrame","webkitRequestAnimationFrame"]),o.patchFunction(n,["alert","prompt"]),c.apply(),f.apply(),i.apply(),u.patchClass("MutationObserver"),u.patchClass("WebKitMutationObserver"),a.apply(),s.apply()}var o=e("./functions"),i=e("./promise"),u=e("./mutation-observer"),a=e("./define-property"),s=e("./register-element"),c=(e("./websocket"),e("./event-target")),f=e("./property-descriptor");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./define-property":6,"./event-target":7,"./functions":8,"./mutation-observer":9,"./promise":10,"./property-descriptor":11,"./register-element":12,"./websocket":13}],6:[function(e,t,n){"use strict";function r(){Object.defineProperty=function(e,t,n){if(i(e,t))throw new TypeError("Cannot assign to read only property '"+t+"' of "+e);return"prototype"!==t&&(n=u(e,t,n)),a(e,t,n)},Object.defineProperties=function(e,t){return Object.keys(t).forEach(function(n){Object.defineProperty(e,n,t[n])}),e},Object.create=function(e,t){return"object"==typeof t&&Object.keys(t).forEach(function(n){t[n]=u(e,n,t[n])}),c(e,t)},Object.getOwnPropertyDescriptor=function(e,t){var n=s(e,t);return i(e,t)&&(n.configurable=!1),n}}function o(e,t,n){return n=u(e,t,n),a(e,t,n)}function i(e,t){return e&&e.__unconfigurables&&e.__unconfigurables[t]}function u(e,t,n){return n.configurable=!0,n.configurable||(e.__unconfigurables||a(e,"__unconfigurables",{writable:!0,value:{}}),e.__unconfigurables[t]=!0),n}var a=Object.defineProperty,s=Object.getOwnPropertyDescriptor,c=Object.create;t.exports={apply:r,_redefineProperty:o}},{}],7:[function(e,t,n){(function(n){"use strict";function r(){if(n.EventTarget)o.patchEventTargetMethods(n.EventTarget.prototype);else{var e=["ApplicationCache","EventSource","FileReader","InputMethodContext","MediaController","MessagePort","Node","Performance","SVGElementInstance","SharedWorker","TextTrack","TextTrackCue","TextTrackList","WebKitNamedFlow","Window","Worker","WorkerGlobalScope","XMLHttpRequestEventTarget","XMLHttpRequestUpload"];e.forEach(function(e){n[e]&&o.patchEventTargetMethods(n[e].prototype)})}}var o=e("../utils");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14}],8:[function(e,t,n){(function(n){"use strict";function r(e,t){t.map(function(e){return e[0].toUpperCase()+e.substr(1)}).forEach(function(t){var r="set"+t,o=e[r];if(o){var i="clear"+t,a={},s="setInterval"===r?u.bindArguments:u.bindArgumentsOnce;n.zone[r]=function(t){var n,r=t;arguments[0]=function(){return delete a[n],r.apply(this,arguments)};var i=s(arguments);return n=o.apply(e,i),a[n]=!0,n},e[r]=function(){return n.zone[r].apply(this,arguments)};var c=e[i];n.zone[i]=function(e){return a[e]&&(delete a[e],n.zone.dequeueTask()),c.apply(this,arguments)},e[i]=function(){return n.zone[i].apply(this,arguments)}}})}function o(e,t){t.forEach(function(t){var r=e[t];r&&(n.zone[t]=function(t){var n=t;arguments[0]=function(){return n.apply(this,arguments)};var o=u.bindArgumentsOnce(arguments);return r.apply(e,o)},e[t]=function(){return zone[t].apply(this,arguments)})})}function i(e,t){t.forEach(function(t){var r=e[t];n.zone[t]=function(){return r.apply(e,arguments)},e[t]=function(){return n.zone[t].apply(this,arguments)}})}var u=e("../utils");t.exports={patchSetClearFunction:r,patchSetFunction:o,patchFunction:i}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14}],9:[function(e,t,n){(function(e){"use strict";function n(t){var n=e[t];if(n){e[t]=function(e){this._o=new n(zone.bind(e,!0))};var r=new n(function(){});e[t].prototype.disconnect=function(){var t=this._o.disconnect.apply(this._o,arguments);return this._active&&e.zone.dequeueTask(),this._active=!1,t},e[t].prototype.observe=function(){return this._active||e.zone.enqueueTask(),this._active=!0,this._o.observe.apply(this._o,arguments)};var o;for(o in r)!function(n){void 0===typeof e[t].prototype&&("function"==typeof r[n]?e[t].prototype[n]=function(){return this._o[n].apply(this._o,arguments)}:Object.defineProperty(e[t].prototype,n,{set:function(e){this._o[n]="function"==typeof e?zone.bind(e):e},get:function(){return this._o[n]}}))}(o)}}t.exports={patchClass:n}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],10:[function(e,t,n){(function(n){"use strict";function r(){n.Promise&&o.patchPrototype(Promise.prototype,["then","catch"])}var o=e("../utils"),i=function(){function e(t){var n=t.then;t.then=function(){var r=o.bindArguments(arguments),i=n.apply(t,r);return e(i)};var r=t["catch"];return t["catch"]=function(){var n=o.bindArguments(arguments),i=r.apply(t,n);return e(i)},t}return n.Promise?function(e){return function(){var t=e.apply(this,arguments);return t instanceof Promise?t:new Promise(function(e,n){t.then(e,n)})}}:function(t){return function(){return e(t.apply(this,arguments))}}}();t.exports={apply:r,bindPromiseFn:i}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14}],11:[function(e,t,n){(function(n){"use strict";function r(){if(o()){var e=s.map(function(e){return"on"+e});a.patchProperties(HTMLElement.prototype,e),a.patchProperties(XMLHttpRequest.prototype),a.patchProperties(WebSocket.prototype)}else i(),a.patchClass("XMLHttpRequest"),u.apply()}function o(){if(!Object.getOwnPropertyDescriptor(HTMLElement.prototype,"onclick")&&"undefined"!=typeof Element){var e=Object.getOwnPropertyDescriptor(Element.prototype,"onclick");if(e&&!e.configurable)return!1}Object.defineProperty(HTMLElement.prototype,"onclick",{get:function(){return!0}});var t=document.createElement("div"),n=!!t.onclick;return Object.defineProperty(HTMLElement.prototype,"onclick",{}),n}function i(){s.forEach(function(e){var t="on"+e;document.addEventListener(e,function(e){for(var r,o=e.target;o;)o[t]&&!o[t]._unbound&&(r=n.zone.bind(o[t]),r._unbound=o[t],o[t]=r),o=o.parentElement},!0)})}var u=e("./websocket"),a=e("../utils"),s="copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror".split(" ");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14,"./websocket":13}],12:[function(e,t,n){(function(n){"use strict";function r(){if("registerElement"in n.document){var e=document.registerElement,t=["createdCallback","attachedCallback","detachedCallback","attributeChangedCallback"];document.registerElement=function(n,r){return t.forEach(function(e){if(r.prototype[e]){var t=Object.getOwnPropertyDescriptor(r.prototype,e);t.value&&(t.value=zone.bind(t.value||r.prototype[e]),o(r.prototype,e,t))}}),e.apply(document,[n,r])}}}var o=e("./define-property")._redefineProperty;t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./define-property":6}],13:[function(e,t,n){(function(n){"use strict";function r(){var e=n.WebSocket;o.patchEventTargetMethods(e.prototype),n.WebSocket=function(t,n){var r,i=arguments.length>1?new e(t,n):new e(t),u=Object.getOwnPropertyDescriptor(i,"onmessage");return u&&u.configurable===!1?(r=Object.create(i),["addEventListener","removeEventListener","send","close"].forEach(function(e){r[e]=function(){return i[e].apply(i,arguments)}})):r=i,o.patchProperties(r,["onclose","onerror","onmessage","onopen"]),r}}var o=e("../utils.js");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils.js":14}],14:[function(e,t,n){(function(e){"use strict";function n(t){for(var n=t.length-1;n>=0;n--)"function"==typeof t[n]&&(t[n]=e.zone.bind(t[n]));return t}function r(t){for(var n=t.length-1;n>=0;n--)"function"==typeof t[n]&&(t[n]=e.zone.bindOnce(t[n]));return t}function o(e,t){t.forEach(function(t){var r=e[t];r&&(e[t]=function(){return r.apply(this,n(arguments))})})}function i(e,t){var n=Object.getOwnPropertyDescriptor(e,t)||{enumerable:!0,configurable:!0};delete n.writable,delete n.value;var r=t.substr(2),o="_"+t;n.set=function(e){this[o]&&this.removeEventListener(r,this[o]),"function"==typeof e?(this[o]=e,this.addEventListener(r,e,!1)):this[o]=null},n.get=function(){return this[o]},Object.defineProperty(e,t,n)}function u(e,t){(t||function(){var t=[];for(var n in e)t.push(n);return t}().filter(function(e){return"on"===e.substr(0,2)})).forEach(function(t){i(e,t)})}function a(t){var n=t.addEventListener;t.addEventListener=function(e,t){return t._bound=t._bound||{},arguments[1]=t._bound[e]=zone.bind(t),n.apply(this,arguments)};var r=t.removeEventListener;t.removeEventListener=function(t,n){if(arguments[1]._bound&&arguments[1]._bound[t]){var o=arguments[1]._bound;arguments[1]=o[t],delete o[t]}var i=r.apply(this,arguments);return e.zone.dequeueTask(n),i}}function s(t){var r=e[t];if(r){e[t]=function(){var e=n(arguments);switch(e.length){case 0:this._o=new r;break;case 1:this._o=new r(e[0]);break;case 2:this._o=new r(e[0],e[1]);break;case 3:this._o=new r(e[0],e[1],e[2]);break;case 4:this._o=new r(e[0],e[1],e[2],e[3]);break;default:throw new Error("what are you even doing?")}};var o,i=new r("MutationObserver"===t.substr(-16)?function(){}:void 0);for(o in i)!function(n){"function"==typeof i[n]?e[t].prototype[n]=function(){return this._o[n].apply(this._o,arguments)}:Object.defineProperty(e[t].prototype,n,{set:function(t){this._o[n]="function"==typeof t?e.zone.bind(t):t},get:function(){return this._o[n]}})}(o)}}t.exports={bindArguments:n,bindArgumentsOnce:r,patchPrototype:o,patchProperty:i,patchProperties:u,patchEventTargetMethods:a,patchClass:s}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]); \ No newline at end of file +!function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(i)return i(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[u]={exports:{}};t[u][0].call(f.exports,function(e){var n=t[u][1][e];return o(n?n:e)},f,f.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;ue;e+=2){var t=Q[e],n=Q[e+1];t(n),Q[e]=void 0,Q[e+1]=void 0}X=0}function h(){try{var t=e,n=t("vertx");return R=n.runOnLoop||n.runOnContext,c()}catch(r){return l()}}function y(){}function v(){return new TypeError("You cannot resolve a promise with itself")}function g(){return new TypeError("A promises callback cannot return that same promise.")}function m(e){try{return e.then}catch(t){return re.error=t,re}}function b(e,t,n,r){try{e.call(t,n,r)}catch(o){return o}}function w(e,t,n){Y(function(e){var r=!1,o=b(n,t,function(n){r||(r=!0,t!==n?E(e,n):P(e,n))},function(t){r||(r=!0,j(e,t))},"Settle: "+(e._label||" unknown promise"));!r&&o&&(r=!0,j(e,o))},e)}function _(e,t){t._state===te?P(e,t._result):t._state===ne?j(e,t._result):T(t,void 0,function(t){E(e,t)},function(t){j(e,t)})}function k(e,t){if(t.constructor===e.constructor)_(e,t);else{var n=m(t);n===re?j(e,re.error):void 0===n?P(e,t):i(n)?w(e,t,n):P(e,t)}}function E(e,t){e===t?j(e,v()):o(t)?k(e,t):P(e,t)}function O(e){e._onerror&&e._onerror(e._result),x(e)}function P(e,t){e._state===ee&&(e._result=t,e._state=te,0!==e._subscribers.length&&Y(x,e))}function j(e,t){e._state===ee&&(e._state=ne,e._result=t,Y(O,e))}function T(e,t,n,r){var o=e._subscribers,i=o.length;e._onerror=null,o[i]=t,o[i+te]=n,o[i+ne]=r,0===i&&e._state&&Y(x,e)}function x(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var r,o,i=e._result,u=0;uu;u++)T(r.resolve(e[u]),void 0,t,n);return o}function F(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var n=new t(y);return E(n,e),n}function D(e){var t=this,n=new t(y);return j(n,e),n}function W(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function H(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function I(e){this._id=fe++,this._state=void 0,this._result=void 0,this._subscribers=[],y!==e&&(i(e)||W(),this instanceof I||H(),z(this,e))}function N(){var e;if("undefined"!=typeof r)e=r;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=e.Promise;(!n||"[object Promise]"!==Object.prototype.toString.call(n.resolve())||n.cast)&&(e.Promise=pe)}var Z;Z=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var R,U,K=Z,X=0,Y=({}.toString,a),$="undefined"!=typeof window?window:void 0,G=$||{},J=G.MutationObserver||G.WebKitMutationObserver,V="undefined"!=typeof n&&"[object process]"==={}.toString.call(n),B="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Q=new Array(1e3);U=V?s():J?f():B?p():void 0===$&&"function"==typeof e?h():l();var ee=void 0,te=1,ne=2,re=new M,oe=new M;S.prototype._validateInput=function(e){return K(e)},S.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},S.prototype._init=function(){this._result=new Array(this.length)};var ie=S;S.prototype._enumerate=function(){for(var e=this,t=e.length,n=e.promise,r=e._input,o=0;n._state===ee&&t>o;o++)e._eachEntry(r[o],o)},S.prototype._eachEntry=function(e,t){var n=this,r=n._instanceConstructor;u(e)?e.constructor===r&&e._state!==ee?(e._onerror=null,n._settledAt(e._state,t,e._result)):n._willSettleAt(r.resolve(e),t):(n._remaining--,n._result[t]=e)},S.prototype._settledAt=function(e,t,n){var r=this,o=r.promise;o._state===ee&&(r._remaining--,e===ne?j(o,n):r._result[t]=n),0===r._remaining&&P(o,r._result)},S.prototype._willSettleAt=function(e,t){var n=this;T(e,void 0,function(e){n._settledAt(te,t,e)},function(e){n._settledAt(ne,t,e)})};var ue=L,ae=q,se=F,ce=D,fe=0,pe=I;I.all=ue,I.race=ae,I.resolve=se,I.reject=ce,I.prototype={constructor:I,then:function(e,t){var n=this,r=n._state;if(r===te&&!e||r===ne&&!t)return this;var o=new this.constructor(y),i=n._result;if(r){var u=arguments[r-1];Y(function(){C(r,o,u,i)})}else T(n,o,e,t);return o},"catch":function(e){return this.then(null,e)}};var le=N,de={Promise:pe,polyfill:le};"function"==typeof define&&define.amd?define(function(){return de}):"undefined"!=typeof t&&t.exports?t.exports=de:"undefined"!=typeof this&&(this.ES6Promise=de),le()}).call(this)}).call(this,{},"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,n){(function(e){"use strict";function n(e){o(this.bind(e))}function r(e){return e.prototype.scheduleMicrotask=n,e}function o(e){m[p]=e,p+=1,1===p&&f()}function i(){var e=0,t=new v(c),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(){n.data=e=++e%2}}function u(){var e=new MessageChannel;return e.port1.onmessage=c,function(){e.port2.postMessage(0)}}function a(){return function(){setTimeout(c,1)}}function s(){var e=Promise.resolve(void 0);return function(){e.then(c)}}function c(){for(var e=0;p>e;e++){var t=m[e];t(),m[e]=void 0}p=0}t.exports={addMicrotaskSupport:r};var f,p=0,l=0==typeof Promise&&-1!==Promise.toString().indexOf("[native code]"),d=e.navigator&&e.navigator.userAgent.toLowerCase().indexOf("firefox")>-1,h="undefined"!=typeof e.window?e.window:void 0,y=h||{},v=y.MutationObserver||y.WebKitMutationObserver,g="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,m=new Array(1e3);f=l&&!d?s():v?i():g?u():a()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(e,t,n){(function(n){"use strict";function r(){o.patchSetClearFunction(n,["timeout","interval","immediate"]),o.patchSetFunction(n,["requestAnimationFrame","mozRequestAnimationFrame","webkitRequestAnimationFrame"]),o.patchFunction(n,["alert","prompt"]),c.apply(),f.apply(),i.apply(),u.patchClass("MutationObserver"),u.patchClass("WebKitMutationObserver"),a.apply(),s.apply()}var o=e("./functions"),i=e("./promise"),u=e("./mutation-observer"),a=e("./define-property"),s=e("./register-element"),c=(e("./websocket"),e("./event-target")),f=e("./property-descriptor");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./define-property":6,"./event-target":7,"./functions":8,"./mutation-observer":9,"./promise":10,"./property-descriptor":11,"./register-element":12,"./websocket":13}],6:[function(e,t,n){"use strict";function r(){Object.defineProperty=function(e,t,n){if(i(e,t))throw new TypeError("Cannot assign to read only property '"+t+"' of "+e);return"prototype"!==t&&(n=u(e,t,n)),a(e,t,n)},Object.defineProperties=function(e,t){return Object.keys(t).forEach(function(n){Object.defineProperty(e,n,t[n])}),e},Object.create=function(e,t){return"object"==typeof t&&Object.keys(t).forEach(function(n){t[n]=u(e,n,t[n])}),c(e,t)},Object.getOwnPropertyDescriptor=function(e,t){var n=s(e,t);return i(e,t)&&(n.configurable=!1),n}}function o(e,t,n){return n=u(e,t,n),a(e,t,n)}function i(e,t){return e&&e.__unconfigurables&&e.__unconfigurables[t]}function u(e,t,n){return n.configurable=!0,n.configurable||(e.__unconfigurables||a(e,"__unconfigurables",{writable:!0,value:{}}),e.__unconfigurables[t]=!0),n}var a=Object.defineProperty,s=Object.getOwnPropertyDescriptor,c=Object.create;t.exports={apply:r,_redefineProperty:o}},{}],7:[function(e,t,n){(function(n){"use strict";function r(){if(n.EventTarget)o.patchEventTargetMethods(n.EventTarget.prototype);else{var e=["ApplicationCache","EventSource","FileReader","InputMethodContext","MediaController","MessagePort","Node","Performance","SVGElementInstance","SharedWorker","TextTrack","TextTrackCue","TextTrackList","WebKitNamedFlow","Window","Worker","WorkerGlobalScope","XMLHttpRequestEventTarget","XMLHttpRequestUpload"];e.forEach(function(e){n[e]&&o.patchEventTargetMethods(n[e].prototype)})}}var o=e("../utils");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14}],8:[function(e,t,n){(function(n){"use strict";function r(e,t){t.map(function(e){return e[0].toUpperCase()+e.substr(1)}).forEach(function(t){var r="set"+t,o=e[r];if(o){var i="clear"+t,a={},s="setInterval"===r?u.bindArguments:u.bindArgumentsOnce;n.zone[r]=function(t){var n,r=t;arguments[0]=function(){return delete a[n],r.apply(this,arguments)};var i=s(arguments);return n=o.apply(e,i),a[n]=!0,n},e[r]=function(){return n.zone[r].apply(this,arguments)};var c=e[i];n.zone[i]=function(e){return a[e]&&(delete a[e],n.zone.dequeueTask()),c.apply(this,arguments)},e[i]=function(){return n.zone[i].apply(this,arguments)}}})}function o(e,t){t.forEach(function(t){var r=e[t];r&&(n.zone[t]=function(t){var n=t;arguments[0]=function(){return n.apply(this,arguments)};var o=u.bindArgumentsOnce(arguments);return r.apply(e,o)},e[t]=function(){return zone[t].apply(this,arguments)})})}function i(e,t){t.forEach(function(t){var r=e[t];n.zone[t]=function(){return r.apply(e,arguments)},e[t]=function(){return n.zone[t].apply(this,arguments)}})}var u=e("../utils");t.exports={patchSetClearFunction:r,patchSetFunction:o,patchFunction:i}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14}],9:[function(e,t,n){(function(e){"use strict";function n(t){var n=e[t];if(n){e[t]=function(e){this._o=new n(zone.bind(e,!0))};var r=new n(function(){});e[t].prototype.disconnect=function(){var t=this._o.disconnect.apply(this._o,arguments);return this._active&&e.zone.dequeueTask(),this._active=!1,t},e[t].prototype.observe=function(){return this._active||e.zone.enqueueTask(),this._active=!0,this._o.observe.apply(this._o,arguments)};var o;for(o in r)!function(n){void 0===typeof e[t].prototype&&("function"==typeof r[n]?e[t].prototype[n]=function(){return this._o[n].apply(this._o,arguments)}:Object.defineProperty(e[t].prototype,n,{set:function(e){this._o[n]="function"==typeof e?zone.bind(e):e},get:function(){return this._o[n]}}))}(o)}}t.exports={patchClass:n}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],10:[function(e,t,n){(function(n){"use strict";function r(){n.Promise&&o.patchPrototype(Promise.prototype,["then","catch"])}var o=e("../utils"),i=function(){function e(t){var n=t.then;t.then=function(){var r=o.bindArguments(arguments),i=n.apply(t,r);return e(i)};var r=t["catch"];return t["catch"]=function(){var n=o.bindArguments(arguments),i=r.apply(t,n);return e(i)},t}return n.Promise?function(e){return function(){var t=e.apply(this,arguments);return t instanceof Promise?t:new Promise(function(e,n){t.then(e,n)})}}:function(t){return function(){return e(t.apply(this,arguments))}}}();t.exports={apply:r,bindPromiseFn:i}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14}],11:[function(e,t,n){(function(n){"use strict";function r(){if(o()){var e=s.map(function(e){return"on"+e});a.patchProperties(HTMLElement.prototype,e),a.patchProperties(XMLHttpRequest.prototype),a.patchProperties(WebSocket.prototype)}else i(),a.patchClass("XMLHttpRequest"),u.apply()}function o(){if(!Object.getOwnPropertyDescriptor(HTMLElement.prototype,"onclick")&&"undefined"!=typeof Element){var e=Object.getOwnPropertyDescriptor(Element.prototype,"onclick");if(e&&!e.configurable)return!1}Object.defineProperty(HTMLElement.prototype,"onclick",{get:function(){return!0}});var t=document.createElement("div"),n=!!t.onclick;return Object.defineProperty(HTMLElement.prototype,"onclick",{}),n}function i(){s.forEach(function(e){var t="on"+e;document.addEventListener(e,function(e){for(var r,o=e.target;o;)o[t]&&!o[t]._unbound&&(r=n.zone.bind(o[t]),r._unbound=o[t],o[t]=r),o=o.parentElement},!0)})}var u=e("./websocket"),a=e("../utils"),s="copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror".split(" ");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils":14,"./websocket":13}],12:[function(e,t,n){(function(n){"use strict";function r(){if("registerElement"in n.document){var e=document.registerElement,t=["createdCallback","attachedCallback","detachedCallback","attributeChangedCallback"];document.registerElement=function(n,r){return t.forEach(function(e){if(r.prototype[e]){var t=Object.getOwnPropertyDescriptor(r.prototype,e);t.value&&(t.value=zone.bind(t.value||r.prototype[e]),o(r.prototype,e,t))}}),e.apply(document,[n,r])}}}var o=e("./define-property")._redefineProperty;t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./define-property":6}],13:[function(e,t,n){(function(n){"use strict";function r(){var e=n.WebSocket;o.patchEventTargetMethods(e.prototype),n.WebSocket=function(t,n){var r,i=arguments.length>1?new e(t,n):new e(t),u=Object.getOwnPropertyDescriptor(i,"onmessage");return u&&u.configurable===!1?(r=Object.create(i),["addEventListener","removeEventListener","send","close"].forEach(function(e){r[e]=function(){return i[e].apply(i,arguments)}})):r=i,o.patchProperties(r,["onclose","onerror","onmessage","onopen"]),r}}var o=e("../utils.js");t.exports={apply:r}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils.js":14}],14:[function(e,t,n){(function(e){"use strict";function n(t){for(var n=t.length-1;n>=0;n--)"function"==typeof t[n]&&(t[n]=e.zone.bind(t[n]));return t}function r(t){for(var n=t.length-1;n>=0;n--)"function"==typeof t[n]&&(t[n]=e.zone.bindOnce(t[n]));return t}function o(e,t){t.forEach(function(t){var r=e[t];r&&(e[t]=function(){return r.apply(this,n(arguments))})})}function i(e,t){var n=Object.getOwnPropertyDescriptor(e,t)||{enumerable:!0,configurable:!0};delete n.writable,delete n.value;var r=t.substr(2),o="_"+t;n.set=function(e){this[o]&&this.removeEventListener(r,this[o]),"function"==typeof e?(this[o]=e,this.addEventListener(r,e,!1)):this[o]=null},n.get=function(){return this[o]},Object.defineProperty(e,t,n)}function u(e,t){(t||function(){var t=[];for(var n in e)t.push(n);return t}().filter(function(e){return"on"===e.substr(0,2)})).forEach(function(t){i(e,t)})}function a(t){var n=t.addEventListener;t.addEventListener=function(e,t){return t._bound=t._bound||{},arguments[1]=t._bound[e]=zone.bind(t),n.apply(this,arguments)};var r=t.removeEventListener;t.removeEventListener=function(t,n){if(arguments[1]._bound&&arguments[1]._bound[t]){var o=arguments[1]._bound;arguments[1]=o[t],delete o[t]}var i=r.apply(this,arguments);return e.zone.dequeueTask(n),i}}function s(t){var r=e[t];if(r){e[t]=function(){var e=n(arguments);switch(e.length){case 0:this._o=new r;break;case 1:this._o=new r(e[0]);break;case 2:this._o=new r(e[0],e[1]);break;case 3:this._o=new r(e[0],e[1],e[2]);break;case 4:this._o=new r(e[0],e[1],e[2],e[3]);break;default:throw new Error("what are you even doing?")}};var o,i=new r("MutationObserver"===t.substr(-16)?function(){}:void 0);for(o in i)!function(n){"function"==typeof i[n]?e[t].prototype[n]=function(){return this._o[n].apply(this._o,arguments)}:Object.defineProperty(e[t].prototype,n,{set:function(t){this._o[n]="function"==typeof t?e.zone.bind(t):t},get:function(){return this._o[n]}})}(o)}}t.exports={bindArguments:n,bindArgumentsOnce:r,patchPrototype:o,patchProperty:i,patchProperties:u,patchEventTargetMethods:a,patchClass:s}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]); \ No newline at end of file diff --git a/lib/microtask.js b/lib/microtask.js index e14b49c87..89d331cf2 100644 --- a/lib/microtask.js +++ b/lib/microtask.js @@ -21,12 +21,13 @@ module.exports = { // TODO(vicb): Create a benchmark for the different methods & the usage of the queue // see https://github.com/angular/zone.js/issues/97 -var hasNativePromise = false; var len = 0; -if (typeof Promise ==! "undefined" && Promise.toString().indexOf("[native code]") !== -1) { - hasNativePromise = true; -} +var hasNativePromise = typeof Promise ==! "undefined" && + Promise.toString().indexOf("[native code]") !== -1; + +var isFirefox = global.navigator && + global.navigator.userAgent.toLowerCase().indexOf('firefox') > -1; function asap(callback) { queue[len] = callback; @@ -92,7 +93,9 @@ function flush() { var scheduleFlush; // Decide what async method to use to triggering processing of queued callbacks: -if (hasNativePromise) { +if (hasNativePromise && !isFirefox) { + // TODO(vicb): remove '!isFirefox' when the bug is fixed: + // https://bugzilla.mozilla.org/show_bug.cgi?id=1162013 scheduleFlush = usePromise(); } else if (BrowserMutationObserver) { scheduleFlush = useMutationObserver(); diff --git a/test/microtasks.spec.js b/test/microtasks.spec.js index 805b5d12b..ad6b445d2 100644 --- a/test/microtasks.spec.js +++ b/test/microtasks.spec.js @@ -21,7 +21,7 @@ describe('Microtasks', function () { }); // Does not currently work with Firefox, see https://bugzilla.mozilla.org/show_bug.cgi?id=1162013 - xit('should correctly schedule microtasks vs macrotasks', function(done) { + it('should correctly schedule microtasks vs macrotasks', function(done) { var log = ['+root']; zone.scheduleMicrotask(function() {