From fd91152e615e3e8fbe69102f370fd32df8e3e174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=A1ko=20Hevery?= Date: Wed, 10 Jan 2018 10:44:48 -0800 Subject: [PATCH] chore: release v0.8.20 --- CHANGELOG.md | 16 + dist/fake-async-test.js | 12 +- dist/webapis-media-query.js | 2 +- dist/webapis-media-query.min.js | 2 +- dist/webapis-rtc-peer-connection.js | 4 +- dist/webapis-rtc-peer-connection.min.js | 2 +- dist/zone-bluebird.js | 2 +- dist/zone-bluebird.min.js | 2 +- dist/zone-error.js | 6 +- dist/zone-error.min.js | 2 +- dist/zone-mix.js | 504 +++++++++++------------- dist/zone-node.js | 355 ++++++++--------- dist/zone-patch-cordova.js | 4 +- dist/zone-patch-cordova.min.js | 2 +- dist/zone-patch-electron.js | 16 +- dist/zone-patch-electron.min.js | 2 +- dist/zone-patch-rxjs.js | 13 +- dist/zone-patch-rxjs.min.js | 2 +- dist/zone-patch-user-media.js | 35 ++ dist/zone-patch-user-media.min.js | 1 + dist/zone-testing-bundle.js | 452 ++++++++++----------- dist/zone-testing-node-bundle.js | 367 +++++++++-------- dist/zone-testing.js | 12 +- dist/zone.js | 440 ++++++++++----------- dist/zone.min.js | 4 +- dist/zone_externs.js | 24 +- package.json | 2 +- 27 files changed, 1122 insertions(+), 1163 deletions(-) create mode 100644 dist/zone-patch-user-media.js create mode 100644 dist/zone-patch-user-media.min.js diff --git a/CHANGELOG.md b/CHANGELOG.md index e90a07617..896989b7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ + +## [0.8.20](https://github.com/angular/zone.js/compare/v0.8.19...0.8.20) (2018-01-10) + + +### Bug Fixes + +* **core:** add comment for shorter var/function name ([67e8178](https://github.com/angular/zone.js/commit/67e8178)) +* **core:** add file check script in travis build ([615a6c1](https://github.com/angular/zone.js/commit/615a6c1)) +* **core:** add helper method in util.ts to shorter zone.wrap/scehduleMacroTask ([8293c37](https://github.com/angular/zone.js/commit/8293c37)) +* **core:** add rxjs test ([31832a7](https://github.com/angular/zone.js/commit/31832a7)) +* **core:** fix [#989](https://github.com/angular/zone.js/issues/989), remove unuse code, use shorter name to reduce bundle size ([73b0061](https://github.com/angular/zone.js/commit/73b0061)) +* **core:** fix shorter name closure conflict ([00a4e31](https://github.com/angular/zone.js/commit/00a4e31)) +* **core:** remove unreadable short names ([957351e](https://github.com/angular/zone.js/commit/957351e)) + + + ## [0.8.18](https://github.com/angular/zone.js/compare/v0.8.17...0.8.18) (2017-09-27) diff --git a/dist/fake-async-test.js b/dist/fake-async-test.js index bb4a2e6d3..fb5c807a8 100644 --- a/dist/fake-async-test.js +++ b/dist/fake-async-test.js @@ -161,7 +161,7 @@ this.pendingTimers = []; this.properties = { 'FakeAsyncTestZoneSpec': this }; this.name = 'fakeAsyncTestZone for ' + namePrefix; - // in case user can't access the construction of FakyAsyncTestSpec + // in case user can't access the construction of FakeAsyncTestSpec // user can also define macroTaskOptions by define a global variable. if (!this.macroTaskOptions) { this.macroTaskOptions = global[Zone.__symbol__('FakeAsyncTestMacroTask')]; @@ -303,16 +303,16 @@ // should pass additional arguments to callback if have any // currently we know process.nextTick will have such additional // arguments - var addtionalArgs = void 0; + var additionalArgs = void 0; if (args) { - var callbackIndex = task.data.callbackIndex; + var callbackIndex = task.data.cbIdx; if (typeof args.length === 'number' && args.length > callbackIndex + 1) { - addtionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); + additionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); } } this._microtasks.push({ func: task.invoke, - args: addtionalArgs, + args: additionalArgs, target: task.data && task.data.target }); break; @@ -350,7 +350,7 @@ task.data.isPeriodic = true; } else { - // not periodic, use setTimout to simulate + // not periodic, use setTimeout to simulate task.data['handleId'] = this._setTimeout(task.invoke, delay, callbackArgs); } break; diff --git a/dist/webapis-media-query.js b/dist/webapis-media-query.js index d8ff5db27..656e51f80 100644 --- a/dist/webapis-media-query.js +++ b/dist/webapis-media-query.js @@ -22,7 +22,7 @@ Zone.__load_patch('mediaQuery', function (global, Zone, api) { if (!global['MediaQueryList']) { return; } - api.patchEventTarget(global, [global['MediaQueryList'].prototype], { addEventListenerFnName: 'addListener', removeEventListenerFnName: 'removeListener' }); + api.patchEventTarget(global, [global['MediaQueryList'].prototype], { add: 'addListener', rm: 'removeListener' }); }); }))); diff --git a/dist/webapis-media-query.min.js b/dist/webapis-media-query.min.js index dc2e5589a..075a3d5bd 100644 --- a/dist/webapis-media-query.min.js +++ b/dist/webapis-media-query.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";Zone.__load_patch("mediaQuery",function(e,t,n){e.MediaQueryList&&n.patchEventTarget(e,[e.MediaQueryList.prototype],{addEventListenerFnName:"addListener",removeEventListenerFnName:"removeListener"})})}); \ 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";Zone.__load_patch("mediaQuery",function(e,t,i){e.MediaQueryList&&i.patchEventTarget(e,[e.MediaQueryList.prototype],{add:"addListener",rm:"removeListener"})})}); \ No newline at end of file diff --git a/dist/webapis-rtc-peer-connection.js b/dist/webapis-rtc-peer-connection.js index 4bbd7c936..728232d67 100644 --- a/dist/webapis-rtc-peer-connection.js +++ b/dist/webapis-rtc-peer-connection.js @@ -28,10 +28,10 @@ Zone.__load_patch('RTCPeerConnection', function (global, Zone, api) { RTCPeerConnection.prototype.addEventListener = RTCPeerConnection.prototype[addSymbol]; RTCPeerConnection.prototype.removeEventListener = RTCPeerConnection.prototype[removeSymbol]; // RTCPeerConnection extends EventTarget, so we must clear the symbol - // to allow pathc RTCPeerConnection.prototype.addEventListener again + // to allow patch RTCPeerConnection.prototype.addEventListener again RTCPeerConnection.prototype[addSymbol] = null; RTCPeerConnection.prototype[removeSymbol] = null; - api.patchEventTarget(global, [RTCPeerConnection.prototype], { useGlobalCallback: false }); + api.patchEventTarget(global, [RTCPeerConnection.prototype], { useG: false }); }); }))); diff --git a/dist/webapis-rtc-peer-connection.min.js b/dist/webapis-rtc-peer-connection.min.js index 9e471c6b9..a2f70d40c 100644 --- a/dist/webapis-rtc-peer-connection.min.js +++ b/dist/webapis-rtc-peer-connection.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";Zone.__load_patch("RTCPeerConnection",function(e,t,o){var n=e.RTCPeerConnection;if(n){var p=o.symbol("addEventListener"),r=o.symbol("removeEventListener");n.prototype.addEventListener=n.prototype[p],n.prototype.removeEventListener=n.prototype[r],n.prototype[p]=null,n.prototype[r]=null,o.patchEventTarget(e,[n.prototype],{useGlobalCallback:!1})}})}); \ 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";Zone.__load_patch("RTCPeerConnection",function(e,t,o){var n=e.RTCPeerConnection;if(n){var p=o.symbol("addEventListener"),r=o.symbol("removeEventListener");n.prototype.addEventListener=n.prototype[p],n.prototype.removeEventListener=n.prototype[r],n.prototype[p]=null,n.prototype[r]=null,o.patchEventTarget(e,[n.prototype],{useG:!1})}})}); \ No newline at end of file diff --git a/dist/zone-bluebird.js b/dist/zone-bluebird.js index a56b94189..4b5b0c797 100644 --- a/dist/zone-bluebird.js +++ b/dist/zone-bluebird.js @@ -18,7 +18,7 @@ * 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 */ -Zone.__load_patch('bluebird', function (global, Zone, api) { +Zone.__load_patch('bluebird', function (global, Zone) { // TODO: @JiaLiPassion, we can automatically patch bluebird // if global.Promise = Bluebird, but sometimes in nodejs, // global.Promise is not Bluebird, and Bluebird is just be diff --git a/dist/zone-bluebird.min.js b/dist/zone-bluebird.min.js index da9f59d31..ad38e5632 100644 --- a/dist/zone-bluebird.min.js +++ b/dist/zone-bluebird.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";Zone.__load_patch("bluebird",function(e,n,t){var o="bluebird";n[n.__symbol__(o)]=function(e){e.setScheduler(function(e){n.current.scheduleMicroTask(o,e)})}})}); \ 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";Zone.__load_patch("bluebird",function(e,n){var t="bluebird";n[n.__symbol__(t)]=function(e){e.setScheduler(function(e){n.current.scheduleMicroTask(t,e)})}})}); \ No newline at end of file diff --git a/dist/zone-error.js b/dist/zone-error.js index 3e029aca7..66f27ddab 100644 --- a/dist/zone-error.js +++ b/dist/zone-error.js @@ -171,7 +171,7 @@ Zone.__load_patch('Error', function (global, Zone, api) { } } } - return value.apply(this, [error, structuredStackTrace]); + return value.call(this, error, structuredStackTrace); }; } }); @@ -197,7 +197,7 @@ Zone.__load_patch('Error', function (global, Zone, api) { var frame = frames_2.shift(); // On safari it is possible to have stack frame with no line number. // This check makes sure that we don't filter frames on name only (must have - // linenumber) + // line number) if (/:\d+:\d+/.test(frame)) { // Get rid of the path so that we don't accidentally find function name in path. // In chrome the separator is `(` and `@` in FF and safari @@ -263,7 +263,7 @@ Zone.__load_patch('Error', function (global, Zone, api) { // all kinds of tasks with one error thrown. childDetectZone.run(function () { childDetectZone.runGuarded(function () { - var fakeTransitionTo = function (toState, fromState1, fromState2) { }; + var fakeTransitionTo = function () { }; childDetectZone.scheduleEventTask(blacklistedStackFramesSymbol, function () { childDetectZone.scheduleMacroTask(blacklistedStackFramesSymbol, function () { childDetectZone.scheduleMicroTask(blacklistedStackFramesSymbol, function () { diff --git a/dist/zone-error.min.js b/dist/zone-error.min.js index 54e6e53f0..4aff20179 100644 --- a/dist/zone-error.min.js +++ b/dist/zone-error.min.js @@ -1 +1 @@ -!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";Zone.__load_patch("Error",function(r,t,e){function n(){var r=this,t=o.apply(this,arguments),i=t.originalStack=t.stack;if(n[f]&&i){for(var s=i.split("\n"),k=e.currentZoneFrame(),p=0;s[p]!==a&&s[p]!==c&&p= 0; i--) { - if (typeof args[i] === FUNCTION) { - args[i] = Zone.current.wrap(args[i], source + '_' + i); + if (typeof args[i] === 'function') { + args[i] = wrapWithCurrentZone(args[i], source + '_' + i); } } return args; } -function wrapFunctionArgs(func, source) { - return function () { - var args = Array.prototype.slice.call(arguments); - var wrappedArgs = bindArguments(args, source ? source : func.name); - return func.apply(this, wrappedArgs); - }; -} -function patchArguments(target, name, source) { - return patchMethod(target, name, function (delegate, delegateName, name) { return function (self, args) { - return delegate && delegate.apply(self, bindArguments(args, source)); - }; }); -} function patchPrototype(prototype, fnNames) { var source = prototype.constructor['name']; var _loop_1 = function (i) { var name_1 = fnNames[i]; var delegate = prototype[name_1]; if (delegate) { - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, name_1); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, name_1); if (!isPropertyWritable(prototypeDesc)) { return "continue"; } @@ -1142,23 +1165,20 @@ function isPropertyWritable(propertyDesc) { if (propertyDesc.writable === false) { return false; } - if (typeof propertyDesc.get === FUNCTION && typeof propertyDesc.set === UNDEFINED) { - return false; - } - return true; + return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined'); } var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope); -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]'); -var isBrowser = !isNode && !isWebWorker && !!(typeof window !== 'undefined' && window['HTMLElement']); +var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']); // we are in electron of nw, so we are both browser and nodejs -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isMix = typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]' && !isWebWorker && - !!(typeof window !== 'undefined' && window['HTMLElement']); + !!(isWindowExists && internalWindow['HTMLElement']); var zoneSymbolEventNames = {}; var wrapFn = function (event) { // https://github.com/angular/zone.js/issues/911, in IE, sometimes @@ -1180,10 +1200,10 @@ var wrapFn = function (event) { return result; }; function patchProperty(obj, prop, prototype) { - var desc = Object.getOwnPropertyDescriptor(obj, prop); + var desc = ObjectGetOwnPropertyDescriptor(obj, prop); if (!desc && prototype) { // when patch window object, use prototype to check prop exist or not - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, prop); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop); if (prototypeDesc) { desc = { enumerable: true, configurable: true }; } @@ -1258,10 +1278,10 @@ function patchProperty(obj, prop, prototype) { // the onclick will be evaluated when first time event was triggered or // the property is accessed, https://github.com/angular/zone.js/issues/525 // so we should use original native get to retrieve the handler - var value = originalDescGet && originalDescGet.apply(this); + var value = originalDescGet && originalDescGet.call(this); if (value) { - desc.set.apply(this, [value]); - if (typeof target[REMOVE_ATTRIBUTE] === FUNCTION) { + desc.set.call(this, value); + if (typeof target[REMOVE_ATTRIBUTE] === 'function') { target.removeAttribute(prop); } return value; @@ -1269,7 +1289,7 @@ function patchProperty(obj, prop, prototype) { } return null; }; - Object.defineProperty(obj, prop, desc); + ObjectDefineProperty(obj, prop, desc); } function patchOnProperties(obj, properties, prototype) { if (properties) { @@ -1334,10 +1354,10 @@ function patchClass(className) { }; } else { - Object.defineProperty(_global[className].prototype, prop, { + ObjectDefineProperty(_global[className].prototype, prop, { set: function (fn) { if (typeof fn === 'function') { - this[originalInstanceKey][prop] = Zone.current.wrap(fn, className + '.' + prop); + this[originalInstanceKey][prop] = wrapWithCurrentZone(fn, className + '.' + prop); // keep callback in wrapped function so we can // use it in Function.prototype.toString to return // the native one. @@ -1363,7 +1383,7 @@ function patchClass(className) { function patchMethod(target, name, patchFn) { var proto = target; while (proto && !proto.hasOwnProperty(name)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && target[name]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1375,7 +1395,7 @@ function patchMethod(target, name, patchFn) { delegate = proto[delegateName] = proto[name]; // check whether proto[name] is writable // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob - var desc = proto && Object.getOwnPropertyDescriptor(proto, name); + var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name); if (isPropertyWritable(desc)) { var patchDelegate_1 = patchFn(delegate, delegateName, name); proto[name] = function () { @@ -1391,7 +1411,7 @@ function patchMacroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1399,9 +1419,8 @@ function patchMacroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMacroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask, null); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask, null); } else { // cause an error by calling it directly. @@ -1413,7 +1432,7 @@ function patchMicroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1421,9 +1440,8 @@ function patchMicroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMicroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask); } else { // cause an error by calling it directly. @@ -1442,8 +1460,7 @@ function isIEOrEdge() { } isDetectedIEOrEdge = true; try { - var ua = window.navigator.userAgent; - var msie = ua.indexOf('MSIE '); + var ua = internalWindow.navigator.userAgent; if (ua.indexOf('MSIE ') !== -1 || ua.indexOf('Trident/') !== -1 || ua.indexOf('Edge/') !== -1) { ieOrEdge = true; } @@ -1462,19 +1479,18 @@ function isIEOrEdge() { */ // override Function.prototype.toString to make zone.js patched function // look like native function -Zone.__load_patch('toString', function (global, Zone, api) { +Zone.__load_patch('toString', function (global, Zone) { // patch Func.prototype.toString to let them look like native var originalFunctionToString = Zone['__zone_symbol__originalToString'] = Function.prototype.toString; - var FUNCTION = 'function'; var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate'); var PROMISE_SYMBOL = zoneSymbol('Promise'); var ERROR_SYMBOL = zoneSymbol('Error'); Function.prototype.toString = function () { - if (typeof this === FUNCTION) { + if (typeof this === 'function') { var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL]; if (originalDelegate) { - if (typeof originalDelegate === FUNCTION) { + if (typeof originalDelegate === 'function') { return originalFunctionToString.apply(this[ORIGINAL_DELEGATE_SYMBOL], arguments); } else { @@ -1518,25 +1534,19 @@ Zone.__load_patch('toString', function (global, Zone, api) { * @fileoverview * @suppress {missingRequire} */ -var TRUE_STR = 'true'; -var FALSE_STR = 'false'; // an identifier to tell ZoneTask do not create a new invoke closure var OPTIMIZED_ZONE_EVENT_TASK_DATA = { - isUsingGlobalCallback: true + useG: true }; var zoneSymbolEventNames$1 = {}; var globalSources = {}; -var CONSTRUCTOR_NAME = 'name'; -var FUNCTION_TYPE = 'function'; -var OBJECT_TYPE = 'object'; -var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; var EVENT_NAME_SYMBOL_REGX = /^__zone_symbol__(\w+)(true|false)$/; var IMMEDIATE_PROPAGATION_SYMBOL = ('__zone_symbol__propagationStopped'); function patchEventTarget(_global, apis, patchOptions) { - var ADD_EVENT_LISTENER = (patchOptions && patchOptions.addEventListenerFnName) || 'addEventListener'; - var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.removeEventListenerFnName) || 'removeEventListener'; - var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listenersFnName) || 'eventListeners'; - var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.removeAllFnName) || 'removeAllListeners'; + var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR; + var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR; + var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners'; + var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners'; var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER); var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':'; var PREPEND_EVENT_LISTENER = 'prependListener'; @@ -1548,7 +1558,7 @@ function patchEventTarget(_global, apis, patchOptions) { return; } var delegate = task.callback; - if (typeof delegate === OBJECT_TYPE && delegate.handleEvent) { + if (typeof delegate === 'object' && delegate.handleEvent) { // create the bind version of handleEvent when invoke task.callback = function (event) { return delegate.handleEvent(event); }; task.originalDelegate = delegate; @@ -1561,7 +1571,7 @@ function patchEventTarget(_global, apis, patchOptions) { // only browser need to do this, nodejs eventEmitter will cal removeListener // inside EventEmitter.once var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback; - target[REMOVE_EVENT_LISTENER].apply(target, [event.type, delegate_1, options]); + target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options); } }; // global shared zoneAwareCallback to handle all event callback with capture = false @@ -1572,7 +1582,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]]; @@ -1604,7 +1614,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]]; @@ -1633,21 +1643,21 @@ function patchEventTarget(_global, apis, patchOptions) { return false; } var useGlobalCallback = true; - if (patchOptions && patchOptions.useGlobalCallback !== undefined) { - useGlobalCallback = patchOptions.useGlobalCallback; + if (patchOptions && patchOptions.useG !== undefined) { + useGlobalCallback = patchOptions.useG; } - var validateHandler = patchOptions && patchOptions.validateHandler; + var validateHandler = patchOptions && patchOptions.vh; var checkDuplicate = true; - if (patchOptions && patchOptions.checkDuplicate !== undefined) { - checkDuplicate = patchOptions.checkDuplicate; + if (patchOptions && patchOptions.chkDup !== undefined) { + checkDuplicate = patchOptions.chkDup; } var returnTarget = false; - if (patchOptions && patchOptions.returnTarget !== undefined) { - returnTarget = patchOptions.returnTarget; + if (patchOptions && patchOptions.rt !== undefined) { + returnTarget = patchOptions.rt; } var proto = obj; while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && obj[ADD_EVENT_LISTENER]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1670,21 +1680,17 @@ function patchEventTarget(_global, apis, patchOptions) { var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] = proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER]; var nativePrependEventListener; - if (patchOptions && patchOptions.prependEventListenerFnName) { - nativePrependEventListener = proto[zoneSymbol(patchOptions.prependEventListenerFnName)] = - proto[patchOptions.prependEventListenerFnName]; + if (patchOptions && patchOptions.prepend) { + nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] = + proto[patchOptions.prepend]; } - var customScheduleGlobal = function (task) { + var customScheduleGlobal = function () { // if there is already a task for the eventName + capture, // just return, because we use the shared globalZoneAwareCallback here. if (taskData.isExisting) { return; } - return nativeAddEventListener.apply(taskData.target, [ - taskData.eventName, - taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - taskData.options - ]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options); }; var customCancelGlobal = function (task) { // if task is not marked as isRemoved, this call is directly @@ -1721,41 +1727,31 @@ function patchEventTarget(_global, apis, patchOptions) { if (!task.allRemoved) { return; } - return nativeRemoveEventListener.apply(task.target, [ - task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - task.options - ]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options); }; var customScheduleNonGlobal = function (task) { - return nativeAddEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customSchedulePrepend = function (task) { - return nativePrependEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customCancelNonGlobal = function (task) { - return nativeRemoveEventListener.apply(task.target, [task.eventName, task.invoke, task.options]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options); }; var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal; var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal; var compareTaskCallbackVsDelegate = function (task, delegate) { var typeOfDelegate = typeof delegate; - if ((typeOfDelegate === FUNCTION_TYPE && task.callback === delegate) || - (typeOfDelegate === OBJECT_TYPE && task.originalDelegate === delegate)) { - // same callback, same capture, same event name, just return - return true; - } - return false; + return (typeOfDelegate === 'function' && task.callback === delegate) || + (typeOfDelegate === 'object' && task.originalDelegate === delegate); }; - var compare = (patchOptions && patchOptions.compareTaskCallbackVsDelegate) ? - patchOptions.compareTaskCallbackVsDelegate : - compareTaskCallbackVsDelegate; + var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate; var blackListedEvents = Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')]; var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) { if (returnTarget === void 0) { returnTarget = false; } if (prepend === void 0) { prepend = false; } return function () { var target = this || _global; - var targetZone = Zone.current; var delegate = arguments[1]; if (!delegate) { return nativeListener.apply(this, arguments); @@ -1764,7 +1760,7 @@ function patchEventTarget(_global, apis, patchOptions) { // case here to improve addEventListener performance // we will create the bind delegate when invoke var isHandleEvent = false; - if (typeof delegate !== FUNCTION_TYPE) { + if (typeof delegate !== 'function') { if (!delegate.handleEvent) { return nativeListener.apply(this, arguments); } @@ -1833,7 +1829,7 @@ function patchEventTarget(_global, apis, patchOptions) { existingTasks = target[symbolEventName] = []; } var source; - var constructorName = target.constructor[CONSTRUCTOR_NAME]; + var constructorName = target.constructor['name']; var targetSource = globalSources[constructorName]; if (targetSource) { source = targetSource[eventName]; @@ -1855,7 +1851,7 @@ function patchEventTarget(_global, apis, patchOptions) { taskData.eventName = eventName; taskData.isExisting = isExisting; var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null; - // keep taskData into data to allow onScheduleEventTask to acess the task information + // keep taskData into data to allow onScheduleEventTask to access the task information if (data) { data.taskData = taskData; } @@ -1929,7 +1925,6 @@ function patchEventTarget(_global, apis, patchOptions) { if (existingTasks) { for (var i = 0; i < existingTasks.length; i++) { var existingTask = existingTasks[i]; - var typeOfDelegate = typeof delegate; if (compare(existingTask, delegate)) { existingTasks.splice(i, 1); // set isRemoved to data for faster invokeTask check @@ -1977,11 +1972,11 @@ function patchEventTarget(_global, apis, patchOptions) { // so just keep removeListener eventListener until // all other eventListeners are removed if (evtName && evtName !== 'removeListener') { - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, [evtName]); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName); } } // remove removeListener listener finally - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, ['removeListener']); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener'); } else { var symbolEventNames = zoneSymbolEventNames$1[eventName]; @@ -1995,7 +1990,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } if (captureTasks) { @@ -2003,7 +1998,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } } @@ -2073,12 +2068,6 @@ function patchTimer(window, setName, cancelName, nameSuffix) { setName += nameSuffix; cancelName += nameSuffix; var tasksByHandleId = {}; - var NUMBER = 'number'; - var STRING = 'string'; - var FUNCTION = 'function'; - var INTERVAL = 'Interval'; - var TIMEOUT = 'Timeout'; - var NOT_SCHEDULED = 'notScheduled'; function scheduleTask(task) { var data = task.data; function timer() { @@ -2086,21 +2075,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task.invoke.apply(this, arguments); } finally { - if (task.data && task.data.isPeriodic) { - // issue-934, task will be cancelled - // even it is a periodic task such as - // setInterval - return; - } - if (typeof data.handleId === NUMBER) { - // in non-nodejs env, we remove timerId - // from local cache - delete tasksByHandleId[data.handleId]; - } - else if (data.handleId) { - // Node returns complex objects as handleIds - // we remove task reference from timer object - data.handleId[taskSymbol] = null; + // issue-934, task will be cancelled + // even it is a periodic task such as + // setInterval + if (!(task.data && task.data.isPeriodic)) { + if (typeof data.handleId === 'number') { + // in non-nodejs env, we remove timerId + // from local cache + delete tasksByHandleId[data.handleId]; + } + else if (data.handleId) { + // Node returns complex objects as handleIds + // we remove task reference from timer object + data.handleId[taskSymbol] = null; + } } } } @@ -2113,21 +2101,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } setNative = patchMethod(window, setName, function (delegate) { return function (self, args) { - if (typeof args[0] === FUNCTION) { - var zone = Zone.current; + if (typeof args[0] === 'function') { var options = { handleId: null, - isPeriodic: nameSuffix === INTERVAL, - delay: (nameSuffix === TIMEOUT || nameSuffix === INTERVAL) ? args[1] || 0 : 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); + var task = scheduleMacroTaskWithCurrentZone(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 (typeof handle === NUMBER) { + if (typeof handle === 'number') { // for non nodejs env, we save handleId: task // mapping in local cache for clearTimeout tasksByHandleId[handle] = task; @@ -2139,12 +2126,12 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } // check whether handle is null, because some polyfill or browser // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame - if (handle && handle.ref && handle.unref && typeof handle.ref === FUNCTION && - typeof handle.unref === FUNCTION) { + if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' && + typeof handle.unref === 'function') { task.ref = handle.ref.bind(handle); task.unref = handle.unref.bind(handle); } - if (typeof handle === NUMBER || handle) { + if (typeof handle === 'number' || handle) { return handle; } return task; @@ -2158,7 +2145,7 @@ function patchTimer(window, setName, cancelName, nameSuffix) { patchMethod(window, cancelName, function (delegate) { return function (self, args) { var id = args[0]; var task; - if (typeof id === NUMBER) { + if (typeof id === 'number') { // non nodejs env. task = tasksByHandleId[id]; } @@ -2170,10 +2157,10 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task = id; } } - if (task && typeof task.type === STRING) { - if (task.state !== NOT_SCHEDULED && + if (task && typeof task.type === 'string') { + if (task.state !== 'notScheduled' && (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) { - if (typeof id === NUMBER) { + if (typeof id === 'number') { delete tasksByHandleId[id]; } else if (id) { @@ -2206,16 +2193,13 @@ var _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] = Object.getOwnPropertyDescriptor; var _create = Object.create; var unconfigurablesKey = zoneSymbol('unconfigurables'); -var PROTOTYPE = 'prototype'; -var OBJECT = 'object'; -var UNDEFINED$1 = 'undefined'; function propertyPatch() { Object.defineProperty = function (obj, prop, desc) { if (isUnconfigurable(obj, prop)) { throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj); } var originalConfigurableFlag = desc.configurable; - if (prop !== PROTOTYPE) { + if (prop !== 'prototype') { desc = rewriteDescriptor(obj, prop, desc); } return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag); @@ -2227,7 +2211,7 @@ function propertyPatch() { return obj; }; Object.create = function (obj, proto) { - if (typeof proto === OBJECT && !Object.isFrozen(proto)) { + if (typeof proto === 'object' && !Object.isFrozen(proto)) { Object.keys(proto).forEach(function (prop) { proto[prop] = rewriteDescriptor(obj, prop, proto[prop]); }); @@ -2274,7 +2258,7 @@ function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) { if (desc.configurable) { // 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$1) { + if (typeof originalConfigurableFlag == 'undefined') { delete desc.configurable; } else { @@ -2315,22 +2299,22 @@ function apply(api, _global) { if (!_global.EventTarget) { patchEventTarget(_global, [WS.prototype]); } - _global.WebSocket = function (a, b) { - var socket = arguments.length > 1 ? new WS(a, b) : new WS(a); + _global.WebSocket = function (x, y) { + var socket = arguments.length > 1 ? new WS(x, y) : new WS(x); var proxySocket; var proxySocketProto; // Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance - var onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage'); + var onmessageDesc = ObjectGetOwnPropertyDescriptor(socket, 'onmessage'); if (onmessageDesc && onmessageDesc.configurable === false) { - proxySocket = Object.create(socket); + proxySocket = ObjectCreate(socket); // socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror' // but proxySocket not, so we will keep socket as prototype and pass it to // patchOnProperties method proxySocketProto = socket; - ['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function (propName) { + [ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR, 'send', 'close'].forEach(function (propName) { proxySocket[propName] = function () { - var args = Array.prototype.slice.call(arguments); - if (propName === 'addEventListener' || propName === 'removeEventListener') { + var args = ArraySlice.call(arguments); + if (propName === ADD_EVENT_LISTENER_STR || propName === REMOVE_EVENT_LISTENER_STR) { var eventName = args.length > 0 ? args[0] : undefined; if (eventName) { var propertySymbol = Zone.__symbol__('ON_PROPERTY' + eventName); @@ -2602,12 +2586,13 @@ function propertyDescriptorPatch(api, _global) { var ignoreProperties = _global.__Zone_ignore_on_properties; // for browsers that we can patch the descriptor: Chrome & Firefox if (isBrowser) { + var internalWindow = window; // in IE/Edge, onProp not exist in window object, but in WindowPrototype // so we need to pass WindowPrototype to check onProp exist or not - patchFilteredProperties(window, eventNames.concat(['messageerror']), ignoreProperties, Object.getPrototypeOf(window)); + patchFilteredProperties(internalWindow, eventNames.concat(['messageerror']), ignoreProperties, ObjectGetPrototypeOf(internalWindow)); patchFilteredProperties(Document.prototype, eventNames, ignoreProperties); - if (typeof window['SVGElement'] !== 'undefined') { - patchFilteredProperties(window['SVGElement'].prototype, eventNames, ignoreProperties); + if (typeof internalWindow['SVGElement'] !== 'undefined') { + patchFilteredProperties(internalWindow['SVGElement'].prototype, eventNames, ignoreProperties); } patchFilteredProperties(Element.prototype, eventNames, ignoreProperties); patchFilteredProperties(HTMLElement.prototype, eventNames, ignoreProperties); @@ -2616,11 +2601,11 @@ function propertyDescriptorPatch(api, _global) { patchFilteredProperties(HTMLBodyElement.prototype, windowEventNames.concat(frameSetEventNames), ignoreProperties); patchFilteredProperties(HTMLFrameElement.prototype, frameEventNames, ignoreProperties); patchFilteredProperties(HTMLIFrameElement.prototype, frameEventNames, ignoreProperties); - var HTMLMarqueeElement_1 = window['HTMLMarqueeElement']; + var HTMLMarqueeElement_1 = internalWindow['HTMLMarqueeElement']; if (HTMLMarqueeElement_1) { patchFilteredProperties(HTMLMarqueeElement_1.prototype, marqueeEventNames, ignoreProperties); } - var Worker_1 = window['Worker']; + var Worker_1 = internalWindow['Worker']; if (Worker_1) { patchFilteredProperties(Worker_1.prototype, workerEventNames, ignoreProperties); } @@ -2652,15 +2637,17 @@ function propertyDescriptorPatch(api, _global) { } } function canPatchViaPropertyDescriptor() { - if ((isBrowser || isMix) && !Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') && + if ((isBrowser || isMix) && !ObjectGetOwnPropertyDescriptor(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'); + var desc = ObjectGetOwnPropertyDescriptor(Element.prototype, 'onclick'); if (desc && !desc.configurable) return false; } - var xhrDesc = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'onreadystatechange'); + var ON_READY_STATE_CHANGE = 'onreadystatechange'; + var XMLHttpRequestPrototype = XMLHttpRequest.prototype; + var xhrDesc = ObjectGetOwnPropertyDescriptor(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE); // add enumerable and configurable here because in opera // by default XMLHttpRequest.prototype.onreadystatechange is undefined // without adding enumerable and configurable will cause onreadystatechange @@ -2668,7 +2655,7 @@ function canPatchViaPropertyDescriptor() { // and if XMLHttpRequest.prototype.onreadystatechange is undefined, // we should set a real desc instead a fake one if (xhrDesc) { - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', { + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, { enumerable: true, configurable: true, get: function () { @@ -2678,12 +2665,12 @@ function canPatchViaPropertyDescriptor() { var req = new XMLHttpRequest(); var result = !!req.onreadystatechange; // restore original desc - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {}); + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {}); return result; } else { - var SYMBOL_FAKE_ONREADYSTATECHANGE_1 = zoneSymbol('fakeonreadystatechange'); - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', { + var SYMBOL_FAKE_ONREADYSTATECHANGE_1 = zoneSymbol('fake'); + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, { enumerable: true, configurable: true, get: function () { @@ -2719,7 +2706,7 @@ function patchViaCapturingAllTheEvents() { } while (elt) { if (elt[onproperty] && !elt[onproperty][unboundKey]) { - bound = Zone.current.wrap(elt[onproperty], source); + bound = wrapWithCurrentZone(elt[onproperty], source); bound[unboundKey] = elt[onproperty]; elt[onproperty] = bound; } @@ -2824,7 +2811,9 @@ function eventTargetPatch(_global, api) { var type = _global[apis[i]]; apiTypes.push(type && type.prototype); } - patchEventTarget(_global, apiTypes, { validateHandler: checkIEAndCrossContext }); + // vh is validateHandler to check event handler + // is valid or not(for security check) + patchEventTarget(_global, apiTypes, { vh: checkIEAndCrossContext }); api.patchEventTarget = patchEventTarget; return true; } @@ -2849,22 +2838,23 @@ function registerElementPatch(_global) { 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); + var prototype = opts.prototype; + if (prototype.hasOwnProperty(callback)) { + var descriptor = ObjectGetOwnPropertyDescriptor(prototype, callback); if (descriptor && descriptor.value) { - descriptor.value = Zone.current.wrap(descriptor.value, source); + descriptor.value = wrapWithCurrentZone(descriptor.value, source); _redefineProperty(opts.prototype, callback, descriptor); } else { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + prototype[callback] = wrapWithCurrentZone(prototype[callback], source); } } - else if (opts.prototype[callback]) { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + else if (prototype[callback]) { + prototype[callback] = wrapWithCurrentZone(prototype[callback], source); } }); } - return _registerElement.apply(document, [name, opts]); + return _registerElement.call(document, name, opts); }; attachOriginToPatched(document.registerElement, _registerElement); } @@ -2883,21 +2873,21 @@ function registerElementPatch(_global) { Zone.__load_patch('util', function (global, Zone, api) { api.patchOnProperties = patchOnProperties; api.patchMethod = patchMethod; - api.patchArguments = patchArguments; + api.bindArguments = bindArguments; }); -Zone.__load_patch('timers', function (global, Zone, api) { +Zone.__load_patch('timers', function (global) { var set = 'set'; var clear = 'clear'; patchTimer(global, set, clear, 'Timeout'); patchTimer(global, set, clear, 'Interval'); patchTimer(global, set, clear, 'Immediate'); }); -Zone.__load_patch('requestAnimationFrame', function (global, Zone, api) { +Zone.__load_patch('requestAnimationFrame', function (global) { patchTimer(global, 'request', 'cancel', 'AnimationFrame'); patchTimer(global, 'mozRequest', 'mozCancel', 'AnimationFrame'); patchTimer(global, 'webkitRequest', 'webkitCancel', 'AnimationFrame'); }); -Zone.__load_patch('blocking', function (global, Zone, api) { +Zone.__load_patch('blocking', function (global, Zone) { var blockingMethods = ['alert', 'prompt', 'confirm']; for (var i = 0; i < blockingMethods.length; i++) { var name_1 = blockingMethods[i]; @@ -2931,17 +2921,17 @@ Zone.__load_patch('on_property', function (global, Zone, api) { propertyPatch(); registerElementPatch(global); }); -Zone.__load_patch('canvas', function (global, Zone, api) { +Zone.__load_patch('canvas', function (global) { var HTMLCanvasElement = global['HTMLCanvasElement']; if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype && HTMLCanvasElement.prototype.toBlob) { patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', function (self, args) { - return { name: 'HTMLCanvasElement.toBlob', target: self, callbackIndex: 0, args: args }; + return { name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args }; }); } }); -Zone.__load_patch('XHR', function (global, Zone, api) { - // Treat XMLHTTPRequest as a macrotask. +Zone.__load_patch('XHR', function (global, Zone) { + // Treat XMLHttpRequest as a macrotask. patchXHR(global); var XHR_TASK = zoneSymbol('xhrTask'); var XHR_SYNC = zoneSymbol('xhrSync'); @@ -2949,19 +2939,18 @@ Zone.__load_patch('XHR', function (global, Zone, api) { var XHR_SCHEDULED = zoneSymbol('xhrScheduled'); var XHR_URL = zoneSymbol('xhrURL'); function patchXHR(window) { + var XMLHttpRequestPrototype = XMLHttpRequest.prototype; function findPendingTask(target) { - var pendingTask = target[XHR_TASK]; - return pendingTask; + return target[XHR_TASK]; } - var SYMBOL_ADDEVENTLISTENER = zoneSymbol('addEventListener'); - var SYMBOL_REMOVEEVENTLISTENER = zoneSymbol('removeEventListener'); - var oriAddListener = XMLHttpRequest.prototype[SYMBOL_ADDEVENTLISTENER]; - var oriRemoveListener = XMLHttpRequest.prototype[SYMBOL_REMOVEEVENTLISTENER]; + var oriAddListener = XMLHttpRequestPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + var oriRemoveListener = XMLHttpRequestPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; if (!oriAddListener) { var XMLHttpRequestEventTarget = window['XMLHttpRequestEventTarget']; if (XMLHttpRequestEventTarget) { - oriAddListener = XMLHttpRequestEventTarget.prototype[SYMBOL_ADDEVENTLISTENER]; - oriRemoveListener = XMLHttpRequestEventTarget.prototype[SYMBOL_REMOVEEVENTLISTENER]; + var XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget.prototype; + oriAddListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + oriRemoveListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; } } var READY_STATE_CHANGE = 'readystatechange'; @@ -2973,11 +2962,11 @@ Zone.__load_patch('XHR', function (global, Zone, api) { // remove existing event listener var listener = target[XHR_LISTENER]; if (!oriAddListener) { - oriAddListener = target[SYMBOL_ADDEVENTLISTENER]; - oriRemoveListener = target[SYMBOL_REMOVEEVENTLISTENER]; + oriAddListener = target[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + oriRemoveListener = target[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; } if (listener) { - oriRemoveListener.apply(target, [READY_STATE_CHANGE, listener]); + oriRemoveListener.call(target, READY_STATE_CHANGE, listener); } var newListener = target[XHR_LISTENER] = function () { if (target.readyState === target.DONE) { @@ -2988,7 +2977,7 @@ Zone.__load_patch('XHR', function (global, Zone, api) { } } }; - oriAddListener.apply(target, [READY_STATE_CHANGE, newListener]); + oriAddListener.call(target, READY_STATE_CHANGE, newListener); var storedTask = target[XHR_TASK]; if (!storedTask) { target[XHR_TASK] = task; @@ -3005,14 +2994,13 @@ Zone.__load_patch('XHR', function (global, Zone, api) { data.aborted = true; return abortNative.apply(data.target, data.args); } - var openNative = patchMethod(window.XMLHttpRequest.prototype, 'open', function () { return function (self, args) { + var openNative = patchMethod(XMLHttpRequestPrototype, 'open', function () { return function (self, args) { self[XHR_SYNC] = args[2] == false; self[XHR_URL] = args[1]; return openNative.apply(self, args); }; }); var XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send'; - var sendNative = patchMethod(window.XMLHttpRequest.prototype, 'send', function () { return function (self, args) { - var zone = Zone.current; + var sendNative = patchMethod(XMLHttpRequestPrototype, 'send', function () { return function (self, args) { if (self[XHR_SYNC]) { // if the XHR is sync there is no task to schedule, just execute the code. return sendNative.apply(self, args); @@ -3026,13 +3014,12 @@ Zone.__load_patch('XHR', function (global, Zone, api) { args: args, aborted: false }; - return zone.scheduleMacroTask(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask); + return scheduleMacroTaskWithCurrentZone(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask); } }; }); - var STRING_TYPE = 'string'; - var abortNative = patchMethod(window.XMLHttpRequest.prototype, 'abort', function (delegate) { return function (self, args) { + var abortNative = patchMethod(XMLHttpRequestPrototype, 'abort', function () { return function (self) { var task = findPendingTask(self); - if (task && typeof task.type == STRING_TYPE) { + if (task && typeof task.type == 'string') { // If the XHR has already completed, do nothing. // If the XHR has already been aborted, do nothing. // Fix #569, call abort multiple times before done will cause @@ -3048,19 +3035,13 @@ Zone.__load_patch('XHR', function (global, Zone, api) { }; }); } }); -Zone.__load_patch('geolocation', function (global, Zone, api) { +Zone.__load_patch('geolocation', function (global) { /// GEO_LOCATION if (global['navigator'] && global['navigator'].geolocation) { patchPrototype(global['navigator'].geolocation, ['getCurrentPosition', 'watchPosition']); } }); -Zone.__load_patch('getUserMedia', function (global, Zone, api) { - var navigator = global['navigator']; - if (navigator && navigator.getUserMedia) { - navigator.getUserMedia = wrapFunctionArgs(navigator.getUserMedia); - } -}); -Zone.__load_patch('PromiseRejectionEvent', function (global, Zone, api) { +Zone.__load_patch('PromiseRejectionEvent', function (global, Zone) { // handle unhandled promise rejection function findPromiseRejectionHandler(evtName) { return function (e) { @@ -3091,13 +3072,7 @@ Zone.__load_patch('PromiseRejectionEvent', function (global, Zone, api) { * 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 */ -Zone.__load_patch('EventEmitter', function (global, Zone, api) { - var callAndReturnFirstParam = function (fn) { - return function (self, args) { - fn(self, args); - return self; - }; - }; +Zone.__load_patch('EventEmitter', function (global) { // For EventEmitter var EE_ADD_LISTENER = 'addListener'; var EE_PREPEND_LISTENER = 'prependListener'; @@ -3106,23 +3081,20 @@ Zone.__load_patch('EventEmitter', function (global, Zone, api) { var EE_LISTENERS = 'listeners'; var EE_ON = 'on'; var compareTaskCallbackVsDelegate = function (task, delegate) { - if (task.callback === delegate || task.callback.listener === delegate) { - // same callback, same capture, same event name, just return - return true; - } - return false; + // same callback, same capture, same event name, just return + return task.callback === delegate || task.callback.listener === delegate; }; function patchEventEmitterMethods(obj) { var result = patchEventTarget(global, [obj], { - useGlobalCallback: false, - addEventListenerFnName: EE_ADD_LISTENER, - removeEventListenerFnName: EE_REMOVE_LISTENER, - prependEventListenerFnName: EE_PREPEND_LISTENER, - removeAllFnName: EE_REMOVE_ALL_LISTENER, - listenersFnName: EE_LISTENERS, - checkDuplicate: false, - returnTarget: true, - compareTaskCallbackVsDelegate: compareTaskCallbackVsDelegate + useG: false, + add: EE_ADD_LISTENER, + rm: EE_REMOVE_LISTENER, + prepend: EE_PREPEND_LISTENER, + rmAll: EE_REMOVE_ALL_LISTENER, + listeners: EE_LISTENERS, + chkDup: false, + rt: true, + diff: compareTaskCallbackVsDelegate }); if (result && result[0]) { obj[EE_ON] = obj[EE_ADD_LISTENER]; @@ -3147,7 +3119,7 @@ Zone.__load_patch('EventEmitter', function (global, Zone, api) { * 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 */ -Zone.__load_patch('fs', function (global, Zone, api) { +Zone.__load_patch('fs', function () { var fs; try { fs = require('fs'); @@ -3170,7 +3142,7 @@ Zone.__load_patch('fs', function (global, Zone, api) { return { name: 'fs.' + name, args: args, - callbackIndex: args.length > 0 ? args.length - 1 : -1, + cbIdx: args.length > 0 ? args.length - 1 : -1, target: self }; }); @@ -3190,9 +3162,9 @@ var clear = 'clear'; Zone.__load_patch('node_util', function (global, Zone, api) { api.patchOnProperties = patchOnProperties; api.patchMethod = patchMethod; - api.patchArguments = patchArguments; + api.bindArguments = bindArguments; }); -Zone.__load_patch('node_timers', function (global, Zone, api) { +Zone.__load_patch('node_timers', function (global, Zone) { // Timers var globalUseTimeoutFromTimer = false; try { @@ -3218,7 +3190,7 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { patchTimer(timers, set, clear, 'Immediate'); } catch (error) { - // timers module not exists, for example, when we using nativescript + // timers module not exists, for example, when we using nativeScript // timers is not available } if (isMix) { @@ -3237,7 +3209,7 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { } else { // global use timers setTimeout, but not equals - // this happenes when use nodejs v0.10.x, global setTimeout will + // this happens when use nodejs v0.10.x, global setTimeout will // use a lazy load version of timers setTimeout // we should not double patch timer's setTimeout // so we only store the __symbol__ for consistency @@ -3247,13 +3219,13 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { } }); // patch process related methods -Zone.__load_patch('nextTick', function (global, Zone, api) { +Zone.__load_patch('nextTick', function () { // patch nextTick as microTask patchMicroTask(process, 'nextTick', function (self, args) { return { name: 'process.nextTick', args: args, - callbackIndex: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1, + cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1, target: process }; }); @@ -3281,7 +3253,7 @@ Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api } }); // Crypto -Zone.__load_patch('crypto', function (global, Zone, api) { +Zone.__load_patch('crypto', function () { var crypto; try { crypto = require('crypto'); @@ -3296,7 +3268,7 @@ Zone.__load_patch('crypto', function (global, Zone, api) { return { name: 'crypto.' + name, args: args, - callbackIndex: (args.length > 0 && typeof args[args.length - 1] === 'function') ? + cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ? args.length - 1 : -1, target: crypto @@ -3305,13 +3277,13 @@ Zone.__load_patch('crypto', function (global, Zone, api) { }); } }); -Zone.__load_patch('console', function (global, Zone, api) { +Zone.__load_patch('console', function (global, Zone) { var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace']; consoleMethods.forEach(function (m) { var originalMethod = console[Zone.__symbol__(m)] = console[m]; if (originalMethod) { console[m] = function () { - var args = Array.prototype.slice.call(arguments); + var args = ArraySlice.call(arguments); if (Zone.current === Zone.root) { return originalMethod.apply(this, args); } diff --git a/dist/zone-node.js b/dist/zone-node.js index 19166a6f4..d4c3b5ff3 100644 --- a/dist/zone-node.js +++ b/dist/zone-node.js @@ -476,12 +476,13 @@ var Zone$1 = (function (global) { this.cancelFn = cancelFn; this.callback = callback; var self = this; - if (type === eventTask && options && options.isUsingGlobalCallback) { + // TODO: @JiaLiPassion options should have interface + if (type === eventTask && options && options.useG) { this.invoke = ZoneTask.invokeTask; } else { this.invoke = function () { - return ZoneTask.invokeTask.apply(global, [self, this, arguments]); + return ZoneTask.invokeTask.call(global, self, this, arguments); }; } } @@ -598,7 +599,6 @@ var Zone$1 = (function (global) { } } } - var showError = !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; _api.microtaskDrainDone(); _isDrainingMicrotaskQueue = false; } @@ -622,7 +622,7 @@ var Zone$1 = (function (global) { patchEventTarget: function () { return []; }, patchOnProperties: noop, patchMethod: function () { return noop; }, - patchArguments: function () { return noop; }, + bindArguments: function () { return null; }, setNativePromise: function (NativePromise) { // sometimes NativePromise.resolve static function // is not ready yet, (such as core-js/es6.promise) @@ -661,6 +661,8 @@ var __values = (undefined && undefined.__values) || function (o) { * found in the LICENSE file at https://angular.io/license */ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { + var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ObjectDefineProperty = Object.defineProperty; function readableObjectToString(obj) { if (obj && obj.toString === Object.prototype.toString) { var className = obj.constructor && obj.constructor.name; @@ -708,7 +710,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { try { var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL]; if (handler && typeof handler === 'function') { - handler.apply(this, [e]); + handler.call(this, e); } } catch (err) { @@ -754,8 +756,6 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { }; }; var TYPE_ERROR = 'Promise resolved with itself'; - var OBJECT = 'object'; - var FUNCTION = 'function'; var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace'); // Promise Resolution function resolvePromise(promise, state, value) { @@ -767,7 +767,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // should only get value.then once based on promise spec. var then = null; try { - if (typeof value === OBJECT || typeof value === FUNCTION) { + if (typeof value === 'object' || typeof value === 'function') { then = value && value.then; } } @@ -784,11 +784,9 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { clearRejectedNoCatch(value); resolvePromise(promise, value[symbolState], value[symbolValue]); } - else if (state !== REJECTED && typeof then === FUNCTION) { + else if (state !== REJECTED && typeof then === 'function') { try { - then.apply(value, [ - onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)) - ]); + then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false))); } catch (err) { onceWrapper(function () { @@ -808,7 +806,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { Zone.currentTask.data[creationTrace]; if (trace) { // only keep the long stack trace into error when in longStackTraceZone - Object.defineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); + ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); } } for (var i = 0; i < queue.length;) { @@ -846,8 +844,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // eventHandler try { var handler = Zone[REJECTION_HANDLED_HANDLER]; - if (handler && typeof handler === FUNCTION) { - handler.apply(this, [{ rejection: promise[symbolValue], promise: promise }]); + if (handler && typeof handler === 'function') { + handler.call(this, { rejection: promise[symbolValue], promise: promise }); } } catch (err) { @@ -863,8 +861,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) { clearRejectedNoCatch(promise); var delegate = promise[symbolState] ? - (typeof onFulfilled === FUNCTION) ? onFulfilled : forwardResolution : - (typeof onRejected === FUNCTION) ? onRejected : forwardRejection; + (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution : + (typeof onRejected === 'function') ? onRejected : forwardRejection; zone.scheduleMicroTask(source, function () { try { resolvePromise(chainPromise, true, zone.run(delegate, undefined, [promise[symbolValue]])); @@ -992,7 +990,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { ZoneAwarePromise['all'] = ZoneAwarePromise.all; var NativePromise = global[symbolPromise] = global['Promise']; var ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise'); - var desc = Object.getOwnPropertyDescriptor(global, 'Promise'); + var desc = ObjectGetOwnPropertyDescriptor(global, 'Promise'); if (!desc || desc.configurable) { desc && delete desc.writable; desc && delete desc.value; @@ -1025,7 +1023,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { api.setNativePromise(NewNativePromise); } }; - Object.defineProperty(global, 'Promise', desc); + ObjectDefineProperty(global, 'Promise', desc); } global['Promise'] = ZoneAwarePromise; var symbolThenPatched = __symbol__('thenPatched'); @@ -1034,11 +1032,11 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { var originalThen = proto.then; // Keep a reference to the original method. proto[symbolThen] = originalThen; - // check Ctor.prototype.then propertyDescritor is writable or not + // check Ctor.prototype.then propertyDescriptor is writable or not // in meteor env, writable is false, we have to make it to be true. - var prop = Object.getOwnPropertyDescriptor(Ctor.prototype, 'then'); + var prop = ObjectGetOwnPropertyDescriptor(Ctor.prototype, 'then'); if (prop && prop.writable === false && prop.configurable) { - Object.defineProperty(Ctor.prototype, 'then', { writable: true }); + ObjectDefineProperty(Ctor.prototype, 'then', { writable: true }); } Ctor.prototype.then = function (onResolve, onReject) { var _this = this; @@ -1065,7 +1063,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { if (NativePromise) { patchThen(NativePromise); var fetch_1 = global['fetch']; - if (typeof fetch_1 == FUNCTION) { + if (typeof fetch_1 == 'function') { global['fetch'] = zoneify(fetch_1); } } @@ -1086,27 +1084,58 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { * @fileoverview * @suppress {undefinedVars,globalThis,missingRequire} */ +// issue #989, to reduce bundle size, use short name +/** Object.getOwnPropertyDescriptor */ +/** + * @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 ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; +/** Object.defineProperty */ +var ObjectDefineProperty = Object.defineProperty; +/** Object.getPrototypeOf */ +var ObjectGetPrototypeOf = Object.getPrototypeOf; +/** Object.create */ + +/** Array.prototype.slice */ +var ArraySlice = Array.prototype.slice; +/** addEventListener string const */ +var ADD_EVENT_LISTENER_STR = 'addEventListener'; +/** removeEventListener string const */ +var REMOVE_EVENT_LISTENER_STR = 'removeEventListener'; +/** zoneSymbol addEventListener */ +var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR); +/** zoneSymbol removeEventListener */ +var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR); +/** true string const */ +var TRUE_STR = 'true'; +/** false string const */ +var FALSE_STR = 'false'; +/** __zone_symbol__ string const */ +var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; +function wrapWithCurrentZone(callback, source) { + return Zone.current.wrap(callback, source); +} +function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) { + return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel); +} var zoneSymbol = Zone.__symbol__; -var _global = typeof window === 'object' && window || typeof self === 'object' && self || global; -var FUNCTION = 'function'; -var UNDEFINED = 'undefined'; +var isWindowExists = typeof window !== 'undefined'; +var internalWindow = isWindowExists ? window : undefined; +var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global; var REMOVE_ATTRIBUTE = 'removeAttribute'; var NULL_ON_PROP_VALUE = [null]; function bindArguments(args, source) { for (var i = args.length - 1; i >= 0; i--) { - if (typeof args[i] === FUNCTION) { - args[i] = Zone.current.wrap(args[i], source + '_' + i); + if (typeof args[i] === 'function') { + args[i] = wrapWithCurrentZone(args[i], source + '_' + i); } } return args; } -function patchArguments(target, name, source) { - return patchMethod(target, name, function (delegate, delegateName, name) { return function (self, args) { - return delegate && delegate.apply(self, bindArguments(args, source)); - }; }); -} - function isPropertyWritable(propertyDesc) { if (!propertyDesc) { return true; @@ -1114,23 +1143,20 @@ function isPropertyWritable(propertyDesc) { if (propertyDesc.writable === false) { return false; } - if (typeof propertyDesc.get === FUNCTION && typeof propertyDesc.set === UNDEFINED) { - return false; - } - return true; + return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined'); } var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope); -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]'); // we are in electron of nw, so we are both browser and nodejs -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isMix = typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]' && !isWebWorker && - !!(typeof window !== 'undefined' && window['HTMLElement']); + !!(isWindowExists && internalWindow['HTMLElement']); var zoneSymbolEventNames = {}; var wrapFn = function (event) { // https://github.com/angular/zone.js/issues/911, in IE, sometimes @@ -1152,10 +1178,10 @@ var wrapFn = function (event) { return result; }; function patchProperty(obj, prop, prototype) { - var desc = Object.getOwnPropertyDescriptor(obj, prop); + var desc = ObjectGetOwnPropertyDescriptor(obj, prop); if (!desc && prototype) { // when patch window object, use prototype to check prop exist or not - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, prop); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop); if (prototypeDesc) { desc = { enumerable: true, configurable: true }; } @@ -1230,10 +1256,10 @@ function patchProperty(obj, prop, prototype) { // the onclick will be evaluated when first time event was triggered or // the property is accessed, https://github.com/angular/zone.js/issues/525 // so we should use original native get to retrieve the handler - var value = originalDescGet && originalDescGet.apply(this); + var value = originalDescGet && originalDescGet.call(this); if (value) { - desc.set.apply(this, [value]); - if (typeof target[REMOVE_ATTRIBUTE] === FUNCTION) { + desc.set.call(this, value); + if (typeof target[REMOVE_ATTRIBUTE] === 'function') { target.removeAttribute(prop); } return value; @@ -1241,7 +1267,7 @@ function patchProperty(obj, prop, prototype) { } return null; }; - Object.defineProperty(obj, prop, desc); + ObjectDefineProperty(obj, prop, desc); } function patchOnProperties(obj, properties, prototype) { if (properties) { @@ -1267,7 +1293,7 @@ var originalInstanceKey = zoneSymbol('originalInstance'); function patchMethod(target, name, patchFn) { var proto = target; while (proto && !proto.hasOwnProperty(name)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && target[name]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1279,7 +1305,7 @@ function patchMethod(target, name, patchFn) { delegate = proto[delegateName] = proto[name]; // check whether proto[name] is writable // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob - var desc = proto && Object.getOwnPropertyDescriptor(proto, name); + var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name); if (isPropertyWritable(desc)) { var patchDelegate_1 = patchFn(delegate, delegateName, name); proto[name] = function () { @@ -1295,7 +1321,7 @@ function patchMacroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1303,9 +1329,8 @@ function patchMacroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMacroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask, null); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask, null); } else { // cause an error by calling it directly. @@ -1317,7 +1342,7 @@ function patchMicroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1325,9 +1350,8 @@ function patchMicroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMicroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask); } else { // cause an error by calling it directly. @@ -1348,19 +1372,18 @@ function attachOriginToPatched(patched, original) { */ // override Function.prototype.toString to make zone.js patched function // look like native function -Zone.__load_patch('toString', function (global, Zone, api) { +Zone.__load_patch('toString', function (global, Zone) { // patch Func.prototype.toString to let them look like native var originalFunctionToString = Zone['__zone_symbol__originalToString'] = Function.prototype.toString; - var FUNCTION = 'function'; var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate'); var PROMISE_SYMBOL = zoneSymbol('Promise'); var ERROR_SYMBOL = zoneSymbol('Error'); Function.prototype.toString = function () { - if (typeof this === FUNCTION) { + if (typeof this === 'function') { var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL]; if (originalDelegate) { - if (typeof originalDelegate === FUNCTION) { + if (typeof originalDelegate === 'function') { return originalFunctionToString.apply(this[ORIGINAL_DELEGATE_SYMBOL], arguments); } else { @@ -1404,25 +1427,19 @@ Zone.__load_patch('toString', function (global, Zone, api) { * @fileoverview * @suppress {missingRequire} */ -var TRUE_STR = 'true'; -var FALSE_STR = 'false'; // an identifier to tell ZoneTask do not create a new invoke closure var OPTIMIZED_ZONE_EVENT_TASK_DATA = { - isUsingGlobalCallback: true + useG: true }; var zoneSymbolEventNames$1 = {}; var globalSources = {}; -var CONSTRUCTOR_NAME = 'name'; -var FUNCTION_TYPE = 'function'; -var OBJECT_TYPE = 'object'; -var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; var EVENT_NAME_SYMBOL_REGX = /^__zone_symbol__(\w+)(true|false)$/; var IMMEDIATE_PROPAGATION_SYMBOL = ('__zone_symbol__propagationStopped'); function patchEventTarget(_global, apis, patchOptions) { - var ADD_EVENT_LISTENER = (patchOptions && patchOptions.addEventListenerFnName) || 'addEventListener'; - var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.removeEventListenerFnName) || 'removeEventListener'; - var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listenersFnName) || 'eventListeners'; - var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.removeAllFnName) || 'removeAllListeners'; + var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR; + var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR; + var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners'; + var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners'; var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER); var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':'; var PREPEND_EVENT_LISTENER = 'prependListener'; @@ -1434,7 +1451,7 @@ function patchEventTarget(_global, apis, patchOptions) { return; } var delegate = task.callback; - if (typeof delegate === OBJECT_TYPE && delegate.handleEvent) { + if (typeof delegate === 'object' && delegate.handleEvent) { // create the bind version of handleEvent when invoke task.callback = function (event) { return delegate.handleEvent(event); }; task.originalDelegate = delegate; @@ -1447,7 +1464,7 @@ function patchEventTarget(_global, apis, patchOptions) { // only browser need to do this, nodejs eventEmitter will cal removeListener // inside EventEmitter.once var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback; - target[REMOVE_EVENT_LISTENER].apply(target, [event.type, delegate_1, options]); + target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options); } }; // global shared zoneAwareCallback to handle all event callback with capture = false @@ -1458,7 +1475,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]]; @@ -1490,7 +1507,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]]; @@ -1519,21 +1536,21 @@ function patchEventTarget(_global, apis, patchOptions) { return false; } var useGlobalCallback = true; - if (patchOptions && patchOptions.useGlobalCallback !== undefined) { - useGlobalCallback = patchOptions.useGlobalCallback; + if (patchOptions && patchOptions.useG !== undefined) { + useGlobalCallback = patchOptions.useG; } - var validateHandler = patchOptions && patchOptions.validateHandler; + var validateHandler = patchOptions && patchOptions.vh; var checkDuplicate = true; - if (patchOptions && patchOptions.checkDuplicate !== undefined) { - checkDuplicate = patchOptions.checkDuplicate; + if (patchOptions && patchOptions.chkDup !== undefined) { + checkDuplicate = patchOptions.chkDup; } var returnTarget = false; - if (patchOptions && patchOptions.returnTarget !== undefined) { - returnTarget = patchOptions.returnTarget; + if (patchOptions && patchOptions.rt !== undefined) { + returnTarget = patchOptions.rt; } var proto = obj; while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && obj[ADD_EVENT_LISTENER]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1556,21 +1573,17 @@ function patchEventTarget(_global, apis, patchOptions) { var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] = proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER]; var nativePrependEventListener; - if (patchOptions && patchOptions.prependEventListenerFnName) { - nativePrependEventListener = proto[zoneSymbol(patchOptions.prependEventListenerFnName)] = - proto[patchOptions.prependEventListenerFnName]; + if (patchOptions && patchOptions.prepend) { + nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] = + proto[patchOptions.prepend]; } - var customScheduleGlobal = function (task) { + var customScheduleGlobal = function () { // if there is already a task for the eventName + capture, // just return, because we use the shared globalZoneAwareCallback here. if (taskData.isExisting) { return; } - return nativeAddEventListener.apply(taskData.target, [ - taskData.eventName, - taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - taskData.options - ]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options); }; var customCancelGlobal = function (task) { // if task is not marked as isRemoved, this call is directly @@ -1607,41 +1620,31 @@ function patchEventTarget(_global, apis, patchOptions) { if (!task.allRemoved) { return; } - return nativeRemoveEventListener.apply(task.target, [ - task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - task.options - ]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options); }; var customScheduleNonGlobal = function (task) { - return nativeAddEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customSchedulePrepend = function (task) { - return nativePrependEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customCancelNonGlobal = function (task) { - return nativeRemoveEventListener.apply(task.target, [task.eventName, task.invoke, task.options]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options); }; var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal; var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal; var compareTaskCallbackVsDelegate = function (task, delegate) { var typeOfDelegate = typeof delegate; - if ((typeOfDelegate === FUNCTION_TYPE && task.callback === delegate) || - (typeOfDelegate === OBJECT_TYPE && task.originalDelegate === delegate)) { - // same callback, same capture, same event name, just return - return true; - } - return false; + return (typeOfDelegate === 'function' && task.callback === delegate) || + (typeOfDelegate === 'object' && task.originalDelegate === delegate); }; - var compare = (patchOptions && patchOptions.compareTaskCallbackVsDelegate) ? - patchOptions.compareTaskCallbackVsDelegate : - compareTaskCallbackVsDelegate; + var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate; var blackListedEvents = Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')]; var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) { if (returnTarget === void 0) { returnTarget = false; } if (prepend === void 0) { prepend = false; } return function () { var target = this || _global; - var targetZone = Zone.current; var delegate = arguments[1]; if (!delegate) { return nativeListener.apply(this, arguments); @@ -1650,7 +1653,7 @@ function patchEventTarget(_global, apis, patchOptions) { // case here to improve addEventListener performance // we will create the bind delegate when invoke var isHandleEvent = false; - if (typeof delegate !== FUNCTION_TYPE) { + if (typeof delegate !== 'function') { if (!delegate.handleEvent) { return nativeListener.apply(this, arguments); } @@ -1719,7 +1722,7 @@ function patchEventTarget(_global, apis, patchOptions) { existingTasks = target[symbolEventName] = []; } var source; - var constructorName = target.constructor[CONSTRUCTOR_NAME]; + var constructorName = target.constructor['name']; var targetSource = globalSources[constructorName]; if (targetSource) { source = targetSource[eventName]; @@ -1741,7 +1744,7 @@ function patchEventTarget(_global, apis, patchOptions) { taskData.eventName = eventName; taskData.isExisting = isExisting; var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null; - // keep taskData into data to allow onScheduleEventTask to acess the task information + // keep taskData into data to allow onScheduleEventTask to access the task information if (data) { data.taskData = taskData; } @@ -1815,7 +1818,6 @@ function patchEventTarget(_global, apis, patchOptions) { if (existingTasks) { for (var i = 0; i < existingTasks.length; i++) { var existingTask = existingTasks[i]; - var typeOfDelegate = typeof delegate; if (compare(existingTask, delegate)) { existingTasks.splice(i, 1); // set isRemoved to data for faster invokeTask check @@ -1863,11 +1865,11 @@ function patchEventTarget(_global, apis, patchOptions) { // so just keep removeListener eventListener until // all other eventListeners are removed if (evtName && evtName !== 'removeListener') { - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, [evtName]); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName); } } // remove removeListener listener finally - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, ['removeListener']); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener'); } else { var symbolEventNames = zoneSymbolEventNames$1[eventName]; @@ -1881,7 +1883,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } if (captureTasks) { @@ -1889,7 +1891,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } } @@ -1936,13 +1938,7 @@ function findEventTasks(target, eventName) { * 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 */ -Zone.__load_patch('EventEmitter', function (global, Zone, api) { - var callAndReturnFirstParam = function (fn) { - return function (self, args) { - fn(self, args); - return self; - }; - }; +Zone.__load_patch('EventEmitter', function (global) { // For EventEmitter var EE_ADD_LISTENER = 'addListener'; var EE_PREPEND_LISTENER = 'prependListener'; @@ -1951,23 +1947,20 @@ Zone.__load_patch('EventEmitter', function (global, Zone, api) { var EE_LISTENERS = 'listeners'; var EE_ON = 'on'; var compareTaskCallbackVsDelegate = function (task, delegate) { - if (task.callback === delegate || task.callback.listener === delegate) { - // same callback, same capture, same event name, just return - return true; - } - return false; + // same callback, same capture, same event name, just return + return task.callback === delegate || task.callback.listener === delegate; }; function patchEventEmitterMethods(obj) { var result = patchEventTarget(global, [obj], { - useGlobalCallback: false, - addEventListenerFnName: EE_ADD_LISTENER, - removeEventListenerFnName: EE_REMOVE_LISTENER, - prependEventListenerFnName: EE_PREPEND_LISTENER, - removeAllFnName: EE_REMOVE_ALL_LISTENER, - listenersFnName: EE_LISTENERS, - checkDuplicate: false, - returnTarget: true, - compareTaskCallbackVsDelegate: compareTaskCallbackVsDelegate + useG: false, + add: EE_ADD_LISTENER, + rm: EE_REMOVE_LISTENER, + prepend: EE_PREPEND_LISTENER, + rmAll: EE_REMOVE_ALL_LISTENER, + listeners: EE_LISTENERS, + chkDup: false, + rt: true, + diff: compareTaskCallbackVsDelegate }); if (result && result[0]) { obj[EE_ON] = obj[EE_ADD_LISTENER]; @@ -1992,7 +1985,7 @@ Zone.__load_patch('EventEmitter', function (global, Zone, api) { * 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 */ -Zone.__load_patch('fs', function (global, Zone, api) { +Zone.__load_patch('fs', function () { var fs; try { fs = require('fs'); @@ -2015,7 +2008,7 @@ Zone.__load_patch('fs', function (global, Zone, api) { return { name: 'fs.' + name, args: args, - callbackIndex: args.length > 0 ? args.length - 1 : -1, + cbIdx: args.length > 0 ? args.length - 1 : -1, target: self }; }); @@ -2041,12 +2034,6 @@ function patchTimer(window, setName, cancelName, nameSuffix) { setName += nameSuffix; cancelName += nameSuffix; var tasksByHandleId = {}; - var NUMBER = 'number'; - var STRING = 'string'; - var FUNCTION = 'function'; - var INTERVAL = 'Interval'; - var TIMEOUT = 'Timeout'; - var NOT_SCHEDULED = 'notScheduled'; function scheduleTask(task) { var data = task.data; function timer() { @@ -2054,21 +2041,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task.invoke.apply(this, arguments); } finally { - if (task.data && task.data.isPeriodic) { - // issue-934, task will be cancelled - // even it is a periodic task such as - // setInterval - return; - } - if (typeof data.handleId === NUMBER) { - // in non-nodejs env, we remove timerId - // from local cache - delete tasksByHandleId[data.handleId]; - } - else if (data.handleId) { - // Node returns complex objects as handleIds - // we remove task reference from timer object - data.handleId[taskSymbol] = null; + // issue-934, task will be cancelled + // even it is a periodic task such as + // setInterval + if (!(task.data && task.data.isPeriodic)) { + if (typeof data.handleId === 'number') { + // in non-nodejs env, we remove timerId + // from local cache + delete tasksByHandleId[data.handleId]; + } + else if (data.handleId) { + // Node returns complex objects as handleIds + // we remove task reference from timer object + data.handleId[taskSymbol] = null; + } } } } @@ -2081,21 +2067,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } setNative = patchMethod(window, setName, function (delegate) { return function (self, args) { - if (typeof args[0] === FUNCTION) { - var zone = Zone.current; + if (typeof args[0] === 'function') { var options = { handleId: null, - isPeriodic: nameSuffix === INTERVAL, - delay: (nameSuffix === TIMEOUT || nameSuffix === INTERVAL) ? args[1] || 0 : 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); + var task = scheduleMacroTaskWithCurrentZone(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 (typeof handle === NUMBER) { + if (typeof handle === 'number') { // for non nodejs env, we save handleId: task // mapping in local cache for clearTimeout tasksByHandleId[handle] = task; @@ -2107,12 +2092,12 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } // check whether handle is null, because some polyfill or browser // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame - if (handle && handle.ref && handle.unref && typeof handle.ref === FUNCTION && - typeof handle.unref === FUNCTION) { + if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' && + typeof handle.unref === 'function') { task.ref = handle.ref.bind(handle); task.unref = handle.unref.bind(handle); } - if (typeof handle === NUMBER || handle) { + if (typeof handle === 'number' || handle) { return handle; } return task; @@ -2126,7 +2111,7 @@ function patchTimer(window, setName, cancelName, nameSuffix) { patchMethod(window, cancelName, function (delegate) { return function (self, args) { var id = args[0]; var task; - if (typeof id === NUMBER) { + if (typeof id === 'number') { // non nodejs env. task = tasksByHandleId[id]; } @@ -2138,10 +2123,10 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task = id; } } - if (task && typeof task.type === STRING) { - if (task.state !== NOT_SCHEDULED && + if (task && typeof task.type === 'string') { + if (task.state !== 'notScheduled' && (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) { - if (typeof id === NUMBER) { + if (typeof id === 'number') { delete tasksByHandleId[id]; } else if (id) { @@ -2170,9 +2155,9 @@ var clear = 'clear'; Zone.__load_patch('node_util', function (global, Zone, api) { api.patchOnProperties = patchOnProperties; api.patchMethod = patchMethod; - api.patchArguments = patchArguments; + api.bindArguments = bindArguments; }); -Zone.__load_patch('node_timers', function (global, Zone, api) { +Zone.__load_patch('node_timers', function (global, Zone) { // Timers var globalUseTimeoutFromTimer = false; try { @@ -2198,7 +2183,7 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { patchTimer(timers, set, clear, 'Immediate'); } catch (error) { - // timers module not exists, for example, when we using nativescript + // timers module not exists, for example, when we using nativeScript // timers is not available } if (isMix) { @@ -2217,7 +2202,7 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { } else { // global use timers setTimeout, but not equals - // this happenes when use nodejs v0.10.x, global setTimeout will + // this happens when use nodejs v0.10.x, global setTimeout will // use a lazy load version of timers setTimeout // we should not double patch timer's setTimeout // so we only store the __symbol__ for consistency @@ -2227,13 +2212,13 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { } }); // patch process related methods -Zone.__load_patch('nextTick', function (global, Zone, api) { +Zone.__load_patch('nextTick', function () { // patch nextTick as microTask patchMicroTask(process, 'nextTick', function (self, args) { return { name: 'process.nextTick', args: args, - callbackIndex: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1, + cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1, target: process }; }); @@ -2261,7 +2246,7 @@ Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api } }); // Crypto -Zone.__load_patch('crypto', function (global, Zone, api) { +Zone.__load_patch('crypto', function () { var crypto; try { crypto = require('crypto'); @@ -2276,7 +2261,7 @@ Zone.__load_patch('crypto', function (global, Zone, api) { return { name: 'crypto.' + name, args: args, - callbackIndex: (args.length > 0 && typeof args[args.length - 1] === 'function') ? + cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ? args.length - 1 : -1, target: crypto @@ -2285,13 +2270,13 @@ Zone.__load_patch('crypto', function (global, Zone, api) { }); } }); -Zone.__load_patch('console', function (global, Zone, api) { +Zone.__load_patch('console', function (global, Zone) { var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace']; consoleMethods.forEach(function (m) { var originalMethod = console[Zone.__symbol__(m)] = console[m]; if (originalMethod) { console[m] = function () { - var args = Array.prototype.slice.call(arguments); + var args = ArraySlice.call(arguments); if (Zone.current === Zone.root) { return originalMethod.apply(this, args); } diff --git a/dist/zone-patch-cordova.js b/dist/zone-patch-cordova.js index 1b0124c95..187f219f2 100644 --- a/dist/zone-patch-cordova.js +++ b/dist/zone-patch-cordova.js @@ -23,7 +23,7 @@ Zone.__load_patch('cordova', function (global, Zone, api) { var SUCCESS_SOURCE_1 = 'cordova.exec.success'; var ERROR_SOURCE_1 = 'cordova.exec.error'; var FUNCTION_1 = 'function'; - var nativeExec_1 = api.patchMethod(global.cordova, 'exec', function (delegate) { return function (self, args) { + var nativeExec_1 = api.patchMethod(global.cordova, 'exec', function () { return function (self, args) { if (args.length > 0 && typeof args[0] === FUNCTION_1) { args[0] = Zone.current.wrap(args[0], SUCCESS_SOURCE_1); } @@ -34,7 +34,7 @@ Zone.__load_patch('cordova', function (global, Zone, api) { }; }); } }); -Zone.__load_patch('cordova.FileReader', function (global, Zone, api) { +Zone.__load_patch('cordova.FileReader', function (global, Zone) { if (global.cordova && typeof global['FileReader'] !== 'undefined') { document.addEventListener('deviceReady', function () { var FileReader = global['FileReader']; diff --git a/dist/zone-patch-cordova.min.js b/dist/zone-patch-cordova.min.js index 60d1864aa..b30c6e97e 100644 --- a/dist/zone-patch-cordova.min.js +++ b/dist/zone-patch-cordova.min.js @@ -1 +1 @@ -!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o():"function"==typeof define&&define.amd?define(o):o()}(this,function(){"use strict";Zone.__load_patch("cordova",function(e,o,r){if(e.cordova)var t="cordova.exec.success",n="cordova.exec.error",a="function",c=r.patchMethod(e.cordova,"exec",function(e){return function(e,r){return r.length>0&&typeof r[0]===a&&(r[0]=o.current.wrap(r[0],t)),r.length>1&&typeof r[1]===a&&(r[1]=o.current.wrap(r[1],n)),c.apply(e,r)}})}),Zone.__load_patch("cordova.FileReader",function(e,o,r){e.cordova&&"undefined"!=typeof e.FileReader&&document.addEventListener("deviceReady",function(){var r=e.FileReader;["abort","error","load","loadstart","loadend","progress"].forEach(function(e){var t=o.__symbol__("ON_PROPERTY"+e);Object.defineProperty(r.prototype,t,{configurable:!0,get:function(){return this._realReader&&this._realReader[t]}})})})})}); \ No newline at end of file +!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o():"function"==typeof define&&define.amd?define(o):o()}(this,function(){"use strict";Zone.__load_patch("cordova",function(e,o,r){if(e.cordova)var t="cordova.exec.success",n="cordova.exec.error",a="function",c=r.patchMethod(e.cordova,"exec",function(){return function(e,r){return r.length>0&&typeof r[0]===a&&(r[0]=o.current.wrap(r[0],t)),r.length>1&&typeof r[1]===a&&(r[1]=o.current.wrap(r[1],n)),c.apply(e,r)}})}),Zone.__load_patch("cordova.FileReader",function(e,o){e.cordova&&"undefined"!=typeof e.FileReader&&document.addEventListener("deviceReady",function(){var r=e.FileReader;["abort","error","load","loadstart","loadend","progress"].forEach(function(e){var t=o.__symbol__("ON_PROPERTY"+e);Object.defineProperty(r.prototype,t,{configurable:!0,get:function(){return this._realReader&&this._realReader[t]}})})})})}); \ No newline at end of file diff --git a/dist/zone-patch-electron.js b/dist/zone-patch-electron.js index 3ce0cd651..2efb290cd 100644 --- a/dist/zone-patch-electron.js +++ b/dist/zone-patch-electron.js @@ -19,22 +19,26 @@ * found in the LICENSE file at https://angular.io/license */ Zone.__load_patch('electron', function (global, Zone, api) { - var FUNCTION = 'function'; - var _a = require('electron'), desktopCapturer = _a.desktopCapturer, shell = _a.shell, CallbackRegistry = _a.CallbackRegistry; + function patchArguments(target, name, source) { + return api.patchMethod(target, name, function (delegate) { return function (self, args) { + return delegate && delegate.apply(self, api.bindArguments(args, source)); + }; }); + } + var _a = require('electron'), desktopCapturer = _a.desktopCapturer, shell = _a.shell, CallbacksRegistry = _a.CallbacksRegistry; // patch api in renderer process directly // desktopCapturer if (desktopCapturer) { - api.patchArguments(desktopCapturer, 'getSources', 'electron.desktopCapturer.getSources'); + patchArguments(desktopCapturer, 'getSources', 'electron.desktopCapturer.getSources'); } // shell if (shell) { - api.patchArguments(shell, 'openExternal', 'electron.shell.openExternal'); + patchArguments(shell, 'openExternal', 'electron.shell.openExternal'); } // patch api in main process through CallbackRegistry - if (!CallbackRegistry) { + if (!CallbacksRegistry) { return; } - api.patchArguments(CallbackRegistry.prototype, 'add', 'CallbackRegistry.add'); + patchArguments(CallbacksRegistry.prototype, 'add', 'CallbackRegistry.add'); }); }))); diff --git a/dist/zone-patch-electron.min.js b/dist/zone-patch-electron.min.js index 038dac7c4..0c049edac 100644 --- a/dist/zone-patch-electron.min.js +++ b/dist/zone-patch-electron.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";Zone.__load_patch("electron",function(e,t,n){var o=require("electron"),r=o.desktopCapturer,c=o.shell,a=o.CallbackRegistry;r&&n.patchArguments(r,"getSources","electron.desktopCapturer.getSources"),c&&n.patchArguments(c,"openExternal","electron.shell.openExternal"),a&&n.patchArguments(a.prototype,"add","CallbackRegistry.add")})}); \ 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";Zone.__load_patch("electron",function(e,t,n){function o(e,t,o){return n.patchMethod(e,t,function(e){return function(t,r){return e&&e.apply(t,n.bindArguments(r,o))}})}var r=require("electron"),c=r.desktopCapturer,u=r.shell,i=r.CallbacksRegistry;c&&o(c,"getSources","electron.desktopCapturer.getSources"),u&&o(u,"openExternal","electron.shell.openExternal"),i&&o(i.prototype,"add","CallbackRegistry.add")})}); \ No newline at end of file diff --git a/dist/zone-patch-rxjs.js b/dist/zone-patch-rxjs.js index db7bd8d88..85cd93b22 100644 --- a/dist/zone-patch-rxjs.js +++ b/dist/zone-patch-rxjs.js @@ -18,14 +18,12 @@ * 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 */ -Zone.__load_patch('rxjs', function (global, Zone, api) { +Zone.__load_patch('rxjs', function (global, Zone) { var symbol = Zone.__symbol__; - var subscribeSource = 'rxjs.subscribe'; var nextSource = 'rxjs.Subscriber.next'; var errorSource = 'rxjs.Subscriber.error'; var completeSource = 'rxjs.Subscriber.complete'; - var unsubscribeSource = 'rxjs.Subscriber.unsubscribe'; - var teardownSource = 'rxjs.Subscriber.teardownLogic'; + var ObjectDefineProperties = Object.defineProperties; var empty = { closed: true, next: function (value) { }, @@ -52,7 +50,7 @@ Zone.__load_patch('rxjs', function (global, Zone, api) { var _symbolSubscribe = symbol('_subscribe'); var _subscribe = ObservablePrototype[_symbolSubscribe] = ObservablePrototype._subscribe; var subscribe = ObservablePrototype[symbolSubscribe] = ObservablePrototype.subscribe; - Object.defineProperties(rxjs_Observable.Observable.prototype, { + ObjectDefineProperties(rxjs_Observable.Observable.prototype, { _zone: { value: null, writable: true, configurable: true }, _zoneSource: { value: null, writable: true, configurable: true }, _zoneSubscribe: { value: null, writable: true, configurable: true }, @@ -103,7 +101,7 @@ Zone.__load_patch('rxjs', function (global, Zone, api) { var unsubscribeSymbol = symbol('unsubscribe'); var unsubscribe = rxjs_Subscription.Subscription.prototype[unsubscribeSymbol] = rxjs_Subscription.Subscription.prototype.unsubscribe; - Object.defineProperties(rxjs_Subscription.Subscription.prototype, { + ObjectDefineProperties(rxjs_Subscription.Subscription.prototype, { _zone: { value: null, writable: true, configurable: true }, _zoneUnsubscribe: { value: null, writable: true, configurable: true }, _unsubscribe: { @@ -305,7 +303,6 @@ Zone.__load_patch('rxjs', function (global, Zone, api) { return; } var scheduleSymbol = symbol('scheduleSymbol'); - var flushSymbol = symbol('flushSymbol'); var zoneSymbol = symbol('zone'); if (asap$$1[scheduleSymbol]) { return; @@ -328,7 +325,7 @@ Zone.__load_patch('rxjs', function (global, Zone, api) { return work.apply(this, arguments); } }; - return schedule.apply(this, [patchedWork, delay, state]); + return schedule.call(this, patchedWork, delay, state); }; }; patchObservable(); diff --git a/dist/zone-patch-rxjs.min.js b/dist/zone-patch-rxjs.min.js index cd33f203f..8a509ada3 100644 --- a/dist/zone-patch-rxjs.min.js +++ b/dist/zone-patch-rxjs.min.js @@ -1 +1 @@ -!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("rxjs/add/observable/bindCallback"),require("rxjs/add/observable/bindNodeCallback"),require("rxjs/add/observable/defer"),require("rxjs/add/observable/forkJoin"),require("rxjs/add/observable/fromEventPattern"),require("rxjs/add/operator/multicast"),require("rxjs/Observable"),require("rxjs/scheduler/asap"),require("rxjs/Subscriber"),require("rxjs/Subscription"),require("rxjs/symbol/rxSubscriber")):"function"==typeof define&&define.amd?define(["rxjs/add/observable/bindCallback","rxjs/add/observable/bindNodeCallback","rxjs/add/observable/defer","rxjs/add/observable/forkJoin","rxjs/add/observable/fromEventPattern","rxjs/add/operator/multicast","rxjs/Observable","rxjs/scheduler/asap","rxjs/Subscriber","rxjs/Subscription","rxjs/symbol/rxSubscriber"],e):e(null,null,null,null,null,null,r.Rx,r.Rx.Scheduler,r.Rx,r.Rx,r.Rx.Symbol)}(this,function(r,e,t,n,i,u,o,s,b,c,a){"use strict";Zone.__load_patch("rxjs",function(r,e,t){function n(r,e,t){if(r){if(r instanceof b.Subscriber)return r;if(r[a.rxSubscriber])return r[a.rxSubscriber]()}return r||e||t?new b.Subscriber(r,e,t):new b.Subscriber(p)}var i=e.__symbol__,u="rxjs.Subscriber.next",l="rxjs.Subscriber.error",f="rxjs.Subscriber.complete",p={closed:!0,next:function(r){},error:function(r){throw r},complete:function(){}},v=function(){var r=o.Observable.prototype,t=i("subscribe"),u=i("_subscribe"),s=r[u]=r._subscribe,b=r[t]=r.subscribe;Object.defineProperties(o.Observable.prototype,{_zone:{value:null,writable:!0,configurable:!0},_zoneSource:{value:null,writable:!0,configurable:!0},_zoneSubscribe:{value:null,writable:!0,configurable:!0},source:{configurable:!0,get:function(){return this._zoneSource},set:function(r){this._zone=e.current,this._zoneSource=r}},_subscribe:{configurable:!0,get:function(){if(this._zoneSubscribe)return this._zoneSubscribe;if(this.constructor===o.Observable)return s;var r=Object.getPrototypeOf(this);return r&&r._subscribe},set:function(r){this._zone=e.current,this._zoneSubscribe=r}},subscribe:{writable:!0,configurable:!0,value:function(r,t,i){var u=this._zone;return u&&u!==e.current?u.run(b,this,[n(r,t,i)]):b.call(this,r,t,i)}}})},d=function(){var r=i("unsubscribe"),t=c.Subscription.prototype[r]=c.Subscription.prototype.unsubscribe;Object.defineProperties(c.Subscription.prototype,{_zone:{value:null,writable:!0,configurable:!0},_zoneUnsubscribe:{value:null,writable:!0,configurable:!0},_unsubscribe:{get:function(){if(this._zoneUnsubscribe)return this._zoneUnsubscribe;var r=Object.getPrototypeOf(this);return r&&r._unsubscribe},set:function(r){this._zone=e.current,this._zoneUnsubscribe=r}},unsubscribe:{writable:!0,configurable:!0,value:function(){var r=this._zone;r&&r!==e.current?r.run(t,this):t.apply(this)}}})},h=function(){var r=b.Subscriber.prototype.next,t=b.Subscriber.prototype.error,n=b.Subscriber.prototype.complete;Object.defineProperty(b.Subscriber.prototype,"destination",{configurable:!0,get:function(){return this._zoneDestination},set:function(r){this._zone=e.current,this._zoneDestination=r}}),b.Subscriber.prototype.next=function(){var t=e.current,n=this._zone;return n&&n!==t?n.run(r,this,arguments,u):r.apply(this,arguments)},b.Subscriber.prototype.error=function(){var r=e.current,n=this._zone;return n&&n!==r?n.run(t,this,arguments,l):t.apply(this,arguments)},b.Subscriber.prototype.complete=function(){var r=e.current,t=this._zone;return t&&t!==r?t.run(n,this,arguments,f):n.apply(this,arguments)}},y=function(r){r._zone=e.current},x=function(r,e){var t=i(e);if(!r[t]){var n=r[t]=r[e];n&&(r[e]=function(){var r=n.apply(this,arguments);return function(){var e=r.apply(this,arguments);return y(e),e}})}},_=function(r,e){var t=i(e);if(!r[t]){var n=r[t]=r[e];n&&(r[e]=function(){var r=n.apply(this,arguments);return y(r),r})}},S=function(r,t){var n=i(t);if(!r[n]){var u=r[n]=r[t];u&&(r[t]=function(){for(var r=e.current,t=Array.prototype.slice.call(arguments),n=function(n){var i=t[n];"function"==typeof i&&(t[n]=function(){var t=Array.prototype.slice.call(arguments),n=e.current;return r&&n&&r!==n?r.run(i,this,t):i.apply(this,t)})},i=0;i0?t[0]:void 0;if("function"!=typeof n){var i=n;n=function(){return i}}t[0]=function(){var t;return t=r&&r!==e.current?r.run(n,this,arguments):n.apply(this,arguments),t&&r&&(t._zone=r),t};var o=u.apply(this,t);return y(o),o})}},z=function(r){if(r){var t=i("scheduleSymbol"),n=(i("flushSymbol"),i("zone"));if(!r[t]){var u=r[t]=r.schedule;r.schedule=function(){var r=Array.prototype.slice.call(arguments),t=r.length>0?r[0]:void 0,i=r.length>1?r[1]:0,o=(r.length>2?r[2]:void 0)||{};o[n]=e.current;var s=function(){var r=Array.prototype.slice.call(arguments),i=r.length>0?r[0]:void 0,u=i&&i[n];return u&&u!==e.current?u.runGuarded(t,this,arguments):t.apply(this,arguments)};return u.apply(this,[s,i,o])}}}};v(),d(),h(),x(o.Observable,"bindCallback"),x(o.Observable,"bindNodeCallback"),_(o.Observable,"defer"),_(o.Observable,"forkJoin"),S(o.Observable,"fromEventPattern"),j(),z(s.asap)})}); \ No newline at end of file +!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("rxjs/add/observable/bindCallback"),require("rxjs/add/observable/bindNodeCallback"),require("rxjs/add/observable/defer"),require("rxjs/add/observable/forkJoin"),require("rxjs/add/observable/fromEventPattern"),require("rxjs/add/operator/multicast"),require("rxjs/Observable"),require("rxjs/scheduler/asap"),require("rxjs/Subscriber"),require("rxjs/Subscription"),require("rxjs/symbol/rxSubscriber")):"function"==typeof define&&define.amd?define(["rxjs/add/observable/bindCallback","rxjs/add/observable/bindNodeCallback","rxjs/add/observable/defer","rxjs/add/observable/forkJoin","rxjs/add/observable/fromEventPattern","rxjs/add/operator/multicast","rxjs/Observable","rxjs/scheduler/asap","rxjs/Subscriber","rxjs/Subscription","rxjs/symbol/rxSubscriber"],e):e(null,null,null,null,null,null,r.Rx,r.Rx.Scheduler,r.Rx,r.Rx,r.Rx.Symbol)}(this,function(r,e,t,n,i,u,o,s,b,c,a){"use strict";Zone.__load_patch("rxjs",function(r,e){function t(r,e,t){if(r){if(r instanceof b.Subscriber)return r;if(r[a.rxSubscriber])return r[a.rxSubscriber]()}return r||e||t?new b.Subscriber(r,e,t):new b.Subscriber(p)}var n=e.__symbol__,i="rxjs.Subscriber.next",u="rxjs.Subscriber.error",l="rxjs.Subscriber.complete",f=Object.defineProperties,p={closed:!0,next:function(r){},error:function(r){throw r},complete:function(){}},v=function(){var r=o.Observable.prototype,i=n("subscribe"),u=n("_subscribe"),s=r[u]=r._subscribe,b=r[i]=r.subscribe;f(o.Observable.prototype,{_zone:{value:null,writable:!0,configurable:!0},_zoneSource:{value:null,writable:!0,configurable:!0},_zoneSubscribe:{value:null,writable:!0,configurable:!0},source:{configurable:!0,get:function(){return this._zoneSource},set:function(r){this._zone=e.current,this._zoneSource=r}},_subscribe:{configurable:!0,get:function(){if(this._zoneSubscribe)return this._zoneSubscribe;if(this.constructor===o.Observable)return s;var r=Object.getPrototypeOf(this);return r&&r._subscribe},set:function(r){this._zone=e.current,this._zoneSubscribe=r}},subscribe:{writable:!0,configurable:!0,value:function(r,n,i){var u=this._zone;return u&&u!==e.current?u.run(b,this,[t(r,n,i)]):b.call(this,r,n,i)}}})},d=function(){var r=n("unsubscribe"),t=c.Subscription.prototype[r]=c.Subscription.prototype.unsubscribe;f(c.Subscription.prototype,{_zone:{value:null,writable:!0,configurable:!0},_zoneUnsubscribe:{value:null,writable:!0,configurable:!0},_unsubscribe:{get:function(){if(this._zoneUnsubscribe)return this._zoneUnsubscribe;var r=Object.getPrototypeOf(this);return r&&r._unsubscribe},set:function(r){this._zone=e.current,this._zoneUnsubscribe=r}},unsubscribe:{writable:!0,configurable:!0,value:function(){var r=this._zone;r&&r!==e.current?r.run(t,this):t.apply(this)}}})},h=function(){var r=b.Subscriber.prototype.next,t=b.Subscriber.prototype.error,n=b.Subscriber.prototype.complete;Object.defineProperty(b.Subscriber.prototype,"destination",{configurable:!0,get:function(){return this._zoneDestination},set:function(r){this._zone=e.current,this._zoneDestination=r}}),b.Subscriber.prototype.next=function(){var t=e.current,n=this._zone;return n&&n!==t?n.run(r,this,arguments,i):r.apply(this,arguments)},b.Subscriber.prototype.error=function(){var r=e.current,n=this._zone;return n&&n!==r?n.run(t,this,arguments,u):t.apply(this,arguments)},b.Subscriber.prototype.complete=function(){var r=e.current,t=this._zone;return t&&t!==r?t.run(n,this,arguments,l):n.apply(this,arguments)}},y=function(r){r._zone=e.current},x=function(r,e){var t=n(e);if(!r[t]){var i=r[t]=r[e];i&&(r[e]=function(){var r=i.apply(this,arguments);return function(){var e=r.apply(this,arguments);return y(e),e}})}},_=function(r,e){var t=n(e);if(!r[t]){var i=r[t]=r[e];i&&(r[e]=function(){var r=i.apply(this,arguments);return y(r),r})}},S=function(r,t){var i=n(t);if(!r[i]){var u=r[i]=r[t];u&&(r[t]=function(){for(var r=e.current,t=Array.prototype.slice.call(arguments),n=function(n){var i=t[n];"function"==typeof i&&(t[n]=function(){var t=Array.prototype.slice.call(arguments),n=e.current;return r&&n&&r!==n?r.run(i,this,t):i.apply(this,t)})},i=0;i0?t[0]:void 0;if("function"!=typeof n){var i=n;n=function(){return i}}t[0]=function(){var t;return t=r&&r!==e.current?r.run(n,this,arguments):n.apply(this,arguments),t&&r&&(t._zone=r),t};var o=u.apply(this,t);return y(o),o})}},z=function(r){if(r){var t=n("scheduleSymbol"),i=n("zone");if(!r[t]){var u=r[t]=r.schedule;r.schedule=function(){var r=Array.prototype.slice.call(arguments),t=r.length>0?r[0]:void 0,n=r.length>1?r[1]:0,o=(r.length>2?r[2]:void 0)||{};o[i]=e.current;var s=function(){var r=Array.prototype.slice.call(arguments),n=r.length>0?r[0]:void 0,u=n&&n[i];return u&&u!==e.current?u.runGuarded(t,this,arguments):t.apply(this,arguments)};return u.call(this,s,n,o)}}}};v(),d(),h(),x(o.Observable,"bindCallback"),x(o.Observable,"bindNodeCallback"),_(o.Observable,"defer"),_(o.Observable,"forkJoin"),S(o.Observable,"fromEventPattern"),j(),z(s.asap)})}); \ No newline at end of file diff --git a/dist/zone-patch-user-media.js b/dist/zone-patch-user-media.js new file mode 100644 index 000000000..8a3c28a58 --- /dev/null +++ b/dist/zone-patch-user-media.js @@ -0,0 +1,35 @@ +/** +* @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'; + +/** + * @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 + */ +Zone.__load_patch('getUserMedia', function (global, Zone, api) { + function wrapFunctionArgs(func, source) { + return function () { + var args = Array.prototype.slice.call(arguments); + var wrappedArgs = api.bindArguments(args, source ? source : func.name); + return func.apply(this, wrappedArgs); + }; + } + var navigator = global['navigator']; + if (navigator && navigator.getUserMedia) { + navigator.getUserMedia = wrapFunctionArgs(navigator.getUserMedia); + } +}); + +}))); diff --git a/dist/zone-patch-user-media.min.js b/dist/zone-patch-user-media.min.js new file mode 100644 index 000000000..8c56fe372 --- /dev/null +++ b/dist/zone-patch-user-media.min.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";Zone.__load_patch("getUserMedia",function(e,t,n){function i(e,t){return function(){var i=Array.prototype.slice.call(arguments),o=n.bindArguments(i,t?t:e.name);return e.apply(this,o)}}var o=e.navigator;o&&o.getUserMedia&&(o.getUserMedia=i(o.getUserMedia))})}); \ No newline at end of file diff --git a/dist/zone-testing-bundle.js b/dist/zone-testing-bundle.js index 8b3c79f9a..7d6eed199 100644 --- a/dist/zone-testing-bundle.js +++ b/dist/zone-testing-bundle.js @@ -476,12 +476,13 @@ var Zone$1 = (function (global) { this.cancelFn = cancelFn; this.callback = callback; var self = this; - if (type === eventTask && options && options.isUsingGlobalCallback) { + // TODO: @JiaLiPassion options should have interface + if (type === eventTask && options && options.useG) { this.invoke = ZoneTask.invokeTask; } else { this.invoke = function () { - return ZoneTask.invokeTask.apply(global, [self, this, arguments]); + return ZoneTask.invokeTask.call(global, self, this, arguments); }; } } @@ -598,7 +599,6 @@ var Zone$1 = (function (global) { } } } - var showError = !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; _api.microtaskDrainDone(); _isDrainingMicrotaskQueue = false; } @@ -622,7 +622,7 @@ var Zone$1 = (function (global) { patchEventTarget: function () { return []; }, patchOnProperties: noop, patchMethod: function () { return noop; }, - patchArguments: function () { return noop; }, + bindArguments: function () { return null; }, setNativePromise: function (NativePromise) { // sometimes NativePromise.resolve static function // is not ready yet, (such as core-js/es6.promise) @@ -661,6 +661,8 @@ var __values = (undefined && undefined.__values) || function (o) { * found in the LICENSE file at https://angular.io/license */ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { + var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ObjectDefineProperty = Object.defineProperty; function readableObjectToString(obj) { if (obj && obj.toString === Object.prototype.toString) { var className = obj.constructor && obj.constructor.name; @@ -708,7 +710,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { try { var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL]; if (handler && typeof handler === 'function') { - handler.apply(this, [e]); + handler.call(this, e); } } catch (err) { @@ -754,8 +756,6 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { }; }; var TYPE_ERROR = 'Promise resolved with itself'; - var OBJECT = 'object'; - var FUNCTION = 'function'; var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace'); // Promise Resolution function resolvePromise(promise, state, value) { @@ -767,7 +767,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // should only get value.then once based on promise spec. var then = null; try { - if (typeof value === OBJECT || typeof value === FUNCTION) { + if (typeof value === 'object' || typeof value === 'function') { then = value && value.then; } } @@ -784,11 +784,9 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { clearRejectedNoCatch(value); resolvePromise(promise, value[symbolState], value[symbolValue]); } - else if (state !== REJECTED && typeof then === FUNCTION) { + else if (state !== REJECTED && typeof then === 'function') { try { - then.apply(value, [ - onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)) - ]); + then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false))); } catch (err) { onceWrapper(function () { @@ -808,7 +806,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { Zone.currentTask.data[creationTrace]; if (trace) { // only keep the long stack trace into error when in longStackTraceZone - Object.defineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); + ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); } } for (var i = 0; i < queue.length;) { @@ -846,8 +844,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // eventHandler try { var handler = Zone[REJECTION_HANDLED_HANDLER]; - if (handler && typeof handler === FUNCTION) { - handler.apply(this, [{ rejection: promise[symbolValue], promise: promise }]); + if (handler && typeof handler === 'function') { + handler.call(this, { rejection: promise[symbolValue], promise: promise }); } } catch (err) { @@ -863,8 +861,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) { clearRejectedNoCatch(promise); var delegate = promise[symbolState] ? - (typeof onFulfilled === FUNCTION) ? onFulfilled : forwardResolution : - (typeof onRejected === FUNCTION) ? onRejected : forwardRejection; + (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution : + (typeof onRejected === 'function') ? onRejected : forwardRejection; zone.scheduleMicroTask(source, function () { try { resolvePromise(chainPromise, true, zone.run(delegate, undefined, [promise[symbolValue]])); @@ -992,7 +990,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { ZoneAwarePromise['all'] = ZoneAwarePromise.all; var NativePromise = global[symbolPromise] = global['Promise']; var ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise'); - var desc = Object.getOwnPropertyDescriptor(global, 'Promise'); + var desc = ObjectGetOwnPropertyDescriptor(global, 'Promise'); if (!desc || desc.configurable) { desc && delete desc.writable; desc && delete desc.value; @@ -1025,7 +1023,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { api.setNativePromise(NewNativePromise); } }; - Object.defineProperty(global, 'Promise', desc); + ObjectDefineProperty(global, 'Promise', desc); } global['Promise'] = ZoneAwarePromise; var symbolThenPatched = __symbol__('thenPatched'); @@ -1034,11 +1032,11 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { var originalThen = proto.then; // Keep a reference to the original method. proto[symbolThen] = originalThen; - // check Ctor.prototype.then propertyDescritor is writable or not + // check Ctor.prototype.then propertyDescriptor is writable or not // in meteor env, writable is false, we have to make it to be true. - var prop = Object.getOwnPropertyDescriptor(Ctor.prototype, 'then'); + var prop = ObjectGetOwnPropertyDescriptor(Ctor.prototype, 'then'); if (prop && prop.writable === false && prop.configurable) { - Object.defineProperty(Ctor.prototype, 'then', { writable: true }); + ObjectDefineProperty(Ctor.prototype, 'then', { writable: true }); } Ctor.prototype.then = function (onResolve, onReject) { var _this = this; @@ -1065,7 +1063,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { if (NativePromise) { patchThen(NativePromise); var fetch_1 = global['fetch']; - if (typeof fetch_1 == FUNCTION) { + if (typeof fetch_1 == 'function') { global['fetch'] = zoneify(fetch_1); } } @@ -1086,39 +1084,64 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { * @fileoverview * @suppress {undefinedVars,globalThis,missingRequire} */ +// issue #989, to reduce bundle size, use short name +/** Object.getOwnPropertyDescriptor */ +/** + * @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 ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; +/** Object.defineProperty */ +var ObjectDefineProperty = Object.defineProperty; +/** Object.getPrototypeOf */ +var ObjectGetPrototypeOf = Object.getPrototypeOf; +/** Object.create */ +var ObjectCreate = Object.create; +/** Array.prototype.slice */ +var ArraySlice = Array.prototype.slice; +/** addEventListener string const */ +var ADD_EVENT_LISTENER_STR = 'addEventListener'; +/** removeEventListener string const */ +var REMOVE_EVENT_LISTENER_STR = 'removeEventListener'; +/** zoneSymbol addEventListener */ +var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR); +/** zoneSymbol removeEventListener */ +var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR); +/** true string const */ +var TRUE_STR = 'true'; +/** false string const */ +var FALSE_STR = 'false'; +/** __zone_symbol__ string const */ +var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; +function wrapWithCurrentZone(callback, source) { + return Zone.current.wrap(callback, source); +} +function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) { + return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel); +} var zoneSymbol = Zone.__symbol__; -var _global = typeof window === 'object' && window || typeof self === 'object' && self || global; -var FUNCTION = 'function'; -var UNDEFINED = 'undefined'; +var isWindowExists = typeof window !== 'undefined'; +var internalWindow = isWindowExists ? window : undefined; +var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global; var REMOVE_ATTRIBUTE = 'removeAttribute'; var NULL_ON_PROP_VALUE = [null]; function bindArguments(args, source) { for (var i = args.length - 1; i >= 0; i--) { - if (typeof args[i] === FUNCTION) { - args[i] = Zone.current.wrap(args[i], source + '_' + i); + if (typeof args[i] === 'function') { + args[i] = wrapWithCurrentZone(args[i], source + '_' + i); } } return args; } -function wrapFunctionArgs(func, source) { - return function () { - var args = Array.prototype.slice.call(arguments); - var wrappedArgs = bindArguments(args, source ? source : func.name); - return func.apply(this, wrappedArgs); - }; -} -function patchArguments(target, name, source) { - return patchMethod(target, name, function (delegate, delegateName, name) { return function (self, args) { - return delegate && delegate.apply(self, bindArguments(args, source)); - }; }); -} function patchPrototype(prototype, fnNames) { var source = prototype.constructor['name']; var _loop_1 = function (i) { var name_1 = fnNames[i]; var delegate = prototype[name_1]; if (delegate) { - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, name_1); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, name_1); if (!isPropertyWritable(prototypeDesc)) { return "continue"; } @@ -1142,23 +1165,20 @@ function isPropertyWritable(propertyDesc) { if (propertyDesc.writable === false) { return false; } - if (typeof propertyDesc.get === FUNCTION && typeof propertyDesc.set === UNDEFINED) { - return false; - } - return true; + return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined'); } var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope); -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]'); -var isBrowser = !isNode && !isWebWorker && !!(typeof window !== 'undefined' && window['HTMLElement']); +var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']); // we are in electron of nw, so we are both browser and nodejs -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isMix = typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]' && !isWebWorker && - !!(typeof window !== 'undefined' && window['HTMLElement']); + !!(isWindowExists && internalWindow['HTMLElement']); var zoneSymbolEventNames = {}; var wrapFn = function (event) { // https://github.com/angular/zone.js/issues/911, in IE, sometimes @@ -1180,10 +1200,10 @@ var wrapFn = function (event) { return result; }; function patchProperty(obj, prop, prototype) { - var desc = Object.getOwnPropertyDescriptor(obj, prop); + var desc = ObjectGetOwnPropertyDescriptor(obj, prop); if (!desc && prototype) { // when patch window object, use prototype to check prop exist or not - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, prop); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop); if (prototypeDesc) { desc = { enumerable: true, configurable: true }; } @@ -1258,10 +1278,10 @@ function patchProperty(obj, prop, prototype) { // the onclick will be evaluated when first time event was triggered or // the property is accessed, https://github.com/angular/zone.js/issues/525 // so we should use original native get to retrieve the handler - var value = originalDescGet && originalDescGet.apply(this); + var value = originalDescGet && originalDescGet.call(this); if (value) { - desc.set.apply(this, [value]); - if (typeof target[REMOVE_ATTRIBUTE] === FUNCTION) { + desc.set.call(this, value); + if (typeof target[REMOVE_ATTRIBUTE] === 'function') { target.removeAttribute(prop); } return value; @@ -1269,7 +1289,7 @@ function patchProperty(obj, prop, prototype) { } return null; }; - Object.defineProperty(obj, prop, desc); + ObjectDefineProperty(obj, prop, desc); } function patchOnProperties(obj, properties, prototype) { if (properties) { @@ -1334,10 +1354,10 @@ function patchClass(className) { }; } else { - Object.defineProperty(_global[className].prototype, prop, { + ObjectDefineProperty(_global[className].prototype, prop, { set: function (fn) { if (typeof fn === 'function') { - this[originalInstanceKey][prop] = Zone.current.wrap(fn, className + '.' + prop); + this[originalInstanceKey][prop] = wrapWithCurrentZone(fn, className + '.' + prop); // keep callback in wrapped function so we can // use it in Function.prototype.toString to return // the native one. @@ -1363,7 +1383,7 @@ function patchClass(className) { function patchMethod(target, name, patchFn) { var proto = target; while (proto && !proto.hasOwnProperty(name)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && target[name]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1375,7 +1395,7 @@ function patchMethod(target, name, patchFn) { delegate = proto[delegateName] = proto[name]; // check whether proto[name] is writable // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob - var desc = proto && Object.getOwnPropertyDescriptor(proto, name); + var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name); if (isPropertyWritable(desc)) { var patchDelegate_1 = patchFn(delegate, delegateName, name); proto[name] = function () { @@ -1391,7 +1411,7 @@ function patchMacroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1399,9 +1419,8 @@ function patchMacroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMacroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask, null); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask, null); } else { // cause an error by calling it directly. @@ -1421,8 +1440,7 @@ function isIEOrEdge() { } isDetectedIEOrEdge = true; try { - var ua = window.navigator.userAgent; - var msie = ua.indexOf('MSIE '); + var ua = internalWindow.navigator.userAgent; if (ua.indexOf('MSIE ') !== -1 || ua.indexOf('Trident/') !== -1 || ua.indexOf('Edge/') !== -1) { ieOrEdge = true; } @@ -1441,19 +1459,18 @@ function isIEOrEdge() { */ // override Function.prototype.toString to make zone.js patched function // look like native function -Zone.__load_patch('toString', function (global, Zone, api) { +Zone.__load_patch('toString', function (global, Zone) { // patch Func.prototype.toString to let them look like native var originalFunctionToString = Zone['__zone_symbol__originalToString'] = Function.prototype.toString; - var FUNCTION = 'function'; var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate'); var PROMISE_SYMBOL = zoneSymbol('Promise'); var ERROR_SYMBOL = zoneSymbol('Error'); Function.prototype.toString = function () { - if (typeof this === FUNCTION) { + if (typeof this === 'function') { var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL]; if (originalDelegate) { - if (typeof originalDelegate === FUNCTION) { + if (typeof originalDelegate === 'function') { return originalFunctionToString.apply(this[ORIGINAL_DELEGATE_SYMBOL], arguments); } else { @@ -1497,25 +1514,19 @@ Zone.__load_patch('toString', function (global, Zone, api) { * @fileoverview * @suppress {missingRequire} */ -var TRUE_STR = 'true'; -var FALSE_STR = 'false'; // an identifier to tell ZoneTask do not create a new invoke closure var OPTIMIZED_ZONE_EVENT_TASK_DATA = { - isUsingGlobalCallback: true + useG: true }; var zoneSymbolEventNames$1 = {}; var globalSources = {}; -var CONSTRUCTOR_NAME = 'name'; -var FUNCTION_TYPE = 'function'; -var OBJECT_TYPE = 'object'; -var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; var EVENT_NAME_SYMBOL_REGX = /^__zone_symbol__(\w+)(true|false)$/; var IMMEDIATE_PROPAGATION_SYMBOL = ('__zone_symbol__propagationStopped'); function patchEventTarget(_global, apis, patchOptions) { - var ADD_EVENT_LISTENER = (patchOptions && patchOptions.addEventListenerFnName) || 'addEventListener'; - var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.removeEventListenerFnName) || 'removeEventListener'; - var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listenersFnName) || 'eventListeners'; - var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.removeAllFnName) || 'removeAllListeners'; + var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR; + var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR; + var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners'; + var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners'; var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER); var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':'; var PREPEND_EVENT_LISTENER = 'prependListener'; @@ -1527,7 +1538,7 @@ function patchEventTarget(_global, apis, patchOptions) { return; } var delegate = task.callback; - if (typeof delegate === OBJECT_TYPE && delegate.handleEvent) { + if (typeof delegate === 'object' && delegate.handleEvent) { // create the bind version of handleEvent when invoke task.callback = function (event) { return delegate.handleEvent(event); }; task.originalDelegate = delegate; @@ -1540,7 +1551,7 @@ function patchEventTarget(_global, apis, patchOptions) { // only browser need to do this, nodejs eventEmitter will cal removeListener // inside EventEmitter.once var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback; - target[REMOVE_EVENT_LISTENER].apply(target, [event.type, delegate_1, options]); + target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options); } }; // global shared zoneAwareCallback to handle all event callback with capture = false @@ -1551,7 +1562,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]]; @@ -1583,7 +1594,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]]; @@ -1612,21 +1623,21 @@ function patchEventTarget(_global, apis, patchOptions) { return false; } var useGlobalCallback = true; - if (patchOptions && patchOptions.useGlobalCallback !== undefined) { - useGlobalCallback = patchOptions.useGlobalCallback; + if (patchOptions && patchOptions.useG !== undefined) { + useGlobalCallback = patchOptions.useG; } - var validateHandler = patchOptions && patchOptions.validateHandler; + var validateHandler = patchOptions && patchOptions.vh; var checkDuplicate = true; - if (patchOptions && patchOptions.checkDuplicate !== undefined) { - checkDuplicate = patchOptions.checkDuplicate; + if (patchOptions && patchOptions.chkDup !== undefined) { + checkDuplicate = patchOptions.chkDup; } var returnTarget = false; - if (patchOptions && patchOptions.returnTarget !== undefined) { - returnTarget = patchOptions.returnTarget; + if (patchOptions && patchOptions.rt !== undefined) { + returnTarget = patchOptions.rt; } var proto = obj; while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && obj[ADD_EVENT_LISTENER]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1649,21 +1660,17 @@ function patchEventTarget(_global, apis, patchOptions) { var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] = proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER]; var nativePrependEventListener; - if (patchOptions && patchOptions.prependEventListenerFnName) { - nativePrependEventListener = proto[zoneSymbol(patchOptions.prependEventListenerFnName)] = - proto[patchOptions.prependEventListenerFnName]; + if (patchOptions && patchOptions.prepend) { + nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] = + proto[patchOptions.prepend]; } - var customScheduleGlobal = function (task) { + var customScheduleGlobal = function () { // if there is already a task for the eventName + capture, // just return, because we use the shared globalZoneAwareCallback here. if (taskData.isExisting) { return; } - return nativeAddEventListener.apply(taskData.target, [ - taskData.eventName, - taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - taskData.options - ]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options); }; var customCancelGlobal = function (task) { // if task is not marked as isRemoved, this call is directly @@ -1700,41 +1707,31 @@ function patchEventTarget(_global, apis, patchOptions) { if (!task.allRemoved) { return; } - return nativeRemoveEventListener.apply(task.target, [ - task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - task.options - ]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options); }; var customScheduleNonGlobal = function (task) { - return nativeAddEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customSchedulePrepend = function (task) { - return nativePrependEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customCancelNonGlobal = function (task) { - return nativeRemoveEventListener.apply(task.target, [task.eventName, task.invoke, task.options]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options); }; var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal; var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal; var compareTaskCallbackVsDelegate = function (task, delegate) { var typeOfDelegate = typeof delegate; - if ((typeOfDelegate === FUNCTION_TYPE && task.callback === delegate) || - (typeOfDelegate === OBJECT_TYPE && task.originalDelegate === delegate)) { - // same callback, same capture, same event name, just return - return true; - } - return false; + return (typeOfDelegate === 'function' && task.callback === delegate) || + (typeOfDelegate === 'object' && task.originalDelegate === delegate); }; - var compare = (patchOptions && patchOptions.compareTaskCallbackVsDelegate) ? - patchOptions.compareTaskCallbackVsDelegate : - compareTaskCallbackVsDelegate; + var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate; var blackListedEvents = Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')]; var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) { if (returnTarget === void 0) { returnTarget = false; } if (prepend === void 0) { prepend = false; } return function () { var target = this || _global; - var targetZone = Zone.current; var delegate = arguments[1]; if (!delegate) { return nativeListener.apply(this, arguments); @@ -1743,7 +1740,7 @@ function patchEventTarget(_global, apis, patchOptions) { // case here to improve addEventListener performance // we will create the bind delegate when invoke var isHandleEvent = false; - if (typeof delegate !== FUNCTION_TYPE) { + if (typeof delegate !== 'function') { if (!delegate.handleEvent) { return nativeListener.apply(this, arguments); } @@ -1812,7 +1809,7 @@ function patchEventTarget(_global, apis, patchOptions) { existingTasks = target[symbolEventName] = []; } var source; - var constructorName = target.constructor[CONSTRUCTOR_NAME]; + var constructorName = target.constructor['name']; var targetSource = globalSources[constructorName]; if (targetSource) { source = targetSource[eventName]; @@ -1834,7 +1831,7 @@ function patchEventTarget(_global, apis, patchOptions) { taskData.eventName = eventName; taskData.isExisting = isExisting; var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null; - // keep taskData into data to allow onScheduleEventTask to acess the task information + // keep taskData into data to allow onScheduleEventTask to access the task information if (data) { data.taskData = taskData; } @@ -1908,7 +1905,6 @@ function patchEventTarget(_global, apis, patchOptions) { if (existingTasks) { for (var i = 0; i < existingTasks.length; i++) { var existingTask = existingTasks[i]; - var typeOfDelegate = typeof delegate; if (compare(existingTask, delegate)) { existingTasks.splice(i, 1); // set isRemoved to data for faster invokeTask check @@ -1956,11 +1952,11 @@ function patchEventTarget(_global, apis, patchOptions) { // so just keep removeListener eventListener until // all other eventListeners are removed if (evtName && evtName !== 'removeListener') { - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, [evtName]); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName); } } // remove removeListener listener finally - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, ['removeListener']); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener'); } else { var symbolEventNames = zoneSymbolEventNames$1[eventName]; @@ -1974,7 +1970,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } if (captureTasks) { @@ -1982,7 +1978,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } } @@ -2052,12 +2048,6 @@ function patchTimer(window, setName, cancelName, nameSuffix) { setName += nameSuffix; cancelName += nameSuffix; var tasksByHandleId = {}; - var NUMBER = 'number'; - var STRING = 'string'; - var FUNCTION = 'function'; - var INTERVAL = 'Interval'; - var TIMEOUT = 'Timeout'; - var NOT_SCHEDULED = 'notScheduled'; function scheduleTask(task) { var data = task.data; function timer() { @@ -2065,21 +2055,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task.invoke.apply(this, arguments); } finally { - if (task.data && task.data.isPeriodic) { - // issue-934, task will be cancelled - // even it is a periodic task such as - // setInterval - return; - } - if (typeof data.handleId === NUMBER) { - // in non-nodejs env, we remove timerId - // from local cache - delete tasksByHandleId[data.handleId]; - } - else if (data.handleId) { - // Node returns complex objects as handleIds - // we remove task reference from timer object - data.handleId[taskSymbol] = null; + // issue-934, task will be cancelled + // even it is a periodic task such as + // setInterval + if (!(task.data && task.data.isPeriodic)) { + if (typeof data.handleId === 'number') { + // in non-nodejs env, we remove timerId + // from local cache + delete tasksByHandleId[data.handleId]; + } + else if (data.handleId) { + // Node returns complex objects as handleIds + // we remove task reference from timer object + data.handleId[taskSymbol] = null; + } } } } @@ -2092,21 +2081,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } setNative = patchMethod(window, setName, function (delegate) { return function (self, args) { - if (typeof args[0] === FUNCTION) { - var zone = Zone.current; + if (typeof args[0] === 'function') { var options = { handleId: null, - isPeriodic: nameSuffix === INTERVAL, - delay: (nameSuffix === TIMEOUT || nameSuffix === INTERVAL) ? args[1] || 0 : 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); + var task = scheduleMacroTaskWithCurrentZone(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 (typeof handle === NUMBER) { + if (typeof handle === 'number') { // for non nodejs env, we save handleId: task // mapping in local cache for clearTimeout tasksByHandleId[handle] = task; @@ -2118,12 +2106,12 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } // check whether handle is null, because some polyfill or browser // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame - if (handle && handle.ref && handle.unref && typeof handle.ref === FUNCTION && - typeof handle.unref === FUNCTION) { + if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' && + typeof handle.unref === 'function') { task.ref = handle.ref.bind(handle); task.unref = handle.unref.bind(handle); } - if (typeof handle === NUMBER || handle) { + if (typeof handle === 'number' || handle) { return handle; } return task; @@ -2137,7 +2125,7 @@ function patchTimer(window, setName, cancelName, nameSuffix) { patchMethod(window, cancelName, function (delegate) { return function (self, args) { var id = args[0]; var task; - if (typeof id === NUMBER) { + if (typeof id === 'number') { // non nodejs env. task = tasksByHandleId[id]; } @@ -2149,10 +2137,10 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task = id; } } - if (task && typeof task.type === STRING) { - if (task.state !== NOT_SCHEDULED && + if (task && typeof task.type === 'string') { + if (task.state !== 'notScheduled' && (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) { - if (typeof id === NUMBER) { + if (typeof id === 'number') { delete tasksByHandleId[id]; } else if (id) { @@ -2185,16 +2173,13 @@ var _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] = Object.getOwnPropertyDescriptor; var _create = Object.create; var unconfigurablesKey = zoneSymbol('unconfigurables'); -var PROTOTYPE = 'prototype'; -var OBJECT = 'object'; -var UNDEFINED$1 = 'undefined'; function propertyPatch() { Object.defineProperty = function (obj, prop, desc) { if (isUnconfigurable(obj, prop)) { throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj); } var originalConfigurableFlag = desc.configurable; - if (prop !== PROTOTYPE) { + if (prop !== 'prototype') { desc = rewriteDescriptor(obj, prop, desc); } return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag); @@ -2206,7 +2191,7 @@ function propertyPatch() { return obj; }; Object.create = function (obj, proto) { - if (typeof proto === OBJECT && !Object.isFrozen(proto)) { + if (typeof proto === 'object' && !Object.isFrozen(proto)) { Object.keys(proto).forEach(function (prop) { proto[prop] = rewriteDescriptor(obj, prop, proto[prop]); }); @@ -2253,7 +2238,7 @@ function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) { if (desc.configurable) { // 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$1) { + if (typeof originalConfigurableFlag == 'undefined') { delete desc.configurable; } else { @@ -2294,22 +2279,22 @@ function apply(api, _global) { if (!_global.EventTarget) { patchEventTarget(_global, [WS.prototype]); } - _global.WebSocket = function (a, b) { - var socket = arguments.length > 1 ? new WS(a, b) : new WS(a); + _global.WebSocket = function (x, y) { + var socket = arguments.length > 1 ? new WS(x, y) : new WS(x); var proxySocket; var proxySocketProto; // Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance - var onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage'); + var onmessageDesc = ObjectGetOwnPropertyDescriptor(socket, 'onmessage'); if (onmessageDesc && onmessageDesc.configurable === false) { - proxySocket = Object.create(socket); + proxySocket = ObjectCreate(socket); // socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror' // but proxySocket not, so we will keep socket as prototype and pass it to // patchOnProperties method proxySocketProto = socket; - ['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function (propName) { + [ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR, 'send', 'close'].forEach(function (propName) { proxySocket[propName] = function () { - var args = Array.prototype.slice.call(arguments); - if (propName === 'addEventListener' || propName === 'removeEventListener') { + var args = ArraySlice.call(arguments); + if (propName === ADD_EVENT_LISTENER_STR || propName === REMOVE_EVENT_LISTENER_STR) { var eventName = args.length > 0 ? args[0] : undefined; if (eventName) { var propertySymbol = Zone.__symbol__('ON_PROPERTY' + eventName); @@ -2581,12 +2566,13 @@ function propertyDescriptorPatch(api, _global) { var ignoreProperties = _global.__Zone_ignore_on_properties; // for browsers that we can patch the descriptor: Chrome & Firefox if (isBrowser) { + var internalWindow = window; // in IE/Edge, onProp not exist in window object, but in WindowPrototype // so we need to pass WindowPrototype to check onProp exist or not - patchFilteredProperties(window, eventNames.concat(['messageerror']), ignoreProperties, Object.getPrototypeOf(window)); + patchFilteredProperties(internalWindow, eventNames.concat(['messageerror']), ignoreProperties, ObjectGetPrototypeOf(internalWindow)); patchFilteredProperties(Document.prototype, eventNames, ignoreProperties); - if (typeof window['SVGElement'] !== 'undefined') { - patchFilteredProperties(window['SVGElement'].prototype, eventNames, ignoreProperties); + if (typeof internalWindow['SVGElement'] !== 'undefined') { + patchFilteredProperties(internalWindow['SVGElement'].prototype, eventNames, ignoreProperties); } patchFilteredProperties(Element.prototype, eventNames, ignoreProperties); patchFilteredProperties(HTMLElement.prototype, eventNames, ignoreProperties); @@ -2595,11 +2581,11 @@ function propertyDescriptorPatch(api, _global) { patchFilteredProperties(HTMLBodyElement.prototype, windowEventNames.concat(frameSetEventNames), ignoreProperties); patchFilteredProperties(HTMLFrameElement.prototype, frameEventNames, ignoreProperties); patchFilteredProperties(HTMLIFrameElement.prototype, frameEventNames, ignoreProperties); - var HTMLMarqueeElement_1 = window['HTMLMarqueeElement']; + var HTMLMarqueeElement_1 = internalWindow['HTMLMarqueeElement']; if (HTMLMarqueeElement_1) { patchFilteredProperties(HTMLMarqueeElement_1.prototype, marqueeEventNames, ignoreProperties); } - var Worker_1 = window['Worker']; + var Worker_1 = internalWindow['Worker']; if (Worker_1) { patchFilteredProperties(Worker_1.prototype, workerEventNames, ignoreProperties); } @@ -2631,15 +2617,17 @@ function propertyDescriptorPatch(api, _global) { } } function canPatchViaPropertyDescriptor() { - if ((isBrowser || isMix) && !Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') && + if ((isBrowser || isMix) && !ObjectGetOwnPropertyDescriptor(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'); + var desc = ObjectGetOwnPropertyDescriptor(Element.prototype, 'onclick'); if (desc && !desc.configurable) return false; } - var xhrDesc = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'onreadystatechange'); + var ON_READY_STATE_CHANGE = 'onreadystatechange'; + var XMLHttpRequestPrototype = XMLHttpRequest.prototype; + var xhrDesc = ObjectGetOwnPropertyDescriptor(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE); // add enumerable and configurable here because in opera // by default XMLHttpRequest.prototype.onreadystatechange is undefined // without adding enumerable and configurable will cause onreadystatechange @@ -2647,7 +2635,7 @@ function canPatchViaPropertyDescriptor() { // and if XMLHttpRequest.prototype.onreadystatechange is undefined, // we should set a real desc instead a fake one if (xhrDesc) { - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', { + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, { enumerable: true, configurable: true, get: function () { @@ -2657,12 +2645,12 @@ function canPatchViaPropertyDescriptor() { var req = new XMLHttpRequest(); var result = !!req.onreadystatechange; // restore original desc - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {}); + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {}); return result; } else { - var SYMBOL_FAKE_ONREADYSTATECHANGE_1 = zoneSymbol('fakeonreadystatechange'); - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', { + var SYMBOL_FAKE_ONREADYSTATECHANGE_1 = zoneSymbol('fake'); + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, { enumerable: true, configurable: true, get: function () { @@ -2698,7 +2686,7 @@ function patchViaCapturingAllTheEvents() { } while (elt) { if (elt[onproperty] && !elt[onproperty][unboundKey]) { - bound = Zone.current.wrap(elt[onproperty], source); + bound = wrapWithCurrentZone(elt[onproperty], source); bound[unboundKey] = elt[onproperty]; elt[onproperty] = bound; } @@ -2803,7 +2791,9 @@ function eventTargetPatch(_global, api) { var type = _global[apis[i]]; apiTypes.push(type && type.prototype); } - patchEventTarget(_global, apiTypes, { validateHandler: checkIEAndCrossContext }); + // vh is validateHandler to check event handler + // is valid or not(for security check) + patchEventTarget(_global, apiTypes, { vh: checkIEAndCrossContext }); api.patchEventTarget = patchEventTarget; return true; } @@ -2828,22 +2818,23 @@ function registerElementPatch(_global) { 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); + var prototype = opts.prototype; + if (prototype.hasOwnProperty(callback)) { + var descriptor = ObjectGetOwnPropertyDescriptor(prototype, callback); if (descriptor && descriptor.value) { - descriptor.value = Zone.current.wrap(descriptor.value, source); + descriptor.value = wrapWithCurrentZone(descriptor.value, source); _redefineProperty(opts.prototype, callback, descriptor); } else { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + prototype[callback] = wrapWithCurrentZone(prototype[callback], source); } } - else if (opts.prototype[callback]) { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + else if (prototype[callback]) { + prototype[callback] = wrapWithCurrentZone(prototype[callback], source); } }); } - return _registerElement.apply(document, [name, opts]); + return _registerElement.call(document, name, opts); }; attachOriginToPatched(document.registerElement, _registerElement); } @@ -2862,21 +2853,21 @@ function registerElementPatch(_global) { Zone.__load_patch('util', function (global, Zone, api) { api.patchOnProperties = patchOnProperties; api.patchMethod = patchMethod; - api.patchArguments = patchArguments; + api.bindArguments = bindArguments; }); -Zone.__load_patch('timers', function (global, Zone, api) { +Zone.__load_patch('timers', function (global) { var set = 'set'; var clear = 'clear'; patchTimer(global, set, clear, 'Timeout'); patchTimer(global, set, clear, 'Interval'); patchTimer(global, set, clear, 'Immediate'); }); -Zone.__load_patch('requestAnimationFrame', function (global, Zone, api) { +Zone.__load_patch('requestAnimationFrame', function (global) { patchTimer(global, 'request', 'cancel', 'AnimationFrame'); patchTimer(global, 'mozRequest', 'mozCancel', 'AnimationFrame'); patchTimer(global, 'webkitRequest', 'webkitCancel', 'AnimationFrame'); }); -Zone.__load_patch('blocking', function (global, Zone, api) { +Zone.__load_patch('blocking', function (global, Zone) { var blockingMethods = ['alert', 'prompt', 'confirm']; for (var i = 0; i < blockingMethods.length; i++) { var name_1 = blockingMethods[i]; @@ -2910,17 +2901,17 @@ Zone.__load_patch('on_property', function (global, Zone, api) { propertyPatch(); registerElementPatch(global); }); -Zone.__load_patch('canvas', function (global, Zone, api) { +Zone.__load_patch('canvas', function (global) { var HTMLCanvasElement = global['HTMLCanvasElement']; if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype && HTMLCanvasElement.prototype.toBlob) { patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', function (self, args) { - return { name: 'HTMLCanvasElement.toBlob', target: self, callbackIndex: 0, args: args }; + return { name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args }; }); } }); -Zone.__load_patch('XHR', function (global, Zone, api) { - // Treat XMLHTTPRequest as a macrotask. +Zone.__load_patch('XHR', function (global, Zone) { + // Treat XMLHttpRequest as a macrotask. patchXHR(global); var XHR_TASK = zoneSymbol('xhrTask'); var XHR_SYNC = zoneSymbol('xhrSync'); @@ -2928,19 +2919,18 @@ Zone.__load_patch('XHR', function (global, Zone, api) { var XHR_SCHEDULED = zoneSymbol('xhrScheduled'); var XHR_URL = zoneSymbol('xhrURL'); function patchXHR(window) { + var XMLHttpRequestPrototype = XMLHttpRequest.prototype; function findPendingTask(target) { - var pendingTask = target[XHR_TASK]; - return pendingTask; + return target[XHR_TASK]; } - var SYMBOL_ADDEVENTLISTENER = zoneSymbol('addEventListener'); - var SYMBOL_REMOVEEVENTLISTENER = zoneSymbol('removeEventListener'); - var oriAddListener = XMLHttpRequest.prototype[SYMBOL_ADDEVENTLISTENER]; - var oriRemoveListener = XMLHttpRequest.prototype[SYMBOL_REMOVEEVENTLISTENER]; + var oriAddListener = XMLHttpRequestPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + var oriRemoveListener = XMLHttpRequestPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; if (!oriAddListener) { var XMLHttpRequestEventTarget = window['XMLHttpRequestEventTarget']; if (XMLHttpRequestEventTarget) { - oriAddListener = XMLHttpRequestEventTarget.prototype[SYMBOL_ADDEVENTLISTENER]; - oriRemoveListener = XMLHttpRequestEventTarget.prototype[SYMBOL_REMOVEEVENTLISTENER]; + var XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget.prototype; + oriAddListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + oriRemoveListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; } } var READY_STATE_CHANGE = 'readystatechange'; @@ -2952,11 +2942,11 @@ Zone.__load_patch('XHR', function (global, Zone, api) { // remove existing event listener var listener = target[XHR_LISTENER]; if (!oriAddListener) { - oriAddListener = target[SYMBOL_ADDEVENTLISTENER]; - oriRemoveListener = target[SYMBOL_REMOVEEVENTLISTENER]; + oriAddListener = target[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + oriRemoveListener = target[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; } if (listener) { - oriRemoveListener.apply(target, [READY_STATE_CHANGE, listener]); + oriRemoveListener.call(target, READY_STATE_CHANGE, listener); } var newListener = target[XHR_LISTENER] = function () { if (target.readyState === target.DONE) { @@ -2967,7 +2957,7 @@ Zone.__load_patch('XHR', function (global, Zone, api) { } } }; - oriAddListener.apply(target, [READY_STATE_CHANGE, newListener]); + oriAddListener.call(target, READY_STATE_CHANGE, newListener); var storedTask = target[XHR_TASK]; if (!storedTask) { target[XHR_TASK] = task; @@ -2984,14 +2974,13 @@ Zone.__load_patch('XHR', function (global, Zone, api) { data.aborted = true; return abortNative.apply(data.target, data.args); } - var openNative = patchMethod(window.XMLHttpRequest.prototype, 'open', function () { return function (self, args) { + var openNative = patchMethod(XMLHttpRequestPrototype, 'open', function () { return function (self, args) { self[XHR_SYNC] = args[2] == false; self[XHR_URL] = args[1]; return openNative.apply(self, args); }; }); var XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send'; - var sendNative = patchMethod(window.XMLHttpRequest.prototype, 'send', function () { return function (self, args) { - var zone = Zone.current; + var sendNative = patchMethod(XMLHttpRequestPrototype, 'send', function () { return function (self, args) { if (self[XHR_SYNC]) { // if the XHR is sync there is no task to schedule, just execute the code. return sendNative.apply(self, args); @@ -3005,13 +2994,12 @@ Zone.__load_patch('XHR', function (global, Zone, api) { args: args, aborted: false }; - return zone.scheduleMacroTask(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask); + return scheduleMacroTaskWithCurrentZone(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask); } }; }); - var STRING_TYPE = 'string'; - var abortNative = patchMethod(window.XMLHttpRequest.prototype, 'abort', function (delegate) { return function (self, args) { + var abortNative = patchMethod(XMLHttpRequestPrototype, 'abort', function () { return function (self) { var task = findPendingTask(self); - if (task && typeof task.type == STRING_TYPE) { + if (task && typeof task.type == 'string') { // If the XHR has already completed, do nothing. // If the XHR has already been aborted, do nothing. // Fix #569, call abort multiple times before done will cause @@ -3027,19 +3015,13 @@ Zone.__load_patch('XHR', function (global, Zone, api) { }; }); } }); -Zone.__load_patch('geolocation', function (global, Zone, api) { +Zone.__load_patch('geolocation', function (global) { /// GEO_LOCATION if (global['navigator'] && global['navigator'].geolocation) { patchPrototype(global['navigator'].geolocation, ['getCurrentPosition', 'watchPosition']); } }); -Zone.__load_patch('getUserMedia', function (global, Zone, api) { - var navigator = global['navigator']; - if (navigator && navigator.getUserMedia) { - navigator.getUserMedia = wrapFunctionArgs(navigator.getUserMedia); - } -}); -Zone.__load_patch('PromiseRejectionEvent', function (global, Zone, api) { +Zone.__load_patch('PromiseRejectionEvent', function (global, Zone) { // handle unhandled promise rejection function findPromiseRejectionHandler(evtName) { return function (e) { @@ -3718,7 +3700,7 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; this.pendingTimers = []; this.properties = { 'FakeAsyncTestZoneSpec': this }; this.name = 'fakeAsyncTestZone for ' + namePrefix; - // in case user can't access the construction of FakyAsyncTestSpec + // in case user can't access the construction of FakeAsyncTestSpec // user can also define macroTaskOptions by define a global variable. if (!this.macroTaskOptions) { this.macroTaskOptions = global[Zone.__symbol__('FakeAsyncTestMacroTask')]; @@ -3860,16 +3842,16 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; // should pass additional arguments to callback if have any // currently we know process.nextTick will have such additional // arguments - var addtionalArgs = void 0; + var additionalArgs = void 0; if (args) { - var callbackIndex = task.data.callbackIndex; + var callbackIndex = task.data.cbIdx; if (typeof args.length === 'number' && args.length > callbackIndex + 1) { - addtionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); + additionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); } } this._microtasks.push({ func: task.invoke, - args: addtionalArgs, + args: additionalArgs, target: task.data && task.data.target }); break; @@ -3907,7 +3889,7 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; task.data.isPeriodic = true; } else { - // not periodic, use setTimout to simulate + // not periodic, use setTimeout to simulate task.data['handleId'] = this._setTimeout(task.invoke, delay, callbackArgs); } break; diff --git a/dist/zone-testing-node-bundle.js b/dist/zone-testing-node-bundle.js index bfa92e32f..cd1f3f47b 100644 --- a/dist/zone-testing-node-bundle.js +++ b/dist/zone-testing-node-bundle.js @@ -476,12 +476,13 @@ var Zone$1 = (function (global) { this.cancelFn = cancelFn; this.callback = callback; var self = this; - if (type === eventTask && options && options.isUsingGlobalCallback) { + // TODO: @JiaLiPassion options should have interface + if (type === eventTask && options && options.useG) { this.invoke = ZoneTask.invokeTask; } else { this.invoke = function () { - return ZoneTask.invokeTask.apply(global, [self, this, arguments]); + return ZoneTask.invokeTask.call(global, self, this, arguments); }; } } @@ -598,7 +599,6 @@ var Zone$1 = (function (global) { } } } - var showError = !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; _api.microtaskDrainDone(); _isDrainingMicrotaskQueue = false; } @@ -622,7 +622,7 @@ var Zone$1 = (function (global) { patchEventTarget: function () { return []; }, patchOnProperties: noop, patchMethod: function () { return noop; }, - patchArguments: function () { return noop; }, + bindArguments: function () { return null; }, setNativePromise: function (NativePromise) { // sometimes NativePromise.resolve static function // is not ready yet, (such as core-js/es6.promise) @@ -661,6 +661,8 @@ var __values = (undefined && undefined.__values) || function (o) { * found in the LICENSE file at https://angular.io/license */ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { + var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ObjectDefineProperty = Object.defineProperty; function readableObjectToString(obj) { if (obj && obj.toString === Object.prototype.toString) { var className = obj.constructor && obj.constructor.name; @@ -708,7 +710,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { try { var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL]; if (handler && typeof handler === 'function') { - handler.apply(this, [e]); + handler.call(this, e); } } catch (err) { @@ -754,8 +756,6 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { }; }; var TYPE_ERROR = 'Promise resolved with itself'; - var OBJECT = 'object'; - var FUNCTION = 'function'; var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace'); // Promise Resolution function resolvePromise(promise, state, value) { @@ -767,7 +767,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // should only get value.then once based on promise spec. var then = null; try { - if (typeof value === OBJECT || typeof value === FUNCTION) { + if (typeof value === 'object' || typeof value === 'function') { then = value && value.then; } } @@ -784,11 +784,9 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { clearRejectedNoCatch(value); resolvePromise(promise, value[symbolState], value[symbolValue]); } - else if (state !== REJECTED && typeof then === FUNCTION) { + else if (state !== REJECTED && typeof then === 'function') { try { - then.apply(value, [ - onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)) - ]); + then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false))); } catch (err) { onceWrapper(function () { @@ -808,7 +806,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { Zone.currentTask.data[creationTrace]; if (trace) { // only keep the long stack trace into error when in longStackTraceZone - Object.defineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); + ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); } } for (var i = 0; i < queue.length;) { @@ -846,8 +844,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // eventHandler try { var handler = Zone[REJECTION_HANDLED_HANDLER]; - if (handler && typeof handler === FUNCTION) { - handler.apply(this, [{ rejection: promise[symbolValue], promise: promise }]); + if (handler && typeof handler === 'function') { + handler.call(this, { rejection: promise[symbolValue], promise: promise }); } } catch (err) { @@ -863,8 +861,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) { clearRejectedNoCatch(promise); var delegate = promise[symbolState] ? - (typeof onFulfilled === FUNCTION) ? onFulfilled : forwardResolution : - (typeof onRejected === FUNCTION) ? onRejected : forwardRejection; + (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution : + (typeof onRejected === 'function') ? onRejected : forwardRejection; zone.scheduleMicroTask(source, function () { try { resolvePromise(chainPromise, true, zone.run(delegate, undefined, [promise[symbolValue]])); @@ -992,7 +990,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { ZoneAwarePromise['all'] = ZoneAwarePromise.all; var NativePromise = global[symbolPromise] = global['Promise']; var ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise'); - var desc = Object.getOwnPropertyDescriptor(global, 'Promise'); + var desc = ObjectGetOwnPropertyDescriptor(global, 'Promise'); if (!desc || desc.configurable) { desc && delete desc.writable; desc && delete desc.value; @@ -1025,7 +1023,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { api.setNativePromise(NewNativePromise); } }; - Object.defineProperty(global, 'Promise', desc); + ObjectDefineProperty(global, 'Promise', desc); } global['Promise'] = ZoneAwarePromise; var symbolThenPatched = __symbol__('thenPatched'); @@ -1034,11 +1032,11 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { var originalThen = proto.then; // Keep a reference to the original method. proto[symbolThen] = originalThen; - // check Ctor.prototype.then propertyDescritor is writable or not + // check Ctor.prototype.then propertyDescriptor is writable or not // in meteor env, writable is false, we have to make it to be true. - var prop = Object.getOwnPropertyDescriptor(Ctor.prototype, 'then'); + var prop = ObjectGetOwnPropertyDescriptor(Ctor.prototype, 'then'); if (prop && prop.writable === false && prop.configurable) { - Object.defineProperty(Ctor.prototype, 'then', { writable: true }); + ObjectDefineProperty(Ctor.prototype, 'then', { writable: true }); } Ctor.prototype.then = function (onResolve, onReject) { var _this = this; @@ -1065,7 +1063,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { if (NativePromise) { patchThen(NativePromise); var fetch_1 = global['fetch']; - if (typeof fetch_1 == FUNCTION) { + if (typeof fetch_1 == 'function') { global['fetch'] = zoneify(fetch_1); } } @@ -1086,27 +1084,58 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { * @fileoverview * @suppress {undefinedVars,globalThis,missingRequire} */ +// issue #989, to reduce bundle size, use short name +/** Object.getOwnPropertyDescriptor */ +/** + * @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 ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; +/** Object.defineProperty */ +var ObjectDefineProperty = Object.defineProperty; +/** Object.getPrototypeOf */ +var ObjectGetPrototypeOf = Object.getPrototypeOf; +/** Object.create */ + +/** Array.prototype.slice */ +var ArraySlice = Array.prototype.slice; +/** addEventListener string const */ +var ADD_EVENT_LISTENER_STR = 'addEventListener'; +/** removeEventListener string const */ +var REMOVE_EVENT_LISTENER_STR = 'removeEventListener'; +/** zoneSymbol addEventListener */ +var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR); +/** zoneSymbol removeEventListener */ +var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR); +/** true string const */ +var TRUE_STR = 'true'; +/** false string const */ +var FALSE_STR = 'false'; +/** __zone_symbol__ string const */ +var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; +function wrapWithCurrentZone(callback, source) { + return Zone.current.wrap(callback, source); +} +function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) { + return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel); +} var zoneSymbol = Zone.__symbol__; -var _global = typeof window === 'object' && window || typeof self === 'object' && self || global; -var FUNCTION = 'function'; -var UNDEFINED = 'undefined'; +var isWindowExists = typeof window !== 'undefined'; +var internalWindow = isWindowExists ? window : undefined; +var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global; var REMOVE_ATTRIBUTE = 'removeAttribute'; var NULL_ON_PROP_VALUE = [null]; function bindArguments(args, source) { for (var i = args.length - 1; i >= 0; i--) { - if (typeof args[i] === FUNCTION) { - args[i] = Zone.current.wrap(args[i], source + '_' + i); + if (typeof args[i] === 'function') { + args[i] = wrapWithCurrentZone(args[i], source + '_' + i); } } return args; } -function patchArguments(target, name, source) { - return patchMethod(target, name, function (delegate, delegateName, name) { return function (self, args) { - return delegate && delegate.apply(self, bindArguments(args, source)); - }; }); -} - function isPropertyWritable(propertyDesc) { if (!propertyDesc) { return true; @@ -1114,23 +1143,20 @@ function isPropertyWritable(propertyDesc) { if (propertyDesc.writable === false) { return false; } - if (typeof propertyDesc.get === FUNCTION && typeof propertyDesc.set === UNDEFINED) { - return false; - } - return true; + return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined'); } var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope); -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]'); // we are in electron of nw, so we are both browser and nodejs -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isMix = typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]' && !isWebWorker && - !!(typeof window !== 'undefined' && window['HTMLElement']); + !!(isWindowExists && internalWindow['HTMLElement']); var zoneSymbolEventNames = {}; var wrapFn = function (event) { // https://github.com/angular/zone.js/issues/911, in IE, sometimes @@ -1152,10 +1178,10 @@ var wrapFn = function (event) { return result; }; function patchProperty(obj, prop, prototype) { - var desc = Object.getOwnPropertyDescriptor(obj, prop); + var desc = ObjectGetOwnPropertyDescriptor(obj, prop); if (!desc && prototype) { // when patch window object, use prototype to check prop exist or not - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, prop); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop); if (prototypeDesc) { desc = { enumerable: true, configurable: true }; } @@ -1230,10 +1256,10 @@ function patchProperty(obj, prop, prototype) { // the onclick will be evaluated when first time event was triggered or // the property is accessed, https://github.com/angular/zone.js/issues/525 // so we should use original native get to retrieve the handler - var value = originalDescGet && originalDescGet.apply(this); + var value = originalDescGet && originalDescGet.call(this); if (value) { - desc.set.apply(this, [value]); - if (typeof target[REMOVE_ATTRIBUTE] === FUNCTION) { + desc.set.call(this, value); + if (typeof target[REMOVE_ATTRIBUTE] === 'function') { target.removeAttribute(prop); } return value; @@ -1241,7 +1267,7 @@ function patchProperty(obj, prop, prototype) { } return null; }; - Object.defineProperty(obj, prop, desc); + ObjectDefineProperty(obj, prop, desc); } function patchOnProperties(obj, properties, prototype) { if (properties) { @@ -1267,7 +1293,7 @@ var originalInstanceKey = zoneSymbol('originalInstance'); function patchMethod(target, name, patchFn) { var proto = target; while (proto && !proto.hasOwnProperty(name)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && target[name]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1279,7 +1305,7 @@ function patchMethod(target, name, patchFn) { delegate = proto[delegateName] = proto[name]; // check whether proto[name] is writable // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob - var desc = proto && Object.getOwnPropertyDescriptor(proto, name); + var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name); if (isPropertyWritable(desc)) { var patchDelegate_1 = patchFn(delegate, delegateName, name); proto[name] = function () { @@ -1295,7 +1321,7 @@ function patchMacroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1303,9 +1329,8 @@ function patchMacroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMacroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask, null); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask, null); } else { // cause an error by calling it directly. @@ -1317,7 +1342,7 @@ function patchMicroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1325,9 +1350,8 @@ function patchMicroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMicroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask); } else { // cause an error by calling it directly. @@ -1348,19 +1372,18 @@ function attachOriginToPatched(patched, original) { */ // override Function.prototype.toString to make zone.js patched function // look like native function -Zone.__load_patch('toString', function (global, Zone, api) { +Zone.__load_patch('toString', function (global, Zone) { // patch Func.prototype.toString to let them look like native var originalFunctionToString = Zone['__zone_symbol__originalToString'] = Function.prototype.toString; - var FUNCTION = 'function'; var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate'); var PROMISE_SYMBOL = zoneSymbol('Promise'); var ERROR_SYMBOL = zoneSymbol('Error'); Function.prototype.toString = function () { - if (typeof this === FUNCTION) { + if (typeof this === 'function') { var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL]; if (originalDelegate) { - if (typeof originalDelegate === FUNCTION) { + if (typeof originalDelegate === 'function') { return originalFunctionToString.apply(this[ORIGINAL_DELEGATE_SYMBOL], arguments); } else { @@ -1404,25 +1427,19 @@ Zone.__load_patch('toString', function (global, Zone, api) { * @fileoverview * @suppress {missingRequire} */ -var TRUE_STR = 'true'; -var FALSE_STR = 'false'; // an identifier to tell ZoneTask do not create a new invoke closure var OPTIMIZED_ZONE_EVENT_TASK_DATA = { - isUsingGlobalCallback: true + useG: true }; var zoneSymbolEventNames$1 = {}; var globalSources = {}; -var CONSTRUCTOR_NAME = 'name'; -var FUNCTION_TYPE = 'function'; -var OBJECT_TYPE = 'object'; -var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; var EVENT_NAME_SYMBOL_REGX = /^__zone_symbol__(\w+)(true|false)$/; var IMMEDIATE_PROPAGATION_SYMBOL = ('__zone_symbol__propagationStopped'); function patchEventTarget(_global, apis, patchOptions) { - var ADD_EVENT_LISTENER = (patchOptions && patchOptions.addEventListenerFnName) || 'addEventListener'; - var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.removeEventListenerFnName) || 'removeEventListener'; - var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listenersFnName) || 'eventListeners'; - var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.removeAllFnName) || 'removeAllListeners'; + var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR; + var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR; + var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners'; + var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners'; var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER); var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':'; var PREPEND_EVENT_LISTENER = 'prependListener'; @@ -1434,7 +1451,7 @@ function patchEventTarget(_global, apis, patchOptions) { return; } var delegate = task.callback; - if (typeof delegate === OBJECT_TYPE && delegate.handleEvent) { + if (typeof delegate === 'object' && delegate.handleEvent) { // create the bind version of handleEvent when invoke task.callback = function (event) { return delegate.handleEvent(event); }; task.originalDelegate = delegate; @@ -1447,7 +1464,7 @@ function patchEventTarget(_global, apis, patchOptions) { // only browser need to do this, nodejs eventEmitter will cal removeListener // inside EventEmitter.once var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback; - target[REMOVE_EVENT_LISTENER].apply(target, [event.type, delegate_1, options]); + target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options); } }; // global shared zoneAwareCallback to handle all event callback with capture = false @@ -1458,7 +1475,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]]; @@ -1490,7 +1507,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]]; @@ -1519,21 +1536,21 @@ function patchEventTarget(_global, apis, patchOptions) { return false; } var useGlobalCallback = true; - if (patchOptions && patchOptions.useGlobalCallback !== undefined) { - useGlobalCallback = patchOptions.useGlobalCallback; + if (patchOptions && patchOptions.useG !== undefined) { + useGlobalCallback = patchOptions.useG; } - var validateHandler = patchOptions && patchOptions.validateHandler; + var validateHandler = patchOptions && patchOptions.vh; var checkDuplicate = true; - if (patchOptions && patchOptions.checkDuplicate !== undefined) { - checkDuplicate = patchOptions.checkDuplicate; + if (patchOptions && patchOptions.chkDup !== undefined) { + checkDuplicate = patchOptions.chkDup; } var returnTarget = false; - if (patchOptions && patchOptions.returnTarget !== undefined) { - returnTarget = patchOptions.returnTarget; + if (patchOptions && patchOptions.rt !== undefined) { + returnTarget = patchOptions.rt; } var proto = obj; while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && obj[ADD_EVENT_LISTENER]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1556,21 +1573,17 @@ function patchEventTarget(_global, apis, patchOptions) { var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] = proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER]; var nativePrependEventListener; - if (patchOptions && patchOptions.prependEventListenerFnName) { - nativePrependEventListener = proto[zoneSymbol(patchOptions.prependEventListenerFnName)] = - proto[patchOptions.prependEventListenerFnName]; + if (patchOptions && patchOptions.prepend) { + nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] = + proto[patchOptions.prepend]; } - var customScheduleGlobal = function (task) { + var customScheduleGlobal = function () { // if there is already a task for the eventName + capture, // just return, because we use the shared globalZoneAwareCallback here. if (taskData.isExisting) { return; } - return nativeAddEventListener.apply(taskData.target, [ - taskData.eventName, - taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - taskData.options - ]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options); }; var customCancelGlobal = function (task) { // if task is not marked as isRemoved, this call is directly @@ -1607,41 +1620,31 @@ function patchEventTarget(_global, apis, patchOptions) { if (!task.allRemoved) { return; } - return nativeRemoveEventListener.apply(task.target, [ - task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - task.options - ]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options); }; var customScheduleNonGlobal = function (task) { - return nativeAddEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customSchedulePrepend = function (task) { - return nativePrependEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customCancelNonGlobal = function (task) { - return nativeRemoveEventListener.apply(task.target, [task.eventName, task.invoke, task.options]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options); }; var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal; var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal; var compareTaskCallbackVsDelegate = function (task, delegate) { var typeOfDelegate = typeof delegate; - if ((typeOfDelegate === FUNCTION_TYPE && task.callback === delegate) || - (typeOfDelegate === OBJECT_TYPE && task.originalDelegate === delegate)) { - // same callback, same capture, same event name, just return - return true; - } - return false; + return (typeOfDelegate === 'function' && task.callback === delegate) || + (typeOfDelegate === 'object' && task.originalDelegate === delegate); }; - var compare = (patchOptions && patchOptions.compareTaskCallbackVsDelegate) ? - patchOptions.compareTaskCallbackVsDelegate : - compareTaskCallbackVsDelegate; + var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate; var blackListedEvents = Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')]; var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) { if (returnTarget === void 0) { returnTarget = false; } if (prepend === void 0) { prepend = false; } return function () { var target = this || _global; - var targetZone = Zone.current; var delegate = arguments[1]; if (!delegate) { return nativeListener.apply(this, arguments); @@ -1650,7 +1653,7 @@ function patchEventTarget(_global, apis, patchOptions) { // case here to improve addEventListener performance // we will create the bind delegate when invoke var isHandleEvent = false; - if (typeof delegate !== FUNCTION_TYPE) { + if (typeof delegate !== 'function') { if (!delegate.handleEvent) { return nativeListener.apply(this, arguments); } @@ -1719,7 +1722,7 @@ function patchEventTarget(_global, apis, patchOptions) { existingTasks = target[symbolEventName] = []; } var source; - var constructorName = target.constructor[CONSTRUCTOR_NAME]; + var constructorName = target.constructor['name']; var targetSource = globalSources[constructorName]; if (targetSource) { source = targetSource[eventName]; @@ -1741,7 +1744,7 @@ function patchEventTarget(_global, apis, patchOptions) { taskData.eventName = eventName; taskData.isExisting = isExisting; var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null; - // keep taskData into data to allow onScheduleEventTask to acess the task information + // keep taskData into data to allow onScheduleEventTask to access the task information if (data) { data.taskData = taskData; } @@ -1815,7 +1818,6 @@ function patchEventTarget(_global, apis, patchOptions) { if (existingTasks) { for (var i = 0; i < existingTasks.length; i++) { var existingTask = existingTasks[i]; - var typeOfDelegate = typeof delegate; if (compare(existingTask, delegate)) { existingTasks.splice(i, 1); // set isRemoved to data for faster invokeTask check @@ -1863,11 +1865,11 @@ function patchEventTarget(_global, apis, patchOptions) { // so just keep removeListener eventListener until // all other eventListeners are removed if (evtName && evtName !== 'removeListener') { - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, [evtName]); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName); } } // remove removeListener listener finally - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, ['removeListener']); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener'); } else { var symbolEventNames = zoneSymbolEventNames$1[eventName]; @@ -1881,7 +1883,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } if (captureTasks) { @@ -1889,7 +1891,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } } @@ -1936,13 +1938,7 @@ function findEventTasks(target, eventName) { * 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 */ -Zone.__load_patch('EventEmitter', function (global, Zone, api) { - var callAndReturnFirstParam = function (fn) { - return function (self, args) { - fn(self, args); - return self; - }; - }; +Zone.__load_patch('EventEmitter', function (global) { // For EventEmitter var EE_ADD_LISTENER = 'addListener'; var EE_PREPEND_LISTENER = 'prependListener'; @@ -1951,23 +1947,20 @@ Zone.__load_patch('EventEmitter', function (global, Zone, api) { var EE_LISTENERS = 'listeners'; var EE_ON = 'on'; var compareTaskCallbackVsDelegate = function (task, delegate) { - if (task.callback === delegate || task.callback.listener === delegate) { - // same callback, same capture, same event name, just return - return true; - } - return false; + // same callback, same capture, same event name, just return + return task.callback === delegate || task.callback.listener === delegate; }; function patchEventEmitterMethods(obj) { var result = patchEventTarget(global, [obj], { - useGlobalCallback: false, - addEventListenerFnName: EE_ADD_LISTENER, - removeEventListenerFnName: EE_REMOVE_LISTENER, - prependEventListenerFnName: EE_PREPEND_LISTENER, - removeAllFnName: EE_REMOVE_ALL_LISTENER, - listenersFnName: EE_LISTENERS, - checkDuplicate: false, - returnTarget: true, - compareTaskCallbackVsDelegate: compareTaskCallbackVsDelegate + useG: false, + add: EE_ADD_LISTENER, + rm: EE_REMOVE_LISTENER, + prepend: EE_PREPEND_LISTENER, + rmAll: EE_REMOVE_ALL_LISTENER, + listeners: EE_LISTENERS, + chkDup: false, + rt: true, + diff: compareTaskCallbackVsDelegate }); if (result && result[0]) { obj[EE_ON] = obj[EE_ADD_LISTENER]; @@ -1992,7 +1985,7 @@ Zone.__load_patch('EventEmitter', function (global, Zone, api) { * 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 */ -Zone.__load_patch('fs', function (global, Zone, api) { +Zone.__load_patch('fs', function () { var fs; try { fs = require('fs'); @@ -2015,7 +2008,7 @@ Zone.__load_patch('fs', function (global, Zone, api) { return { name: 'fs.' + name, args: args, - callbackIndex: args.length > 0 ? args.length - 1 : -1, + cbIdx: args.length > 0 ? args.length - 1 : -1, target: self }; }); @@ -2041,12 +2034,6 @@ function patchTimer(window, setName, cancelName, nameSuffix) { setName += nameSuffix; cancelName += nameSuffix; var tasksByHandleId = {}; - var NUMBER = 'number'; - var STRING = 'string'; - var FUNCTION = 'function'; - var INTERVAL = 'Interval'; - var TIMEOUT = 'Timeout'; - var NOT_SCHEDULED = 'notScheduled'; function scheduleTask(task) { var data = task.data; function timer() { @@ -2054,21 +2041,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task.invoke.apply(this, arguments); } finally { - if (task.data && task.data.isPeriodic) { - // issue-934, task will be cancelled - // even it is a periodic task such as - // setInterval - return; - } - if (typeof data.handleId === NUMBER) { - // in non-nodejs env, we remove timerId - // from local cache - delete tasksByHandleId[data.handleId]; - } - else if (data.handleId) { - // Node returns complex objects as handleIds - // we remove task reference from timer object - data.handleId[taskSymbol] = null; + // issue-934, task will be cancelled + // even it is a periodic task such as + // setInterval + if (!(task.data && task.data.isPeriodic)) { + if (typeof data.handleId === 'number') { + // in non-nodejs env, we remove timerId + // from local cache + delete tasksByHandleId[data.handleId]; + } + else if (data.handleId) { + // Node returns complex objects as handleIds + // we remove task reference from timer object + data.handleId[taskSymbol] = null; + } } } } @@ -2081,21 +2067,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } setNative = patchMethod(window, setName, function (delegate) { return function (self, args) { - if (typeof args[0] === FUNCTION) { - var zone = Zone.current; + if (typeof args[0] === 'function') { var options = { handleId: null, - isPeriodic: nameSuffix === INTERVAL, - delay: (nameSuffix === TIMEOUT || nameSuffix === INTERVAL) ? args[1] || 0 : 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); + var task = scheduleMacroTaskWithCurrentZone(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 (typeof handle === NUMBER) { + if (typeof handle === 'number') { // for non nodejs env, we save handleId: task // mapping in local cache for clearTimeout tasksByHandleId[handle] = task; @@ -2107,12 +2092,12 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } // check whether handle is null, because some polyfill or browser // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame - if (handle && handle.ref && handle.unref && typeof handle.ref === FUNCTION && - typeof handle.unref === FUNCTION) { + if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' && + typeof handle.unref === 'function') { task.ref = handle.ref.bind(handle); task.unref = handle.unref.bind(handle); } - if (typeof handle === NUMBER || handle) { + if (typeof handle === 'number' || handle) { return handle; } return task; @@ -2126,7 +2111,7 @@ function patchTimer(window, setName, cancelName, nameSuffix) { patchMethod(window, cancelName, function (delegate) { return function (self, args) { var id = args[0]; var task; - if (typeof id === NUMBER) { + if (typeof id === 'number') { // non nodejs env. task = tasksByHandleId[id]; } @@ -2138,10 +2123,10 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task = id; } } - if (task && typeof task.type === STRING) { - if (task.state !== NOT_SCHEDULED && + if (task && typeof task.type === 'string') { + if (task.state !== 'notScheduled' && (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) { - if (typeof id === NUMBER) { + if (typeof id === 'number') { delete tasksByHandleId[id]; } else if (id) { @@ -2170,9 +2155,9 @@ var clear = 'clear'; Zone.__load_patch('node_util', function (global, Zone, api) { api.patchOnProperties = patchOnProperties; api.patchMethod = patchMethod; - api.patchArguments = patchArguments; + api.bindArguments = bindArguments; }); -Zone.__load_patch('node_timers', function (global, Zone, api) { +Zone.__load_patch('node_timers', function (global, Zone) { // Timers var globalUseTimeoutFromTimer = false; try { @@ -2198,7 +2183,7 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { patchTimer(timers, set, clear, 'Immediate'); } catch (error) { - // timers module not exists, for example, when we using nativescript + // timers module not exists, for example, when we using nativeScript // timers is not available } if (isMix) { @@ -2217,7 +2202,7 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { } else { // global use timers setTimeout, but not equals - // this happenes when use nodejs v0.10.x, global setTimeout will + // this happens when use nodejs v0.10.x, global setTimeout will // use a lazy load version of timers setTimeout // we should not double patch timer's setTimeout // so we only store the __symbol__ for consistency @@ -2227,13 +2212,13 @@ Zone.__load_patch('node_timers', function (global, Zone, api) { } }); // patch process related methods -Zone.__load_patch('nextTick', function (global, Zone, api) { +Zone.__load_patch('nextTick', function () { // patch nextTick as microTask patchMicroTask(process, 'nextTick', function (self, args) { return { name: 'process.nextTick', args: args, - callbackIndex: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1, + cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1, target: process }; }); @@ -2261,7 +2246,7 @@ Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api } }); // Crypto -Zone.__load_patch('crypto', function (global, Zone, api) { +Zone.__load_patch('crypto', function () { var crypto; try { crypto = require('crypto'); @@ -2276,7 +2261,7 @@ Zone.__load_patch('crypto', function (global, Zone, api) { return { name: 'crypto.' + name, args: args, - callbackIndex: (args.length > 0 && typeof args[args.length - 1] === 'function') ? + cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ? args.length - 1 : -1, target: crypto @@ -2285,13 +2270,13 @@ Zone.__load_patch('crypto', function (global, Zone, api) { }); } }); -Zone.__load_patch('console', function (global, Zone, api) { +Zone.__load_patch('console', function (global, Zone) { var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace']; consoleMethods.forEach(function (m) { var originalMethod = console[Zone.__symbol__(m)] = console[m]; if (originalMethod) { console[m] = function () { - var args = Array.prototype.slice.call(arguments); + var args = ArraySlice.call(arguments); if (Zone.current === Zone.root) { return originalMethod.apply(this, args); } @@ -2958,7 +2943,7 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; this.pendingTimers = []; this.properties = { 'FakeAsyncTestZoneSpec': this }; this.name = 'fakeAsyncTestZone for ' + namePrefix; - // in case user can't access the construction of FakyAsyncTestSpec + // in case user can't access the construction of FakeAsyncTestSpec // user can also define macroTaskOptions by define a global variable. if (!this.macroTaskOptions) { this.macroTaskOptions = global[Zone.__symbol__('FakeAsyncTestMacroTask')]; @@ -3100,16 +3085,16 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; // should pass additional arguments to callback if have any // currently we know process.nextTick will have such additional // arguments - var addtionalArgs = void 0; + var additionalArgs = void 0; if (args) { - var callbackIndex = task.data.callbackIndex; + var callbackIndex = task.data.cbIdx; if (typeof args.length === 'number' && args.length > callbackIndex + 1) { - addtionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); + additionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); } } this._microtasks.push({ func: task.invoke, - args: addtionalArgs, + args: additionalArgs, target: task.data && task.data.target }); break; @@ -3147,7 +3132,7 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; task.data.isPeriodic = true; } else { - // not periodic, use setTimout to simulate + // not periodic, use setTimeout to simulate task.data['handleId'] = this._setTimeout(task.invoke, delay, callbackArgs); } break; diff --git a/dist/zone-testing.js b/dist/zone-testing.js index b8ab642e3..1bdcad041 100644 --- a/dist/zone-testing.js +++ b/dist/zone-testing.js @@ -658,7 +658,7 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; this.pendingTimers = []; this.properties = { 'FakeAsyncTestZoneSpec': this }; this.name = 'fakeAsyncTestZone for ' + namePrefix; - // in case user can't access the construction of FakyAsyncTestSpec + // in case user can't access the construction of FakeAsyncTestSpec // user can also define macroTaskOptions by define a global variable. if (!this.macroTaskOptions) { this.macroTaskOptions = global[Zone.__symbol__('FakeAsyncTestMacroTask')]; @@ -800,16 +800,16 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; // should pass additional arguments to callback if have any // currently we know process.nextTick will have such additional // arguments - var addtionalArgs = void 0; + var additionalArgs = void 0; if (args) { - var callbackIndex = task.data.callbackIndex; + var callbackIndex = task.data.cbIdx; if (typeof args.length === 'number' && args.length > callbackIndex + 1) { - addtionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); + additionalArgs = Array.prototype.slice.call(args, callbackIndex + 1); } } this._microtasks.push({ func: task.invoke, - args: addtionalArgs, + args: additionalArgs, target: task.data && task.data.target }); break; @@ -847,7 +847,7 @@ Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec; task.data.isPeriodic = true; } else { - // not periodic, use setTimout to simulate + // not periodic, use setTimeout to simulate task.data['handleId'] = this._setTimeout(task.invoke, delay, callbackArgs); } break; diff --git a/dist/zone.js b/dist/zone.js index 3d28db64d..651ac6966 100644 --- a/dist/zone.js +++ b/dist/zone.js @@ -476,12 +476,13 @@ var Zone$1 = (function (global) { this.cancelFn = cancelFn; this.callback = callback; var self = this; - if (type === eventTask && options && options.isUsingGlobalCallback) { + // TODO: @JiaLiPassion options should have interface + if (type === eventTask && options && options.useG) { this.invoke = ZoneTask.invokeTask; } else { this.invoke = function () { - return ZoneTask.invokeTask.apply(global, [self, this, arguments]); + return ZoneTask.invokeTask.call(global, self, this, arguments); }; } } @@ -598,7 +599,6 @@ var Zone$1 = (function (global) { } } } - var showError = !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; _api.microtaskDrainDone(); _isDrainingMicrotaskQueue = false; } @@ -622,7 +622,7 @@ var Zone$1 = (function (global) { patchEventTarget: function () { return []; }, patchOnProperties: noop, patchMethod: function () { return noop; }, - patchArguments: function () { return noop; }, + bindArguments: function () { return null; }, setNativePromise: function (NativePromise) { // sometimes NativePromise.resolve static function // is not ready yet, (such as core-js/es6.promise) @@ -661,6 +661,8 @@ var __values = (undefined && undefined.__values) || function (o) { * found in the LICENSE file at https://angular.io/license */ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { + var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ObjectDefineProperty = Object.defineProperty; function readableObjectToString(obj) { if (obj && obj.toString === Object.prototype.toString) { var className = obj.constructor && obj.constructor.name; @@ -708,7 +710,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { try { var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL]; if (handler && typeof handler === 'function') { - handler.apply(this, [e]); + handler.call(this, e); } } catch (err) { @@ -754,8 +756,6 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { }; }; var TYPE_ERROR = 'Promise resolved with itself'; - var OBJECT = 'object'; - var FUNCTION = 'function'; var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace'); // Promise Resolution function resolvePromise(promise, state, value) { @@ -767,7 +767,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // should only get value.then once based on promise spec. var then = null; try { - if (typeof value === OBJECT || typeof value === FUNCTION) { + if (typeof value === 'object' || typeof value === 'function') { then = value && value.then; } } @@ -784,11 +784,9 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { clearRejectedNoCatch(value); resolvePromise(promise, value[symbolState], value[symbolValue]); } - else if (state !== REJECTED && typeof then === FUNCTION) { + else if (state !== REJECTED && typeof then === 'function') { try { - then.apply(value, [ - onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)) - ]); + then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false))); } catch (err) { onceWrapper(function () { @@ -808,7 +806,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { Zone.currentTask.data[creationTrace]; if (trace) { // only keep the long stack trace into error when in longStackTraceZone - Object.defineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); + ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace }); } } for (var i = 0; i < queue.length;) { @@ -846,8 +844,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { // eventHandler try { var handler = Zone[REJECTION_HANDLED_HANDLER]; - if (handler && typeof handler === FUNCTION) { - handler.apply(this, [{ rejection: promise[symbolValue], promise: promise }]); + if (handler && typeof handler === 'function') { + handler.call(this, { rejection: promise[symbolValue], promise: promise }); } } catch (err) { @@ -863,8 +861,8 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) { clearRejectedNoCatch(promise); var delegate = promise[symbolState] ? - (typeof onFulfilled === FUNCTION) ? onFulfilled : forwardResolution : - (typeof onRejected === FUNCTION) ? onRejected : forwardRejection; + (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution : + (typeof onRejected === 'function') ? onRejected : forwardRejection; zone.scheduleMicroTask(source, function () { try { resolvePromise(chainPromise, true, zone.run(delegate, undefined, [promise[symbolValue]])); @@ -992,7 +990,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { ZoneAwarePromise['all'] = ZoneAwarePromise.all; var NativePromise = global[symbolPromise] = global['Promise']; var ZONE_AWARE_PROMISE = Zone.__symbol__('ZoneAwarePromise'); - var desc = Object.getOwnPropertyDescriptor(global, 'Promise'); + var desc = ObjectGetOwnPropertyDescriptor(global, 'Promise'); if (!desc || desc.configurable) { desc && delete desc.writable; desc && delete desc.value; @@ -1025,7 +1023,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { api.setNativePromise(NewNativePromise); } }; - Object.defineProperty(global, 'Promise', desc); + ObjectDefineProperty(global, 'Promise', desc); } global['Promise'] = ZoneAwarePromise; var symbolThenPatched = __symbol__('thenPatched'); @@ -1034,11 +1032,11 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { var originalThen = proto.then; // Keep a reference to the original method. proto[symbolThen] = originalThen; - // check Ctor.prototype.then propertyDescritor is writable or not + // check Ctor.prototype.then propertyDescriptor is writable or not // in meteor env, writable is false, we have to make it to be true. - var prop = Object.getOwnPropertyDescriptor(Ctor.prototype, 'then'); + var prop = ObjectGetOwnPropertyDescriptor(Ctor.prototype, 'then'); if (prop && prop.writable === false && prop.configurable) { - Object.defineProperty(Ctor.prototype, 'then', { writable: true }); + ObjectDefineProperty(Ctor.prototype, 'then', { writable: true }); } Ctor.prototype.then = function (onResolve, onReject) { var _this = this; @@ -1065,7 +1063,7 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { if (NativePromise) { patchThen(NativePromise); var fetch_1 = global['fetch']; - if (typeof fetch_1 == FUNCTION) { + if (typeof fetch_1 == 'function') { global['fetch'] = zoneify(fetch_1); } } @@ -1086,39 +1084,64 @@ Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) { * @fileoverview * @suppress {undefinedVars,globalThis,missingRequire} */ +// issue #989, to reduce bundle size, use short name +/** Object.getOwnPropertyDescriptor */ +/** + * @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 ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; +/** Object.defineProperty */ +var ObjectDefineProperty = Object.defineProperty; +/** Object.getPrototypeOf */ +var ObjectGetPrototypeOf = Object.getPrototypeOf; +/** Object.create */ +var ObjectCreate = Object.create; +/** Array.prototype.slice */ +var ArraySlice = Array.prototype.slice; +/** addEventListener string const */ +var ADD_EVENT_LISTENER_STR = 'addEventListener'; +/** removeEventListener string const */ +var REMOVE_EVENT_LISTENER_STR = 'removeEventListener'; +/** zoneSymbol addEventListener */ +var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR); +/** zoneSymbol removeEventListener */ +var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR); +/** true string const */ +var TRUE_STR = 'true'; +/** false string const */ +var FALSE_STR = 'false'; +/** __zone_symbol__ string const */ +var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; +function wrapWithCurrentZone(callback, source) { + return Zone.current.wrap(callback, source); +} +function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) { + return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel); +} var zoneSymbol = Zone.__symbol__; -var _global = typeof window === 'object' && window || typeof self === 'object' && self || global; -var FUNCTION = 'function'; -var UNDEFINED = 'undefined'; +var isWindowExists = typeof window !== 'undefined'; +var internalWindow = isWindowExists ? window : undefined; +var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global; var REMOVE_ATTRIBUTE = 'removeAttribute'; var NULL_ON_PROP_VALUE = [null]; function bindArguments(args, source) { for (var i = args.length - 1; i >= 0; i--) { - if (typeof args[i] === FUNCTION) { - args[i] = Zone.current.wrap(args[i], source + '_' + i); + if (typeof args[i] === 'function') { + args[i] = wrapWithCurrentZone(args[i], source + '_' + i); } } return args; } -function wrapFunctionArgs(func, source) { - return function () { - var args = Array.prototype.slice.call(arguments); - var wrappedArgs = bindArguments(args, source ? source : func.name); - return func.apply(this, wrappedArgs); - }; -} -function patchArguments(target, name, source) { - return patchMethod(target, name, function (delegate, delegateName, name) { return function (self, args) { - return delegate && delegate.apply(self, bindArguments(args, source)); - }; }); -} function patchPrototype(prototype, fnNames) { var source = prototype.constructor['name']; var _loop_1 = function (i) { var name_1 = fnNames[i]; var delegate = prototype[name_1]; if (delegate) { - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, name_1); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, name_1); if (!isPropertyWritable(prototypeDesc)) { return "continue"; } @@ -1142,23 +1165,20 @@ function isPropertyWritable(propertyDesc) { if (propertyDesc.writable === false) { return false; } - if (typeof propertyDesc.get === FUNCTION && typeof propertyDesc.set === UNDEFINED) { - return false; - } - return true; + return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined'); } var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope); -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]'); -var isBrowser = !isNode && !isWebWorker && !!(typeof window !== 'undefined' && window['HTMLElement']); +var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']); // we are in electron of nw, so we are both browser and nodejs -// Make sure to access `process` through `_global` so that WebPack does not accidently browserify +// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify // this code. var isMix = typeof _global.process !== 'undefined' && {}.toString.call(_global.process) === '[object process]' && !isWebWorker && - !!(typeof window !== 'undefined' && window['HTMLElement']); + !!(isWindowExists && internalWindow['HTMLElement']); var zoneSymbolEventNames = {}; var wrapFn = function (event) { // https://github.com/angular/zone.js/issues/911, in IE, sometimes @@ -1180,10 +1200,10 @@ var wrapFn = function (event) { return result; }; function patchProperty(obj, prop, prototype) { - var desc = Object.getOwnPropertyDescriptor(obj, prop); + var desc = ObjectGetOwnPropertyDescriptor(obj, prop); if (!desc && prototype) { // when patch window object, use prototype to check prop exist or not - var prototypeDesc = Object.getOwnPropertyDescriptor(prototype, prop); + var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop); if (prototypeDesc) { desc = { enumerable: true, configurable: true }; } @@ -1258,10 +1278,10 @@ function patchProperty(obj, prop, prototype) { // the onclick will be evaluated when first time event was triggered or // the property is accessed, https://github.com/angular/zone.js/issues/525 // so we should use original native get to retrieve the handler - var value = originalDescGet && originalDescGet.apply(this); + var value = originalDescGet && originalDescGet.call(this); if (value) { - desc.set.apply(this, [value]); - if (typeof target[REMOVE_ATTRIBUTE] === FUNCTION) { + desc.set.call(this, value); + if (typeof target[REMOVE_ATTRIBUTE] === 'function') { target.removeAttribute(prop); } return value; @@ -1269,7 +1289,7 @@ function patchProperty(obj, prop, prototype) { } return null; }; - Object.defineProperty(obj, prop, desc); + ObjectDefineProperty(obj, prop, desc); } function patchOnProperties(obj, properties, prototype) { if (properties) { @@ -1334,10 +1354,10 @@ function patchClass(className) { }; } else { - Object.defineProperty(_global[className].prototype, prop, { + ObjectDefineProperty(_global[className].prototype, prop, { set: function (fn) { if (typeof fn === 'function') { - this[originalInstanceKey][prop] = Zone.current.wrap(fn, className + '.' + prop); + this[originalInstanceKey][prop] = wrapWithCurrentZone(fn, className + '.' + prop); // keep callback in wrapped function so we can // use it in Function.prototype.toString to return // the native one. @@ -1363,7 +1383,7 @@ function patchClass(className) { function patchMethod(target, name, patchFn) { var proto = target; while (proto && !proto.hasOwnProperty(name)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && target[name]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1375,7 +1395,7 @@ function patchMethod(target, name, patchFn) { delegate = proto[delegateName] = proto[name]; // check whether proto[name] is writable // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob - var desc = proto && Object.getOwnPropertyDescriptor(proto, name); + var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name); if (isPropertyWritable(desc)) { var patchDelegate_1 = patchFn(delegate, delegateName, name); proto[name] = function () { @@ -1391,7 +1411,7 @@ function patchMacroTask(obj, funcName, metaCreator) { var setNative = null; function scheduleTask(task) { var data = task.data; - data.args[data.callbackIndex] = function () { + data.args[data.cbIdx] = function () { task.invoke.apply(this, arguments); }; setNative.apply(data.target, data.args); @@ -1399,9 +1419,8 @@ function patchMacroTask(obj, funcName, metaCreator) { } setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) { var meta = metaCreator(self, args); - if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') { - var task = Zone.current.scheduleMacroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask, null); - return task; + if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { + return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask, null); } else { // cause an error by calling it directly. @@ -1421,8 +1440,7 @@ function isIEOrEdge() { } isDetectedIEOrEdge = true; try { - var ua = window.navigator.userAgent; - var msie = ua.indexOf('MSIE '); + var ua = internalWindow.navigator.userAgent; if (ua.indexOf('MSIE ') !== -1 || ua.indexOf('Trident/') !== -1 || ua.indexOf('Edge/') !== -1) { ieOrEdge = true; } @@ -1441,19 +1459,18 @@ function isIEOrEdge() { */ // override Function.prototype.toString to make zone.js patched function // look like native function -Zone.__load_patch('toString', function (global, Zone, api) { +Zone.__load_patch('toString', function (global, Zone) { // patch Func.prototype.toString to let them look like native var originalFunctionToString = Zone['__zone_symbol__originalToString'] = Function.prototype.toString; - var FUNCTION = 'function'; var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate'); var PROMISE_SYMBOL = zoneSymbol('Promise'); var ERROR_SYMBOL = zoneSymbol('Error'); Function.prototype.toString = function () { - if (typeof this === FUNCTION) { + if (typeof this === 'function') { var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL]; if (originalDelegate) { - if (typeof originalDelegate === FUNCTION) { + if (typeof originalDelegate === 'function') { return originalFunctionToString.apply(this[ORIGINAL_DELEGATE_SYMBOL], arguments); } else { @@ -1497,25 +1514,19 @@ Zone.__load_patch('toString', function (global, Zone, api) { * @fileoverview * @suppress {missingRequire} */ -var TRUE_STR = 'true'; -var FALSE_STR = 'false'; // an identifier to tell ZoneTask do not create a new invoke closure var OPTIMIZED_ZONE_EVENT_TASK_DATA = { - isUsingGlobalCallback: true + useG: true }; var zoneSymbolEventNames$1 = {}; var globalSources = {}; -var CONSTRUCTOR_NAME = 'name'; -var FUNCTION_TYPE = 'function'; -var OBJECT_TYPE = 'object'; -var ZONE_SYMBOL_PREFIX = '__zone_symbol__'; var EVENT_NAME_SYMBOL_REGX = /^__zone_symbol__(\w+)(true|false)$/; var IMMEDIATE_PROPAGATION_SYMBOL = ('__zone_symbol__propagationStopped'); function patchEventTarget(_global, apis, patchOptions) { - var ADD_EVENT_LISTENER = (patchOptions && patchOptions.addEventListenerFnName) || 'addEventListener'; - var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.removeEventListenerFnName) || 'removeEventListener'; - var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listenersFnName) || 'eventListeners'; - var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.removeAllFnName) || 'removeAllListeners'; + var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR; + var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR; + var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners'; + var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners'; var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER); var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':'; var PREPEND_EVENT_LISTENER = 'prependListener'; @@ -1527,7 +1538,7 @@ function patchEventTarget(_global, apis, patchOptions) { return; } var delegate = task.callback; - if (typeof delegate === OBJECT_TYPE && delegate.handleEvent) { + if (typeof delegate === 'object' && delegate.handleEvent) { // create the bind version of handleEvent when invoke task.callback = function (event) { return delegate.handleEvent(event); }; task.originalDelegate = delegate; @@ -1540,7 +1551,7 @@ function patchEventTarget(_global, apis, patchOptions) { // only browser need to do this, nodejs eventEmitter will cal removeListener // inside EventEmitter.once var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback; - target[REMOVE_EVENT_LISTENER].apply(target, [event.type, delegate_1, options]); + target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options); } }; // global shared zoneAwareCallback to handle all event callback with capture = false @@ -1551,7 +1562,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]]; @@ -1583,7 +1594,7 @@ function patchEventTarget(_global, apis, patchOptions) { if (!event) { return; } - // event.target is needed for Samusung TV and SourceBuffer + // event.target is needed for Samsung TV and SourceBuffer // || global is needed https://github.com/angular/zone.js/issues/190 var target = this || event.target || _global; var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]]; @@ -1612,21 +1623,21 @@ function patchEventTarget(_global, apis, patchOptions) { return false; } var useGlobalCallback = true; - if (patchOptions && patchOptions.useGlobalCallback !== undefined) { - useGlobalCallback = patchOptions.useGlobalCallback; + if (patchOptions && patchOptions.useG !== undefined) { + useGlobalCallback = patchOptions.useG; } - var validateHandler = patchOptions && patchOptions.validateHandler; + var validateHandler = patchOptions && patchOptions.vh; var checkDuplicate = true; - if (patchOptions && patchOptions.checkDuplicate !== undefined) { - checkDuplicate = patchOptions.checkDuplicate; + if (patchOptions && patchOptions.chkDup !== undefined) { + checkDuplicate = patchOptions.chkDup; } var returnTarget = false; - if (patchOptions && patchOptions.returnTarget !== undefined) { - returnTarget = patchOptions.returnTarget; + if (patchOptions && patchOptions.rt !== undefined) { + returnTarget = patchOptions.rt; } var proto = obj; while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) { - proto = Object.getPrototypeOf(proto); + proto = ObjectGetPrototypeOf(proto); } if (!proto && obj[ADD_EVENT_LISTENER]) { // somehow we did not find it, but we can see it. This happens on IE for Window properties. @@ -1649,21 +1660,17 @@ function patchEventTarget(_global, apis, patchOptions) { var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] = proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER]; var nativePrependEventListener; - if (patchOptions && patchOptions.prependEventListenerFnName) { - nativePrependEventListener = proto[zoneSymbol(patchOptions.prependEventListenerFnName)] = - proto[patchOptions.prependEventListenerFnName]; + if (patchOptions && patchOptions.prepend) { + nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] = + proto[patchOptions.prepend]; } - var customScheduleGlobal = function (task) { + var customScheduleGlobal = function () { // if there is already a task for the eventName + capture, // just return, because we use the shared globalZoneAwareCallback here. if (taskData.isExisting) { return; } - return nativeAddEventListener.apply(taskData.target, [ - taskData.eventName, - taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - taskData.options - ]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options); }; var customCancelGlobal = function (task) { // if task is not marked as isRemoved, this call is directly @@ -1700,41 +1707,31 @@ function patchEventTarget(_global, apis, patchOptions) { if (!task.allRemoved) { return; } - return nativeRemoveEventListener.apply(task.target, [ - task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, - task.options - ]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options); }; var customScheduleNonGlobal = function (task) { - return nativeAddEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customSchedulePrepend = function (task) { - return nativePrependEventListener.apply(taskData.target, [taskData.eventName, task.invoke, taskData.options]); + return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options); }; var customCancelNonGlobal = function (task) { - return nativeRemoveEventListener.apply(task.target, [task.eventName, task.invoke, task.options]); + return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options); }; var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal; var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal; var compareTaskCallbackVsDelegate = function (task, delegate) { var typeOfDelegate = typeof delegate; - if ((typeOfDelegate === FUNCTION_TYPE && task.callback === delegate) || - (typeOfDelegate === OBJECT_TYPE && task.originalDelegate === delegate)) { - // same callback, same capture, same event name, just return - return true; - } - return false; + return (typeOfDelegate === 'function' && task.callback === delegate) || + (typeOfDelegate === 'object' && task.originalDelegate === delegate); }; - var compare = (patchOptions && patchOptions.compareTaskCallbackVsDelegate) ? - patchOptions.compareTaskCallbackVsDelegate : - compareTaskCallbackVsDelegate; + var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate; var blackListedEvents = Zone[Zone.__symbol__('BLACK_LISTED_EVENTS')]; var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) { if (returnTarget === void 0) { returnTarget = false; } if (prepend === void 0) { prepend = false; } return function () { var target = this || _global; - var targetZone = Zone.current; var delegate = arguments[1]; if (!delegate) { return nativeListener.apply(this, arguments); @@ -1743,7 +1740,7 @@ function patchEventTarget(_global, apis, patchOptions) { // case here to improve addEventListener performance // we will create the bind delegate when invoke var isHandleEvent = false; - if (typeof delegate !== FUNCTION_TYPE) { + if (typeof delegate !== 'function') { if (!delegate.handleEvent) { return nativeListener.apply(this, arguments); } @@ -1812,7 +1809,7 @@ function patchEventTarget(_global, apis, patchOptions) { existingTasks = target[symbolEventName] = []; } var source; - var constructorName = target.constructor[CONSTRUCTOR_NAME]; + var constructorName = target.constructor['name']; var targetSource = globalSources[constructorName]; if (targetSource) { source = targetSource[eventName]; @@ -1834,7 +1831,7 @@ function patchEventTarget(_global, apis, patchOptions) { taskData.eventName = eventName; taskData.isExisting = isExisting; var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null; - // keep taskData into data to allow onScheduleEventTask to acess the task information + // keep taskData into data to allow onScheduleEventTask to access the task information if (data) { data.taskData = taskData; } @@ -1908,7 +1905,6 @@ function patchEventTarget(_global, apis, patchOptions) { if (existingTasks) { for (var i = 0; i < existingTasks.length; i++) { var existingTask = existingTasks[i]; - var typeOfDelegate = typeof delegate; if (compare(existingTask, delegate)) { existingTasks.splice(i, 1); // set isRemoved to data for faster invokeTask check @@ -1956,11 +1952,11 @@ function patchEventTarget(_global, apis, patchOptions) { // so just keep removeListener eventListener until // all other eventListeners are removed if (evtName && evtName !== 'removeListener') { - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, [evtName]); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName); } } // remove removeListener listener finally - this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].apply(this, ['removeListener']); + this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener'); } else { var symbolEventNames = zoneSymbolEventNames$1[eventName]; @@ -1974,7 +1970,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } if (captureTasks) { @@ -1982,7 +1978,7 @@ function patchEventTarget(_global, apis, patchOptions) { for (var i = 0; i < removeTasks.length; i++) { var task = removeTasks[i]; var delegate = task.originalDelegate ? task.originalDelegate : task.callback; - this[REMOVE_EVENT_LISTENER].apply(this, [eventName, delegate, task.options]); + this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options); } } } @@ -2052,12 +2048,6 @@ function patchTimer(window, setName, cancelName, nameSuffix) { setName += nameSuffix; cancelName += nameSuffix; var tasksByHandleId = {}; - var NUMBER = 'number'; - var STRING = 'string'; - var FUNCTION = 'function'; - var INTERVAL = 'Interval'; - var TIMEOUT = 'Timeout'; - var NOT_SCHEDULED = 'notScheduled'; function scheduleTask(task) { var data = task.data; function timer() { @@ -2065,21 +2055,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task.invoke.apply(this, arguments); } finally { - if (task.data && task.data.isPeriodic) { - // issue-934, task will be cancelled - // even it is a periodic task such as - // setInterval - return; - } - if (typeof data.handleId === NUMBER) { - // in non-nodejs env, we remove timerId - // from local cache - delete tasksByHandleId[data.handleId]; - } - else if (data.handleId) { - // Node returns complex objects as handleIds - // we remove task reference from timer object - data.handleId[taskSymbol] = null; + // issue-934, task will be cancelled + // even it is a periodic task such as + // setInterval + if (!(task.data && task.data.isPeriodic)) { + if (typeof data.handleId === 'number') { + // in non-nodejs env, we remove timerId + // from local cache + delete tasksByHandleId[data.handleId]; + } + else if (data.handleId) { + // Node returns complex objects as handleIds + // we remove task reference from timer object + data.handleId[taskSymbol] = null; + } } } } @@ -2092,21 +2081,20 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } setNative = patchMethod(window, setName, function (delegate) { return function (self, args) { - if (typeof args[0] === FUNCTION) { - var zone = Zone.current; + if (typeof args[0] === 'function') { var options = { handleId: null, - isPeriodic: nameSuffix === INTERVAL, - delay: (nameSuffix === TIMEOUT || nameSuffix === INTERVAL) ? args[1] || 0 : 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); + var task = scheduleMacroTaskWithCurrentZone(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 (typeof handle === NUMBER) { + if (typeof handle === 'number') { // for non nodejs env, we save handleId: task // mapping in local cache for clearTimeout tasksByHandleId[handle] = task; @@ -2118,12 +2106,12 @@ function patchTimer(window, setName, cancelName, nameSuffix) { } // check whether handle is null, because some polyfill or browser // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame - if (handle && handle.ref && handle.unref && typeof handle.ref === FUNCTION && - typeof handle.unref === FUNCTION) { + if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' && + typeof handle.unref === 'function') { task.ref = handle.ref.bind(handle); task.unref = handle.unref.bind(handle); } - if (typeof handle === NUMBER || handle) { + if (typeof handle === 'number' || handle) { return handle; } return task; @@ -2137,7 +2125,7 @@ function patchTimer(window, setName, cancelName, nameSuffix) { patchMethod(window, cancelName, function (delegate) { return function (self, args) { var id = args[0]; var task; - if (typeof id === NUMBER) { + if (typeof id === 'number') { // non nodejs env. task = tasksByHandleId[id]; } @@ -2149,10 +2137,10 @@ function patchTimer(window, setName, cancelName, nameSuffix) { task = id; } } - if (task && typeof task.type === STRING) { - if (task.state !== NOT_SCHEDULED && + if (task && typeof task.type === 'string') { + if (task.state !== 'notScheduled' && (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) { - if (typeof id === NUMBER) { + if (typeof id === 'number') { delete tasksByHandleId[id]; } else if (id) { @@ -2185,16 +2173,13 @@ var _getOwnPropertyDescriptor = Object[zoneSymbol('getOwnPropertyDescriptor')] = Object.getOwnPropertyDescriptor; var _create = Object.create; var unconfigurablesKey = zoneSymbol('unconfigurables'); -var PROTOTYPE = 'prototype'; -var OBJECT = 'object'; -var UNDEFINED$1 = 'undefined'; function propertyPatch() { Object.defineProperty = function (obj, prop, desc) { if (isUnconfigurable(obj, prop)) { throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj); } var originalConfigurableFlag = desc.configurable; - if (prop !== PROTOTYPE) { + if (prop !== 'prototype') { desc = rewriteDescriptor(obj, prop, desc); } return _tryDefineProperty(obj, prop, desc, originalConfigurableFlag); @@ -2206,7 +2191,7 @@ function propertyPatch() { return obj; }; Object.create = function (obj, proto) { - if (typeof proto === OBJECT && !Object.isFrozen(proto)) { + if (typeof proto === 'object' && !Object.isFrozen(proto)) { Object.keys(proto).forEach(function (prop) { proto[prop] = rewriteDescriptor(obj, prop, proto[prop]); }); @@ -2253,7 +2238,7 @@ function _tryDefineProperty(obj, prop, desc, originalConfigurableFlag) { if (desc.configurable) { // 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$1) { + if (typeof originalConfigurableFlag == 'undefined') { delete desc.configurable; } else { @@ -2294,22 +2279,22 @@ function apply(api, _global) { if (!_global.EventTarget) { patchEventTarget(_global, [WS.prototype]); } - _global.WebSocket = function (a, b) { - var socket = arguments.length > 1 ? new WS(a, b) : new WS(a); + _global.WebSocket = function (x, y) { + var socket = arguments.length > 1 ? new WS(x, y) : new WS(x); var proxySocket; var proxySocketProto; // Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance - var onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage'); + var onmessageDesc = ObjectGetOwnPropertyDescriptor(socket, 'onmessage'); if (onmessageDesc && onmessageDesc.configurable === false) { - proxySocket = Object.create(socket); + proxySocket = ObjectCreate(socket); // socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror' // but proxySocket not, so we will keep socket as prototype and pass it to // patchOnProperties method proxySocketProto = socket; - ['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function (propName) { + [ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR, 'send', 'close'].forEach(function (propName) { proxySocket[propName] = function () { - var args = Array.prototype.slice.call(arguments); - if (propName === 'addEventListener' || propName === 'removeEventListener') { + var args = ArraySlice.call(arguments); + if (propName === ADD_EVENT_LISTENER_STR || propName === REMOVE_EVENT_LISTENER_STR) { var eventName = args.length > 0 ? args[0] : undefined; if (eventName) { var propertySymbol = Zone.__symbol__('ON_PROPERTY' + eventName); @@ -2581,12 +2566,13 @@ function propertyDescriptorPatch(api, _global) { var ignoreProperties = _global.__Zone_ignore_on_properties; // for browsers that we can patch the descriptor: Chrome & Firefox if (isBrowser) { + var internalWindow = window; // in IE/Edge, onProp not exist in window object, but in WindowPrototype // so we need to pass WindowPrototype to check onProp exist or not - patchFilteredProperties(window, eventNames.concat(['messageerror']), ignoreProperties, Object.getPrototypeOf(window)); + patchFilteredProperties(internalWindow, eventNames.concat(['messageerror']), ignoreProperties, ObjectGetPrototypeOf(internalWindow)); patchFilteredProperties(Document.prototype, eventNames, ignoreProperties); - if (typeof window['SVGElement'] !== 'undefined') { - patchFilteredProperties(window['SVGElement'].prototype, eventNames, ignoreProperties); + if (typeof internalWindow['SVGElement'] !== 'undefined') { + patchFilteredProperties(internalWindow['SVGElement'].prototype, eventNames, ignoreProperties); } patchFilteredProperties(Element.prototype, eventNames, ignoreProperties); patchFilteredProperties(HTMLElement.prototype, eventNames, ignoreProperties); @@ -2595,11 +2581,11 @@ function propertyDescriptorPatch(api, _global) { patchFilteredProperties(HTMLBodyElement.prototype, windowEventNames.concat(frameSetEventNames), ignoreProperties); patchFilteredProperties(HTMLFrameElement.prototype, frameEventNames, ignoreProperties); patchFilteredProperties(HTMLIFrameElement.prototype, frameEventNames, ignoreProperties); - var HTMLMarqueeElement_1 = window['HTMLMarqueeElement']; + var HTMLMarqueeElement_1 = internalWindow['HTMLMarqueeElement']; if (HTMLMarqueeElement_1) { patchFilteredProperties(HTMLMarqueeElement_1.prototype, marqueeEventNames, ignoreProperties); } - var Worker_1 = window['Worker']; + var Worker_1 = internalWindow['Worker']; if (Worker_1) { patchFilteredProperties(Worker_1.prototype, workerEventNames, ignoreProperties); } @@ -2631,15 +2617,17 @@ function propertyDescriptorPatch(api, _global) { } } function canPatchViaPropertyDescriptor() { - if ((isBrowser || isMix) && !Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') && + if ((isBrowser || isMix) && !ObjectGetOwnPropertyDescriptor(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'); + var desc = ObjectGetOwnPropertyDescriptor(Element.prototype, 'onclick'); if (desc && !desc.configurable) return false; } - var xhrDesc = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'onreadystatechange'); + var ON_READY_STATE_CHANGE = 'onreadystatechange'; + var XMLHttpRequestPrototype = XMLHttpRequest.prototype; + var xhrDesc = ObjectGetOwnPropertyDescriptor(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE); // add enumerable and configurable here because in opera // by default XMLHttpRequest.prototype.onreadystatechange is undefined // without adding enumerable and configurable will cause onreadystatechange @@ -2647,7 +2635,7 @@ function canPatchViaPropertyDescriptor() { // and if XMLHttpRequest.prototype.onreadystatechange is undefined, // we should set a real desc instead a fake one if (xhrDesc) { - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', { + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, { enumerable: true, configurable: true, get: function () { @@ -2657,12 +2645,12 @@ function canPatchViaPropertyDescriptor() { var req = new XMLHttpRequest(); var result = !!req.onreadystatechange; // restore original desc - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {}); + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, xhrDesc || {}); return result; } else { - var SYMBOL_FAKE_ONREADYSTATECHANGE_1 = zoneSymbol('fakeonreadystatechange'); - Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', { + var SYMBOL_FAKE_ONREADYSTATECHANGE_1 = zoneSymbol('fake'); + ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, { enumerable: true, configurable: true, get: function () { @@ -2698,7 +2686,7 @@ function patchViaCapturingAllTheEvents() { } while (elt) { if (elt[onproperty] && !elt[onproperty][unboundKey]) { - bound = Zone.current.wrap(elt[onproperty], source); + bound = wrapWithCurrentZone(elt[onproperty], source); bound[unboundKey] = elt[onproperty]; elt[onproperty] = bound; } @@ -2803,7 +2791,9 @@ function eventTargetPatch(_global, api) { var type = _global[apis[i]]; apiTypes.push(type && type.prototype); } - patchEventTarget(_global, apiTypes, { validateHandler: checkIEAndCrossContext }); + // vh is validateHandler to check event handler + // is valid or not(for security check) + patchEventTarget(_global, apiTypes, { vh: checkIEAndCrossContext }); api.patchEventTarget = patchEventTarget; return true; } @@ -2828,22 +2818,23 @@ function registerElementPatch(_global) { 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); + var prototype = opts.prototype; + if (prototype.hasOwnProperty(callback)) { + var descriptor = ObjectGetOwnPropertyDescriptor(prototype, callback); if (descriptor && descriptor.value) { - descriptor.value = Zone.current.wrap(descriptor.value, source); + descriptor.value = wrapWithCurrentZone(descriptor.value, source); _redefineProperty(opts.prototype, callback, descriptor); } else { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + prototype[callback] = wrapWithCurrentZone(prototype[callback], source); } } - else if (opts.prototype[callback]) { - opts.prototype[callback] = Zone.current.wrap(opts.prototype[callback], source); + else if (prototype[callback]) { + prototype[callback] = wrapWithCurrentZone(prototype[callback], source); } }); } - return _registerElement.apply(document, [name, opts]); + return _registerElement.call(document, name, opts); }; attachOriginToPatched(document.registerElement, _registerElement); } @@ -2862,21 +2853,21 @@ function registerElementPatch(_global) { Zone.__load_patch('util', function (global, Zone, api) { api.patchOnProperties = patchOnProperties; api.patchMethod = patchMethod; - api.patchArguments = patchArguments; + api.bindArguments = bindArguments; }); -Zone.__load_patch('timers', function (global, Zone, api) { +Zone.__load_patch('timers', function (global) { var set = 'set'; var clear = 'clear'; patchTimer(global, set, clear, 'Timeout'); patchTimer(global, set, clear, 'Interval'); patchTimer(global, set, clear, 'Immediate'); }); -Zone.__load_patch('requestAnimationFrame', function (global, Zone, api) { +Zone.__load_patch('requestAnimationFrame', function (global) { patchTimer(global, 'request', 'cancel', 'AnimationFrame'); patchTimer(global, 'mozRequest', 'mozCancel', 'AnimationFrame'); patchTimer(global, 'webkitRequest', 'webkitCancel', 'AnimationFrame'); }); -Zone.__load_patch('blocking', function (global, Zone, api) { +Zone.__load_patch('blocking', function (global, Zone) { var blockingMethods = ['alert', 'prompt', 'confirm']; for (var i = 0; i < blockingMethods.length; i++) { var name_1 = blockingMethods[i]; @@ -2910,17 +2901,17 @@ Zone.__load_patch('on_property', function (global, Zone, api) { propertyPatch(); registerElementPatch(global); }); -Zone.__load_patch('canvas', function (global, Zone, api) { +Zone.__load_patch('canvas', function (global) { var HTMLCanvasElement = global['HTMLCanvasElement']; if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype && HTMLCanvasElement.prototype.toBlob) { patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', function (self, args) { - return { name: 'HTMLCanvasElement.toBlob', target: self, callbackIndex: 0, args: args }; + return { name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args }; }); } }); -Zone.__load_patch('XHR', function (global, Zone, api) { - // Treat XMLHTTPRequest as a macrotask. +Zone.__load_patch('XHR', function (global, Zone) { + // Treat XMLHttpRequest as a macrotask. patchXHR(global); var XHR_TASK = zoneSymbol('xhrTask'); var XHR_SYNC = zoneSymbol('xhrSync'); @@ -2928,19 +2919,18 @@ Zone.__load_patch('XHR', function (global, Zone, api) { var XHR_SCHEDULED = zoneSymbol('xhrScheduled'); var XHR_URL = zoneSymbol('xhrURL'); function patchXHR(window) { + var XMLHttpRequestPrototype = XMLHttpRequest.prototype; function findPendingTask(target) { - var pendingTask = target[XHR_TASK]; - return pendingTask; + return target[XHR_TASK]; } - var SYMBOL_ADDEVENTLISTENER = zoneSymbol('addEventListener'); - var SYMBOL_REMOVEEVENTLISTENER = zoneSymbol('removeEventListener'); - var oriAddListener = XMLHttpRequest.prototype[SYMBOL_ADDEVENTLISTENER]; - var oriRemoveListener = XMLHttpRequest.prototype[SYMBOL_REMOVEEVENTLISTENER]; + var oriAddListener = XMLHttpRequestPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + var oriRemoveListener = XMLHttpRequestPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; if (!oriAddListener) { var XMLHttpRequestEventTarget = window['XMLHttpRequestEventTarget']; if (XMLHttpRequestEventTarget) { - oriAddListener = XMLHttpRequestEventTarget.prototype[SYMBOL_ADDEVENTLISTENER]; - oriRemoveListener = XMLHttpRequestEventTarget.prototype[SYMBOL_REMOVEEVENTLISTENER]; + var XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget.prototype; + oriAddListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + oriRemoveListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; } } var READY_STATE_CHANGE = 'readystatechange'; @@ -2952,11 +2942,11 @@ Zone.__load_patch('XHR', function (global, Zone, api) { // remove existing event listener var listener = target[XHR_LISTENER]; if (!oriAddListener) { - oriAddListener = target[SYMBOL_ADDEVENTLISTENER]; - oriRemoveListener = target[SYMBOL_REMOVEEVENTLISTENER]; + oriAddListener = target[ZONE_SYMBOL_ADD_EVENT_LISTENER]; + oriRemoveListener = target[ZONE_SYMBOL_REMOVE_EVENT_LISTENER]; } if (listener) { - oriRemoveListener.apply(target, [READY_STATE_CHANGE, listener]); + oriRemoveListener.call(target, READY_STATE_CHANGE, listener); } var newListener = target[XHR_LISTENER] = function () { if (target.readyState === target.DONE) { @@ -2967,7 +2957,7 @@ Zone.__load_patch('XHR', function (global, Zone, api) { } } }; - oriAddListener.apply(target, [READY_STATE_CHANGE, newListener]); + oriAddListener.call(target, READY_STATE_CHANGE, newListener); var storedTask = target[XHR_TASK]; if (!storedTask) { target[XHR_TASK] = task; @@ -2984,14 +2974,13 @@ Zone.__load_patch('XHR', function (global, Zone, api) { data.aborted = true; return abortNative.apply(data.target, data.args); } - var openNative = patchMethod(window.XMLHttpRequest.prototype, 'open', function () { return function (self, args) { + var openNative = patchMethod(XMLHttpRequestPrototype, 'open', function () { return function (self, args) { self[XHR_SYNC] = args[2] == false; self[XHR_URL] = args[1]; return openNative.apply(self, args); }; }); var XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send'; - var sendNative = patchMethod(window.XMLHttpRequest.prototype, 'send', function () { return function (self, args) { - var zone = Zone.current; + var sendNative = patchMethod(XMLHttpRequestPrototype, 'send', function () { return function (self, args) { if (self[XHR_SYNC]) { // if the XHR is sync there is no task to schedule, just execute the code. return sendNative.apply(self, args); @@ -3005,13 +2994,12 @@ Zone.__load_patch('XHR', function (global, Zone, api) { args: args, aborted: false }; - return zone.scheduleMacroTask(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask); + return scheduleMacroTaskWithCurrentZone(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask); } }; }); - var STRING_TYPE = 'string'; - var abortNative = patchMethod(window.XMLHttpRequest.prototype, 'abort', function (delegate) { return function (self, args) { + var abortNative = patchMethod(XMLHttpRequestPrototype, 'abort', function () { return function (self) { var task = findPendingTask(self); - if (task && typeof task.type == STRING_TYPE) { + if (task && typeof task.type == 'string') { // If the XHR has already completed, do nothing. // If the XHR has already been aborted, do nothing. // Fix #569, call abort multiple times before done will cause @@ -3027,19 +3015,13 @@ Zone.__load_patch('XHR', function (global, Zone, api) { }; }); } }); -Zone.__load_patch('geolocation', function (global, Zone, api) { +Zone.__load_patch('geolocation', function (global) { /// GEO_LOCATION if (global['navigator'] && global['navigator'].geolocation) { patchPrototype(global['navigator'].geolocation, ['getCurrentPosition', 'watchPosition']); } }); -Zone.__load_patch('getUserMedia', function (global, Zone, api) { - var navigator = global['navigator']; - if (navigator && navigator.getUserMedia) { - navigator.getUserMedia = wrapFunctionArgs(navigator.getUserMedia); - } -}); -Zone.__load_patch('PromiseRejectionEvent', function (global, Zone, api) { +Zone.__load_patch('PromiseRejectionEvent', function (global, Zone) { // handle unhandled promise rejection function findPromiseRejectionHandler(evtName) { return function (e) { diff --git a/dist/zone.min.js b/dist/zone.min.js index a89a96190..9c6bff9af 100644 --- a/dist/zone.min.js +++ b/dist/zone.min.js @@ -1,2 +1,2 @@ -!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--)typeof e[n]===L&&(e[n]=Zone.current.wrap(e[n],t+"_"+n));return e}function t(t,n){return function(){var r=Array.prototype.slice.call(arguments),o=e(r,n?n:t.name);return t.apply(this,o)}}function n(t,n,r){return c(t,n,function(t,n,o){return function(n,o){return t&&t.apply(n,e(o,r))}})}function r(t,n){for(var r=t.constructor.name,a=function(a){var i=n[a],s=t[i];if(s){var c=Object.getOwnPropertyDescriptor(t,i);if(!o(c))return"continue";t[i]=function(t){var n=function(){return t.apply(this,e(arguments,r+"."+i))};return l(n,t),n}(s)}},i=0;i=0&&"function"==typeof o[a.callbackIndex]){var i=Zone.current.scheduleMacroTask(a.name,o[a.callbackIndex],a,r,null);return i}return e.apply(t,o)}})}function l(e,t){e[j("OriginalDelegate")]=t}function p(){if(X)return U;X=!0;try{var e=window.navigator.userAgent;e.indexOf("MSIE ");return e.indexOf("MSIE ")===-1&&e.indexOf("Trident/")===-1&&e.indexOf("Edge/")===-1||(U=!0),U}catch(t){}}function f(e,t,n){function r(t,n){if(!t)return!1;var r=!0;n&&void 0!==n.useGlobalCallback&&(r=n.useGlobalCallback);var d=n&&n.validateHandler,y=!0;n&&void 0!==n.checkDuplicate&&(y=n.checkDuplicate);var k=!1;n&&void 0!==n.returnTarget&&(k=n.returnTarget);for(var m=t;m&&!m.hasOwnProperty(o);)m=Object.getPrototypeOf(m);if(!m&&t[o]&&(m=t),!m)return!1;if(m[c])return!1;var _,b={},T=m[c]=m[o],w=m[j(a)]=m[a],E=m[j(i)]=m[i],D=m[j(s)]=m[s];n&&n.prependEventListenerFnName&&(_=m[j(n.prependEventListenerFnName)]=m[n.prependEventListenerFnName]);var O=function(e){if(!b.isExisting)return T.apply(b.target,[b.eventName,b.capture?g:v,b.options])},S=function(e){if(!e.isRemoved){var t=K[e.eventName],n=void 0;t&&(n=t[e.capture?W:G]);var r=n&&e.target[n];if(r)for(var o=0;o1?new n(e,t):new n(e),s=Object.getOwnPropertyDescriptor(a,"onmessage");return s&&s.configurable===!1?(r=Object.create(a),o=a,["addEventListener","removeEventListener","send","close"].forEach(function(e){r[e]=function(){var t=Array.prototype.slice.call(arguments);if("addEventListener"===e||"removeEventListener"===e){var n=t.length>0?t[0]:void 0;if(n){var o=Zone.__symbol__("ON_PROPERTY"+n);a[o]=r[o]}}return a[e].apply(a,t)}})):r=a,i(r,["close","error","message","open"],o),r};var r=t.WebSocket;for(var o in n)r[o]=n[o]}function T(e,t,n){if(!n)return t;var r=n.filter(function(t){return t.target===e});if(!r||0===r.length)return t;var o=r[0].ignoreProperties;return t.filter(function(e){return o.indexOf(e)===-1})}function w(e,t,n,r){var o=T(e,t,n);i(e,o,r)}function E(e,t){if(!x||q){var n="undefined"!=typeof WebSocket;if(D()){var r=t.__Zone_ignore_on_properties;if(F){w(window,Se.concat(["messageerror"]),r,Object.getPrototypeOf(window)),w(Document.prototype,Se,r),"undefined"!=typeof window.SVGElement&&w(window.SVGElement.prototype,Se,r),w(Element.prototype,Se,r),w(HTMLElement.prototype,Se,r),w(HTMLMediaElement.prototype,ve,r),w(HTMLFrameSetElement.prototype,he.concat(be),r),w(HTMLBodyElement.prototype,he.concat(be),r),w(HTMLFrameElement.prototype,_e,r),w(HTMLIFrameElement.prototype,_e,r);var o=window.HTMLMarqueeElement;o&&w(o.prototype,Te,r);var a=window.Worker;a&&w(a.prototype,Oe,r)}w(XMLHttpRequest.prototype,we,r);var i=t.XMLHttpRequestEventTarget;i&&w(i&&i.prototype,we,r),"undefined"!=typeof IDBIndex&&(w(IDBIndex.prototype,Ee,r),w(IDBRequest.prototype,Ee,r),w(IDBOpenDBRequest.prototype,Ee,r),w(IDBDatabase.prototype,Ee,r),w(IDBTransaction.prototype,Ee,r),w(IDBCursor.prototype,Ee,r)),n&&w(WebSocket.prototype,De,r)}else O(),s("XMLHttpRequest"),n&&b(e,t)}}function D(){if((F||q)&&!Object.getOwnPropertyDescriptor(HTMLElement.prototype,"onclick")&&"undefined"!=typeof Element){var e=Object.getOwnPropertyDescriptor(Element.prototype,"onclick");if(e&&!e.configurable)return!1}var t=Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype,"onreadystatechange");if(t){Object.defineProperty(XMLHttpRequest.prototype,"onreadystatechange",{enumerable:!0,configurable:!0,get:function(){return!0}});var n=new XMLHttpRequest,r=!!n.onreadystatechange;return Object.defineProperty(XMLHttpRequest.prototype,"onreadystatechange",t||{}),r}var o=j("fakeonreadystatechange");Object.defineProperty(XMLHttpRequest.prototype,"onreadystatechange",{enumerable:!0,configurable:!0,get:function(){return this[o]},set:function(e){this[o]=e}});var n=new XMLHttpRequest,a=function(){};n.onreadystatechange=a;var r=n[o]===a;return n.onreadystatechange=null,r}function O(){for(var e=function(e){var t=Se[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][Ze]&&(t=Zone.current.wrap(o[n],r),t[Ze]=o[n],o[n]=t),o=o.parentElement},!0)},t=0;t",this._properties=t&&t.properties||{},this._zoneDelegate=new f(this,this._parent&&this._parent._zoneDelegate,t)}return r.assertZonePatched=function(){if(e.Promise!==P.ZoneAwarePromise)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(r,"root",{get:function(){for(var e=r.current;e.parent;)e=e.parent;return e},enumerable:!0,configurable:!0}),Object.defineProperty(r,"current",{get:function(){return j.zone},enumerable:!0,configurable:!0}),Object.defineProperty(r,"currentTask",{get:function(){return C},enumerable:!0,configurable:!0}),r.__load_patch=function(o,a){if(P.hasOwnProperty(o))throw Error("Already loaded patch: "+o);if(!e["__Zone_disable_"+o]){var i="Zone:"+o;t(i),P[o]=a(e,r,z),n(i,i)}},Object.defineProperty(r.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),r.prototype.get=function(e){var t=this.getZoneWith(e);if(t)return t._properties[e]},r.prototype.getZoneWith=function(e){for(var t=this;t;){if(t._properties.hasOwnProperty(e))return t;t=t._parent}return null},r.prototype.fork=function(e){if(!e)throw new Error("ZoneSpec required!");return this._zoneDelegate.fork(this,e)},r.prototype.wrap=function(e,t){if(typeof e!==s)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)}},r.prototype.run=function(e,t,n,r){void 0===t&&(t=void 0),void 0===n&&(n=null),void 0===r&&(r=null),j={parent:j,zone:this};try{return this._zoneDelegate.invoke(this,e,t,n,r)}finally{j=j.parent}},r.prototype.runGuarded=function(e,t,n,r){void 0===t&&(t=null),void 0===n&&(n=null),void 0===r&&(r=null),j={parent:j,zone:this};try{try{return this._zoneDelegate.invoke(this,e,t,n,r)}catch(o){if(this._zoneDelegate.handleError(this,o))throw o}}finally{j=j.parent}},r.prototype.runTask=function(e,t,n){if(e.zone!=this)throw new Error("A task can only be run in the zone of creation! (Creation: "+(e.zone||m).name+"; Execution: "+this.name+")");var r=e.state===_;if(!r||e.type!==Z){var o=e.state!=w;o&&e._transitionTo(w,T),e.runCount++;var a=C;C=e,j={parent:j,zone:this};try{e.type==S&&e.data&&!e.data.isPeriodic&&(e.cancelFn=null);try{return this._zoneDelegate.invokeTask(this,e,t,n)}catch(i){if(this._zoneDelegate.handleError(this,i))throw i}}finally{e.state!==_&&e.state!==D&&(e.type==Z||e.data&&e.data.isPeriodic?o&&e._transitionTo(T,w):(e.runCount=0,this._updateTaskCount(e,-1),o&&e._transitionTo(_,w,_))),j=j.parent,C=a}}},r.prototype.scheduleTask=function(e){if(e.zone&&e.zone!==this)for(var t=this;t;){if(t===e.zone)throw Error("can not reschedule task to "+this.name+" which is descendants of the original zone "+e.zone.name);t=t.parent}e._transitionTo(b,_);var n=[];e._zoneDelegates=n,e._zone=this;try{e=this._zoneDelegate.scheduleTask(this,e)}catch(r){throw e._transitionTo(D,b,_),this._zoneDelegate.handleError(this,r),r}return e._zoneDelegates===n&&this._updateTaskCount(e,1),e.state==b&&e._transitionTo(T,b),e},r.prototype.scheduleMicroTask=function(e,t,n,r){return this.scheduleTask(new h(O,e,t,n,r,null))},r.prototype.scheduleMacroTask=function(e,t,n,r,o){return this.scheduleTask(new h(S,e,t,n,r,o))},r.prototype.scheduleEventTask=function(e,t,n,r,o){return this.scheduleTask(new h(Z,e,t,n,r,o))},r.prototype.cancelTask=function(e){if(e.zone!=this)throw new Error("A task can only be cancelled in the zone of creation! (Creation: "+(e.zone||m).name+"; Execution: "+this.name+")");e._transitionTo(E,T,w);try{this._zoneDelegate.cancelTask(this,e)}catch(t){throw e._transitionTo(D,E),this._zoneDelegate.handleError(this,t),t}return this._updateTaskCount(e,-1),e._transitionTo(_,E),e.runCount=0,e},r.prototype._updateTaskCount=function(e,t){var n=e._zoneDelegates;t==-1&&(e._zoneDelegates=null);for(var r=0;r0,macroTask:n.macroTask>0,eventTask:n.eventTask>0,change:e};this.hasTask(this.zone,a)}},e}(),h=function(){function t(n,r,o,a,i,s){this._zone=null,this.runCount=0,this._zoneDelegates=null,this._state="notScheduled",this.type=n,this.source=r,this.data=a,this.scheduleFn=i,this.cancelFn=s,this.callback=o;var c=this;n===Z&&a&&a.isUsingGlobalCallback?this.invoke=t.invokeTask:this.invoke=function(){return t.invokeTask.apply(e,[c,this,arguments])}}return t.invokeTask=function(e,t,n){e||(e=this),L++;try{return e.runCount++,e.zone.runTask(e,t,n)}finally{1==L&&o(),L--}},Object.defineProperty(t.prototype,"zone",{get:function(){return this._zone},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),t.prototype.cancelScheduleRequest=function(){this._transitionTo(_,b)},t.prototype._transitionTo=function(e,t,n){if(this._state!==t&&this._state!==n)throw new Error(this.type+" '"+this.source+"': can not transition to '"+e+"', expecting state '"+t+"'"+(n?" or '"+n+"'":"")+", was '"+this._state+"'.");this._state=e,e==_&&(this._zoneDelegates=null)},t.prototype.toString=function(){return this.data&&"undefined"!=typeof this.data.handleId?this.data.handleId:Object.prototype.toString.call(this)},t.prototype.toJSON=function(){return{type:this.type,state:this.state,source:this.source,zone:this.zone.name,runCount:this.runCount}},t}(),d=i("setTimeout"),v=i("Promise"),g=i("then"),y=[],k=!1,m={name:"NO ZONE"},_="notScheduled",b="scheduling",T="scheduled",w="running",E="canceling",D="unknown",O="microTask",S="macroTask",Z="eventTask",P={},z={symbol:i,currentZoneFrame:function(){return j},onUnhandledError:a,microtaskDrainDone:a,scheduleMicroTask:r,showUncaughtError:function(){return!u[i("ignoreConsoleErrorUncaughtError")]},patchEventTarget:function(){return[]},patchOnProperties:a,patchMethod:function(){return a},patchArguments:function(){return a},setNativePromise:function(e){e&&typeof e.resolve===s&&(l=e.resolve(0))}},j={parent:null,zone:new u(null,null)},C=null,L=0;return n("Zone","Zone"),e.Zone=u}("undefined"!=typeof window&&window||"undefined"!=typeof self&&self||global),function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}});Zone.__load_patch("ZoneAwarePromise",function(e,t,n){function r(e){if(e&&e.toString===Object.prototype.toString){var t=e.constructor&&e.constructor.name;return(t?t:"")+": "+JSON.stringify(e)}return e?e.toString():Object.prototype.toString.call(e)}function o(e){n.onUnhandledError(e);try{var r=t[m];r&&"function"==typeof r&&r.apply(this,[e])}catch(o){}}function a(e){return e&&e.then}function i(e){return e}function s(e){return I.reject(e)}function c(e,t){return function(n){try{u(e,t,n)}catch(r){u(e,!1,r)}}}function u(e,o,a){var i=S();if(e===a)throw new TypeError(Z);if(e[_]===w){var s=null;try{typeof a!==P&&typeof a!==j||(s=a&&a.then)}catch(f){return i(function(){u(e,!1,f)})(),e}if(o!==D&&a instanceof I&&a.hasOwnProperty(_)&&a.hasOwnProperty(b)&&a[_]!==w)l(a),u(e,a[_],a[b]);else if(o!==D&&typeof s===j)try{s.apply(a,[i(c(e,o)),i(c(e,!1))])}catch(f){i(function(){u(e,!1,f)})()}else{e[_]=o;var h=e[b];if(e[b]=a,o===D&&a instanceof Error){var d=t.currentTask&&t.currentTask.data&&t.currentTask.data[k];d&&Object.defineProperty(a,C,{configurable:!0,enumerable:!1,writable:!0,value:d})}for(var g=0;g=0;r--)"function"==typeof t[r]&&(t[r]=e(t[r],n+"_"+r));return t}function r(e,t){for(var r=e.constructor.name,a=function(a){var i=t[a],s=e[i];if(s){var c=j(e,i);if(!o(c))return"continue";e[i]=function(e){var t=function(){return e.apply(this,n(arguments,r+"."+i))};return l(t,e),t}(s)}},i=0;i=0&&"function"==typeof a[i.cbIdx]?t(i.name,a[i.cbIdx],i,o,null):e.apply(n,a)}})}function l(e,t){e[N("OriginalDelegate")]=t}function f(){if(ne)return re;ne=!0;try{var e=X.navigator.userAgent;return e.indexOf("MSIE ")===-1&&e.indexOf("Trident/")===-1&&e.indexOf("Edge/")===-1||(re=!0),re}catch(t){}}function p(e,t,n){function r(t,n){if(!t)return!1;var r=!0;n&&void 0!==n.useG&&(r=n.useG);var d=n&&n.vh,y=!0;n&&void 0!==n.chkDup&&(y=n.chkDup);var m=!1;n&&void 0!==n.rt&&(m=n.rt);for(var k=t;k&&!k.hasOwnProperty(o);)k=I(k);if(!k&&t[o]&&(k=t),!k)return!1;if(k[c])return!1;var _,b={},T=k[c]=k[o],w=k[N(a)]=k[a],E=k[N(i)]=k[i],S=k[N(s)]=k[s];n&&n.prepend&&(_=k[N(n.prepend)]=k[n.prepend]);var D=function(){if(!b.isExisting)return T.call(b.target,b.eventName,b.capture?g:v,b.options)},Z=function(e){if(!e.isRemoved){var t=ae[e.eventName],n=void 0;t&&(n=t[e.capture?q:A]);var r=n&&e.target[n];if(r)for(var o=0;o1?new n(e,t):new n(e),s=j(a,"onmessage");return s&&s.configurable===!1?(r=L(a),o=a,[R,x,"send","close"].forEach(function(e){r[e]=function(){var t=M.call(arguments);if(e===R||e===x){var n=t.length>0?t[0]:void 0;if(n){var o=Zone.__symbol__("ON_PROPERTY"+n);a[o]=r[o]}}return a[e].apply(a,t)}})):r=a,i(r,["close","error","message","open"],o),r};var r=t.WebSocket;for(var o in n)r[o]=n[o]}function T(e,t,n){if(!n)return t;var r=n.filter(function(t){return t.target===e});if(!r||0===r.length)return t;var o=r[0].ignoreProperties;return t.filter(function(e){return o.indexOf(e)===-1})}function w(e,t,n,r){var o=T(e,t,n);i(e,o,r)}function E(e,t){if(!J||Q){var n="undefined"!=typeof WebSocket;if(S()){var r=t.__Zone_ignore_on_properties;if(Y){var o=window;w(o,Pe.concat(["messageerror"]),r,I(o)),w(Document.prototype,Pe,r),"undefined"!=typeof o.SVGElement&&w(o.SVGElement.prototype,Pe,r),w(Element.prototype,Pe,r),w(HTMLElement.prototype,Pe,r),w(HTMLMediaElement.prototype,me,r),w(HTMLFrameSetElement.prototype,ge.concat(Ee),r),w(HTMLBodyElement.prototype,ge.concat(Ee),r),w(HTMLFrameElement.prototype,we,r),w(HTMLIFrameElement.prototype,we,r);var a=o.HTMLMarqueeElement;a&&w(a.prototype,Se,r);var i=o.Worker;i&&w(i.prototype,Oe,r)}w(XMLHttpRequest.prototype,De,r);var c=t.XMLHttpRequestEventTarget;c&&w(c&&c.prototype,De,r),"undefined"!=typeof IDBIndex&&(w(IDBIndex.prototype,Ze,r),w(IDBRequest.prototype,Ze,r),w(IDBOpenDBRequest.prototype,Ze,r),w(IDBDatabase.prototype,Ze,r),w(IDBTransaction.prototype,Ze,r),w(IDBCursor.prototype,Ze,r)),n&&w(WebSocket.prototype,ze,r)}else D(),s("XMLHttpRequest"),n&&b(e,t)}}function S(){if((Y||Q)&&!j(HTMLElement.prototype,"onclick")&&"undefined"!=typeof Element){var e=j(Element.prototype,"onclick");if(e&&!e.configurable)return!1}var t="onreadystatechange",n=XMLHttpRequest.prototype,r=j(n,t);if(r){C(n,t,{enumerable:!0,configurable:!0,get:function(){return!0}});var o=new XMLHttpRequest,a=!!o.onreadystatechange;return C(n,t,r||{}),a}var i=N("fake");C(n,t,{enumerable:!0,configurable:!0,get:function(){return this[i]},set:function(e){this[i]=e}});var o=new XMLHttpRequest,s=function(){};o.onreadystatechange=s;var a=o[i]===s;return o.onreadystatechange=null,a}function D(){for(var t=function(t){var n=Pe[t],r="on"+n;self.addEventListener(n,function(t){var n,o,a=t.target;for(o=a?a.constructor.name+"."+r:"unknown."+r;a;)a[r]&&!a[r][je]&&(n=e(a[r],o),n[je]=a[r],a[r]=n),a=a.parentElement},!0)},n=0;n",this._properties=t&&t.properties||{},this._zoneDelegate=new p(this,this._parent&&this._parent._zoneDelegate,t)}return r.assertZonePatched=function(){if(e.Promise!==O.ZoneAwarePromise)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(r,"root",{get:function(){for(var e=r.current;e.parent;)e=e.parent;return e},enumerable:!0,configurable:!0}),Object.defineProperty(r,"current",{get:function(){return j.zone},enumerable:!0,configurable:!0}),Object.defineProperty(r,"currentTask",{get:function(){return C},enumerable:!0,configurable:!0}),r.__load_patch=function(o,a){if(O.hasOwnProperty(o))throw Error("Already loaded patch: "+o);if(!e["__Zone_disable_"+o]){var i="Zone:"+o;t(i),O[o]=a(e,r,P),n(i,i)}},Object.defineProperty(r.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),r.prototype.get=function(e){var t=this.getZoneWith(e);if(t)return t._properties[e]},r.prototype.getZoneWith=function(e){for(var t=this;t;){if(t._properties.hasOwnProperty(e))return t;t=t._parent}return null},r.prototype.fork=function(e){if(!e)throw new Error("ZoneSpec required!");return this._zoneDelegate.fork(this,e)},r.prototype.wrap=function(e,t){if(typeof e!==s)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)}},r.prototype.run=function(e,t,n,r){void 0===t&&(t=void 0),void 0===n&&(n=null),void 0===r&&(r=null),j={parent:j,zone:this};try{return this._zoneDelegate.invoke(this,e,t,n,r)}finally{j=j.parent}},r.prototype.runGuarded=function(e,t,n,r){void 0===t&&(t=null),void 0===n&&(n=null),void 0===r&&(r=null),j={parent:j,zone:this};try{try{return this._zoneDelegate.invoke(this,e,t,n,r)}catch(o){if(this._zoneDelegate.handleError(this,o))throw o}}finally{j=j.parent}},r.prototype.runTask=function(e,t,n){if(e.zone!=this)throw new Error("A task can only be run in the zone of creation! (Creation: "+(e.zone||k).name+"; Execution: "+this.name+")");var r=e.state===_;if(!r||e.type!==z){var o=e.state!=w;o&&e._transitionTo(w,T),e.runCount++;var a=C;C=e,j={parent:j,zone:this};try{e.type==Z&&e.data&&!e.data.isPeriodic&&(e.cancelFn=null);try{return this._zoneDelegate.invokeTask(this,e,t,n)}catch(i){if(this._zoneDelegate.handleError(this,i))throw i}}finally{e.state!==_&&e.state!==S&&(e.type==z||e.data&&e.data.isPeriodic?o&&e._transitionTo(T,w):(e.runCount=0,this._updateTaskCount(e,-1),o&&e._transitionTo(_,w,_))),j=j.parent,C=a}}},r.prototype.scheduleTask=function(e){if(e.zone&&e.zone!==this)for(var t=this;t;){if(t===e.zone)throw Error("can not reschedule task to "+this.name+" which is descendants of the original zone "+e.zone.name);t=t.parent}e._transitionTo(b,_);var n=[];e._zoneDelegates=n,e._zone=this;try{e=this._zoneDelegate.scheduleTask(this,e)}catch(r){throw e._transitionTo(S,b,_),this._zoneDelegate.handleError(this,r),r}return e._zoneDelegates===n&&this._updateTaskCount(e,1),e.state==b&&e._transitionTo(T,b),e},r.prototype.scheduleMicroTask=function(e,t,n,r){return this.scheduleTask(new h(D,e,t,n,r,null))},r.prototype.scheduleMacroTask=function(e,t,n,r,o){return this.scheduleTask(new h(Z,e,t,n,r,o))},r.prototype.scheduleEventTask=function(e,t,n,r,o){return this.scheduleTask(new h(z,e,t,n,r,o))},r.prototype.cancelTask=function(e){if(e.zone!=this)throw new Error("A task can only be cancelled in the zone of creation! (Creation: "+(e.zone||k).name+"; Execution: "+this.name+")");e._transitionTo(E,T,w);try{this._zoneDelegate.cancelTask(this,e)}catch(t){throw e._transitionTo(S,E),this._zoneDelegate.handleError(this,t),t}return this._updateTaskCount(e,-1),e._transitionTo(_,E),e.runCount=0,e},r.prototype._updateTaskCount=function(e,t){var n=e._zoneDelegates;t==-1&&(e._zoneDelegates=null);for(var r=0;r0,macroTask:n.macroTask>0,eventTask:n.eventTask>0,change:e};this.hasTask(this.zone,a)}},e}(),h=function(){function t(n,r,o,a,i,s){this._zone=null,this.runCount=0,this._zoneDelegates=null,this._state="notScheduled",this.type=n,this.source=r,this.data=a,this.scheduleFn=i,this.cancelFn=s,this.callback=o;var c=this;n===z&&a&&a.useG?this.invoke=t.invokeTask:this.invoke=function(){return t.invokeTask.call(e,c,this,arguments)}}return t.invokeTask=function(e,t,n){e||(e=this),I++;try{return e.runCount++,e.zone.runTask(e,t,n)}finally{1==I&&o(),I--}},Object.defineProperty(t.prototype,"zone",{get:function(){return this._zone},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),t.prototype.cancelScheduleRequest=function(){this._transitionTo(_,b)},t.prototype._transitionTo=function(e,t,n){if(this._state!==t&&this._state!==n)throw new Error(this.type+" '"+this.source+"': can not transition to '"+e+"', expecting state '"+t+"'"+(n?" or '"+n+"'":"")+", was '"+this._state+"'.");this._state=e,e==_&&(this._zoneDelegates=null)},t.prototype.toString=function(){return this.data&&"undefined"!=typeof this.data.handleId?this.data.handleId:Object.prototype.toString.call(this)},t.prototype.toJSON=function(){return{type:this.type,state:this.state,source:this.source,zone:this.zone.name,runCount:this.runCount}},t}(),d=i("setTimeout"),v=i("Promise"),g=i("then"),y=[],m=!1,k={name:"NO ZONE"},_="notScheduled",b="scheduling",T="scheduled",w="running",E="canceling",S="unknown",D="microTask",Z="macroTask",z="eventTask",O={},P={symbol:i,currentZoneFrame:function(){return j},onUnhandledError:a,microtaskDrainDone:a,scheduleMicroTask:r,showUncaughtError:function(){return!u[i("ignoreConsoleErrorUncaughtError")]},patchEventTarget:function(){return[]},patchOnProperties:a,patchMethod:function(){return a},bindArguments:function(){return null},setNativePromise:function(e){e&&typeof e.resolve===s&&(l=e.resolve(0))}},j={parent:null,zone:new u(null,null)},C=null,I=0;return n("Zone","Zone"),e.Zone=u}("undefined"!=typeof window&&window||"undefined"!=typeof self&&self||global),function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}});Zone.__load_patch("ZoneAwarePromise",function(e,t,n){function r(e){if(e&&e.toString===Object.prototype.toString){var t=e.constructor&&e.constructor.name;return(t?t:"")+": "+JSON.stringify(e)}return e?e.toString():Object.prototype.toString.call(e)}function o(e){n.onUnhandledError(e);try{var r=t[b];r&&"function"==typeof r&&r.call(this,e)}catch(o){}}function a(e){return e&&e.then}function i(e){return e}function s(e){return M.reject(e)}function c(e,t){return function(n){try{u(e,t,n)}catch(r){u(e,!1,r)}}}function u(e,o,a){var i=O();if(e===a)throw new TypeError(j);if(e[T]===S){var s=null;try{"object"!=typeof a&&"function"!=typeof a||(s=a&&a.then)}catch(p){return i(function(){u(e,!1,p)})(),e}if(o!==Z&&a instanceof M&&a.hasOwnProperty(T)&&a.hasOwnProperty(w)&&a[T]!==S)l(a),u(e,a[T],a[w]);else if(o!==Z&&"function"==typeof s)try{s.call(a,i(c(e,o)),i(c(e,!1)))}catch(p){i(function(){u(e,!1,p)})()}else{e[T]=o;var h=e[w];if(e[w]=a,o===Z&&a instanceof Error){var d=t.currentTask&&t.currentTask.data&&t.currentTask.data[_];d&&v(a,C,{configurable:!0,enumerable:!1,writable:!0,value:d})}for(var g=0;g