diff --git a/dist/async-test.js b/dist/async-test.js index ff32608d3..e71ba6392 100644 --- a/dist/async-test.js +++ b/dist/async-test.js @@ -1,68 +1,81 @@ -(function () { - var AsyncTestZoneSpec = (function () { - function AsyncTestZoneSpec(finishCallback, failCallback, namePrefix) { - this._pendingMicroTasks = false; - this._pendingMacroTasks = false; - this._alreadyErrored = false; - this.runZone = Zone.current; - this._finishCallback = finishCallback; - this._failCallback = failCallback; - this.name = 'asyncTestZone for ' + namePrefix; +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + +var AsyncTestZoneSpec = (function () { + function AsyncTestZoneSpec(finishCallback, failCallback, namePrefix) { + this._pendingMicroTasks = false; + this._pendingMacroTasks = false; + this._alreadyErrored = false; + this.runZone = Zone.current; + this._finishCallback = finishCallback; + this._failCallback = failCallback; + this.name = 'asyncTestZone for ' + namePrefix; + } + AsyncTestZoneSpec.prototype._finishCallbackIfDone = function () { + var _this = this; + if (!(this._pendingMicroTasks || this._pendingMacroTasks)) { + // We do this because we would like to catch unhandled rejected promises. + this.runZone.run(function () { + setTimeout(function () { + if (!_this._alreadyErrored && !(_this._pendingMicroTasks || _this._pendingMacroTasks)) { + _this._finishCallback(); + } + }, 0); + }); } - AsyncTestZoneSpec.prototype._finishCallbackIfDone = function () { - var _this = this; - if (!(this._pendingMicroTasks || this._pendingMacroTasks)) { - // We do this because we would like to catch unhandled rejected promises. - this.runZone.run(function () { - setTimeout(function () { - if (!_this._alreadyErrored && !(_this._pendingMicroTasks || _this._pendingMacroTasks)) { - _this._finishCallback(); - } - }, 0); - }); - } - }; - // Note - we need to use onInvoke at the moment to call finish when a test is - // fully synchronous. TODO(juliemr): remove this when the logic for - // onHasTask changes and it calls whenever the task queues are dirty. - AsyncTestZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) { - try { - return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); - } - finally { - this._finishCallbackIfDone(); - } - }; - AsyncTestZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) { - // Let the parent try to handle the error. - var result = parentZoneDelegate.handleError(targetZone, error); - if (result) { - this._failCallback(error); - this._alreadyErrored = true; - } - return false; - }; - AsyncTestZoneSpec.prototype.onScheduleTask = function (delegate, currentZone, targetZone, task) { - if (task.type == 'macroTask' && task.source == 'setInterval') { - this._failCallback('Cannot use setInterval from within an async zone test.'); - return; - } - return delegate.scheduleTask(targetZone, task); - }; - AsyncTestZoneSpec.prototype.onHasTask = function (delegate, current, target, hasTaskState) { - delegate.hasTask(target, hasTaskState); - if (hasTaskState.change == 'microTask') { - this._pendingMicroTasks = hasTaskState.microTask; - this._finishCallbackIfDone(); - } - else if (hasTaskState.change == 'macroTask') { - this._pendingMacroTasks = hasTaskState.macroTask; - this._finishCallbackIfDone(); - } - }; - return AsyncTestZoneSpec; - }()); - // Export the class so that new instances can be created with proper - // constructor params. - Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; -})(); \ No newline at end of file + }; + // Note - we need to use onInvoke at the moment to call finish when a test is + // fully synchronous. TODO(juliemr): remove this when the logic for + // onHasTask changes and it calls whenever the task queues are dirty. + AsyncTestZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) { + try { + return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); + } + finally { + this._finishCallbackIfDone(); + } + }; + AsyncTestZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) { + // Let the parent try to handle the error. + var result = parentZoneDelegate.handleError(targetZone, error); + if (result) { + this._failCallback(error); + this._alreadyErrored = true; + } + return false; + }; + AsyncTestZoneSpec.prototype.onScheduleTask = function (delegate, currentZone, targetZone, task) { + if (task.type == 'macroTask' && task.source == 'setInterval') { + this._failCallback('Cannot use setInterval from within an async zone test.'); + return; + } + return delegate.scheduleTask(targetZone, task); + }; + AsyncTestZoneSpec.prototype.onHasTask = function (delegate, current, target, hasTaskState) { + delegate.hasTask(target, hasTaskState); + if (hasTaskState.change == 'microTask') { + this._pendingMicroTasks = hasTaskState.microTask; + this._finishCallbackIfDone(); + } + else if (hasTaskState.change == 'macroTask') { + this._pendingMacroTasks = hasTaskState.macroTask; + this._finishCallbackIfDone(); + } + }; + return AsyncTestZoneSpec; +}()); +// Export the class so that new instances can be created with proper +// constructor params. +Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; + +}))); diff --git a/dist/fake-async-test.js b/dist/fake-async-test.js index 937e1b8a2..b65f4712b 100644 --- a/dist/fake-async-test.js +++ b/dist/fake-async-test.js @@ -1,3 +1,16 @@ +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + (function (global) { var Scheduler = (function () { function Scheduler() { @@ -235,4 +248,6 @@ // Export the class so that new instances can be created with proper // constructor params. Zone['FakeAsyncTestZoneSpec'] = FakeAsyncTestZoneSpec; -})(typeof window === 'object' && window || typeof self === 'object' && self || global); \ No newline at end of file +})(typeof window === 'object' && window || typeof self === 'object' && self || global); + +}))); diff --git a/dist/jasmine-patch.js b/dist/jasmine-patch.js index c088e34d0..48bd03c1c 100644 --- a/dist/jasmine-patch.js +++ b/dist/jasmine-patch.js @@ -1,3 +1,16 @@ +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + var __extends = (undefined && undefined.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } @@ -108,4 +121,6 @@ var __extends = (undefined && undefined.__extends) || function (d, b) { }; return ZoneQueueRunner; }(QueueRunner)); -})(); \ No newline at end of file +})(); + +}))); diff --git a/dist/jasmine-patch.min.js b/dist/jasmine-patch.min.js index 5f185560f..916e90019 100644 --- a/dist/jasmine-patch.min.js +++ b/dist/jasmine-patch.min.js @@ -1 +1 @@ -var __extends=function(e,n){function r(){this.constructor=e}for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)};!function(){function e(e){return function(){return i.run(e,this,arguments)}}function n(e){return 0==e.length?function(){return c.run(e,this)}:function(n){return c.run(e,this,[n])}}if(!Zone)throw new Error("Missing: zone.js");if("undefined"==typeof jasmine)throw new Error("Missing: jasmine.js");if(jasmine.__zone_patch__)throw new Error("'jasmine' has already been patched with 'Zone'.");jasmine.__zone_patch__=!0;var r=Zone.SyncTestZoneSpec,t=Zone.ProxyZoneSpec;if(!r)throw new Error("Missing: SyncTestZoneSpec");if(!t)throw new Error("Missing: ProxyZoneSpec");var o=Zone.current,i=o.fork(new r("jasmine.describe")),c=null,u=jasmine.getEnv();["describe","xdescribe","fdescribe"].forEach(function(n){var r=u[n];u[n]=function(n,t){return r.call(this,n,e(t))}}),["it","xit","fit"].forEach(function(e){var r=u[e];u[e]=function(e,t,o){return arguments[1]=n(t),r.apply(this,arguments)}}),["beforeEach","afterEach"].forEach(function(e){var r=u[e];u[e]=function(e,t){return arguments[0]=n(e),r.apply(this,arguments)}});var s=jasmine.QueueRunner;jasmine.QueueRunner=function(e){function n(n){n.onComplete=function(e){return function(){c=null,o.scheduleMicroTask("jasmine.onComplete",e)}}(n.onComplete),e.call(this,n)}return __extends(n,e),n.prototype.execute=function(){var n=this;if(Zone.current!==o)throw new Error("Unexpected Zone: "+Zone.current.name);c=o.fork(new t),Zone.currentTask?e.prototype.execute.call(this):Zone.current.scheduleMicroTask("jasmine.execute().forceTask",function(){return e.prototype.execute.call(n)})},n}(s)}(); \ No newline at end of file +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(this,function(){"use strict";var e=function(e,n){function r(){this.constructor=e}for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)};!function(){function n(e){return function(){return c.run(e,this,arguments)}}function r(e){return 0==e.length?function(){return u.run(e,this)}:function(n){return u.run(e,this,[n])}}if(!Zone)throw new Error("Missing: zone.js");if("undefined"==typeof jasmine)throw new Error("Missing: jasmine.js");if(jasmine.__zone_patch__)throw new Error("'jasmine' has already been patched with 'Zone'.");jasmine.__zone_patch__=!0;var t=Zone.SyncTestZoneSpec,o=Zone.ProxyZoneSpec;if(!t)throw new Error("Missing: SyncTestZoneSpec");if(!o)throw new Error("Missing: ProxyZoneSpec");var i=Zone.current,c=i.fork(new t("jasmine.describe")),u=null,s=jasmine.getEnv();["describe","xdescribe","fdescribe"].forEach(function(e){var r=s[e];s[e]=function(e,t){return r.call(this,e,n(t))}}),["it","xit","fit"].forEach(function(e){var n=s[e];s[e]=function(e,t,o){return arguments[1]=r(t),n.apply(this,arguments)}}),["beforeEach","afterEach"].forEach(function(e){var n=s[e];s[e]=function(e,t){return arguments[0]=r(e),n.apply(this,arguments)}});var f=jasmine.QueueRunner;jasmine.QueueRunner=function(n){function r(e){e.onComplete=function(e){return function(){u=null,i.scheduleMicroTask("jasmine.onComplete",e)}}(e.onComplete),n.call(this,e)}return e(r,n),r.prototype.execute=function(){var e=this;if(Zone.current!==i)throw new Error("Unexpected Zone: "+Zone.current.name);u=i.fork(new o),Zone.currentTask?n.prototype.execute.call(this):Zone.current.scheduleMicroTask("jasmine.execute().forceTask",function(){return n.prototype.execute.call(e)})},r}(f)}()}); \ No newline at end of file diff --git a/dist/long-stack-trace-zone.js b/dist/long-stack-trace-zone.js index 33f2fff0a..e68ac62fc 100644 --- a/dist/long-stack-trace-zone.js +++ b/dist/long-stack-trace-zone.js @@ -1,132 +1,145 @@ -(function () { - var NEWLINE = '\n'; - var SEP = ' ------------- '; - var IGNORE_FRAMES = []; - var creationTrace = '__creationTrace__'; - var LongStackTrace = (function () { - function LongStackTrace() { - this.error = getStacktrace(); - this.timestamp = new Date(); - } - return LongStackTrace; - }()); - function getStacktraceWithUncaughtError() { - return new Error('STACKTRACE TRACKING'); +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + +var NEWLINE = '\n'; +var SEP = ' ------------- '; +var IGNORE_FRAMES = []; +var creationTrace = '__creationTrace__'; +var LongStackTrace = (function () { + function LongStackTrace() { + this.error = getStacktrace(); + this.timestamp = new Date(); } - function getStacktraceWithCaughtError() { - try { - throw getStacktraceWithUncaughtError(); - } - catch (e) { - return e; - } + return LongStackTrace; +}()); +function getStacktraceWithUncaughtError() { + return new Error('STACKTRACE TRACKING'); +} +function getStacktraceWithCaughtError() { + try { + throw getStacktraceWithUncaughtError(); } - // Some implementations of exception handling don't create a stack trace if the exception - // isn't thrown, however it's faster not to actually throw the exception. - var error = getStacktraceWithUncaughtError(); - var coughtError = getStacktraceWithCaughtError(); - var getStacktrace = error.stack - ? getStacktraceWithUncaughtError - : (coughtError.stack ? getStacktraceWithCaughtError : getStacktraceWithUncaughtError); - function getFrames(error) { - return error.stack ? error.stack.split(NEWLINE) : []; + catch (e) { + return e; } - function addErrorStack(lines, error) { - var trace = getFrames(error); - for (var i = 0; i < trace.length; i++) { - var frame = trace[i]; - // Filter out the Frames which are part of stack capturing. - if (!(i < IGNORE_FRAMES.length && IGNORE_FRAMES[i] === frame)) { - lines.push(trace[i]); - } +} +// Some implementations of exception handling don't create a stack trace if the exception +// isn't thrown, however it's faster not to actually throw the exception. +var error = getStacktraceWithUncaughtError(); +var coughtError = getStacktraceWithCaughtError(); +var getStacktrace = error.stack + ? getStacktraceWithUncaughtError + : (coughtError.stack ? getStacktraceWithCaughtError : getStacktraceWithUncaughtError); +function getFrames(error) { + return error.stack ? error.stack.split(NEWLINE) : []; +} +function addErrorStack(lines, error) { + var trace = getFrames(error); + for (var i = 0; i < trace.length; i++) { + var frame = trace[i]; + // Filter out the Frames which are part of stack capturing. + if (!(i < IGNORE_FRAMES.length && IGNORE_FRAMES[i] === frame)) { + lines.push(trace[i]); } } - function renderLongStackTrace(frames, stack) { - var longTrace = [stack]; - if (frames) { - var timestamp = new Date().getTime(); - for (var i = 0; i < frames.length; i++) { - var traceFrames = frames[i]; - var lastTime = traceFrames.timestamp; - longTrace.push(SEP + " Elapsed: " + (timestamp - lastTime.getTime()) + " ms; At: " + lastTime + " " + SEP); - addErrorStack(longTrace, traceFrames.error); - timestamp = lastTime.getTime(); - } +} +function renderLongStackTrace(frames, stack) { + var longTrace = [stack]; + if (frames) { + var timestamp = new Date().getTime(); + for (var i = 0; i < frames.length; i++) { + var traceFrames = frames[i]; + var lastTime = traceFrames.timestamp; + longTrace.push(SEP + " Elapsed: " + (timestamp - lastTime.getTime()) + " ms; At: " + lastTime + " " + SEP); + addErrorStack(longTrace, traceFrames.error); + timestamp = lastTime.getTime(); } - return longTrace.join(NEWLINE); } - Zone['longStackTraceZoneSpec'] = { - name: 'long-stack-trace', - longStackTraceLimit: 10, - onScheduleTask: function (parentZoneDelegate, currentZone, targetZone, task) { - var currentTask = Zone.currentTask; - var trace = currentTask && currentTask.data && currentTask.data[creationTrace] || []; - trace = [new LongStackTrace()].concat(trace); - if (trace.length > this.longStackTraceLimit) { - trace.length = this.longStackTraceLimit; + return longTrace.join(NEWLINE); +} +Zone['longStackTraceZoneSpec'] = { + name: 'long-stack-trace', + longStackTraceLimit: 10, + onScheduleTask: function (parentZoneDelegate, currentZone, targetZone, task) { + var currentTask = Zone.currentTask; + var trace = currentTask && currentTask.data && currentTask.data[creationTrace] || []; + trace = [new LongStackTrace()].concat(trace); + if (trace.length > this.longStackTraceLimit) { + trace.length = this.longStackTraceLimit; + } + if (!task.data) + task.data = {}; + task.data[creationTrace] = trace; + return parentZoneDelegate.scheduleTask(targetZone, task); + }, + onHandleError: function (parentZoneDelegate, currentZone, targetZone, error) { + var parentTask = Zone.currentTask || error.task; + if (error instanceof Error && parentTask) { + var stackSetSucceded = null; + try { + var descriptor = Object.getOwnPropertyDescriptor(error, 'stack'); + if (descriptor && descriptor.configurable) { + var delegateGet_1 = descriptor.get; + var value_1 = descriptor.value; + descriptor = { + get: function () { + return renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], delegateGet_1 ? delegateGet_1.apply(this) : value_1); + } + }; + Object.defineProperty(error, 'stack', descriptor); + stackSetSucceded = true; + } } - if (!task.data) - task.data = {}; - task.data[creationTrace] = trace; - return parentZoneDelegate.scheduleTask(targetZone, task); - }, - onHandleError: function (parentZoneDelegate, currentZone, targetZone, error) { - var parentTask = Zone.currentTask || error.task; - if (error instanceof Error && parentTask) { - var stackSetSucceded = null; + catch (e) { } + var longStack = stackSetSucceded ? null : renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], error.stack); + if (!stackSetSucceded) { try { - var descriptor = Object.getOwnPropertyDescriptor(error, 'stack'); - if (descriptor && descriptor.configurable) { - var delegateGet_1 = descriptor.get; - var value_1 = descriptor.value; - descriptor = { - get: function () { - return renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], delegateGet_1 ? delegateGet_1.apply(this) : value_1); - } - }; - Object.defineProperty(error, 'stack', descriptor); - stackSetSucceded = true; - } + stackSetSucceded = error.stack = longStack; } catch (e) { } - var longStack = stackSetSucceded ? null : renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], error.stack); - if (!stackSetSucceded) { - try { - stackSetSucceded = error.stack = longStack; - } - catch (e) { } - } - if (!stackSetSucceded) { - try { - stackSetSucceded = error.longStack = longStack; - } - catch (e) { } + } + if (!stackSetSucceded) { + try { + stackSetSucceded = error.longStack = longStack; } + catch (e) { } } - return parentZoneDelegate.handleError(targetZone, error); - } - }; - function captureStackTraces(stackTraces, count) { - if (count > 0) { - stackTraces.push(getFrames((new LongStackTrace()).error)); - captureStackTraces(stackTraces, count - 1); } + return parentZoneDelegate.handleError(targetZone, error); } - function computeIgnoreFrames() { - var frames = []; - captureStackTraces(frames, 2); - var frames1 = frames[0]; - var frames2 = frames[1]; - for (var i = 0; i < frames1.length; i++) { - var frame1 = frames1[i]; - var frame2 = frames2[i]; - if (frame1 === frame2) { - IGNORE_FRAMES.push(frame1); - } - else { - break; - } +}; +function captureStackTraces(stackTraces, count) { + if (count > 0) { + stackTraces.push(getFrames((new LongStackTrace()).error)); + captureStackTraces(stackTraces, count - 1); + } +} +function computeIgnoreFrames() { + var frames = []; + captureStackTraces(frames, 2); + var frames1 = frames[0]; + var frames2 = frames[1]; + for (var i = 0; i < frames1.length; i++) { + var frame1 = frames1[i]; + var frame2 = frames2[i]; + if (frame1 === frame2) { + IGNORE_FRAMES.push(frame1); + } + else { + break; } } - computeIgnoreFrames(); -})(); \ No newline at end of file +} +computeIgnoreFrames(); + +}))); diff --git a/dist/long-stack-trace-zone.min.js b/dist/long-stack-trace-zone.min.js index b64649941..db33700a3 100644 --- a/dist/long-stack-trace-zone.min.js +++ b/dist/long-stack-trace-zone.min.js @@ -1 +1 @@ -!function(){function t(){return new Error("STACKTRACE TRACKING")}function r(){try{throw t()}catch(r){return r}}function a(t){return t.stack?t.stack.split(i):[]}function n(t,r){for(var n=a(r),e=0;e0&&(t.push(a((new l).error)),c(t,r-1))}function o(){var t=[];c(t,2);for(var r=t[0],a=t[1],n=0;nthis.longStackTraceLimit&&(c.length=this.longStackTraceLimit),n.data||(n.data={}),n.data[f]=c,t.scheduleTask(a,n)},onHandleError:function(t,r,a,n){var c=Zone.currentTask||n.task;if(n instanceof Error&&c){var o=null;try{var i=Object.getOwnPropertyDescriptor(n,"stack");if(i&&i.configurable){var u=i.get,s=i.value;i={get:function(){return e(c.data&&c.data[f],u?u.apply(this):s)}},Object.defineProperty(n,"stack",i),o=!0}}catch(l){}var h=o?null:e(c.data&&c.data[f],n.stack);if(!o)try{o=n.stack=h}catch(l){}if(!o)try{o=n.longStack=h}catch(l){}}return t.handleError(a,n)}},o()}(); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(this,function(){"use strict";function t(){return new Error("STACKTRACE TRACKING")}function e(){try{throw t()}catch(e){return e}}function n(t){return t.stack?t.stack.split(i):[]}function r(t,e){for(var r=n(e),a=0;a0&&(t.push(n((new l).error)),c(t,e-1))}function o(){var t=[];c(t,2);for(var e=t[0],n=t[1],r=0;rthis.longStackTraceLimit&&(c.length=this.longStackTraceLimit),r.data||(r.data={}),r.data[f]=c,t.scheduleTask(n,r)},onHandleError:function(t,e,n,r){var c=Zone.currentTask||r.task;if(r instanceof Error&&c){var o=null;try{var i=Object.getOwnPropertyDescriptor(r,"stack");if(i&&i.configurable){var u=i.get,s=i.value;i={get:function(){return a(c.data&&c.data[f],u?u.apply(this):s)}},Object.defineProperty(r,"stack",i),o=!0}}catch(l){}var h=o?null:a(c.data&&c.data[f],r.stack);if(!o)try{o=r.stack=h}catch(l){}if(!o)try{o=r.longStack=h}catch(l){}}return t.handleError(n,r)}},o()}); \ No newline at end of file diff --git a/dist/proxy.js b/dist/proxy.js index a3d0f9972..bc1d8e8b2 100644 --- a/dist/proxy.js +++ b/dist/proxy.js @@ -1,108 +1,121 @@ -(function () { - var ProxyZoneSpec = (function () { - function ProxyZoneSpec(defaultSpecDelegate) { - if (defaultSpecDelegate === void 0) { defaultSpecDelegate = null; } - this.defaultSpecDelegate = defaultSpecDelegate; - this.name = 'ProxyZone'; - this.properties = { 'ProxyZoneSpec': this }; - this.propertyKeys = null; - this.setDelegate(defaultSpecDelegate); - } - ProxyZoneSpec.get = function () { - return Zone.current.get('ProxyZoneSpec'); - }; - ProxyZoneSpec.isLoaded = function () { - return ProxyZoneSpec.get() instanceof ProxyZoneSpec; - }; - ProxyZoneSpec.assertPresent = function () { - if (!this.isLoaded()) { - throw new Error("Expected to be running in 'ProxyZone', but it was not found."); - } - return ProxyZoneSpec.get(); - }; - ProxyZoneSpec.prototype.setDelegate = function (delegateSpec) { - var _this = this; - this._delegateSpec = delegateSpec; - this.propertyKeys && this.propertyKeys.forEach(function (key) { return delete _this.properties[key]; }); - this.propertyKeys = null; - if (delegateSpec && delegateSpec.properties) { - this.propertyKeys = Object.keys(delegateSpec.properties); - this.propertyKeys.forEach(function (k) { return _this.properties[k] = delegateSpec.properties[k]; }); - } - }; - ProxyZoneSpec.prototype.getDelegate = function () { - return this._delegateSpec; - }; - ProxyZoneSpec.prototype.resetDelegate = function () { - this.setDelegate(this.defaultSpecDelegate); - }; - ProxyZoneSpec.prototype.onFork = function (parentZoneDelegate, currentZone, targetZone, zoneSpec) { - if (this._delegateSpec && this._delegateSpec.onFork) { - return this._delegateSpec.onFork(parentZoneDelegate, currentZone, targetZone, zoneSpec); - } - else { - return parentZoneDelegate.fork(targetZone, zoneSpec); - } - }; - ProxyZoneSpec.prototype.onIntercept = function (parentZoneDelegate, currentZone, targetZone, delegate, source) { - if (this._delegateSpec && this._delegateSpec.onIntercept) { - return this._delegateSpec.onIntercept(parentZoneDelegate, currentZone, targetZone, delegate, source); - } - else { - return parentZoneDelegate.intercept(targetZone, delegate, source); - } - }; - ProxyZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) { - if (this._delegateSpec && this._delegateSpec.onInvoke) { - return this._delegateSpec.onInvoke(parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source); - } - else { - return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); - } - }; - ProxyZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) { - if (this._delegateSpec && this._delegateSpec.onHandleError) { - return this._delegateSpec.onHandleError(parentZoneDelegate, currentZone, targetZone, error); - } - else { - return parentZoneDelegate.handleError(targetZone, error); - } - }; - ProxyZoneSpec.prototype.onScheduleTask = function (parentZoneDelegate, currentZone, targetZone, task) { - if (this._delegateSpec && this._delegateSpec.onScheduleTask) { - return this._delegateSpec.onScheduleTask(parentZoneDelegate, currentZone, targetZone, task); - } - else { - return parentZoneDelegate.scheduleTask(targetZone, task); - } - }; - ProxyZoneSpec.prototype.onInvokeTask = function (parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) { - if (this._delegateSpec && this._delegateSpec.onFork) { - return this._delegateSpec.onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs); - } - else { - return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs); - } - }; - ProxyZoneSpec.prototype.onCancelTask = function (parentZoneDelegate, currentZone, targetZone, task) { - if (this._delegateSpec && this._delegateSpec.onCancelTask) { - return this._delegateSpec.onCancelTask(parentZoneDelegate, currentZone, targetZone, task); - } - else { - return parentZoneDelegate.cancelTask(targetZone, task); - } - }; - ProxyZoneSpec.prototype.onHasTask = function (delegate, current, target, hasTaskState) { - if (this._delegateSpec && this._delegateSpec.onHasTask) { - this._delegateSpec.onHasTask(delegate, current, target, hasTaskState); - } - else { - delegate.hasTask(target, hasTaskState); - } - }; - return ProxyZoneSpec; - }()); - // Export the class so that new instances can be created with proper - // constructor params. - Zone['ProxyZoneSpec'] = ProxyZoneSpec; -})(); \ No newline at end of file +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + +var ProxyZoneSpec = (function () { + function ProxyZoneSpec(defaultSpecDelegate) { + if (defaultSpecDelegate === void 0) { defaultSpecDelegate = null; } + this.defaultSpecDelegate = defaultSpecDelegate; + this.name = 'ProxyZone'; + this.properties = { 'ProxyZoneSpec': this }; + this.propertyKeys = null; + this.setDelegate(defaultSpecDelegate); + } + ProxyZoneSpec.get = function () { + return Zone.current.get('ProxyZoneSpec'); + }; + ProxyZoneSpec.isLoaded = function () { + return ProxyZoneSpec.get() instanceof ProxyZoneSpec; + }; + ProxyZoneSpec.assertPresent = function () { + if (!this.isLoaded()) { + throw new Error("Expected to be running in 'ProxyZone', but it was not found."); + } + return ProxyZoneSpec.get(); + }; + ProxyZoneSpec.prototype.setDelegate = function (delegateSpec) { + var _this = this; + this._delegateSpec = delegateSpec; + this.propertyKeys && this.propertyKeys.forEach(function (key) { return delete _this.properties[key]; }); + this.propertyKeys = null; + if (delegateSpec && delegateSpec.properties) { + this.propertyKeys = Object.keys(delegateSpec.properties); + this.propertyKeys.forEach(function (k) { return _this.properties[k] = delegateSpec.properties[k]; }); + } + }; + ProxyZoneSpec.prototype.getDelegate = function () { + return this._delegateSpec; + }; + ProxyZoneSpec.prototype.resetDelegate = function () { + this.setDelegate(this.defaultSpecDelegate); + }; + ProxyZoneSpec.prototype.onFork = function (parentZoneDelegate, currentZone, targetZone, zoneSpec) { + if (this._delegateSpec && this._delegateSpec.onFork) { + return this._delegateSpec.onFork(parentZoneDelegate, currentZone, targetZone, zoneSpec); + } + else { + return parentZoneDelegate.fork(targetZone, zoneSpec); + } + }; + ProxyZoneSpec.prototype.onIntercept = function (parentZoneDelegate, currentZone, targetZone, delegate, source) { + if (this._delegateSpec && this._delegateSpec.onIntercept) { + return this._delegateSpec.onIntercept(parentZoneDelegate, currentZone, targetZone, delegate, source); + } + else { + return parentZoneDelegate.intercept(targetZone, delegate, source); + } + }; + ProxyZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) { + if (this._delegateSpec && this._delegateSpec.onInvoke) { + return this._delegateSpec.onInvoke(parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source); + } + else { + return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); + } + }; + ProxyZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) { + if (this._delegateSpec && this._delegateSpec.onHandleError) { + return this._delegateSpec.onHandleError(parentZoneDelegate, currentZone, targetZone, error); + } + else { + return parentZoneDelegate.handleError(targetZone, error); + } + }; + ProxyZoneSpec.prototype.onScheduleTask = function (parentZoneDelegate, currentZone, targetZone, task) { + if (this._delegateSpec && this._delegateSpec.onScheduleTask) { + return this._delegateSpec.onScheduleTask(parentZoneDelegate, currentZone, targetZone, task); + } + else { + return parentZoneDelegate.scheduleTask(targetZone, task); + } + }; + ProxyZoneSpec.prototype.onInvokeTask = function (parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) { + if (this._delegateSpec && this._delegateSpec.onFork) { + return this._delegateSpec.onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs); + } + else { + return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs); + } + }; + ProxyZoneSpec.prototype.onCancelTask = function (parentZoneDelegate, currentZone, targetZone, task) { + if (this._delegateSpec && this._delegateSpec.onCancelTask) { + return this._delegateSpec.onCancelTask(parentZoneDelegate, currentZone, targetZone, task); + } + else { + return parentZoneDelegate.cancelTask(targetZone, task); + } + }; + ProxyZoneSpec.prototype.onHasTask = function (delegate, current, target, hasTaskState) { + if (this._delegateSpec && this._delegateSpec.onHasTask) { + this._delegateSpec.onHasTask(delegate, current, target, hasTaskState); + } + else { + delegate.hasTask(target, hasTaskState); + } + }; + return ProxyZoneSpec; +}()); +// Export the class so that new instances can be created with proper +// constructor params. +Zone['ProxyZoneSpec'] = ProxyZoneSpec; + +}))); diff --git a/dist/proxy.min.js b/dist/proxy.min.js index b2ee177bc..591695710 100644 --- a/dist/proxy.min.js +++ b/dist/proxy.min.js @@ -1 +1 @@ -!function(){var e=function(){function e(e){void 0===e&&(e=null),this.defaultSpecDelegate=e,this.name="ProxyZone",this.properties={ProxyZoneSpec:this},this.propertyKeys=null,this.setDelegate(e)}return e.get=function(){return Zone.current.get("ProxyZoneSpec")},e.isLoaded=function(){return e.get()instanceof e},e.assertPresent=function(){if(!this.isLoaded())throw new Error("Expected to be running in 'ProxyZone', but it was not found.");return e.get()},e.prototype.setDelegate=function(e){var t=this;this._delegateSpec=e,this.propertyKeys&&this.propertyKeys.forEach(function(e){return delete t.properties[e]}),this.propertyKeys=null,e&&e.properties&&(this.propertyKeys=Object.keys(e.properties),this.propertyKeys.forEach(function(n){return t.properties[n]=e.properties[n]}))},e.prototype.getDelegate=function(){return this._delegateSpec},e.prototype.resetDelegate=function(){this.setDelegate(this.defaultSpecDelegate)},e.prototype.onFork=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onFork?this._delegateSpec.onFork(e,t,n,o):e.fork(n,o)},e.prototype.onIntercept=function(e,t,n,o,r){return this._delegateSpec&&this._delegateSpec.onIntercept?this._delegateSpec.onIntercept(e,t,n,o,r):e.intercept(n,o,r)},e.prototype.onInvoke=function(e,t,n,o,r,s,p){return this._delegateSpec&&this._delegateSpec.onInvoke?this._delegateSpec.onInvoke(e,t,n,o,r,s,p):e.invoke(n,o,r,s,p)},e.prototype.onHandleError=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onHandleError?this._delegateSpec.onHandleError(e,t,n,o):e.handleError(n,o)},e.prototype.onScheduleTask=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onScheduleTask?this._delegateSpec.onScheduleTask(e,t,n,o):e.scheduleTask(n,o)},e.prototype.onInvokeTask=function(e,t,n,o,r,s){return this._delegateSpec&&this._delegateSpec.onFork?this._delegateSpec.onInvokeTask(e,t,n,o,r,s):e.invokeTask(n,o,r,s)},e.prototype.onCancelTask=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onCancelTask?this._delegateSpec.onCancelTask(e,t,n,o):e.cancelTask(n,o)},e.prototype.onHasTask=function(e,t,n,o){this._delegateSpec&&this._delegateSpec.onHasTask?this._delegateSpec.onHasTask(e,t,n,o):e.hasTask(n,o)},e}();Zone.ProxyZoneSpec=e}(); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";var e=function(){function e(e){void 0===e&&(e=null),this.defaultSpecDelegate=e,this.name="ProxyZone",this.properties={ProxyZoneSpec:this},this.propertyKeys=null,this.setDelegate(e)}return e.get=function(){return Zone.current.get("ProxyZoneSpec")},e.isLoaded=function(){return e.get()instanceof e},e.assertPresent=function(){if(!this.isLoaded())throw new Error("Expected to be running in 'ProxyZone', but it was not found.");return e.get()},e.prototype.setDelegate=function(e){var t=this;this._delegateSpec=e,this.propertyKeys&&this.propertyKeys.forEach(function(e){return delete t.properties[e]}),this.propertyKeys=null,e&&e.properties&&(this.propertyKeys=Object.keys(e.properties),this.propertyKeys.forEach(function(n){return t.properties[n]=e.properties[n]}))},e.prototype.getDelegate=function(){return this._delegateSpec},e.prototype.resetDelegate=function(){this.setDelegate(this.defaultSpecDelegate)},e.prototype.onFork=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onFork?this._delegateSpec.onFork(e,t,n,o):e.fork(n,o)},e.prototype.onIntercept=function(e,t,n,o,r){return this._delegateSpec&&this._delegateSpec.onIntercept?this._delegateSpec.onIntercept(e,t,n,o,r):e.intercept(n,o,r)},e.prototype.onInvoke=function(e,t,n,o,r,s,p){return this._delegateSpec&&this._delegateSpec.onInvoke?this._delegateSpec.onInvoke(e,t,n,o,r,s,p):e.invoke(n,o,r,s,p)},e.prototype.onHandleError=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onHandleError?this._delegateSpec.onHandleError(e,t,n,o):e.handleError(n,o)},e.prototype.onScheduleTask=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onScheduleTask?this._delegateSpec.onScheduleTask(e,t,n,o):e.scheduleTask(n,o)},e.prototype.onInvokeTask=function(e,t,n,o,r,s){return this._delegateSpec&&this._delegateSpec.onFork?this._delegateSpec.onInvokeTask(e,t,n,o,r,s):e.invokeTask(n,o,r,s)},e.prototype.onCancelTask=function(e,t,n,o){return this._delegateSpec&&this._delegateSpec.onCancelTask?this._delegateSpec.onCancelTask(e,t,n,o):e.cancelTask(n,o)},e.prototype.onHasTask=function(e,t,n,o){this._delegateSpec&&this._delegateSpec.onHasTask?this._delegateSpec.onHasTask(e,t,n,o):e.hasTask(n,o)},e}();Zone.ProxyZoneSpec=e}); \ No newline at end of file diff --git a/dist/sync-test.js b/dist/sync-test.js index 948398208..214e9daab 100644 --- a/dist/sync-test.js +++ b/dist/sync-test.js @@ -1,23 +1,36 @@ -(function () { - var SyncTestZoneSpec = (function () { - function SyncTestZoneSpec(namePrefix) { - this.runZone = Zone.current; - this.name = 'syncTestZone for ' + namePrefix; +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + +var SyncTestZoneSpec = (function () { + function SyncTestZoneSpec(namePrefix) { + this.runZone = Zone.current; + this.name = 'syncTestZone for ' + namePrefix; + } + SyncTestZoneSpec.prototype.onScheduleTask = function (delegate, current, target, task) { + switch (task.type) { + case 'microTask': + case 'macroTask': + throw new Error("Cannot call " + task.source + " from within a sync test."); + case 'eventTask': + task = delegate.scheduleTask(target, task); + break; } - SyncTestZoneSpec.prototype.onScheduleTask = function (delegate, current, target, task) { - switch (task.type) { - case 'microTask': - case 'macroTask': - throw new Error("Cannot call " + task.source + " from within a sync test."); - case 'eventTask': - task = delegate.scheduleTask(target, task); - break; - } - return task; - }; - return SyncTestZoneSpec; - }()); - // Export the class so that new instances can be created with proper - // constructor params. - Zone['SyncTestZoneSpec'] = SyncTestZoneSpec; -})(); \ No newline at end of file + return task; + }; + return SyncTestZoneSpec; +}()); +// Export the class so that new instances can be created with proper +// constructor params. +Zone['SyncTestZoneSpec'] = SyncTestZoneSpec; + +}))); diff --git a/dist/task-tracking.js b/dist/task-tracking.js index ccd3e742b..0cfd9eae1 100644 --- a/dist/task-tracking.js +++ b/dist/task-tracking.js @@ -1,3 +1,16 @@ +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + /** * A `TaskTrackingZoneSpec` allows one to track all outstanding Tasks. * @@ -60,4 +73,6 @@ var TaskTrackingZoneSpec = (function () { }()); // Export the class so that new instances can be created with proper // constructor params. -Zone['TaskTrackingZoneSpec'] = TaskTrackingZoneSpec; \ No newline at end of file +Zone['TaskTrackingZoneSpec'] = TaskTrackingZoneSpec; + +}))); diff --git a/dist/task-tracking.min.js b/dist/task-tracking.min.js index 0a713fc59..efdbe8cdd 100644 --- a/dist/task-tracking.min.js +++ b/dist/task-tracking.min.js @@ -1 +1 @@ -var TaskTrackingZoneSpec=function(){function e(){this.name="TaskTrackingZone",this.microTasks=[],this.macroTasks=[],this.eventTasks=[],this.properties={TaskTrackingZone:this}}return e.get=function(){return Zone.current.get("TaskTrackingZone")},e.prototype.getTasksFor=function(e){switch(e){case"microTask":return this.microTasks;case"macroTask":return this.macroTasks;case"eventTask":return this.eventTasks}throw new Error("Unknown task format: "+e)},e.prototype.onScheduleTask=function(e,t,n,s){s.creationLocation=new Error("Task '"+s.type+"' from '"+s.source+"'.");var r=this.getTasksFor(s.type);return r.push(s),e.scheduleTask(n,s)},e.prototype.onCancelTask=function(e,t,n,s){for(var r=this.getTasksFor(s.type),a=0;a 'click', etc + var eventName = prop.substr(2); + var _prop = '_' + prop; + desc.set = function (fn) { + if (this[_prop]) { + this.removeEventListener(eventName, this[_prop]); + } + if (typeof fn === 'function') { + var wrapFn = function (event) { + var result; + result = fn.apply(this, arguments); + if (result != undefined && !result) + event.preventDefault(); + }; + this[_prop] = wrapFn; + this.addEventListener(eventName, wrapFn, false); + } + else { + this[_prop] = null; + } + }; + // The getter would return undefined for unassigned properties but the default value of an unassigned property is null + desc.get = function () { + return this[_prop] || null; + }; + Object.defineProperty(obj, prop, desc); +} + + + var EVENT_TASKS = zoneSymbol('eventTasks'); // For EventTarget var ADD_EVENT_LISTENER = 'addEventListener'; @@ -710,7 +775,11 @@ function makeZoneAwareListeners(fnName) { } var zoneAwareAddEventListener = makeZoneAwareAddListener(ADD_EVENT_LISTENER, REMOVE_EVENT_LISTENER); var zoneAwareRemoveEventListener = makeZoneAwareRemoveListener(REMOVE_EVENT_LISTENER); + var originalInstanceKey = zoneSymbol('originalInstance'); +// wrap some native API on `window` + + function createNamedFn(name, delegate) { try { return (Function('f', "return function " + name + "(){return f(this, arguments)}"))(delegate); @@ -801,15 +870,15 @@ var EE_PREPEND_LISTENER = 'prependListener'; var EE_REMOVE_LISTENER = 'removeListener'; var EE_LISTENERS = 'listeners'; var EE_ON = 'on'; -var zoneAwareAddListener = makeZoneAwareAddListener(EE_ADD_LISTENER, EE_REMOVE_LISTENER, false, true); +var zoneAwareAddListener$1 = makeZoneAwareAddListener(EE_ADD_LISTENER, EE_REMOVE_LISTENER, false, true); var zoneAwarePrependListener = makeZoneAwareAddListener(EE_PREPEND_LISTENER, EE_REMOVE_LISTENER, false, true); -var zoneAwareRemoveListener = makeZoneAwareRemoveListener(EE_REMOVE_LISTENER, false); +var zoneAwareRemoveListener$1 = makeZoneAwareRemoveListener(EE_REMOVE_LISTENER, false); var zoneAwareListeners = makeZoneAwareListeners(EE_LISTENERS); function patchEventEmitterMethods(obj) { if (obj && obj.addListener) { - patchMethod(obj, EE_ADD_LISTENER, function () { return zoneAwareAddListener; }); + patchMethod(obj, EE_ADD_LISTENER, function () { return zoneAwareAddListener$1; }); patchMethod(obj, EE_PREPEND_LISTENER, function () { return zoneAwarePrependListener; }); - patchMethod(obj, EE_REMOVE_LISTENER, function () { return zoneAwareRemoveListener; }); + patchMethod(obj, EE_REMOVE_LISTENER, function () { return zoneAwareRemoveListener$1; }); patchMethod(obj, EE_LISTENERS, function () { return zoneAwareListeners; }); obj[EE_ON] = obj[EE_ADD_LISTENER]; return true; @@ -950,4 +1019,6 @@ if (httpClient && httpClient.ClientRequest) { return new ClientRequest_1(options, zone.wrap(callback, 'http.ClientRequest')); } }; -} \ No newline at end of file +} + +}))); diff --git a/dist/zone.js b/dist/zone.js index 090435247..a6e5c2f9b 100644 --- a/dist/zone.js +++ b/dist/zone.js @@ -1,5 +1,16 @@ -; -; +/** +* @license +* Copyright Google Inc. All Rights Reserved. +* +* Use of this source code is governed by an MIT-style license that can be +* found in the LICENSE file at https://angular.io/license +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, (function () { 'use strict'; + var Zone$1 = (function (global) { if (global.Zone) { throw new Error('Zone already loaded.'); @@ -26,25 +37,25 @@ var Zone$1 = (function (global) { enumerable: true, configurable: true }); - ; + Object.defineProperty(Zone, "currentTask", { get: function () { return _currentTask; }, enumerable: true, configurable: true }); - ; + Object.defineProperty(Zone.prototype, "parent", { get: function () { return this._parent; }, enumerable: true, configurable: true }); - ; + Object.defineProperty(Zone.prototype, "name", { get: function () { return this._name; }, enumerable: true, configurable: true }); - ; + Zone.prototype.get = function (key) { var zone = this.getZoneWith(key); if (zone) @@ -153,7 +164,7 @@ var Zone$1 = (function (global) { Zone.__symbol__ = __symbol__; return Zone; }()); - ; + var ZoneDelegate = (function () { function ZoneDelegate(zone, parentDelegate, zoneSpec) { this._taskCounts = { microTask: 0, macroTask: 0, eventTask: 0 }; @@ -311,7 +322,7 @@ var Zone$1 = (function (global) { return ZoneTask; }()); function __symbol__(name) { return '__zone_symbol__' + name; } - ; + var symbolSetTimeout = __symbol__('setTimeout'); var symbolPromise = __symbol__('Promise'); var symbolThen = __symbol__('then'); @@ -418,12 +429,12 @@ var Zone$1 = (function (global) { throw new Error("Uncaught (in promise): " + value); } catch (e) { - var error = e; - error.rejection = value; - error.promise = promise; - error.zone = Zone.current; - error.task = Zone.currentTask; - _uncaughtPromiseErrors.push(error); + var error_1 = e; + error_1.rejection = value; + error_1.promise = promise; + error_1.zone = Zone.current; + error_1.task = Zone.currentTask; + _uncaughtPromiseErrors.push(error_1); scheduleQueueDrain(); } } @@ -553,7 +564,15 @@ var Zone$1 = (function (global) { if (NativePromise) { patchThen(NativePromise); if (typeof global['fetch'] !== 'undefined') { - var fetchPromise = global['fetch']('about:blank'); + var fetchPromise = void 0; + try { + // In MS Edge this throws + fetchPromise = global['fetch'](); + } + catch (e) { + // In Chrome this throws instead. + fetchPromise = global['fetch']('about:blank'); + } // ignore output to prevent error; fetchPromise.then(function () { return null; }, function () { return null; }); if (fetchPromise.constructor != NativePromise) { @@ -581,7 +600,7 @@ function bindArguments(args, source) { } return args; } -; + function patchPrototype(prototype, fnNames) { var source = prototype.constructor['name']; var _loop_1 = function(i) { @@ -599,7 +618,7 @@ function patchPrototype(prototype, fnNames) { _loop_1(i); } } -; + var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope); var isNode = (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'); var isBrowser = !isNode && !isWebWorker && !!(typeof window !== 'undefined' && window['HTMLElement']); @@ -642,7 +661,7 @@ function patchProperty(obj, prop) { }; Object.defineProperty(obj, prop, desc); } -; + function patchOnProperties(obj, properties) { var onProperties = []; for (var prop in obj) { @@ -659,7 +678,7 @@ function patchOnProperties(obj, properties) { } } } -; + var EVENT_TASKS = zoneSymbol('eventTasks'); // For EventTarget var ADD_EVENT_LISTENER = 'addEventListener'; @@ -775,6 +794,7 @@ function makeZoneAwareRemoveListener(fnName, useCapturingParam) { } }; } + var zoneAwareAddEventListener = makeZoneAwareAddListener(ADD_EVENT_LISTENER, REMOVE_EVENT_LISTENER); var zoneAwareRemoveEventListener = makeZoneAwareRemoveListener(REMOVE_EVENT_LISTENER); function patchEventTargetMethods(obj) { @@ -849,7 +869,7 @@ function patchClass(className) { } } } -; + function createNamedFn(name, delegate) { try { return (Function('f', "return function " + name + "(){return f(this, arguments)}"))(delegate); @@ -944,13 +964,13 @@ function propertyPatch() { return desc; }; } -; + function _redefineProperty(obj, prop, desc) { var originalConfigurableFlag = desc.configurable; desc = rewriteDescriptor(obj, prop, desc); return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag); } -; + function isUnconfigurable(obj, prop) { return obj && obj[unconfigurablesKey] && obj[unconfigurablesKey][prop]; } @@ -1116,7 +1136,7 @@ function canPatchViaPropertyDescriptor() { Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {}); return result; } -; + var unboundKey = zoneSymbol('unbound'); // Whenever any eventListener fires, we check the eventListener target and all parents // for `onwhatever` properties and replace them with zone-bound functions @@ -1146,9 +1166,8 @@ function patchViaCapturingAllTheEvents() { for (var i = 0; i < eventNames.length; i++) { _loop_1(i); } - ; + } -; function patchTimer(window, setName, cancelName, nameSuffix) { var setNative = null; @@ -1303,4 +1322,6 @@ if (_global['navigator'] && _global['navigator'].geolocation) { 'getCurrentPosition', 'watchPosition' ]); -} \ No newline at end of file +} + +}))); diff --git a/dist/zone.min.js b/dist/zone.min.js index 59a6e46ad..03e39d0bd 100644 --- a/dist/zone.min.js +++ b/dist/zone.min.js @@ -1 +1 @@ -function bindArguments(e,t){for(var n=e.length-1;n>=0;n--)"function"==typeof e[n]&&(e[n]=Zone.current.wrap(e[n],t+"_"+n));return e}function patchPrototype(e,t){for(var n=e.constructor.name,r=function(r){var o=t[r],a=e[o];a&&(e[o]=function(e){return function(){return e.apply(this,bindArguments(arguments,n+"."+o))}}(a))},o=0;o1?new t(e,n):new t(e),a=Object.getOwnPropertyDescriptor(o,"onmessage");return a&&a.configurable===!1?(r=Object.create(o),["addEventListener","removeEventListener","send","close"].forEach(function(e){r[e]=function(){return o[e].apply(o,arguments)}})):r=o,patchOnProperties(r,["close","error","message","open"]),r};for(var n in t)e.WebSocket[n]=t[n]}function propertyDescriptorPatch(e){if(!isNode){var t="undefined"!=typeof WebSocket;canPatchViaPropertyDescriptor()?(isBrowser&&patchOnProperties(HTMLElement.prototype,eventNames),patchOnProperties(XMLHttpRequest.prototype,null),"undefined"!=typeof IDBIndex&&(patchOnProperties(IDBIndex.prototype,null),patchOnProperties(IDBRequest.prototype,null),patchOnProperties(IDBOpenDBRequest.prototype,null),patchOnProperties(IDBDatabase.prototype,null),patchOnProperties(IDBTransaction.prototype,null),patchOnProperties(IDBCursor.prototype,null)),t&&patchOnProperties(WebSocket.prototype,null)):(patchViaCapturingAllTheEvents(),patchClass("XMLHttpRequest"),t&&apply(e))}}function canPatchViaPropertyDescriptor(){if(isBrowser&&!Object.getOwnPropertyDescriptor(HTMLElement.prototype,"onclick")&&"undefined"!=typeof Element){var e=Object.getOwnPropertyDescriptor(Element.prototype,"onclick");if(e&&!e.configurable)return!1}Object.defineProperty(XMLHttpRequest.prototype,"onreadystatechange",{get:function(){return!0}});var t=new XMLHttpRequest,n=!!t.onreadystatechange;return Object.defineProperty(XMLHttpRequest.prototype,"onreadystatechange",{}),n}function patchViaCapturingAllTheEvents(){for(var e=function(e){var t=eventNames[e],n="on"+t;document.addEventListener(t,function(e){var t,r,o=e.target;for(r=o?o.constructor.name+"."+n:"unknown."+n;o;)o[n]&&!o[n][unboundKey]&&(t=Zone.current.wrap(o[n],r),t[unboundKey]=o[n],o[n]=t),o=o.parentElement},!0)},t=0;t",this._properties=t&&t.properties||{},this._zoneDelegate=new g(this,this._parent&&this._parent._zoneDelegate,t)}return n.assertZonePatched=function(){if(e.Promise!==M)throw new Error("Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.\nMost likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.)")},Object.defineProperty(n,"current",{get:function(){return _},enumerable:!0,configurable:!0}),Object.defineProperty(n,"currentTask",{get:function(){return T},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),n.prototype.get=function(e){var t=this.getZoneWith(e);if(t)return t._properties[e]},n.prototype.getZoneWith=function(e){for(var t=this;t;){if(t._properties.hasOwnProperty(e))return t;t=t._parent}return null},n.prototype.fork=function(e){if(!e)throw new Error("ZoneSpec required!");return this._zoneDelegate.fork(this,e)},n.prototype.wrap=function(e,t){if("function"!=typeof e)throw new Error("Expecting function got: "+e);var n=this._zoneDelegate.intercept(this,e,t),r=this;return function(){return r.runGuarded(n,this,arguments,t)}},n.prototype.run=function(e,t,n,r){void 0===t&&(t=null),void 0===n&&(n=null),void 0===r&&(r=null);var o=_;_=this;try{return this._zoneDelegate.invoke(this,e,t,n,r)}finally{_=o}},n.prototype.runGuarded=function(e,t,n,r){void 0===t&&(t=null),void 0===n&&(n=null),void 0===r&&(r=null);var o=_;_=this;try{try{return this._zoneDelegate.invoke(this,e,t,n,r)}catch(a){if(this._zoneDelegate.handleError(this,a))throw a}}finally{_=o}},n.prototype.runTask=function(e,t,n){if(e.runCount++,e.zone!=this)throw new Error("A task can only be run in the zone which created it! (Creation: "+e.zone.name+"; Execution: "+this.name+")");var r=T;T=e;var o=_;_=this;try{"macroTask"==e.type&&e.data&&!e.data.isPeriodic&&(e.cancelFn=null);try{return this._zoneDelegate.invokeTask(this,e,t,n)}catch(a){if(this._zoneDelegate.handleError(this,a))throw a}}finally{_=o,T=r}},n.prototype.scheduleMicroTask=function(e,t,n,r){return this._zoneDelegate.scheduleTask(this,new y("microTask",this,e,t,n,r,null))},n.prototype.scheduleMacroTask=function(e,t,n,r,o){return this._zoneDelegate.scheduleTask(this,new y("macroTask",this,e,t,n,r,o))},n.prototype.scheduleEventTask=function(e,t,n,r,o){return this._zoneDelegate.scheduleTask(this,new y("eventTask",this,e,t,n,r,o))},n.prototype.cancelTask=function(e){var t=this._zoneDelegate.cancelTask(this,e);return e.runCount=-1,e.cancelFn=null,t},n.__symbol__=t,n}(),g=function(){function e(e,t,n){this._taskCounts={microTask:0,macroTask:0,eventTask:0},this.zone=e,this._parentDelegate=t,this._forkZS=n&&(n&&n.onFork?n:t._forkZS),this._forkDlgt=n&&(n.onFork?t:t._forkDlgt),this._interceptZS=n&&(n.onIntercept?n:t._interceptZS),this._interceptDlgt=n&&(n.onIntercept?t:t._interceptDlgt),this._invokeZS=n&&(n.onInvoke?n:t._invokeZS),this._invokeDlgt=n&&(n.onInvoke?t:t._invokeDlgt),this._handleErrorZS=n&&(n.onHandleError?n:t._handleErrorZS),this._handleErrorDlgt=n&&(n.onHandleError?t:t._handleErrorDlgt),this._scheduleTaskZS=n&&(n.onScheduleTask?n:t._scheduleTaskZS),this._scheduleTaskDlgt=n&&(n.onScheduleTask?t:t._scheduleTaskDlgt),this._invokeTaskZS=n&&(n.onInvokeTask?n:t._invokeTaskZS),this._invokeTaskDlgt=n&&(n.onInvokeTask?t:t._invokeTaskDlgt),this._cancelTaskZS=n&&(n.onCancelTask?n:t._cancelTaskZS),this._cancelTaskDlgt=n&&(n.onCancelTask?t:t._cancelTaskDlgt),this._hasTaskZS=n&&(n.onHasTask?n:t._hasTaskZS),this._hasTaskDlgt=n&&(n.onHasTask?t:t._hasTaskDlgt)}return e.prototype.fork=function(e,t){return this._forkZS?this._forkZS.onFork(this._forkDlgt,this.zone,e,t):new d(e,t)},e.prototype.intercept=function(e,t,n){return this._interceptZS?this._interceptZS.onIntercept(this._interceptDlgt,this.zone,e,t,n):t},e.prototype.invoke=function(e,t,n,r,o){return this._invokeZS?this._invokeZS.onInvoke(this._invokeDlgt,this.zone,e,t,n,r,o):t.apply(n,r)},e.prototype.handleError=function(e,t){return!this._handleErrorZS||this._handleErrorZS.onHandleError(this._handleErrorDlgt,this.zone,e,t)},e.prototype.scheduleTask=function(e,t){try{if(this._scheduleTaskZS)return this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt,this.zone,e,t);if(t.scheduleFn)t.scheduleFn(t);else{if("microTask"!=t.type)throw new Error("Task is missing scheduleFn.");r(t)}return t}finally{e==this.zone&&this._updateTaskCount(t.type,1)}},e.prototype.invokeTask=function(e,t,n,r){try{return this._invokeTaskZS?this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt,this.zone,e,t,n,r):t.callback.apply(n,r)}finally{e!=this.zone||"eventTask"==t.type||t.data&&t.data.isPeriodic||this._updateTaskCount(t.type,-1)}},e.prototype.cancelTask=function(e,t){var n;if(this._cancelTaskZS)n=this._cancelTaskZS.onCancelTask(this._cancelTaskDlgt,this.zone,e,t);else{if(!t.cancelFn)throw new Error("Task does not support cancellation, or is already canceled.");n=t.cancelFn(t)}return e==this.zone&&this._updateTaskCount(t.type,-1),n},e.prototype.hasTask=function(e,t){return this._hasTaskZS&&this._hasTaskZS.onHasTask(this._hasTaskDlgt,this.zone,e,t)},e.prototype._updateTaskCount=function(e,t){var n=this._taskCounts,r=n[e],o=n[e]=r+t;if(o<0)throw new Error("More tasks executed then were scheduled.");if(0==r||0==o){var a={microTask:n.microTask>0,macroTask:n.macroTask>0,eventTask:n.eventTask>0,change:e};try{this.hasTask(this.zone,a)}finally{this._parentDelegate&&this._parentDelegate._updateTaskCount(e,t)}}},e}(),y=function(){function e(e,t,n,r,o,i,s){this.runCount=0,this.type=e,this.zone=t,this.source=n,this.data=o,this.scheduleFn=i,this.cancelFn=s,this.callback=r;var c=this;this.invoke=function(){S++;try{return t.runTask(c,this,arguments)}finally{1==S&&a(),S--}}}return e.prototype.toString=function(){return this.data&&"undefined"!=typeof this.data.handleId?this.data.handleId:this.toString()},e}(),v=t("setTimeout"),k=t("Promise"),b=t("then"),_=new d(null,null),T=null,m=[],E=!1,w=[],S=0,P=t("state"),D=t("value"),O="Promise.then",z=null,I=!0,R=!1,Z=0,M=function(){function e(t){var n=this;if(!(n instanceof e))throw new Error("Must be an instanceof Promise.");n[P]=z,n[D]=[];try{t&&t(u(n,I),u(n,R))}catch(r){l(n,!1,r)}}return e.resolve=function(e){return l(new this(null),I,e)},e.reject=function(e){return l(new this(null),R,e)},e.race=function(e){function t(e){a&&(a=r(e))}function n(e){a&&(a=o(e))}for(var r,o,a=new this(function(e,t){r=e,o=t}),s=0,c=e;s=0;n--)"function"==typeof e[n]&&(e[n]=Zone.current.wrap(e[n],t+"_"+n));return e}function t(t,n){for(var r=t.constructor.name,o=function(o){var a=n[o],i=t[a];i&&(t[a]=function(t){return function(){return t.apply(this,e(arguments,r+"."+a))}}(i))},a=0;a1?new t(e,n):new t(e),i=Object.getOwnPropertyDescriptor(a,"onmessage");return i&&i.configurable===!1?(o=Object.create(a),["addEventListener","removeEventListener","send","close"].forEach(function(e){o[e]=function(){return a[e].apply(a,arguments)}})):o=a,r(o,["close","error","message","open"]),o};for(var n in t)e.WebSocket[n]=t[n]}function m(e){if(!Z){var t="undefined"!=typeof WebSocket;T()?(O&&r(HTMLElement.prototype,X),r(XMLHttpRequest.prototype,null),"undefined"!=typeof IDBIndex&&(r(IDBIndex.prototype,null),r(IDBRequest.prototype,null),r(IDBOpenDBRequest.prototype,null),r(IDBDatabase.prototype,null),r(IDBTransaction.prototype,null),r(IDBCursor.prototype,null)),t&&r(WebSocket.prototype,null)):(w(),c("XMLHttpRequest"),t&&b(e))}}function T(){if(O&&!Object.getOwnPropertyDescriptor(HTMLElement.prototype,"onclick")&&"undefined"!=typeof Element){var e=Object.getOwnPropertyDescriptor(Element.prototype,"onclick");if(e&&!e.configurable)return!1}Object.defineProperty(XMLHttpRequest.prototype,"onreadystatechange",{get:function(){return!0}});var t=new XMLHttpRequest,n=!!t.onreadystatechange;return Object.defineProperty(XMLHttpRequest.prototype,"onreadystatechange",{}),n}function w(){for(var e=function(e){var t=X[e],n="on"+t;document.addEventListener(t,function(e){var t,r,o=e.target;for(r=o?o.constructor.name+"."+n:"unknown."+n;o;)o[n]&&!o[n][A]&&(t=Zone.current.wrap(o[n],r),t[A]=o[n],o[n]=t),o=o.parentElement},!0)},t=0;t",this._properties=t&&t.properties||{},this._zoneDelegate=new v(this,this._parent&&this._parent._zoneDelegate,t)}return n.assertZonePatched=function(){if(e.Promise!==C)throw new Error("Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.\nMost likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.)")},Object.defineProperty(n,"current",{get:function(){return m},enumerable:!0,configurable:!0}),Object.defineProperty(n,"currentTask",{get:function(){return T},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),n.prototype.get=function(e){var t=this.getZoneWith(e);if(t)return t._properties[e]},n.prototype.getZoneWith=function(e){for(var t=this;t;){if(t._properties.hasOwnProperty(e))return t;t=t._parent}return null},n.prototype.fork=function(e){if(!e)throw new Error("ZoneSpec required!");return this._zoneDelegate.fork(this,e)},n.prototype.wrap=function(e,t){if("function"!=typeof e)throw new Error("Expecting function got: "+e);var n=this._zoneDelegate.intercept(this,e,t),r=this;return function(){return r.runGuarded(n,this,arguments,t)}},n.prototype.run=function(e,t,n,r){void 0===t&&(t=null),void 0===n&&(n=null),void 0===r&&(r=null);var o=m;m=this;try{return this._zoneDelegate.invoke(this,e,t,n,r)}finally{m=o}},n.prototype.runGuarded=function(e,t,n,r){void 0===t&&(t=null),void 0===n&&(n=null),void 0===r&&(r=null);var o=m;m=this;try{try{return this._zoneDelegate.invoke(this,e,t,n,r)}catch(a){if(this._zoneDelegate.handleError(this,a))throw a}}finally{m=o}},n.prototype.runTask=function(e,t,n){if(e.runCount++,e.zone!=this)throw new Error("A task can only be run in the zone which created it! (Creation: "+e.zone.name+"; Execution: "+this.name+")");var r=T;T=e;var o=m;m=this;try{"macroTask"==e.type&&e.data&&!e.data.isPeriodic&&(e.cancelFn=null);try{return this._zoneDelegate.invokeTask(this,e,t,n)}catch(a){if(this._zoneDelegate.handleError(this,a))throw a}}finally{m=o,T=r}},n.prototype.scheduleMicroTask=function(e,t,n,r){return this._zoneDelegate.scheduleTask(this,new g("microTask",this,e,t,n,r,null))},n.prototype.scheduleMacroTask=function(e,t,n,r,o){return this._zoneDelegate.scheduleTask(this,new g("macroTask",this,e,t,n,r,o))},n.prototype.scheduleEventTask=function(e,t,n,r,o){return this._zoneDelegate.scheduleTask(this,new g("eventTask",this,e,t,n,r,o))},n.prototype.cancelTask=function(e){var t=this._zoneDelegate.cancelTask(this,e);return e.runCount=-1,e.cancelFn=null,t},n.__symbol__=t,n}(),v=function(){function e(e,t,n){this._taskCounts={microTask:0,macroTask:0,eventTask:0},this.zone=e,this._parentDelegate=t,this._forkZS=n&&(n&&n.onFork?n:t._forkZS),this._forkDlgt=n&&(n.onFork?t:t._forkDlgt),this._interceptZS=n&&(n.onIntercept?n:t._interceptZS),this._interceptDlgt=n&&(n.onIntercept?t:t._interceptDlgt),this._invokeZS=n&&(n.onInvoke?n:t._invokeZS),this._invokeDlgt=n&&(n.onInvoke?t:t._invokeDlgt),this._handleErrorZS=n&&(n.onHandleError?n:t._handleErrorZS),this._handleErrorDlgt=n&&(n.onHandleError?t:t._handleErrorDlgt),this._scheduleTaskZS=n&&(n.onScheduleTask?n:t._scheduleTaskZS),this._scheduleTaskDlgt=n&&(n.onScheduleTask?t:t._scheduleTaskDlgt),this._invokeTaskZS=n&&(n.onInvokeTask?n:t._invokeTaskZS),this._invokeTaskDlgt=n&&(n.onInvokeTask?t:t._invokeTaskDlgt),this._cancelTaskZS=n&&(n.onCancelTask?n:t._cancelTaskZS),this._cancelTaskDlgt=n&&(n.onCancelTask?t:t._cancelTaskDlgt),this._hasTaskZS=n&&(n.onHasTask?n:t._hasTaskZS),this._hasTaskDlgt=n&&(n.onHasTask?t:t._hasTaskDlgt)}return e.prototype.fork=function(e,t){return this._forkZS?this._forkZS.onFork(this._forkDlgt,this.zone,e,t):new d(e,t)},e.prototype.intercept=function(e,t,n){return this._interceptZS?this._interceptZS.onIntercept(this._interceptDlgt,this.zone,e,t,n):t},e.prototype.invoke=function(e,t,n,r,o){return this._invokeZS?this._invokeZS.onInvoke(this._invokeDlgt,this.zone,e,t,n,r,o):t.apply(n,r)},e.prototype.handleError=function(e,t){return!this._handleErrorZS||this._handleErrorZS.onHandleError(this._handleErrorDlgt,this.zone,e,t)},e.prototype.scheduleTask=function(e,t){try{if(this._scheduleTaskZS)return this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt,this.zone,e,t);if(t.scheduleFn)t.scheduleFn(t);else{if("microTask"!=t.type)throw new Error("Task is missing scheduleFn.");r(t)}return t}finally{e==this.zone&&this._updateTaskCount(t.type,1)}},e.prototype.invokeTask=function(e,t,n,r){try{return this._invokeTaskZS?this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt,this.zone,e,t,n,r):t.callback.apply(n,r)}finally{e!=this.zone||"eventTask"==t.type||t.data&&t.data.isPeriodic||this._updateTaskCount(t.type,-1)}},e.prototype.cancelTask=function(e,t){var n;if(this._cancelTaskZS)n=this._cancelTaskZS.onCancelTask(this._cancelTaskDlgt,this.zone,e,t);else{if(!t.cancelFn)throw new Error("Task does not support cancellation, or is already canceled.");n=t.cancelFn(t)}return e==this.zone&&this._updateTaskCount(t.type,-1),n},e.prototype.hasTask=function(e,t){return this._hasTaskZS&&this._hasTaskZS.onHasTask(this._hasTaskDlgt,this.zone,e,t)},e.prototype._updateTaskCount=function(e,t){var n=this._taskCounts,r=n[e],o=n[e]=r+t;if(o<0)throw new Error("More tasks executed then were scheduled.");if(0==r||0==o){var a={microTask:n.microTask>0,macroTask:n.macroTask>0,eventTask:n.eventTask>0,change:e};try{this.hasTask(this.zone,a)}finally{this._parentDelegate&&this._parentDelegate._updateTaskCount(e,t)}}},e}(),g=function(){function e(e,t,n,r,o,i,s){this.runCount=0,this.type=e,this.zone=t,this.source=n,this.data=o,this.scheduleFn=i,this.cancelFn=s,this.callback=r;var u=this;this.invoke=function(){E++;try{return t.runTask(u,this,arguments)}finally{1==E&&a(),E--}}}return e.prototype.toString=function(){return this.data&&"undefined"!=typeof this.data.handleId?this.data.handleId:this.toString()},e}(),y=t("setTimeout"),k=t("Promise"),b=t("then"),m=new d(null,null),T=null,w=[],_=!1,D=[],E=0,S=t("state"),P=t("value"),Z="Promise.then",O=null,j=!0,z=!1,I=0,C=function(){function e(t){var n=this;if(!(n instanceof e))throw new Error("Must be an instanceof Promise.");n[S]=O,n[P]=[];try{t&&t(c(n,j),c(n,z))}catch(r){l(n,!1,r)}}return e.resolve=function(e){return l(new this(null),j,e)},e.reject=function(e){return l(new this(null),z,e)},e.race=function(e){function t(e){a&&(a=r(e))}function n(e){a&&(a=o(e))}for(var r,o,a=new this(function(e,t){r=e,o=t}),s=0,u=e;s { - setTimeout(() => { - if (!this._alreadyErrored && !(this._pendingMicroTasks || this._pendingMacroTasks)) { - this._finishCallback(); - } - }, 0); - }); - } + _finishCallbackIfDone() { + if (!(this._pendingMicroTasks || this._pendingMacroTasks)) { + // We do this because we would like to catch unhandled rejected promises. + this.runZone.run(() => { + setTimeout(() => { + if (!this._alreadyErrored && !(this._pendingMicroTasks || this._pendingMacroTasks)) { + this._finishCallback(); + } + }, 0); + }); } + } - // ZoneSpec implementation below. + // ZoneSpec implementation below. - name: string; + name: string; - // Note - we need to use onInvoke at the moment to call finish when a test is - // fully synchronous. TODO(juliemr): remove this when the logic for - // onHasTask changes and it calls whenever the task queues are dirty. - onInvoke(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - delegate: Function, applyThis: any, applyArgs: any[], source: string): any { - try { - return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); - } finally { - this._finishCallbackIfDone(); - } + // Note - we need to use onInvoke at the moment to call finish when a test is + // fully synchronous. TODO(juliemr): remove this when the logic for + // onHasTask changes and it calls whenever the task queues are dirty. + onInvoke(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + delegate: Function, applyThis: any, applyArgs: any[], source: string): any { + try { + return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); + } finally { + this._finishCallbackIfDone(); } + } - onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - error: any): boolean { - // Let the parent try to handle the error. - const result = parentZoneDelegate.handleError(targetZone, error); - if (result) { - this._failCallback(error); - this._alreadyErrored = true; - } - return false; + onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + error: any): boolean { + // Let the parent try to handle the error. + const result = parentZoneDelegate.handleError(targetZone, error); + if (result) { + this._failCallback(error); + this._alreadyErrored = true; } + return false; + } - onScheduleTask(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): Task { - if (task.type == 'macroTask' && task.source == 'setInterval') { - this._failCallback('Cannot use setInterval from within an async zone test.'); - return; - } - - return delegate.scheduleTask(targetZone, task); + onScheduleTask(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): Task { + if (task.type == 'macroTask' && task.source == 'setInterval') { + this._failCallback('Cannot use setInterval from within an async zone test.'); + return; } - onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) { - delegate.hasTask(target, hasTaskState); - if (hasTaskState.change == 'microTask') { - this._pendingMicroTasks = hasTaskState.microTask; - this._finishCallbackIfDone(); - } else if (hasTaskState.change == 'macroTask') { - this._pendingMacroTasks = hasTaskState.macroTask; - this._finishCallbackIfDone(); - } + return delegate.scheduleTask(targetZone, task); + } + + onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) { + delegate.hasTask(target, hasTaskState); + if (hasTaskState.change == 'microTask') { + this._pendingMicroTasks = hasTaskState.microTask; + this._finishCallbackIfDone(); + } else if (hasTaskState.change == 'macroTask') { + this._pendingMacroTasks = hasTaskState.macroTask; + this._finishCallbackIfDone(); } } +} - // Export the class so that new instances can be created with proper - // constructor params. - Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; -})(); +// Export the class so that new instances can be created with proper +// constructor params. +Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; diff --git a/lib/zone-spec/long-stack-trace.ts b/lib/zone-spec/long-stack-trace.ts index 4048c9a5e..ece2dc9ce 100644 --- a/lib/zone-spec/long-stack-trace.ts +++ b/lib/zone-spec/long-stack-trace.ts @@ -1,146 +1,143 @@ -'use strict'; -(function() { - const NEWLINE = '\n'; - const SEP = ' ------------- '; - const IGNORE_FRAMES = []; - const creationTrace = '__creationTrace__'; - - class LongStackTrace { - error: Error = getStacktrace(); - timestamp: Date = new Date(); - - } - - function getStacktraceWithUncaughtError (): Error { - return new Error('STACKTRACE TRACKING'); +const NEWLINE = '\n'; +const SEP = ' ------------- '; +const IGNORE_FRAMES = []; +const creationTrace = '__creationTrace__'; + +class LongStackTrace { + error: Error = getStacktrace(); + timestamp: Date = new Date(); + +} + +function getStacktraceWithUncaughtError (): Error { + return new Error('STACKTRACE TRACKING'); +} + +function getStacktraceWithCaughtError(): Error { + try { + throw getStacktraceWithUncaughtError(); + } catch (e) { + return e; } - - function getStacktraceWithCaughtError(): Error { - try { - throw getStacktraceWithUncaughtError(); - } catch (e) { - return e; +} + +// Some implementations of exception handling don't create a stack trace if the exception +// isn't thrown, however it's faster not to actually throw the exception. +const error = getStacktraceWithUncaughtError(); +const coughtError = getStacktraceWithCaughtError(); +const getStacktrace = error.stack + ? getStacktraceWithUncaughtError + : (coughtError.stack ? getStacktraceWithCaughtError: getStacktraceWithUncaughtError); + +function getFrames(error: Error): string[] { + return error.stack ? error.stack.split(NEWLINE) : []; +} + +function addErrorStack(lines:string[], error:Error):void { + let trace: string[] = getFrames(error); + for (let i = 0; i < trace.length; i++) { + const frame = trace[i]; + // Filter out the Frames which are part of stack capturing. + if (! (i < IGNORE_FRAMES.length && IGNORE_FRAMES[i] === frame)) { + lines.push(trace[i]); } } +} - // Some implementations of exception handling don't create a stack trace if the exception - // isn't thrown, however it's faster not to actually throw the exception. - const error = getStacktraceWithUncaughtError(); - const coughtError = getStacktraceWithCaughtError(); - const getStacktrace = error.stack - ? getStacktraceWithUncaughtError - : (coughtError.stack ? getStacktraceWithCaughtError: getStacktraceWithUncaughtError); +function renderLongStackTrace(frames: LongStackTrace[], stack: string): string { + const longTrace: string[] = [stack]; - function getFrames(error: Error): string[] { - return error.stack ? error.stack.split(NEWLINE) : []; - } + if (frames) { + let timestamp = new Date().getTime(); + for (let i = 0; i < frames.length; i++) { + const traceFrames: LongStackTrace = frames[i]; + const lastTime = traceFrames.timestamp; + longTrace.push(`${SEP} Elapsed: ${timestamp - lastTime.getTime()} ms; At: ${lastTime} ${SEP}`); + addErrorStack(longTrace, traceFrames.error); - function addErrorStack(lines:string[], error:Error):void { - let trace: string[] = getFrames(error); - for (let i = 0; i < trace.length; i++) { - const frame = trace[i]; - // Filter out the Frames which are part of stack capturing. - if (! (i < IGNORE_FRAMES.length && IGNORE_FRAMES[i] === frame)) { - lines.push(trace[i]); - } + timestamp = lastTime.getTime(); } } - function renderLongStackTrace(frames: LongStackTrace[], stack: string): string { - const longTrace: string[] = [stack]; - - if (frames) { - let timestamp = new Date().getTime(); - for (let i = 0; i < frames.length; i++) { - const traceFrames: LongStackTrace = frames[i]; - const lastTime = traceFrames.timestamp; - longTrace.push(`${SEP} Elapsed: ${timestamp - lastTime.getTime()} ms; At: ${lastTime} ${SEP}`); - addErrorStack(longTrace, traceFrames.error); - - timestamp = lastTime.getTime(); - } + return longTrace.join(NEWLINE); +} + +Zone['longStackTraceZoneSpec'] = { + name: 'long-stack-trace', + longStackTraceLimit: 10, // Max number of task to keep the stack trace for. + + onScheduleTask: function(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + task: Task): any + { + const currentTask = Zone.currentTask; + let trace = currentTask && currentTask.data && currentTask.data[creationTrace] || []; + trace = [new LongStackTrace()].concat(trace); + if (trace.length > this.longStackTraceLimit) { + trace.length = this.longStackTraceLimit; } - - return longTrace.join(NEWLINE); - } - - Zone['longStackTraceZoneSpec'] = { - name: 'long-stack-trace', - longStackTraceLimit: 10, // Max number of task to keep the stack trace for. - - onScheduleTask: function(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - task: Task): any - { - const currentTask = Zone.currentTask; - let trace = currentTask && currentTask.data && currentTask.data[creationTrace] || []; - trace = [new LongStackTrace()].concat(trace); - if (trace.length > this.longStackTraceLimit) { - trace.length = this.longStackTraceLimit; + if (!task.data) task.data = {}; + task.data[creationTrace] = trace; + return parentZoneDelegate.scheduleTask(targetZone, task); + }, + + onHandleError: function(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + error: any): any + { + const parentTask = Zone.currentTask || error.task; + if (error instanceof Error && parentTask) { + var stackSetSucceded: string|boolean = null; + try { + let descriptor = Object.getOwnPropertyDescriptor(error, 'stack'); + if (descriptor && descriptor.configurable) { + const delegateGet = descriptor.get; + const value = descriptor.value; + descriptor = { + get: function () { + return renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], + delegateGet ? delegateGet.apply(this) : value); + } + }; + Object.defineProperty(error, 'stack', descriptor); + stackSetSucceded = true; + } + } catch (e) { } + var longStack: string = stackSetSucceded ? null : renderLongStackTrace( + parentTask.data && parentTask.data[creationTrace], error.stack); + if (!stackSetSucceded) { + try { + stackSetSucceded = error.stack = longStack; + } catch (e) { } } - if (!task.data) task.data = {}; - task.data[creationTrace] = trace; - return parentZoneDelegate.scheduleTask(targetZone, task); - }, - - onHandleError: function(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - error: any): any - { - const parentTask = Zone.currentTask || error.task; - if (error instanceof Error && parentTask) { - var stackSetSucceded: string|boolean = null; + if (!stackSetSucceded) { try { - let descriptor = Object.getOwnPropertyDescriptor(error, 'stack'); - if (descriptor && descriptor.configurable) { - const delegateGet = descriptor.get; - const value = descriptor.value; - descriptor = { - get: function () { - return renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], - delegateGet ? delegateGet.apply(this) : value); - } - }; - Object.defineProperty(error, 'stack', descriptor); - stackSetSucceded = true; - } + stackSetSucceded = (error as any).longStack = longStack; } catch (e) { } - var longStack: string = stackSetSucceded ? null : renderLongStackTrace( - parentTask.data && parentTask.data[creationTrace], error.stack); - if (!stackSetSucceded) { - try { - stackSetSucceded = error.stack = longStack; - } catch (e) { } - } - if (!stackSetSucceded) { - try { - stackSetSucceded = (error as any).longStack = longStack; - } catch (e) { } - } } - return parentZoneDelegate.handleError(targetZone, error); - } - }; - - function captureStackTraces(stackTraces: string[][], count: number): void { - if (count > 0) { - stackTraces.push(getFrames((new LongStackTrace()).error)); - captureStackTraces(stackTraces, count - 1); } + return parentZoneDelegate.handleError(targetZone, error); } +}; - function computeIgnoreFrames() { - const frames: string[][] = []; - captureStackTraces(frames, 2); - const frames1 = frames[0]; - const frames2 = frames[1]; - for (let i = 0; i < frames1.length; i++) { - const frame1 = frames1[i]; - const frame2 = frames2[i]; - if (frame1 === frame2) { - IGNORE_FRAMES.push(frame1); - } else { - break; - } +function captureStackTraces(stackTraces: string[][], count: number): void { + if (count > 0) { + stackTraces.push(getFrames((new LongStackTrace()).error)); + captureStackTraces(stackTraces, count - 1); + } +} + +function computeIgnoreFrames() { + const frames: string[][] = []; + captureStackTraces(frames, 2); + const frames1 = frames[0]; + const frames2 = frames[1]; + for (let i = 0; i < frames1.length; i++) { + const frame1 = frames1[i]; + const frame2 = frames2[i]; + if (frame1 === frame2) { + IGNORE_FRAMES.push(frame1); + } else { + break; } } - computeIgnoreFrames(); -})(); +} +computeIgnoreFrames(); diff --git a/lib/zone-spec/proxy.ts b/lib/zone-spec/proxy.ts index 7c70741f3..63a619aac 100644 --- a/lib/zone-spec/proxy.ts +++ b/lib/zone-spec/proxy.ts @@ -1,128 +1,126 @@ -(function () { - class ProxyZoneSpec implements ZoneSpec { - name: string = 'ProxyZone'; +class ProxyZoneSpec implements ZoneSpec { + name: string = 'ProxyZone'; - private _delegateSpec: ZoneSpec; + private _delegateSpec: ZoneSpec; - properties: {[k: string]: any} = {'ProxyZoneSpec': this}; - propertyKeys: string[] = null; + properties: {[k: string]: any} = {'ProxyZoneSpec': this}; + propertyKeys: string[] = null; - static get(): ProxyZoneSpec { - return Zone.current.get('ProxyZoneSpec'); - } + static get(): ProxyZoneSpec { + return Zone.current.get('ProxyZoneSpec'); + } - static isLoaded(): boolean { - return ProxyZoneSpec.get() instanceof ProxyZoneSpec; - } + static isLoaded(): boolean { + return ProxyZoneSpec.get() instanceof ProxyZoneSpec; + } - static assertPresent(): ProxyZoneSpec { - if (!this.isLoaded()) { - throw new Error(`Expected to be running in 'ProxyZone', but it was not found.`); - } - return ProxyZoneSpec.get(); + static assertPresent(): ProxyZoneSpec { + if (!this.isLoaded()) { + throw new Error(`Expected to be running in 'ProxyZone', but it was not found.`); } + return ProxyZoneSpec.get(); + } - constructor(private defaultSpecDelegate: ZoneSpec = null) { - this.setDelegate(defaultSpecDelegate); - } + constructor(private defaultSpecDelegate: ZoneSpec = null) { + this.setDelegate(defaultSpecDelegate); + } - setDelegate(delegateSpec: ZoneSpec) { - this._delegateSpec = delegateSpec; - this.propertyKeys && this.propertyKeys.forEach((key) => delete this.properties[key]); - this.propertyKeys = null; - if (delegateSpec && delegateSpec.properties) { - this.propertyKeys = Object.keys(delegateSpec.properties); - this.propertyKeys.forEach((k) => this.properties[k] = delegateSpec.properties[k]); - } + setDelegate(delegateSpec: ZoneSpec) { + this._delegateSpec = delegateSpec; + this.propertyKeys && this.propertyKeys.forEach((key) => delete this.properties[key]); + this.propertyKeys = null; + if (delegateSpec && delegateSpec.properties) { + this.propertyKeys = Object.keys(delegateSpec.properties); + this.propertyKeys.forEach((k) => this.properties[k] = delegateSpec.properties[k]); } + } - getDelegate() { - return this._delegateSpec; - } + getDelegate() { + return this._delegateSpec; + } - resetDelegate() { - this.setDelegate(this.defaultSpecDelegate); - } + resetDelegate() { + this.setDelegate(this.defaultSpecDelegate); + } - onFork(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - zoneSpec: ZoneSpec): Zone { - if (this._delegateSpec && this._delegateSpec.onFork) { - return this._delegateSpec.onFork(parentZoneDelegate, currentZone, targetZone, zoneSpec); - } else { - return parentZoneDelegate.fork(targetZone, zoneSpec); - } + onFork(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + zoneSpec: ZoneSpec): Zone { + if (this._delegateSpec && this._delegateSpec.onFork) { + return this._delegateSpec.onFork(parentZoneDelegate, currentZone, targetZone, zoneSpec); + } else { + return parentZoneDelegate.fork(targetZone, zoneSpec); } + } - onIntercept(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - delegate: Function, source: string): Function { - if (this._delegateSpec && this._delegateSpec.onIntercept) { - return this._delegateSpec.onIntercept(parentZoneDelegate, currentZone, targetZone, delegate, source); - } else { - return parentZoneDelegate.intercept(targetZone, delegate, source); - } + onIntercept(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + delegate: Function, source: string): Function { + if (this._delegateSpec && this._delegateSpec.onIntercept) { + return this._delegateSpec.onIntercept(parentZoneDelegate, currentZone, targetZone, delegate, source); + } else { + return parentZoneDelegate.intercept(targetZone, delegate, source); } + } - onInvoke(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - delegate: Function, applyThis: any, applyArgs: any[], source: string): any { - if (this._delegateSpec && this._delegateSpec.onInvoke) { - return this._delegateSpec.onInvoke(parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source); - } else { - return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); - } + onInvoke(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + delegate: Function, applyThis: any, applyArgs: any[], source: string): any { + if (this._delegateSpec && this._delegateSpec.onInvoke) { + return this._delegateSpec.onInvoke(parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source); + } else { + return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); } + } - onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - error: any): boolean { - if (this._delegateSpec && this._delegateSpec.onHandleError) { - return this._delegateSpec.onHandleError(parentZoneDelegate, currentZone, targetZone, error); - } else { - return parentZoneDelegate.handleError(targetZone, error); - } + onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + error: any): boolean { + if (this._delegateSpec && this._delegateSpec.onHandleError) { + return this._delegateSpec.onHandleError(parentZoneDelegate, currentZone, targetZone, error); + } else { + return parentZoneDelegate.handleError(targetZone, error); } + } - onScheduleTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - task: Task): Task { - if (this._delegateSpec && this._delegateSpec.onScheduleTask) { - return this._delegateSpec.onScheduleTask(parentZoneDelegate, currentZone, targetZone, task); - } else { - return parentZoneDelegate.scheduleTask(targetZone, task); - } + onScheduleTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + task: Task): Task { + if (this._delegateSpec && this._delegateSpec.onScheduleTask) { + return this._delegateSpec.onScheduleTask(parentZoneDelegate, currentZone, targetZone, task); + } else { + return parentZoneDelegate.scheduleTask(targetZone, task); } + } - onInvokeTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - task: Task, applyThis: any, applyArgs: any): any { - if (this._delegateSpec && this._delegateSpec.onFork) { - return this._delegateSpec.onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs); - } else { - return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs); - } + onInvokeTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + task: Task, applyThis: any, applyArgs: any): any { + if (this._delegateSpec && this._delegateSpec.onFork) { + return this._delegateSpec.onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs); + } else { + return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs); } + } - onCancelTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - task: Task): any { - if (this._delegateSpec && this._delegateSpec.onCancelTask) { - return this._delegateSpec.onCancelTask(parentZoneDelegate, currentZone, targetZone, task); - } else { - return parentZoneDelegate.cancelTask(targetZone, task); - } + onCancelTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + task: Task): any { + if (this._delegateSpec && this._delegateSpec.onCancelTask) { + return this._delegateSpec.onCancelTask(parentZoneDelegate, currentZone, targetZone, task); + } else { + return parentZoneDelegate.cancelTask(targetZone, task); } + } - onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, - hasTaskState: HasTaskState): void { - if (this._delegateSpec && this._delegateSpec.onHasTask) { - this._delegateSpec.onHasTask(delegate, current, target, hasTaskState); - } else { - delegate.hasTask(target, hasTaskState); - } + onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, + hasTaskState: HasTaskState): void { + if (this._delegateSpec && this._delegateSpec.onHasTask) { + this._delegateSpec.onHasTask(delegate, current, target, hasTaskState); + } else { + delegate.hasTask(target, hasTaskState); } } +} - // Export the class so that new instances can be created with proper - // constructor params. - Zone['ProxyZoneSpec'] = ProxyZoneSpec; -})(); +// Export the class so that new instances can be created with proper +// constructor params. +Zone['ProxyZoneSpec'] = ProxyZoneSpec; diff --git a/lib/zone-spec/sync-test.ts b/lib/zone-spec/sync-test.ts index 59799fa4b..5b95c484b 100644 --- a/lib/zone-spec/sync-test.ts +++ b/lib/zone-spec/sync-test.ts @@ -1,29 +1,27 @@ -(function() { - class SyncTestZoneSpec implements ZoneSpec { - runZone = Zone.current; +class SyncTestZoneSpec implements ZoneSpec { + runZone = Zone.current; - constructor(namePrefix: string) { - this.name = 'syncTestZone for ' + namePrefix; - } + constructor(namePrefix: string) { + this.name = 'syncTestZone for ' + namePrefix; + } - // ZoneSpec implementation below. + // ZoneSpec implementation below. - name: string; + name: string; - onScheduleTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): Task { - switch (task.type) { - case 'microTask': - case 'macroTask': - throw new Error(`Cannot call ${task.source} from within a sync test.`); - case 'eventTask': - task = delegate.scheduleTask(target, task); - break; - } - return task; + onScheduleTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): Task { + switch (task.type) { + case 'microTask': + case 'macroTask': + throw new Error(`Cannot call ${task.source} from within a sync test.`); + case 'eventTask': + task = delegate.scheduleTask(target, task); + break; } + return task; } +} - // Export the class so that new instances can be created with proper - // constructor params. - Zone['SyncTestZoneSpec'] = SyncTestZoneSpec; -})(); +// Export the class so that new instances can be created with proper +// constructor params. +Zone['SyncTestZoneSpec'] = SyncTestZoneSpec; diff --git a/lib/zone.ts b/lib/zone.ts index 534516310..03e4b2385 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -867,7 +867,7 @@ const Zone: ZoneType = (function(global: any) { if (this.data && typeof this.data.handleId !== 'undefined') { return this.data.handleId; } else { - return this.toString(); + return Object.prototype.toString.call(this); } } } @@ -994,7 +994,7 @@ const Zone: ZoneType = (function(global: any) { if (queue.length == 0 && state == REJECTED) { promise[symbolState] = REJECTED_NO_CATCH; try { - throw new Error("Uncaught (in promise): " + value); + throw new Error("Uncaught (in promise): " + value + (value && value.stack ? '\n' + value.stack : '')); } catch (e) { const error: UncaughtPromiseError = e; error.rejection = value; @@ -1145,10 +1145,17 @@ const Zone: ZoneType = (function(global: any) { if (NativePromise) { patchThen(NativePromise); if (typeof global['fetch'] !== 'undefined') { - const fetchPromise = global['fetch']('about:blank'); + let fetchPromise: Promise; + try { + // In MS Edge this throws + fetchPromise = global['fetch'](); + } catch (e) { + // In Chrome this throws instead. + fetchPromise = global['fetch']('about:blank'); + } // ignore output to prevent error; fetchPromise.then(() => null, () => null); - if (fetchPromise.constructor != NativePromise) { + if (fetchPromise.constructor != NativePromise && fetchPromise.constructor != ZoneAwarePromise) { patchThen(fetchPromise.constructor); } } diff --git a/package.json b/package.json index 31b604b0f..1004667d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zone.js", - "version": "0.6.22", + "version": "0.6.25", "description": "Zones for JavaScript", "main": "dist/zone-node.js", "browser": "dist/zone.js", @@ -38,6 +38,7 @@ "@types/systemjs": "^0.19.30", "concurrently": "^2.2.0", "es6-promise": "^3.0.2", + "whatwg-fetch": "^1.0.0", "gulp": "^3.8.11", "gulp-rename": "^1.2.2", "gulp-rollup": "^2.3.0", @@ -53,7 +54,6 @@ "karma-safari-launcher": "^0.1.1", "karma-sauce-launcher": "^0.2.10", "karma-sourcemap-loader": "^0.3.6", - "karma-webpack": "^1.7.0", "nodejs-websocket": "^1.2.0", "pump": "^1.0.1", "systemjs": "^0.19.37", diff --git a/sauce.conf.js b/sauce.conf.js index 5fc5d2fb9..facaec940 100644 --- a/sauce.conf.js +++ b/sauce.conf.js @@ -70,12 +70,12 @@ module.exports = function (config) { platform: 'Windows 10', version: '11' }, - /*'SL_MSEDGE13': { + 'SL_MSEDGE13': { base: 'SauceLabs', browserName: 'MicrosoftEdge', platform: 'Windows 10', version: '13.10586' - },*/ + }, 'SL_ANDROID4.1': { base: 'SauceLabs', browserName: 'android', diff --git a/test/common/Promise.spec.ts b/test/common/Promise.spec.ts index 66529547a..6a3ece99d 100644 --- a/test/common/Promise.spec.ts +++ b/test/common/Promise.spec.ts @@ -233,6 +233,7 @@ describe('Promise', ifEnvSupports('Promise', function () { var promiseError: Error = null; var zone: Zone = null; var task: Task = null; + var error: Error = null; queueZone.fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, @@ -244,13 +245,19 @@ describe('Promise', ifEnvSupports('Promise', function () { }).run(() => { zone = Zone.current; task = Zone.currentTask; - Promise.reject('rejectedErrorShouldBeHandled'); + error = new Error('rejectedErrorShouldBeHandled'); + try { + // throw so that the stack trace is captured + throw error; + } catch (e) {} + Promise.reject(error); expect(promiseError).toBe(null); }); setTimeout(() => null); setTimeout(() => { - expect(promiseError.message).toBe('Uncaught (in promise): rejectedErrorShouldBeHandled'); - expect(promiseError['rejection']).toBe('rejectedErrorShouldBeHandled'); + expect(promiseError.message).toBe('Uncaught (in promise): ' + error + + (error.stack ? '\n' + error.stack : '')); + expect(promiseError['rejection']).toBe(error); expect(promiseError['zone']).toBe(zone); expect(promiseError['task']).toBe(task); done(); @@ -334,17 +341,22 @@ describe('Promise', ifEnvSupports('Promise', function () { }); }); - it('should work for blob response', function(done) { - testZone.run(function() { - global['fetch']('/base/test/assets/sample.json').then(function(response: any) { + it('should work for blob response', function (done) { + testZone.run(function () { + global['fetch']('/base/test/assets/sample.json').then(function (response:any) { var fetchZone = Zone.current; expect(fetchZone).toBe(testZone); - response.blob().then(function(blob) { - expect(Zone.current).toBe(fetchZone); - expect(blob instanceof Blob).toEqual(true); + // Android 4.3- doesn't support response.blob() + if (response.blob) { + response.blob().then(function (blob) { + expect(Zone.current).toBe(fetchZone); + expect(blob instanceof Blob).toEqual(true); + done(); + }); + } else { done(); - }); + } }); }); }); @@ -355,13 +367,19 @@ describe('Promise', ifEnvSupports('Promise', function () { var fetchZone = Zone.current; expect(fetchZone).toBe(testZone); - response.arrayBuffer().then(function(blob) { - expect(Zone.current).toBe(fetchZone); - expect(blob instanceof ArrayBuffer).toEqual(true); + // Android 4.3- doesn't support response.arrayBuffer() + if (response.arrayBuffer) { + response.arrayBuffer().then(function (blob) { + expect(Zone.current).toBe(fetchZone); + expect(blob instanceof ArrayBuffer).toEqual(true); + done(); + }); + } else { done(); - }); + } }); }); }); + })); })); diff --git a/test/zone-spec/fake-async-test.spec.ts b/test/zone-spec/fake-async-test.spec.ts index 96e491ab1..12639fb4f 100644 --- a/test/zone-spec/fake-async-test.spec.ts +++ b/test/zone-spec/fake-async-test.spec.ts @@ -59,7 +59,7 @@ describe('FakeAsyncTestZoneSpec', () => { fakeAsyncTestZone.run(() => { Promise.resolve(null).then((_) => { throw new Error('async'); }); expect(() => { testZoneSpec.flushMicrotasks(); }) - .toThrowError('Uncaught (in promise): Error: async'); + .toThrowError(/Uncaught \(in promise\): Error: async/); }); });