From 531d0ecc105dd62020780b4e73fdbe5b25306d99 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 1 May 2015 22:35:20 -0700 Subject: [PATCH] fix: don't fork new zones for callbacks from the root zone BREAKING CHANGE: New child zones are now created only from a async task that installed a custom zone. Previously even without a custom zone installed (e.g. LongStacktracesZone), we would spawn new child zones for all asynchronous events. This is undesirable and generally not useful. It does not make sense for us to create new zones for callbacks from the root zone since we care only about callbacks from installed custom zones. This reduces the overhead of zones. This primarily means that LongStackTraces zone won't be able to trace events back to Zone.init(), but instead the starting point will be the installation of the LongStacktracesZone. In all practical situations this should be sufficient. Closes #92 --- dist/zone-microtask.js | 2 +- dist/zone-microtask.min.js | 2 +- dist/zone.js | 2 +- dist/zone.min.js | 2 +- lib/core.js | 2 +- test/zone.spec.js | 24 ++++++++++++++++++++++++ 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/dist/zone-microtask.js b/dist/zone-microtask.js index e9cca8ed2..55b65e01b 100644 --- a/dist/zone-microtask.js +++ b/dist/zone-microtask.js @@ -83,7 +83,7 @@ Zone.prototype = { bind: function (fn, skipEnqueue) { skipEnqueue || this.enqueueTask(fn); - var zone = this.fork(); + var zone = this.isRootZone() ? this : this.fork(); return function zoneBoundFn() { return zone.run(fn, this, arguments); }; diff --git a/dist/zone-microtask.min.js b/dist/zone-microtask.min.js index 5873bd4c8..fc3880baa 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 Z(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function H(e){this._id=fe++,this._state=void 0,this._result=void 0,this._subscribers=[],y!==e&&(i(e)||W(),this instanceof H||Z(),z(this,e))}function I(){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 N;N=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var R,U,K=N,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=H;H.all=ue,H.race=ae,H.resolve=se,H.reject=ce,H.prototype={constructor:H,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=I,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 +!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 N=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 Z(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function R(e){this._id=fe++,this._state=void 0,this._result=void 0,this._subscribers=[],y!==e&&(i(e)||W(),this instanceof R||Z(),z(this,e))}function H(){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 I;I=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var N,U,K=I,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=R;R.all=ue,R.race=ae,R.resolve=se,R.reject=ce,R.prototype={constructor:R,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=H,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/dist/zone.js b/dist/zone.js index cd1890567..57e688834 100644 --- a/dist/zone.js +++ b/dist/zone.js @@ -78,7 +78,7 @@ Zone.prototype = { bind: function (fn, skipEnqueue) { skipEnqueue || this.enqueueTask(fn); - var zone = this.fork(); + var zone = this.isRootZone() ? this : this.fork(); return function zoneBoundFn() { return zone.run(fn, this, arguments); }; diff --git a/dist/zone.min.js b/dist/zone.min.js index 8cfc36de0..9c30ca164 100644 --- a/dist/zone.min.js +++ b/dist/zone.min.js @@ -1 +1 @@ -!function e(t,n,o){function r(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 r(n?n:e)},f,f.exports,e,t,n,o)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u1?new e(t,n):new e(t),u=Object.getOwnPropertyDescriptor(i,"onmessage");return u&&u.configurable===!1?(o=Object.create(i),["addEventListener","removeEventListener","send","close"].forEach(function(e){o[e]=function(){return i[e].apply(i,arguments)}})):o=i,r.patchProperties(o,["onclose","onerror","onmessage","onopen"]),o}}var r=e("../utils.js");t.exports={apply:o}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils.js":12}],12:[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 o(t){for(var n=t.length-1;n>=0;n--)"function"==typeof t[n]&&(t[n]=e.zone.bindOnce(t[n]));return t}function r(e,t){t.forEach(function(t){var o=e[t];o&&(e[t]=function(){return o.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 o=t.substr(2),r="_"+t;n.set=function(e){this[r]&&this.removeEventListener(o,this[r]),"function"==typeof e?(this[r]=e,this.addEventListener(o,e,!1)):this[r]=null},n.get=function(){return this[r]},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 o=t.removeEventListener;t.removeEventListener=function(t,n){if(arguments[1]._bound&&arguments[1]._bound[t]){var r=arguments[1]._bound;arguments[1]=r[t],delete r[t]}var i=o.apply(this,arguments);return e.zone.dequeueTask(n),i}}function s(t){var o=e[t];if(o){e[t]=function(){var e=n(arguments);switch(e.length){case 0:this._o=new o;break;case 1:this._o=new o(e[0]);break;case 2:this._o=new o(e[0],e[1]);break;case 3:this._o=new o(e[0],e[1],e[2]);break;case 4:this._o=new o(e[0],e[1],e[2],e[3]);break;default:throw new Error("what are you even doing?")}};var r,i=new o("MutationObserver"===t.substr(-16)?function(){}:void 0);for(r 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]}})}(r)}}t.exports={bindArguments:n,bindArgumentsOnce:o,patchPrototype:r,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,o){function r(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 r(n?n:e)},f,f.exports,e,t,n,o)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u1?new e(t,n):new e(t),u=Object.getOwnPropertyDescriptor(i,"onmessage");return u&&u.configurable===!1?(o=Object.create(i),["addEventListener","removeEventListener","send","close"].forEach(function(e){o[e]=function(){return i[e].apply(i,arguments)}})):o=i,r.patchProperties(o,["onclose","onerror","onmessage","onopen"]),o}}var r=e("../utils.js");t.exports={apply:o}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../utils.js":12}],12:[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 o(t){for(var n=t.length-1;n>=0;n--)"function"==typeof t[n]&&(t[n]=e.zone.bindOnce(t[n]));return t}function r(e,t){t.forEach(function(t){var o=e[t];o&&(e[t]=function(){return o.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 o=t.substr(2),r="_"+t;n.set=function(e){this[r]&&this.removeEventListener(o,this[r]),"function"==typeof e?(this[r]=e,this.addEventListener(o,e,!1)):this[r]=null},n.get=function(){return this[r]},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 o=t.removeEventListener;t.removeEventListener=function(t,n){if(arguments[1]._bound&&arguments[1]._bound[t]){var r=arguments[1]._bound;arguments[1]=r[t],delete r[t]}var i=o.apply(this,arguments);return e.zone.dequeueTask(n),i}}function s(t){var o=e[t];if(o){e[t]=function(){var e=n(arguments);switch(e.length){case 0:this._o=new o;break;case 1:this._o=new o(e[0]);break;case 2:this._o=new o(e[0],e[1]);break;case 3:this._o=new o(e[0],e[1],e[2]);break;case 4:this._o=new o(e[0],e[1],e[2],e[3]);break;default:throw new Error("what are you even doing?")}};var r,i=new o("MutationObserver"===t.substr(-16)?function(){}:void 0);for(r 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]}})}(r)}}t.exports={bindArguments:n,bindArgumentsOnce:o,patchPrototype:r,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/core.js b/lib/core.js index 52d71eeeb..422e17cce 100644 --- a/lib/core.js +++ b/lib/core.js @@ -59,7 +59,7 @@ Zone.prototype = { bind: function (fn, skipEnqueue) { skipEnqueue || this.enqueueTask(fn); - var zone = this.fork(); + var zone = this.isRootZone() ? this : this.fork(); return function zoneBoundFn() { return zone.run(fn, this, arguments); }; diff --git a/test/zone.spec.js b/test/zone.spec.js index f99133732..257d8df89 100644 --- a/test/zone.spec.js +++ b/test/zone.spec.js @@ -149,6 +149,30 @@ describe('Zone', function () { }); + describe('bind', function() { + + it('should execute all callbacks from root zone without forking zones', function(done) { + // using setTimeout for the test which relies on patching via bind + setTimeout(function() { + expect(zone.isRootZone()).toBe(true); + done(); + }); + }); + + + it('should fork a zone for non-root zone', function(done) { + // using setTimeout for the test which relies on patching via bind + var childZone = zone.fork(); + childZone.run(function() { + setTimeout(function() { + expect(zone.parent).toBe(childZone); + done(); + }); + }); + }); + }); + + describe('fork', function () { it('should fork deep copy', function () { var protoZone = { too: { deep: true } },