diff --git a/dist/async-test.js b/dist/async-test.js index e71ba6392..2f1feaad8 100644 --- a/dist/async-test.js +++ b/dist/async-test.js @@ -11,6 +11,13 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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 + */ var AsyncTestZoneSpec = (function () { function AsyncTestZoneSpec(finishCallback, failCallback, namePrefix) { this._pendingMicroTasks = false; diff --git a/dist/fake-async-test.js b/dist/fake-async-test.js index b65f4712b..2d73d419c 100644 --- a/dist/fake-async-test.js +++ b/dist/fake-async-test.js @@ -11,6 +11,13 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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) { var Scheduler = (function () { function Scheduler() { @@ -27,13 +34,7 @@ var currentId = id < 0 ? this.nextId++ : id; var endTime = this._currentTime + delay; // Insert so that scheduler queue remains sorted by end time. - var newEntry = { - endTime: endTime, - id: currentId, - func: cb, - args: args, - delay: delay - }; + var newEntry = { endTime: endTime, id: currentId, func: cb, args: args, delay: delay }; var i = 0; for (; i < this._schedulerQueue.length; i++) { var currentEntry = this._schedulerQueue[i]; @@ -54,16 +55,17 @@ }; Scheduler.prototype.tick = function (millis) { if (millis === void 0) { millis = 0; } - this._currentTime += millis; + var finalTime = this._currentTime + millis; while (this._schedulerQueue.length > 0) { var current = this._schedulerQueue[0]; - if (this._currentTime < current.endTime) { + if (finalTime < current.endTime) { // Done processing the queue since it's sorted by endTime. break; } else { // Time to run scheduled function. Remove it from the head of queue. var current_1 = this._schedulerQueue.shift(); + this._currentTime = current_1.endTime; var retval = current_1.func.apply(global, current_1.args); if (!retval) { // Uncaught exception in the current scheduled function. Stop processing the queue. @@ -71,6 +73,7 @@ } } } + this._currentTime = finalTime; }; return Scheduler; }()); @@ -110,7 +113,7 @@ completers.onError.apply(global); } } - // Return true if there were no errors, false otherwise. + // Return true if there were no errors, false otherwise. return _this._lastError === null; }; }; @@ -161,7 +164,7 @@ var id = this._scheduler.nextId; var completers = { onSuccess: null, onError: this._dequeuePeriodicTimer(id) }; var cb = this._fnAndFlush(fn, completers); - // Use the callback created above to requeue on success. + // Use the callback created above to requeue on success. completers.onSuccess = this._requeuePeriodicTimer(cb, interval, args, id); // Queue the callback and dequeue the periodic timer only on error. this._scheduler.scheduleFunction(cb, interval, args); diff --git a/dist/jasmine-patch.js b/dist/jasmine-patch.js index 48bd03c1c..d188c8cfe 100644 --- a/dist/jasmine-patch.js +++ b/dist/jasmine-patch.js @@ -11,40 +11,51 @@ (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; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -}; +/** + * @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 () { + var __extends = function (d, b) { + for (var p in b) + if (b.hasOwnProperty(p)) + d[p] = b[p]; + function __() { + this.constructor = d; + } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; // Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs // in a testZone (ProxyZone). (See: angular/zone.js#91 & angular/angular#10503) if (!Zone) - throw new Error("Missing: zone.js"); + throw new Error('Missing: zone.js'); if (typeof jasmine == 'undefined') - throw new Error("Missing: jasmine.js"); + throw new Error('Missing: jasmine.js'); if (jasmine['__zone_patch__']) - throw new Error("'jasmine' has already been patched with 'Zone'."); + throw new Error('\'jasmine\' has already been patched with \'Zone\'.'); jasmine['__zone_patch__'] = true; var SyncTestZoneSpec = Zone['SyncTestZoneSpec']; var ProxyZoneSpec = Zone['ProxyZoneSpec']; if (!SyncTestZoneSpec) - throw new Error("Missing: SyncTestZoneSpec"); + throw new Error('Missing: SyncTestZoneSpec'); if (!ProxyZoneSpec) - throw new Error("Missing: ProxyZoneSpec"); + throw new Error('Missing: ProxyZoneSpec'); var ambientZone = Zone.current; - // Create a synchronous-only zone in which to run `describe` blocks in order to raise an - // error if any asynchronous operations are attempted inside of a `describe` but outside of + // Create a synchronous-only zone in which to run `describe` blocks in order to raise an + // error if any asynchronous operations are attempted inside of a `describe` but outside of // a `beforeEach` or `it`. var syncZone = ambientZone.fork(new SyncTestZoneSpec('jasmine.describe')); // This is the zone which will be used for running individual tests. // It will be a proxy zone, so that the tests function can retroactively install - // different zones. + // different zones. // Example: // - In beforeEach() do childZone = Zone.current.fork(...); - // - In it() try to do fakeAsync(). The issue is that because the beforeEach forked the + // - In it() try to do fakeAsync(). The issue is that because the beforeEach forked the // zone outside of fakeAsync it will be able to escope the fakeAsync rules. - // - Because ProxyZone is parent fo `childZone` fakeAsync can retroactively add + // - Because ProxyZone is parent fo `childZone` fakeAsync can retroactively add // fakeAsync behavior to the childZone. var testProxyZone = null; // Monkey patch all of the jasmine DSL so that each function runs in appropriate zone. @@ -87,9 +98,11 @@ var __extends = (undefined && undefined.__extends) || function (d, b) { // The `done` callback is only passed through if the function expects at least one argument. // Note we have to make a function with correct number of arguments, otherwise jasmine will // think that all functions are sync or async. - return (testBody.length == 0) - ? function () { return testProxyZone.run(testBody, this); } - : function (done) { return testProxyZone.run(testBody, this, [done]); }; + return (testBody.length == 0) ? function () { + return testProxyZone.run(testBody, this); + } : function (done) { + return testProxyZone.run(testBody, this, [done]); + }; } var QueueRunner = jasmine.QueueRunner; jasmine.QueueRunner = (function (_super) { @@ -105,7 +118,7 @@ var __extends = (undefined && undefined.__extends) || function (d, b) { ZoneQueueRunner.prototype.execute = function () { var _this = this; if (Zone.current !== ambientZone) - throw new Error("Unexpected Zone: " + Zone.current.name); + throw new Error('Unexpected Zone: ' + Zone.current.name); testProxyZone = ambientZone.fork(new ProxyZoneSpec()); if (!Zone.currentTask) { // if we are not running in a task then if someone would register a @@ -113,7 +126,7 @@ var __extends = (undefined && undefined.__extends) || function (d, b) { // addEventListener callback would think that it is the top most task and would // drain the microtask queue on element.click() which would be incorrect. // For this reason we always force a task when running jasmine tests. - Zone.current.scheduleMicroTask('jasmine.execute().forceTask', function () { return _super.prototype.execute.call(_this); }); + Zone.current.scheduleMicroTask('jasmine.execute().forceTask', function () { return QueueRunner.prototype.execute.call(_this); }); } else { _super.prototype.execute.call(this); diff --git a/dist/jasmine-patch.min.js b/dist/jasmine-patch.min.js index 916e90019..b4695a0d2 100644 --- a/dist/jasmine-patch.min.js +++ b/dist/jasmine-patch.min.js @@ -1 +1 @@ -!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 +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(this,function(){"use strict";!function(){function e(e){return function(){return c.run(e,this,arguments)}}function n(e){return 0==e.length?function(){return u.run(e,this)}:function(n){return u.run(e,this,[n])}}var r=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)};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(n){var r=s[n];s[n]=function(n,t){return r.call(this,n,e(t))}}),["it","xit","fit"].forEach(function(e){var r=s[e];s[e]=function(e,t,o){return arguments[1]=n(t),r.apply(this,arguments)}}),["beforeEach","afterEach"].forEach(function(e){var r=s[e];s[e]=function(e,t){return arguments[0]=n(e),r.apply(this,arguments)}});var f=jasmine.QueueRunner;jasmine.QueueRunner=function(e){function n(n){n.onComplete=function(e){return function(){u=null,i.scheduleMicroTask("jasmine.onComplete",e)}}(n.onComplete),e.call(this,n)}return r(n,e),n.prototype.execute=function(){var n=this;if(Zone.current!==i)throw new Error("Unexpected Zone: "+Zone.current.name);u=i.fork(new o),Zone.currentTask?e.prototype.execute.call(this):Zone.current.scheduleMicroTask("jasmine.execute().forceTask",function(){return f.prototype.execute.call(n)})},n}(f)}()}); \ No newline at end of file diff --git a/dist/long-stack-trace-zone.js b/dist/long-stack-trace-zone.js index e68ac62fc..680a7cd6f 100644 --- a/dist/long-stack-trace-zone.js +++ b/dist/long-stack-trace-zone.js @@ -11,6 +11,13 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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 + */ var NEWLINE = '\n'; var SEP = ' ------------- '; var IGNORE_FRAMES = []; @@ -37,9 +44,9 @@ function getStacktraceWithCaughtError() { // 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); +var getStacktrace = error.stack ? + getStacktraceWithUncaughtError : + (coughtError.stack ? getStacktraceWithCaughtError : getStacktraceWithUncaughtError); function getFrames(error) { return error.stack ? error.stack.split(NEWLINE) : []; } @@ -100,19 +107,24 @@ Zone['longStackTraceZoneSpec'] = { stackSetSucceded = true; } } - catch (e) { } - var longStack = stackSetSucceded ? null : renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], error.stack); + catch (e) { + } + var longStack = stackSetSucceded ? + null : + renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], error.stack); if (!stackSetSucceded) { try { stackSetSucceded = error.stack = longStack; } - catch (e) { } + catch (e) { + } } if (!stackSetSucceded) { try { stackSetSucceded = error.longStack = longStack; } - catch (e) { } + catch (e) { + } } } return parentZoneDelegate.handleError(targetZone, error); diff --git a/dist/proxy.js b/dist/proxy.js index bc1d8e8b2..c09fbd8ae 100644 --- a/dist/proxy.js +++ b/dist/proxy.js @@ -11,6 +11,13 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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 + */ var ProxyZoneSpec = (function () { function ProxyZoneSpec(defaultSpecDelegate) { if (defaultSpecDelegate === void 0) { defaultSpecDelegate = null; } diff --git a/dist/sync-test.js b/dist/sync-test.js index 214e9daab..197f13d63 100644 --- a/dist/sync-test.js +++ b/dist/sync-test.js @@ -11,6 +11,13 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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 + */ var SyncTestZoneSpec = (function () { function SyncTestZoneSpec(namePrefix) { this.runZone = Zone.current; diff --git a/dist/task-tracking.js b/dist/task-tracking.js index 0cfd9eae1..40fc31f41 100644 --- a/dist/task-tracking.js +++ b/dist/task-tracking.js @@ -11,6 +11,13 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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 + */ /** * A `TaskTrackingZoneSpec` allows one to track all outstanding Tasks. * @@ -30,9 +37,12 @@ var TaskTrackingZoneSpec = (function () { }; TaskTrackingZoneSpec.prototype.getTasksFor = function (type) { switch (type) { - case 'microTask': return this.microTasks; - case 'macroTask': return this.macroTasks; - case 'eventTask': return this.eventTasks; + case 'microTask': + return this.microTasks; + case 'macroTask': + return this.macroTasks; + case 'eventTask': + return this.eventTasks; } throw new Error('Unknown task format: ' + type); }; diff --git a/dist/wtf.js b/dist/wtf.js index b637b6c28..207bb9db0 100644 --- a/dist/wtf.js +++ b/dist/wtf.js @@ -11,6 +11,13 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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) { @@ -40,8 +47,8 @@ WtfZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) { var scope = WtfZoneSpec.invokeScope[source]; if (!scope) { - scope = WtfZoneSpec.invokeScope[source] - = wtfEvents.createScope("Zone:invoke:" + source + "(ascii zone)"); + scope = WtfZoneSpec.invokeScope[source] = + wtfEvents.createScope("Zone:invoke:" + source + "(ascii zone)"); } return wtfTrace.leaveScope(scope(zonePathName(targetZone)), parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source)); }; @@ -52,8 +59,8 @@ var key = task.type + ':' + task.source; var instance = WtfZoneSpec.scheduleInstance[key]; if (!instance) { - instance = WtfZoneSpec.scheduleInstance[key] - = wtfEvents.createInstance("Zone:schedule:" + key + "(ascii zone, any data)"); + instance = WtfZoneSpec.scheduleInstance[key] = + wtfEvents.createInstance("Zone:schedule:" + key + "(ascii zone, any data)"); } var retValue = parentZoneDelegate.scheduleTask(targetZone, task); instance(zonePathName(targetZone), shallowObj(task.data, 2)); @@ -63,8 +70,8 @@ var source = task.source; var scope = WtfZoneSpec.invokeTaskScope[source]; if (!scope) { - scope = WtfZoneSpec.invokeTaskScope[source] - = wtfEvents.createScope("Zone:invokeTask:" + source + "(ascii zone)"); + scope = WtfZoneSpec.invokeTaskScope[source] = + wtfEvents.createScope("Zone:invokeTask:" + source + "(ascii zone)"); } return wtfTrace.leaveScope(scope(zonePathName(targetZone)), parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs)); }; @@ -72,8 +79,8 @@ var key = task.source; var instance = WtfZoneSpec.cancelInstance[key]; if (!instance) { - instance = WtfZoneSpec.cancelInstance[key] - = wtfEvents.createInstance("Zone:cancel:" + key + "(ascii zone, any options)"); + instance = WtfZoneSpec.cancelInstance[key] = + wtfEvents.createInstance("Zone:cancel:" + key + "(ascii zone, any options)"); } var retValue = parentZoneDelegate.cancelTask(targetZone, task); instance(zonePathName(targetZone), shallowObj(task.data, 2)); diff --git a/dist/zone-node.js b/dist/zone-node.js index 7a4011233..854d996d9 100644 --- a/dist/zone-node.js +++ b/dist/zone-node.js @@ -11,6 +11,15 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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 + */ + + var Zone$1 = (function (global) { if (global.Zone) { throw new Error('Zone already loaded.'); @@ -21,37 +30,46 @@ var Zone$1 = (function (global) { this._parent = parent; this._name = zoneSpec ? zoneSpec.name || 'unnamed' : ''; this._properties = zoneSpec && zoneSpec.properties || {}; - this._zoneDelegate = new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec); + this._zoneDelegate = + new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec); } Zone.assertZonePatched = function () { if (global.Promise !== ZoneAwarePromise) { - throw new Error("Zone.js has detected that ZoneAwarePromise `(window|global).Promise` " + - "has been overwritten.\n" + - "Most 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.)"); + throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' + + 'has been overwritten.\n' + + 'Most 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(Zone, "current", { - get: function () { return _currentZone; }, + get: function () { + return _currentZone; + }, enumerable: true, configurable: true }); Object.defineProperty(Zone, "currentTask", { - get: function () { return _currentTask; }, + get: function () { + return _currentTask; + }, enumerable: true, configurable: true }); Object.defineProperty(Zone.prototype, "parent", { - get: function () { return this._parent; }, + get: function () { + return this._parent; + }, enumerable: true, configurable: true }); Object.defineProperty(Zone.prototype, "name", { - get: function () { return this._name; }, + get: function () { + return this._name; + }, enumerable: true, configurable: true }); @@ -122,8 +140,8 @@ var Zone$1 = (function (global) { Zone.prototype.runTask = function (task, applyThis, applyArgs) { task.runCount++; if (task.zone != this) - throw new Error('A task can only be run in the zone which created it! (Creation: ' + - task.zone.name + '; Execution: ' + this.name + ')'); + throw new Error('A task can only be run in the zone which created it! (Creation: ' + task.zone.name + + '; Execution: ' + this.name + ')'); var previousTask = _currentTask; _currentTask = task; var oldZone = _currentZone; @@ -172,40 +190,51 @@ var Zone$1 = (function (global) { this._parentDelegate = parentDelegate; this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS); this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt); - this._interceptZS = zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS); - this._interceptDlgt = zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt); + this._interceptZS = + zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS); + this._interceptDlgt = + zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt); this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS); - this._invokeDlgt = zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt); - this._handleErrorZS = zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS); - this._handleErrorDlgt = zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt); - this._scheduleTaskZS = zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS); - this._scheduleTaskDlgt = zoneSpec && (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt); - this._invokeTaskZS = zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS); - this._invokeTaskDlgt = zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt); - this._cancelTaskZS = zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS); - this._cancelTaskDlgt = zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt); + this._invokeDlgt = + zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt); + this._handleErrorZS = + zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS); + this._handleErrorDlgt = + zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt); + this._scheduleTaskZS = + zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS); + this._scheduleTaskDlgt = + zoneSpec && (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt); + this._invokeTaskZS = + zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS); + this._invokeTaskDlgt = + zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt); + this._cancelTaskZS = + zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS); + this._cancelTaskDlgt = + zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt); this._hasTaskZS = zoneSpec && (zoneSpec.onHasTask ? zoneSpec : parentDelegate._hasTaskZS); - this._hasTaskDlgt = zoneSpec && (zoneSpec.onHasTask ? parentDelegate : parentDelegate._hasTaskDlgt); + this._hasTaskDlgt = + zoneSpec && (zoneSpec.onHasTask ? parentDelegate : parentDelegate._hasTaskDlgt); } ZoneDelegate.prototype.fork = function (targetZone, zoneSpec) { - return this._forkZS - ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) - : new Zone(targetZone, zoneSpec); + return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) : + new Zone(targetZone, zoneSpec); }; ZoneDelegate.prototype.intercept = function (targetZone, callback, source) { - return this._interceptZS - ? this._interceptZS.onIntercept(this._interceptDlgt, this.zone, targetZone, callback, source) - : callback; + return this._interceptZS ? + this._interceptZS.onIntercept(this._interceptDlgt, this.zone, targetZone, callback, source) : + callback; }; ZoneDelegate.prototype.invoke = function (targetZone, callback, applyThis, applyArgs, source) { - return this._invokeZS - ? this._invokeZS.onInvoke(this._invokeDlgt, this.zone, targetZone, callback, applyThis, applyArgs, source) - : callback.apply(applyThis, applyArgs); + return this._invokeZS ? + this._invokeZS.onInvoke(this._invokeDlgt, this.zone, targetZone, callback, applyThis, applyArgs, source) : + callback.apply(applyThis, applyArgs); }; ZoneDelegate.prototype.handleError = function (targetZone, error) { - return this._handleErrorZS - ? this._handleErrorZS.onHandleError(this._handleErrorDlgt, this.zone, targetZone, error) - : true; + return this._handleErrorZS ? + this._handleErrorZS.onHandleError(this._handleErrorDlgt, this.zone, targetZone, error) : + true; }; ZoneDelegate.prototype.scheduleTask = function (targetZone, task) { try { @@ -231,12 +260,13 @@ var Zone$1 = (function (global) { }; ZoneDelegate.prototype.invokeTask = function (targetZone, task, applyThis, applyArgs) { try { - return this._invokeTaskZS - ? this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this.zone, targetZone, task, applyThis, applyArgs) - : task.callback.apply(applyThis, applyArgs); + return this._invokeTaskZS ? + this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this.zone, targetZone, task, applyThis, applyArgs) : + task.callback.apply(applyThis, applyArgs); } finally { - if (targetZone == this.zone && (task.type != 'eventTask') && !(task.data && task.data.isPeriodic)) { + if (targetZone == this.zone && (task.type != 'eventTask') && + !(task.data && task.data.isPeriodic)) { this._updateTaskCount(task.type, -1); } } @@ -259,7 +289,8 @@ var Zone$1 = (function (global) { return value; }; ZoneDelegate.prototype.hasTask = function (targetZone, isEmpty) { - return this._hasTaskZS && this._hasTaskZS.onHasTask(this._hasTaskDlgt, this.zone, targetZone, isEmpty); + return this._hasTaskZS && + this._hasTaskZS.onHasTask(this._hasTaskDlgt, this.zone, targetZone, isEmpty); }; ZoneDelegate.prototype._updateTaskCount = function (type, count) { var counts = this._taskCounts; @@ -316,12 +347,14 @@ var Zone$1 = (function (global) { return this.data.handleId; } else { - return this.toString(); + return Object.prototype.toString.call(this); } }; return ZoneTask; }()); - function __symbol__(name) { return '__zone_symbol__' + name; } + function __symbol__(name) { + return '__zone_symbol__' + name; + } var symbolSetTimeout = __symbol__('setTimeout'); var symbolPromise = __symbol__('Promise'); @@ -376,7 +409,9 @@ var Zone$1 = (function (global) { var _loop_1 = function() { var uncaughtPromiseError = _uncaughtPromiseErrors.shift(); try { - uncaughtPromiseError.zone.runGuarded(function () { throw uncaughtPromiseError; }); + uncaughtPromiseError.zone.runGuarded(function () { + throw uncaughtPromiseError; + }); } catch (e) { consoleError(e); @@ -392,8 +427,12 @@ var Zone$1 = (function (global) { function isThenable(value) { return value && value.then; } - function forwardResolution(value) { return value; } - function forwardRejection(rejection) { return ZoneAwarePromise.reject(rejection); } + function forwardResolution(value) { + return value; + } + function forwardRejection(rejection) { + return ZoneAwarePromise.reject(rejection); + } var symbolState = __symbol__('state'); var symbolValue = __symbol__('value'); var source = 'Promise.then'; @@ -426,7 +465,8 @@ var Zone$1 = (function (global) { 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) { var error_1 = e; @@ -490,9 +530,16 @@ var Zone$1 = (function (global) { ZoneAwarePromise.race = function (values) { var resolve; var reject; - var promise = new this(function (res, rej) { resolve = res; reject = rej; }); - function onResolve(value) { promise && (promise = null || resolve(value)); } - function onReject(error) { promise && (promise = null || reject(error)); } + var promise = new this(function (res, rej) { + _a = [res, rej], resolve = _a[0], reject = _a[1]; + var _a; + }); + function onResolve(value) { + promise && (promise = null || resolve(value)); + } + function onReject(error) { + promise && (promise = null || reject(error)); + } for (var _i = 0, values_1 = values; _i < values_1.length; _i++) { var value = values_1[_i]; if (!isThenable(value)) { @@ -505,7 +552,10 @@ var Zone$1 = (function (global) { ZoneAwarePromise.all = function (values) { var resolve; var reject; - var promise = new this(function (res, rej) { resolve = res; reject = rej; }); + var promise = new this(function (res, rej) { + resolve = res; + reject = rej; + }); var count = 0; var resolvedValues = []; for (var _i = 0, values_2 = values; _i < values_2.length; _i++) { @@ -552,13 +602,14 @@ var Zone$1 = (function (global) { global.Promise = ZoneAwarePromise; function patchThen(NativePromise) { var NativePromiseProtototype = NativePromise.prototype; - var NativePromiseThen = NativePromiseProtototype[__symbol__('then')] - = NativePromiseProtototype.then; + var NativePromiseThen = NativePromiseProtototype[__symbol__('then')] = + NativePromiseProtototype.then; NativePromiseProtototype.then = function (onResolve, onReject) { var nativePromise = this; return new ZoneAwarePromise(function (resolve, reject) { NativePromiseThen.call(nativePromise, resolve, reject); - }).then(onResolve, onReject); + }) + .then(onResolve, onReject); }; } if (NativePromise) { @@ -575,7 +626,8 @@ var Zone$1 = (function (global) { } // ignore output to prevent error; fetchPromise.then(function () { return null; }, function () { return null; }); - if (fetchPromise.constructor != NativePromise) { + if (fetchPromise.constructor != NativePromise && + fetchPromise.constructor != ZoneAwarePromise) { patchThen(fetchPromise.constructor); } } @@ -586,9 +638,11 @@ var Zone$1 = (function (global) { })(typeof window === 'object' && window || typeof self === 'object' && self || global); /** - * Suppress closure compiler errors about unknown 'process' variable - * @fileoverview - * @suppress {undefinedVars} + * @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 */ var zoneSymbol = Zone['__symbol__']; var _global$1 = typeof window === 'object' && window || typeof self === 'object' && self || global; @@ -607,10 +661,7 @@ function bindArguments(args, source) { var isNode = (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'); function patchProperty(obj, prop) { - var desc = Object.getOwnPropertyDescriptor(obj, prop) || { - enumerable: true, - configurable: true - }; + var desc = Object.getOwnPropertyDescriptor(obj, prop) || { enumerable: true, configurable: true }; // A property descriptor cannot have getter/setter and be writable // deleting the writable and value properties avoids this error: // @@ -639,7 +690,8 @@ function patchProperty(obj, prop) { this[_prop] = null; } }; - // The getter would return undefined for unassigned properties but the default value of an unassigned property is 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; }; @@ -658,9 +710,7 @@ function findExistingRegisteredTask(target, handler, name, capture, remove) { for (var i = 0; i < eventTasks.length; i++) { var eventTask = eventTasks[i]; var data = eventTask.data; - if (data.handler === handler - && data.useCapturing === capture - && data.eventName === name) { + if (data.handler === handler && data.useCapturing === capture && data.eventName === name) { if (remove) { eventTasks.splice(i, 1); } @@ -713,13 +763,14 @@ function makeZoneAwareAddListener(addFnName, removeFnName, useCapturingParam, al // In cross site contexts (such as WebDriver frameworks like Selenium), // accessing the handler object here will cause an exception to be thrown which // will fail tests prematurely. - validZoneHandler = handler && handler.toString() === "[object FunctionWrapper]"; + validZoneHandler = handler && handler.toString() === '[object FunctionWrapper]'; } catch (e) { // Returning nothing here is fine, because objects in a cross-site context are unusable return; } - // Ignore special listeners of IE11 & Edge dev tools, see https://github.com/angular/zone.js/issues/150 + // Ignore special listeners of IE11 & Edge dev tools, see + // https://github.com/angular/zone.js/issues/150 if (!delegate || validZoneHandler) { return target[addFnSymbol](eventName, handler, useCapturing); } @@ -768,6 +819,9 @@ function makeZoneAwareListeners(fnName) { return function zoneAwareEventListeners(self, args) { var eventName = args[0]; var target = self || _global$1; + if (!target[EVENT_TASKS]) { + return []; + } return target[EVENT_TASKS] .filter(function (task) { return task.data.eventName === eventName; }) .map(function (task) { return task.data.handler; }); @@ -793,7 +847,7 @@ function createNamedFn(name, delegate) { } function patchMethod(target, name, patchFn) { var proto = target; - while (proto && !proto.hasOwnProperty(name)) { + while (proto && Object.getOwnPropertyNames(proto).indexOf(name) === -1) { proto = Object.getPrototypeOf(proto); } if (!proto && target[name]) { @@ -809,61 +863,13 @@ function patchMethod(target, name, patchFn) { return delegate; } -function patchTimer(window, setName, cancelName, nameSuffix) { - var setNative = null; - var clearNative = null; - setName += nameSuffix; - cancelName += nameSuffix; - function scheduleTask(task) { - var data = task.data; - data.args[0] = task.invoke; - data.handleId = setNative.apply(window, data.args); - return task; - } - function clearTask(task) { - return clearNative(task.data.handleId); - } - setNative = patchMethod(window, setName, function (delegate) { return function (self, args) { - if (typeof args[0] === 'function') { - var zone = Zone.current; - var options = { - handleId: null, - isPeriodic: nameSuffix === 'Interval', - delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null, - args: args - }; - var task = zone.scheduleMacroTask(setName, args[0], options, scheduleTask, clearTask); - if (!task) { - return task; - } - // Node.js must additionally support the ref and unref functions. - var handle = task.data.handleId; - if (handle.ref && handle.unref) { - task.ref = handle.ref.bind(handle); - task.unref = handle.unref.bind(handle); - } - return task; - } - else { - // cause an error by calling it directly. - return delegate.apply(window, args); - } - }; }); - clearNative = patchMethod(window, cancelName, function (delegate) { return function (self, args) { - var task = args[0]; - if (task && typeof task.type === 'string') { - if (task.cancelFn && task.data.isPeriodic || task.runCount === 0) { - // Do not cancel already canceled functions - task.zone.cancelTask(task); - } - } - else { - // cause an error by calling it directly. - delegate.apply(window, args); - } - }; }); -} - +/** + * @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 + */ // For EventEmitter var EE_ADD_LISTENER = 'addListener'; var EE_PREPEND_LISTENER = 'prependListener'; @@ -892,57 +898,35 @@ var events; try { events = require('events'); } -catch (err) { } +catch (err) { +} if (events && events.EventEmitter) { patchEventEmitterMethods(events.EventEmitter.prototype); } +/** + * @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 + */ var fs; try { fs = require('fs'); } -catch (err) { } +catch (err) { +} // TODO(alxhub): Patch `watch` and `unwatchFile`. var TO_PATCH = [ - 'access', - 'appendFile', - 'chmod', - 'chown', - 'close', - 'exists', - 'fchmod', - 'fchown', - 'fdatasync', - 'fstat', - 'fsync', - 'ftruncate', - 'futimes', - 'lchmod', - 'lchown', - 'link', - 'lstat', - 'mkdir', - 'mkdtemp', - 'open', - 'read', - 'readdir', - 'readFile', - 'readlink', - 'realpath', - 'rename', - 'rmdir', - 'stat', - 'symlink', - 'truncate', - 'unlink', - 'utimes', - 'write', - 'writeFile', + 'access', 'appendFile', 'chmod', 'chown', 'close', 'exists', 'fchmod', + 'fchown', 'fdatasync', 'fstat', 'fsync', 'ftruncate', 'futimes', 'lchmod', + 'lchown', 'link', 'lstat', 'mkdir', 'mkdtemp', 'open', 'read', + 'readdir', 'readFile', 'readlink', 'realpath', 'rename', 'rmdir', 'stat', + 'symlink', 'truncate', 'unlink', 'utimes', 'write', 'writeFile', ]; if (fs) { - TO_PATCH - .filter(function (name) { return !!fs[name] && typeof fs[name] === 'function'; }) - .forEach(function (name) { + TO_PATCH.filter(function (name) { return !!fs[name] && typeof fs[name] === 'function'; }).forEach(function (name) { fs[name] = (function (delegate) { return function () { return delegate.apply(this, bindArguments(arguments, 'fs.' + name)); @@ -951,6 +935,83 @@ if (fs) { }); } +/** + * @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 patchTimer(window, setName, cancelName, nameSuffix) { + var setNative = null; + var clearNative = null; + setName += nameSuffix; + cancelName += nameSuffix; + var tasksByHandleId = {}; + function scheduleTask(task) { + var data = task.data; + data.args[0] = function () { + task.invoke.apply(this, arguments); + delete tasksByHandleId[data.handleId]; + }; + data.handleId = setNative.apply(window, data.args); + tasksByHandleId[data.handleId] = task; + return task; + } + function clearTask(task) { + delete tasksByHandleId[task.data.handleId]; + return clearNative(task.data.handleId); + } + setNative = + patchMethod(window, setName, function (delegate) { return function (self, args) { + if (typeof args[0] === 'function') { + var zone = Zone.current; + var options = { + handleId: null, + isPeriodic: nameSuffix === 'Interval', + delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null, + args: args + }; + var task = zone.scheduleMacroTask(setName, args[0], options, scheduleTask, clearTask); + if (!task) { + return task; + } + // Node.js must additionally support the ref and unref functions. + var handle = task.data.handleId; + if (handle.ref && handle.unref) { + task.ref = handle.ref.bind(handle); + task.unref = handle.unref.bind(handle); + } + return task; + } + else { + // cause an error by calling it directly. + return delegate.apply(window, args); + } + }; }); + clearNative = + patchMethod(window, cancelName, function (delegate) { return function (self, args) { + var task = typeof args[0] === 'number' ? tasksByHandleId[args[0]] : args[0]; + if (task && typeof task.type === 'string') { + if (task.cancelFn && task.data.isPeriodic || task.runCount === 0) { + // Do not cancel already canceled functions + task.zone.cancelTask(task); + } + } + else { + // cause an error by calling it directly. + delegate.apply(window, args); + } + }; }); +} + +/** + * @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 + */ var set = 'set'; var clear = 'clear'; var _global = typeof window === 'object' && window || typeof self === 'object' && self || global; @@ -970,7 +1031,8 @@ var crypto; try { crypto = require('crypto'); } -catch (err) { } +catch (err) { +} // TODO(gdi2290): implement a better way to patch these methods if (crypto) { var nativeRandomBytes_1 = crypto.randomBytes; @@ -1007,7 +1069,8 @@ var httpClient; try { httpClient = require('_http_client'); } -catch (err) { } +catch (err) { +} if (httpClient && httpClient.ClientRequest) { var ClientRequest_1 = httpClient.ClientRequest.bind(httpClient); httpClient.ClientRequest = function (options, callback) { diff --git a/dist/zone.js b/dist/zone.js index a6e5c2f9b..e171aca25 100644 --- a/dist/zone.js +++ b/dist/zone.js @@ -11,6 +11,15 @@ (factory()); }(this, (function () { 'use strict'; +/** + * @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 + */ + + var Zone$1 = (function (global) { if (global.Zone) { throw new Error('Zone already loaded.'); @@ -21,37 +30,46 @@ var Zone$1 = (function (global) { this._parent = parent; this._name = zoneSpec ? zoneSpec.name || 'unnamed' : ''; this._properties = zoneSpec && zoneSpec.properties || {}; - this._zoneDelegate = new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec); + this._zoneDelegate = + new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec); } Zone.assertZonePatched = function () { if (global.Promise !== ZoneAwarePromise) { - throw new Error("Zone.js has detected that ZoneAwarePromise `(window|global).Promise` " + - "has been overwritten.\n" + - "Most 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.)"); + throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' + + 'has been overwritten.\n' + + 'Most 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(Zone, "current", { - get: function () { return _currentZone; }, + get: function () { + return _currentZone; + }, enumerable: true, configurable: true }); Object.defineProperty(Zone, "currentTask", { - get: function () { return _currentTask; }, + get: function () { + return _currentTask; + }, enumerable: true, configurable: true }); Object.defineProperty(Zone.prototype, "parent", { - get: function () { return this._parent; }, + get: function () { + return this._parent; + }, enumerable: true, configurable: true }); Object.defineProperty(Zone.prototype, "name", { - get: function () { return this._name; }, + get: function () { + return this._name; + }, enumerable: true, configurable: true }); @@ -122,8 +140,8 @@ var Zone$1 = (function (global) { Zone.prototype.runTask = function (task, applyThis, applyArgs) { task.runCount++; if (task.zone != this) - throw new Error('A task can only be run in the zone which created it! (Creation: ' + - task.zone.name + '; Execution: ' + this.name + ')'); + throw new Error('A task can only be run in the zone which created it! (Creation: ' + task.zone.name + + '; Execution: ' + this.name + ')'); var previousTask = _currentTask; _currentTask = task; var oldZone = _currentZone; @@ -172,40 +190,51 @@ var Zone$1 = (function (global) { this._parentDelegate = parentDelegate; this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS); this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt); - this._interceptZS = zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS); - this._interceptDlgt = zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt); + this._interceptZS = + zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS); + this._interceptDlgt = + zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt); this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS); - this._invokeDlgt = zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt); - this._handleErrorZS = zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS); - this._handleErrorDlgt = zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt); - this._scheduleTaskZS = zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS); - this._scheduleTaskDlgt = zoneSpec && (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt); - this._invokeTaskZS = zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS); - this._invokeTaskDlgt = zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt); - this._cancelTaskZS = zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS); - this._cancelTaskDlgt = zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt); + this._invokeDlgt = + zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt); + this._handleErrorZS = + zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS); + this._handleErrorDlgt = + zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt); + this._scheduleTaskZS = + zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS); + this._scheduleTaskDlgt = + zoneSpec && (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt); + this._invokeTaskZS = + zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS); + this._invokeTaskDlgt = + zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt); + this._cancelTaskZS = + zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS); + this._cancelTaskDlgt = + zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt); this._hasTaskZS = zoneSpec && (zoneSpec.onHasTask ? zoneSpec : parentDelegate._hasTaskZS); - this._hasTaskDlgt = zoneSpec && (zoneSpec.onHasTask ? parentDelegate : parentDelegate._hasTaskDlgt); + this._hasTaskDlgt = + zoneSpec && (zoneSpec.onHasTask ? parentDelegate : parentDelegate._hasTaskDlgt); } ZoneDelegate.prototype.fork = function (targetZone, zoneSpec) { - return this._forkZS - ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) - : new Zone(targetZone, zoneSpec); + return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) : + new Zone(targetZone, zoneSpec); }; ZoneDelegate.prototype.intercept = function (targetZone, callback, source) { - return this._interceptZS - ? this._interceptZS.onIntercept(this._interceptDlgt, this.zone, targetZone, callback, source) - : callback; + return this._interceptZS ? + this._interceptZS.onIntercept(this._interceptDlgt, this.zone, targetZone, callback, source) : + callback; }; ZoneDelegate.prototype.invoke = function (targetZone, callback, applyThis, applyArgs, source) { - return this._invokeZS - ? this._invokeZS.onInvoke(this._invokeDlgt, this.zone, targetZone, callback, applyThis, applyArgs, source) - : callback.apply(applyThis, applyArgs); + return this._invokeZS ? + this._invokeZS.onInvoke(this._invokeDlgt, this.zone, targetZone, callback, applyThis, applyArgs, source) : + callback.apply(applyThis, applyArgs); }; ZoneDelegate.prototype.handleError = function (targetZone, error) { - return this._handleErrorZS - ? this._handleErrorZS.onHandleError(this._handleErrorDlgt, this.zone, targetZone, error) - : true; + return this._handleErrorZS ? + this._handleErrorZS.onHandleError(this._handleErrorDlgt, this.zone, targetZone, error) : + true; }; ZoneDelegate.prototype.scheduleTask = function (targetZone, task) { try { @@ -231,12 +260,13 @@ var Zone$1 = (function (global) { }; ZoneDelegate.prototype.invokeTask = function (targetZone, task, applyThis, applyArgs) { try { - return this._invokeTaskZS - ? this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this.zone, targetZone, task, applyThis, applyArgs) - : task.callback.apply(applyThis, applyArgs); + return this._invokeTaskZS ? + this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this.zone, targetZone, task, applyThis, applyArgs) : + task.callback.apply(applyThis, applyArgs); } finally { - if (targetZone == this.zone && (task.type != 'eventTask') && !(task.data && task.data.isPeriodic)) { + if (targetZone == this.zone && (task.type != 'eventTask') && + !(task.data && task.data.isPeriodic)) { this._updateTaskCount(task.type, -1); } } @@ -259,7 +289,8 @@ var Zone$1 = (function (global) { return value; }; ZoneDelegate.prototype.hasTask = function (targetZone, isEmpty) { - return this._hasTaskZS && this._hasTaskZS.onHasTask(this._hasTaskDlgt, this.zone, targetZone, isEmpty); + return this._hasTaskZS && + this._hasTaskZS.onHasTask(this._hasTaskDlgt, this.zone, targetZone, isEmpty); }; ZoneDelegate.prototype._updateTaskCount = function (type, count) { var counts = this._taskCounts; @@ -316,12 +347,14 @@ var Zone$1 = (function (global) { return this.data.handleId; } else { - return this.toString(); + return Object.prototype.toString.call(this); } }; return ZoneTask; }()); - function __symbol__(name) { return '__zone_symbol__' + name; } + function __symbol__(name) { + return '__zone_symbol__' + name; + } var symbolSetTimeout = __symbol__('setTimeout'); var symbolPromise = __symbol__('Promise'); @@ -376,7 +409,9 @@ var Zone$1 = (function (global) { var _loop_1 = function() { var uncaughtPromiseError = _uncaughtPromiseErrors.shift(); try { - uncaughtPromiseError.zone.runGuarded(function () { throw uncaughtPromiseError; }); + uncaughtPromiseError.zone.runGuarded(function () { + throw uncaughtPromiseError; + }); } catch (e) { consoleError(e); @@ -392,8 +427,12 @@ var Zone$1 = (function (global) { function isThenable(value) { return value && value.then; } - function forwardResolution(value) { return value; } - function forwardRejection(rejection) { return ZoneAwarePromise.reject(rejection); } + function forwardResolution(value) { + return value; + } + function forwardRejection(rejection) { + return ZoneAwarePromise.reject(rejection); + } var symbolState = __symbol__('state'); var symbolValue = __symbol__('value'); var source = 'Promise.then'; @@ -426,7 +465,8 @@ var Zone$1 = (function (global) { 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) { var error_1 = e; @@ -490,9 +530,16 @@ var Zone$1 = (function (global) { ZoneAwarePromise.race = function (values) { var resolve; var reject; - var promise = new this(function (res, rej) { resolve = res; reject = rej; }); - function onResolve(value) { promise && (promise = null || resolve(value)); } - function onReject(error) { promise && (promise = null || reject(error)); } + var promise = new this(function (res, rej) { + _a = [res, rej], resolve = _a[0], reject = _a[1]; + var _a; + }); + function onResolve(value) { + promise && (promise = null || resolve(value)); + } + function onReject(error) { + promise && (promise = null || reject(error)); + } for (var _i = 0, values_1 = values; _i < values_1.length; _i++) { var value = values_1[_i]; if (!isThenable(value)) { @@ -505,7 +552,10 @@ var Zone$1 = (function (global) { ZoneAwarePromise.all = function (values) { var resolve; var reject; - var promise = new this(function (res, rej) { resolve = res; reject = rej; }); + var promise = new this(function (res, rej) { + resolve = res; + reject = rej; + }); var count = 0; var resolvedValues = []; for (var _i = 0, values_2 = values; _i < values_2.length; _i++) { @@ -552,13 +602,14 @@ var Zone$1 = (function (global) { global.Promise = ZoneAwarePromise; function patchThen(NativePromise) { var NativePromiseProtototype = NativePromise.prototype; - var NativePromiseThen = NativePromiseProtototype[__symbol__('then')] - = NativePromiseProtototype.then; + var NativePromiseThen = NativePromiseProtototype[__symbol__('then')] = + NativePromiseProtototype.then; NativePromiseProtototype.then = function (onResolve, onReject) { var nativePromise = this; return new ZoneAwarePromise(function (resolve, reject) { NativePromiseThen.call(nativePromise, resolve, reject); - }).then(onResolve, onReject); + }) + .then(onResolve, onReject); }; } if (NativePromise) { @@ -575,7 +626,8 @@ var Zone$1 = (function (global) { } // ignore output to prevent error; fetchPromise.then(function () { return null; }, function () { return null; }); - if (fetchPromise.constructor != NativePromise) { + if (fetchPromise.constructor != NativePromise && + fetchPromise.constructor != ZoneAwarePromise) { patchThen(fetchPromise.constructor); } } @@ -586,9 +638,11 @@ var Zone$1 = (function (global) { })(typeof window === 'object' && window || typeof self === 'object' && self || global); /** - * Suppress closure compiler errors about unknown 'process' variable - * @fileoverview - * @suppress {undefinedVars} + * @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 */ var zoneSymbol = Zone['__symbol__']; var _global$1 = typeof window === 'object' && window || typeof self === 'object' && self || global; @@ -623,10 +677,7 @@ var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof W var isNode = (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'); var isBrowser = !isNode && !isWebWorker && !!(typeof window !== 'undefined' && window['HTMLElement']); function patchProperty(obj, prop) { - var desc = Object.getOwnPropertyDescriptor(obj, prop) || { - enumerable: true, - configurable: true - }; + var desc = Object.getOwnPropertyDescriptor(obj, prop) || { enumerable: true, configurable: true }; // A property descriptor cannot have getter/setter and be writable // deleting the writable and value properties avoids this error: // @@ -655,7 +706,8 @@ function patchProperty(obj, prop) { this[_prop] = null; } }; - // The getter would return undefined for unassigned properties but the default value of an unassigned property is 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; }; @@ -689,9 +741,7 @@ function findExistingRegisteredTask(target, handler, name, capture, remove) { for (var i = 0; i < eventTasks.length; i++) { var eventTask = eventTasks[i]; var data = eventTask.data; - if (data.handler === handler - && data.useCapturing === capture - && data.eventName === name) { + if (data.handler === handler && data.useCapturing === capture && data.eventName === name) { if (remove) { eventTasks.splice(i, 1); } @@ -744,13 +794,14 @@ function makeZoneAwareAddListener(addFnName, removeFnName, useCapturingParam, al // In cross site contexts (such as WebDriver frameworks like Selenium), // accessing the handler object here will cause an exception to be thrown which // will fail tests prematurely. - validZoneHandler = handler && handler.toString() === "[object FunctionWrapper]"; + validZoneHandler = handler && handler.toString() === '[object FunctionWrapper]'; } catch (e) { // Returning nothing here is fine, because objects in a cross-site context are unusable return; } - // Ignore special listeners of IE11 & Edge dev tools, see https://github.com/angular/zone.js/issues/150 + // Ignore special listeners of IE11 & Edge dev tools, see + // https://github.com/angular/zone.js/issues/150 if (!delegate || validZoneHandler) { return target[addFnSymbol](eventName, handler, useCapturing); } @@ -831,7 +882,8 @@ function patchClass(className) { case 4: this[originalInstanceKey] = new OriginalClass(a[0], a[1], a[2], a[3]); break; - default: throw new Error('Arg list too long.'); + default: + throw new Error('Arg list too long.'); } }; var instance = new OriginalClass(function () { }); @@ -883,7 +935,7 @@ function createNamedFn(name, delegate) { } function patchMethod(target, name, patchFn) { var proto = target; - while (proto && !proto.hasOwnProperty(name)) { + while (proto && Object.getOwnPropertyNames(proto).indexOf(name) === -1) { proto = Object.getPrototypeOf(proto); } if (!proto && target[name]) { @@ -899,36 +951,90 @@ function patchMethod(target, name, patchFn) { return delegate; } -var WTF_ISSUE_555 = 'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video'; -var NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Window,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex'.split(','); -var EVENT_TARGET = 'EventTarget'; -function eventTargetPatch(_global) { - var apis = []; - var isWtf = _global['wtf']; - if (isWtf) { - // Workaround for: https://github.com/google/tracing-framework/issues/555 - apis = WTF_ISSUE_555.split(',').map(function (v) { return 'HTML' + v + 'Element'; }).concat(NO_EVENT_TARGET); - } - else if (_global[EVENT_TARGET]) { - apis.push(EVENT_TARGET); - } - else { - // Note: EventTarget is not available in all browsers, - // if it's not available, we instead patch the APIs in the IDL that inherit from EventTarget - apis = NO_EVENT_TARGET; +/** + * @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 patchTimer(window, setName, cancelName, nameSuffix) { + var setNative = null; + var clearNative = null; + setName += nameSuffix; + cancelName += nameSuffix; + var tasksByHandleId = {}; + function scheduleTask(task) { + var data = task.data; + data.args[0] = function () { + task.invoke.apply(this, arguments); + delete tasksByHandleId[data.handleId]; + }; + data.handleId = setNative.apply(window, data.args); + tasksByHandleId[data.handleId] = task; + return task; } - for (var i = 0; i < apis.length; i++) { - var type = _global[apis[i]]; - patchEventTargetMethods(type && type.prototype); + function clearTask(task) { + delete tasksByHandleId[task.data.handleId]; + return clearNative(task.data.handleId); } + setNative = + patchMethod(window, setName, function (delegate) { return function (self, args) { + if (typeof args[0] === 'function') { + var zone = Zone.current; + var options = { + handleId: null, + isPeriodic: nameSuffix === 'Interval', + delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null, + args: args + }; + var task = zone.scheduleMacroTask(setName, args[0], options, scheduleTask, clearTask); + if (!task) { + return task; + } + // Node.js must additionally support the ref and unref functions. + var handle = task.data.handleId; + if (handle.ref && handle.unref) { + task.ref = handle.ref.bind(handle); + task.unref = handle.unref.bind(handle); + } + return task; + } + else { + // cause an error by calling it directly. + return delegate.apply(window, args); + } + }; }); + clearNative = + patchMethod(window, cancelName, function (delegate) { return function (self, args) { + var task = typeof args[0] === 'number' ? tasksByHandleId[args[0]] : args[0]; + if (task && typeof task.type === 'string') { + if (task.cancelFn && task.data.isPeriodic || task.runCount === 0) { + // Do not cancel already canceled functions + task.zone.cancelTask(task); + } + } + else { + // cause an error by calling it directly. + delegate.apply(window, args); + } + }; }); } +/** + * @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 + */ /* * This is necessary for Chrome and Chrome mobile, to enable * things like redefining `createdCallback` on an element. */ var _defineProperty = Object[zoneSymbol('defineProperty')] = Object.defineProperty; -var _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] = Object.getOwnPropertyDescriptor; +var _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] = + Object.getOwnPropertyDescriptor; var _create = Object.create; var unconfigurablesKey = zoneSymbol('unconfigurables'); function propertyPatch() { @@ -990,7 +1096,8 @@ function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) { } catch (e) { if (desc.configurable) { - // In case of errors, when the configurable flag was likely set by rewriteDescriptor(), let's retry with the original flag value + // In case of errors, when the configurable flag was likely set by rewriteDescriptor(), let's + // retry with the original flag value if (typeof originalConfigurableFlag == 'undefined') { delete desc.configurable; } @@ -1017,40 +1124,45 @@ function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) { } } -function registerElementPatch(_global) { - if (!isBrowser || !('registerElement' in _global.document)) { - return; +/** + * @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 + */ +var WTF_ISSUE_555 = 'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video'; +var NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Window,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex' + .split(','); +var EVENT_TARGET = 'EventTarget'; +function eventTargetPatch(_global) { + var apis = []; + var isWtf = _global['wtf']; + if (isWtf) { + // Workaround for: https://github.com/google/tracing-framework/issues/555 + apis = WTF_ISSUE_555.split(',').map(function (v) { return 'HTML' + v + 'Element'; }).concat(NO_EVENT_TARGET); + } + else if (_global[EVENT_TARGET]) { + apis.push(EVENT_TARGET); + } + else { + // Note: EventTarget is not available in all browsers, + // if it's not available, we instead patch the APIs in the IDL that inherit from EventTarget + apis = NO_EVENT_TARGET; + } + for (var i = 0; i < apis.length; i++) { + var type = _global[apis[i]]; + patchEventTargetMethods(type && type.prototype); } - var _registerElement = document.registerElement; - var callbacks = [ - 'createdCallback', - 'attachedCallback', - 'detachedCallback', - 'attributeChangedCallback' - ]; - document.registerElement = function (name, opts) { - if (opts && opts.prototype) { - callbacks.forEach(function (callback) { - var source = 'Document.registerElement::' + callback; - if (opts.prototype.hasOwnProperty(callback)) { - var descriptor = Object.getOwnPropertyDescriptor(opts.prototype, callback); - if (descriptor && descriptor.value) { - descriptor.value = Zone.current.wrap(descriptor.value, source); - _redefineProperty(opts.prototype, callback, descriptor); - } - else { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); - } - } - else if (opts.prototype[callback]) { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); - } - }); - } - return _registerElement.apply(document, [name, opts]); - }; } +/** + * @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 + */ // we have to patch the instance since the proto is non-configurable function apply(_global) { var WS = _global.WebSocket; @@ -1084,7 +1196,15 @@ function apply(_global) { } } -var eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror'.split(' '); +/** + * @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 + */ +var eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror' + .split(' '); function propertyDescriptorPatch(_global) { if (isNode) { return; @@ -1118,8 +1238,8 @@ function propertyDescriptorPatch(_global) { } } function canPatchViaPropertyDescriptor() { - if (isBrowser && !Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') - && typeof Element !== 'undefined') { + if (isBrowser && !Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') && + typeof Element !== 'undefined') { // WebKit https://bugs.webkit.org/show_bug.cgi?id=134364 // IDL interface attributes are not configurable var desc = Object.getOwnPropertyDescriptor(Element.prototype, 'onclick'); @@ -1145,7 +1265,7 @@ function patchViaCapturingAllTheEvents() { var _loop_1 = function(i) { var property = eventNames[i]; var onproperty = 'on' + property; - document.addEventListener(property, function (event) { + self.addEventListener(property, function (event) { var elt = event.target, bound, source; if (elt) { source = elt.constructor['name'] + '.' + onproperty; @@ -1169,61 +1289,49 @@ function patchViaCapturingAllTheEvents() { } -function patchTimer(window, setName, cancelName, nameSuffix) { - var setNative = null; - var clearNative = null; - setName += nameSuffix; - cancelName += nameSuffix; - function scheduleTask(task) { - var data = task.data; - data.args[0] = task.invoke; - data.handleId = setNative.apply(window, data.args); - return task; - } - function clearTask(task) { - return clearNative(task.data.handleId); +/** + * @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 registerElementPatch(_global) { + if (!isBrowser || !('registerElement' in _global.document)) { + return; } - setNative = patchMethod(window, setName, function (delegate) { return function (self, args) { - if (typeof args[0] === 'function') { - var zone = Zone.current; - var options = { - handleId: null, - isPeriodic: nameSuffix === 'Interval', - delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null, - args: args - }; - var task = zone.scheduleMacroTask(setName, args[0], options, scheduleTask, clearTask); - if (!task) { - return task; - } - // Node.js must additionally support the ref and unref functions. - var handle = task.data.handleId; - if (handle.ref && handle.unref) { - task.ref = handle.ref.bind(handle); - task.unref = handle.unref.bind(handle); - } - return task; - } - else { - // cause an error by calling it directly. - return delegate.apply(window, args); - } - }; }); - clearNative = patchMethod(window, cancelName, function (delegate) { return function (self, args) { - var task = args[0]; - if (task && typeof task.type === 'string') { - if (task.cancelFn && task.data.isPeriodic || task.runCount === 0) { - // Do not cancel already canceled functions - task.zone.cancelTask(task); - } - } - else { - // cause an error by calling it directly. - delegate.apply(window, args); + var _registerElement = document.registerElement; + var callbacks = ['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback']; + document.registerElement = function (name, opts) { + if (opts && opts.prototype) { + callbacks.forEach(function (callback) { + var source = 'Document.registerElement::' + callback; + if (opts.prototype.hasOwnProperty(callback)) { + var descriptor = Object.getOwnPropertyDescriptor(opts.prototype, callback); + if (descriptor && descriptor.value) { + descriptor.value = Zone.current.wrap(descriptor.value, source); + _redefineProperty(opts.prototype, callback, descriptor); + } + else { + opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + } + } + else if (opts.prototype[callback]) { + opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + } + }); } - }; }); + return _registerElement.apply(document, [name, opts]); + }; } +/** + * @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 + */ var set = 'set'; var clear = 'clear'; var blockingMethods = ['alert', 'prompt', 'confirm']; @@ -1274,8 +1382,7 @@ function patchXHR(window) { sendNative.apply(data.target, data.args); return task; } - function placeholderCallback() { - } + function placeholderCallback() { } function clearTask(task) { var data = task.data; // Note - ideally, we would call data.target.removeEventListener here, but it's too late @@ -1294,13 +1401,7 @@ function patchXHR(window) { return sendNative.apply(self, args); } else { - var options = { - target: self, - isPeriodic: false, - delay: null, - args: args, - aborted: false - }; + var options = { target: self, isPeriodic: false, delay: null, args: args, aborted: false }; return zone.scheduleMacroTask('XMLHttpRequest.send', placeholderCallback, options, scheduleTask, clearTask); } }; }); @@ -1313,15 +1414,13 @@ function patchXHR(window) { } task.zone.cancelTask(task); } - // Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no task to cancel. Do nothing. + // Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no task + // to cancel. Do nothing. }; }); } /// GEO_LOCATION if (_global['navigator'] && _global['navigator'].geolocation) { - patchPrototype(_global['navigator'].geolocation, [ - 'getCurrentPosition', - 'watchPosition' - ]); + patchPrototype(_global['navigator'].geolocation, ['getCurrentPosition', 'watchPosition']); } }))); diff --git a/dist/zone.min.js b/dist/zone.min.js index 03e39d0bd..86053fc15 100644 --- a/dist/zone.min.js +++ b/dist/zone.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";function e(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 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=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(!P){var t="undefined"!=typeof WebSocket;T()?(Z&&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(Z&&!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;self.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:Object.prototype.toString.call(this)},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"),O=t("value"),P="Promise.then",Z=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]=Z,n[O]=[];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){n=[e,t],r=n[0],o=n[1];var n}),s=0,u=e;s