build: reformat repo to new clang@1.4.0 (#36613)

PR Close #36613
This commit is contained in:
Joey Perrott
2020-04-13 16:40:21 -07:00
committed by atscott
parent 5e80e7e216
commit 698b0288be
1160 changed files with 31667 additions and 24000 deletions

View File

@ -7,7 +7,7 @@
*/
import {globalSources, patchEventPrototype, patchEventTarget, zoneSymbolEventNames} from '../common/events';
import {ADD_EVENT_LISTENER_STR, ArraySlice, FALSE_STR, ObjectCreate, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, attachOriginToPatched, bindArguments, isBrowser, isIEOrEdge, isMix, isNode, patchClass, patchMacroTask, patchMethod, patchOnProperties, wrapWithCurrentZone} from '../common/utils';
import {ADD_EVENT_LISTENER_STR, ArraySlice, attachOriginToPatched, bindArguments, FALSE_STR, isBrowser, isIEOrEdge, isMix, isNode, ObjectCreate, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, patchClass, patchMacroTask, patchMethod, patchOnProperties, REMOVE_EVENT_LISTENER_STR, TRUE_STR, wrapWithCurrentZone, ZONE_SYMBOL_PREFIX} from '../common/utils';
import {patchCallbacks} from './browser-util';
import {eventNames, filterProperties} from './property-descriptor';
@ -45,7 +45,17 @@ Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api.attachOriginToPatched = attachOriginToPatched;
api._redefineProperty = Object.defineProperty;
api.patchCallbacks = patchCallbacks;
api.getGlobalObjects = () =>
({globalSources, zoneSymbolEventNames, eventNames, isBrowser, isMix, isNode, TRUE_STR,
FALSE_STR, ZONE_SYMBOL_PREFIX, ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR});
api.getGlobalObjects = () => ({
globalSources,
zoneSymbolEventNames,
eventNames,
isBrowser,
isMix,
isNode,
TRUE_STR,
FALSE_STR,
ZONE_SYMBOL_PREFIX,
ADD_EVENT_LISTENER_STR,
REMOVE_EVENT_LISTENER_STR
});
});

View File

@ -16,23 +16,25 @@ import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy';
import {registerElementPatch} from './register-element';
(function(_global: any) {
const symbolPrefix = _global['__Zone_symbol_prefix'] || '__zone_symbol__';
function __symbol__(name: string) { return symbolPrefix + name; }
_global[__symbol__('legacyPatch')] = function() {
const Zone = _global['Zone'];
Zone.__load_patch('defineProperty', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api._redefineProperty = _redefineProperty;
propertyPatch();
});
Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
registerElementPatch(global, api);
});
const symbolPrefix = _global['__Zone_symbol_prefix'] || '__zone_symbol__';
function __symbol__(name: string) {
return symbolPrefix + name;
}
_global[__symbol__('legacyPatch')] = function() {
const Zone = _global['Zone'];
Zone.__load_patch('defineProperty', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api._redefineProperty = _redefineProperty;
propertyPatch();
});
Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
registerElementPatch(global, api);
});
Zone.__load_patch('EventTargetLegacy', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
eventTargetLegacyPatch(global, api);
propertyDescriptorLegacyPatch(api, global);
});
};
Zone.__load_patch('EventTargetLegacy', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
eventTargetLegacyPatch(global, api);
propertyDescriptorLegacyPatch(api, global);
});
};
})(typeof window !== 'undefined' ?
window :
typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {});

View File

@ -12,7 +12,7 @@
import {findEventTasks} from '../common/events';
import {patchTimer} from '../common/timers';
import {ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, zoneSymbol} from '../common/utils';
import {patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, zoneSymbol} from '../common/utils';
import {patchCustomElements} from './custom-elements';
import {eventTargetPatch, patchEvent} from './event-target';
@ -99,7 +99,9 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
}
const XMLHttpRequestPrototype: any = XMLHttpRequest.prototype;
function findPendingTask(target: any) { return target[XHR_TASK]; }
function findPendingTask(target: any) {
return target[XHR_TASK];
}
let oriAddListener = XMLHttpRequestPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER];
let oriRemoveListener = XMLHttpRequestPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
@ -170,7 +172,7 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
if (!storedTask) {
target[XHR_TASK] = task;
}
sendNative !.apply(target, data.args);
sendNative!.apply(target, data.args);
target[XHR_SCHEDULED] = true;
return task;
}
@ -182,14 +184,14 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
// Note - ideally, we would call data.target.removeEventListener here, but it's too late
// to prevent it from firing. So instead, we store info for the event listener.
data.aborted = true;
return abortNative !.apply(data.target, data.args);
return abortNative!.apply(data.target, data.args);
}
const openNative =
patchMethod(XMLHttpRequestPrototype, 'open', () => function(self: any, args: any[]) {
self[XHR_SYNC] = args[2] == false;
self[XHR_URL] = args[1];
return openNative !.apply(self, args);
return openNative!.apply(self, args);
});
const XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send';
@ -201,11 +203,11 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
// a fetch is scheduling, so we are using xhr to polyfill fetch
// and because we already schedule macroTask for fetch, we should
// not schedule a macroTask for xhr again
return sendNative !.apply(self, args);
return sendNative!.apply(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);
return sendNative!.apply(self, args);
} else {
const options: XHROptions =
{target: self, url: self[XHR_URL], isPeriodic: false, args: args, aborted: false};
@ -235,7 +237,7 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
task.zone.cancelTask(task);
} else if ((Zone.current as any)[fetchTaskAborting] === true) {
// the abort is called from fetch polyfill, we need to call native abort of XHR.
return abortNative !.apply(self, args);
return abortNative!.apply(self, args);
}
// Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
// task

View File

@ -7,7 +7,7 @@
*/
export function patchCustomElements(_global: any, api: _ZonePrivate) {
const {isBrowser, isMix} = api.getGlobalObjects() !;
const {isBrowser, isMix} = api.getGlobalObjects()!;
if ((!isBrowser && !isMix) || !_global['customElements'] || !('customElements' in _global)) {
return;
}

View File

@ -36,7 +36,9 @@ export function propertyPatch() {
};
Object.defineProperties = function(obj, props) {
Object.keys(props).forEach(function(prop) { Object.defineProperty(obj, prop, props[prop]); });
Object.keys(props).forEach(function(prop) {
Object.defineProperty(obj, prop, props[prop]);
});
return obj;
};

View File

@ -8,7 +8,7 @@
export function eventTargetLegacyPatch(_global: any, api: _ZonePrivate) {
const {eventNames, globalSources, zoneSymbolEventNames, TRUE_STR, FALSE_STR, ZONE_SYMBOL_PREFIX} =
api.getGlobalObjects() !;
api.getGlobalObjects()!;
const WTF_ISSUE_555 =
'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video';
const NO_EVENT_TARGET =

View File

@ -12,7 +12,7 @@ export function eventTargetPatch(_global: any, api: _ZonePrivate) {
return;
}
const {eventNames, zoneSymbolEventNames, TRUE_STR, FALSE_STR, ZONE_SYMBOL_PREFIX} =
api.getGlobalObjects() !;
api.getGlobalObjects()!;
// predefine all __zone_symbol__ + eventName + true/false string
for (let i = 0; i < eventNames.length; i++) {
const eventName = eventNames[i];

View File

@ -13,7 +13,7 @@
import * as webSocketPatch from './websocket';
export function propertyDescriptorLegacyPatch(api: _ZonePrivate, _global: any) {
const {isNode, isMix} = api.getGlobalObjects() !;
const {isNode, isMix} = api.getGlobalObjects()!;
if (isNode && !isMix) {
return;
}
@ -31,7 +31,7 @@ export function propertyDescriptorLegacyPatch(api: _ZonePrivate, _global: any) {
}
function canPatchViaPropertyDescriptor(api: _ZonePrivate, _global: any) {
const {isBrowser, isMix} = api.getGlobalObjects() !;
const {isBrowser, isMix} = api.getGlobalObjects()!;
if ((isBrowser || isMix) &&
!api.ObjectGetOwnPropertyDescriptor(HTMLElement.prototype, 'onclick') &&
typeof Element !== 'undefined') {
@ -42,9 +42,13 @@ function canPatchViaPropertyDescriptor(api: _ZonePrivate, _global: any) {
// try to use onclick to detect whether we can patch via propertyDescriptor
// because XMLHttpRequest is not available in service worker
if (desc) {
api.ObjectDefineProperty(
Element.prototype, 'onclick',
{enumerable: true, configurable: true, get: function() { return true; }});
api.ObjectDefineProperty(Element.prototype, 'onclick', {
enumerable: true,
configurable: true,
get: function() {
return true;
}
});
const div = document.createElement('div');
const result = !!div.onclick;
api.ObjectDefineProperty(Element.prototype, 'onclick', desc);
@ -70,9 +74,13 @@ function canPatchViaPropertyDescriptor(api: _ZonePrivate, _global: any) {
// and if XMLHttpRequest.prototype.onreadystatechange is undefined,
// we should set a real desc instead a fake one
if (xhrDesc) {
api.ObjectDefineProperty(
XMLHttpRequestPrototype, ON_READY_STATE_CHANGE,
{enumerable: true, configurable: true, get: function() { return true; }});
api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
enumerable: true,
configurable: true,
get: function() {
return true;
}
});
const req = new XMLHttpRequest();
const result = !!req.onreadystatechange;
// restore original desc
@ -83,8 +91,12 @@ function canPatchViaPropertyDescriptor(api: _ZonePrivate, _global: any) {
api.ObjectDefineProperty(XMLHttpRequestPrototype, ON_READY_STATE_CHANGE, {
enumerable: true,
configurable: true,
get: function() { return this[SYMBOL_FAKE_ONREADYSTATECHANGE]; },
set: function(value) { this[SYMBOL_FAKE_ONREADYSTATECHANGE] = value; }
get: function() {
return this[SYMBOL_FAKE_ONREADYSTATECHANGE];
},
set: function(value) {
this[SYMBOL_FAKE_ONREADYSTATECHANGE] = value;
}
});
const req = new XMLHttpRequest();
const detectFunc = () => {};
@ -99,7 +111,7 @@ function canPatchViaPropertyDescriptor(api: _ZonePrivate, _global: any) {
// for `onwhatever` properties and replace them with zone-bound functions
// - Chrome (for now)
function patchViaCapturingAllTheEvents(api: _ZonePrivate) {
const {eventNames} = api.getGlobalObjects() !;
const {eventNames} = api.getGlobalObjects()!;
const unboundKey = api.symbol('unbound');
for (let i = 0; i < eventNames.length; i++) {
const property = eventNames[i];

View File

@ -10,7 +10,7 @@
* @suppress {globalThis}
*/
import {ObjectGetPrototypeOf, isBrowser, isIE, isMix, isNode, patchOnProperties} from '../common/utils';
import {isBrowser, isIE, isMix, isNode, ObjectGetPrototypeOf, patchOnProperties} from '../common/utils';
const globalEventHandlersEventNames = [
'abort',

View File

@ -7,7 +7,7 @@
*/
export function registerElementPatch(_global: any, api: _ZonePrivate) {
const {isBrowser, isMix} = api.getGlobalObjects() !;
const {isBrowser, isMix} = api.getGlobalObjects()!;
if ((!isBrowser && !isMix) || !('registerElement' in (<any>_global).document)) {
return;
}

View File

@ -83,7 +83,9 @@ Zone.__load_patch('ResizeObserver', (global: any, Zone: any, api: _ZonePrivate)
ResizeObserver.prototype, 'disconnect', (delegate: Function) => (self: any, args: any[]) => {
const targets = self[resizeObserverSymbol];
if (targets) {
targets.forEach((target: any) => { target[resizeObserverSymbol] = undefined; });
targets.forEach((target: any) => {
target[resizeObserverSymbol] = undefined;
});
self[resizeObserverSymbol] = undefined;
}
return delegate.apply(self, args);

View File

@ -8,7 +8,7 @@
// we have to patch the instance since the proto is non-configurable
export function apply(api: _ZonePrivate, _global: any) {
const {ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR} = api.getGlobalObjects() !;
const {ADD_EVENT_LISTENER_STR, REMOVE_EVENT_LISTENER_STR} = api.getGlobalObjects()!;
const WS = (<any>_global).WebSocket;
// On Safari window.EventTarget doesn't exist so need to patch WS add/removeEventListener
// On older Chrome, no need since EventTarget was already patched

View File

@ -1,10 +1,10 @@
/**
* @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
*/
* @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
*/
/**
* @fileoverview Externs for zone.js
@ -148,8 +148,8 @@ Zone.prototype.scheduleMicroTask = function(source, callback, data, customSchedu
* @param {?function(!Task)=} customCancel
* @return {!MacroTask} macroTask
*/
Zone.prototype.scheduleMacroTask = function(source, callback, data, customSchedule, customCancel) {
};
Zone.prototype.scheduleMacroTask = function(
source, callback, data, customSchedule, customCancel) {};
/**
* @param {string} source
@ -159,8 +159,8 @@ Zone.prototype.scheduleMacroTask = function(source, callback, data, customSchedu
* @param {?function(!Task)=} customCancel
* @return {!EventTask} eventTask
*/
Zone.prototype.scheduleEventTask = function(source, callback, data, customSchedule, customCancel) {
};
Zone.prototype.scheduleEventTask = function(
source, callback, data, customSchedule, customCancel) {};
/**
* @param {!Task} task

View File

@ -53,7 +53,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
global['Error'] = ZoneAwareError;
const stackRewrite = 'stackRewrite';
type BlackListedStackFramesPolicy = 'default' | 'disable' | 'lazy';
type BlackListedStackFramesPolicy = 'default'|'disable'|'lazy';
const blackListedStackFramesPolicy: BlackListedStackFramesPolicy =
global['__Zone_Error_BlacklistedStackFrames_policy'] || 'default';
@ -75,7 +75,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
}
function buildZoneAwareStackFrames(
originalStack: string, zoneFrame: _ZoneFrame | ZoneFrameName | null, isZoneFrame = true) {
originalStack: string, zoneFrame: _ZoneFrame|ZoneFrameName|null, isZoneFrame = true) {
let frames: string[] = originalStack.split('\n');
let i = 0;
// Find the first frame
@ -115,7 +115,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
* This is ZoneAwareError which processes the stack frame and cleans up extra frames as well as
* adds zone information to it.
*/
function ZoneAwareError(this: unknown | typeof NativeError): Error {
function ZoneAwareError(this: unknown|typeof NativeError): Error {
// We always have to return native error otherwise the browser console will not work.
let error: Error = NativeError.apply(this, arguments);
// Save original stack trace
@ -190,8 +190,12 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
nativeErrorProperties.forEach(prop => {
if (specialPropertyNames.filter(sp => sp === prop).length === 0) {
Object.defineProperty(ZoneAwareError, prop, {
get: function() { return NativeError[prop]; },
set: function(value) { NativeError[prop] = value; }
get: function() {
return NativeError[prop];
},
set: function(value) {
NativeError[prop] = value;
}
});
}
});
@ -203,8 +207,12 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
// make sure that ZoneAwareError has the same property which forwards to NativeError.
Object.defineProperty(ZoneAwareError, 'stackTraceLimit', {
get: function() { return NativeError.stackTraceLimit; },
set: function(value) { return NativeError.stackTraceLimit = value; }
get: function() {
return NativeError.stackTraceLimit;
},
set: function(value) {
return NativeError.stackTraceLimit = value;
}
});
}
@ -220,7 +228,9 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
const ZONE_CAPTURESTACKTRACE = 'zoneCaptureStackTrace';
Object.defineProperty(ZoneAwareError, 'prepareStackTrace', {
get: function() { return NativeError.prepareStackTrace; },
get: function() {
return NativeError.prepareStackTrace;
},
set: function(value) {
if (!value || typeof value !== 'function') {
return NativeError.prepareStackTrace = value;
@ -347,13 +357,21 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
blacklistedStackFramesSymbol,
() => {
childDetectZone.scheduleMicroTask(
blacklistedStackFramesSymbol, () => { throw new Error(); }, undefined,
blacklistedStackFramesSymbol,
() => {
throw new Error();
},
undefined,
(t: Task) => {
(t as any)._transitionTo = fakeTransitionTo;
t.invoke();
});
childDetectZone.scheduleMicroTask(
blacklistedStackFramesSymbol, () => { throw Error(); }, undefined,
blacklistedStackFramesSymbol,
() => {
throw Error();
},
undefined,
(t: Task) => {
(t as any)._transitionTo = fakeTransitionTo;
t.invoke();

View File

@ -10,7 +10,7 @@
* @suppress {missingRequire}
*/
import {ADD_EVENT_LISTENER_STR, FALSE_STR, ObjectGetPrototypeOf, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, attachOriginToPatched, isNode, zoneSymbol} from './utils';
import {ADD_EVENT_LISTENER_STR, attachOriginToPatched, FALSE_STR, isNode, ObjectGetPrototypeOf, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, zoneSymbol} from './utils';
/** @internal **/
@ -23,8 +23,11 @@ let passiveSupported = false;
if (typeof window !== 'undefined') {
try {
const options =
Object.defineProperty({}, 'passive', {get: function() { passiveSupported = true; }});
const options = Object.defineProperty({}, 'passive', {
get: function() {
passiveSupported = true;
}
});
window.addEventListener('test', options, options);
window.removeEventListener('test', options, options);
} catch (err) {

View File

@ -53,7 +53,7 @@ Zone.__load_patch('fetch', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
const signal = options && options.signal;
return new Promise((res, rej) => {
const task = Zone.current.scheduleMacroTask(
'fetch', placeholder, { fetchArgs: args } as FetchTaskData,
'fetch', placeholder, {fetchArgs: args} as FetchTaskData,
() => {
let fetchPromise;
let zone = Zone.current;

View File

@ -50,11 +50,13 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
}
}
data.args[0] = timer;
data.handleId = setNative !.apply(window, data.args);
data.handleId = setNative!.apply(window, data.args);
return task;
}
function clearTask(task: Task) { return clearNative !((<TimerOptions>task.data).handleId); }
function clearTask(task: Task) {
return clearNative!((<TimerOptions>task.data).handleId);
}
setNative =
patchMethod(window, setName, (delegate: Function) => function(self: any, args: any[]) {
@ -116,7 +118,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
}
if (task && typeof task.type === 'string') {
if (task.state !== 'notScheduled' &&
(task.cancelFn && task.data !.isPeriodic || task.runCount === 0)) {
(task.cancelFn && task.data!.isPeriodic || task.runCount === 0)) {
if (typeof id === 'number') {
delete tasksByHandleId[id];
} else if (id) {

View File

@ -250,8 +250,8 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
// so we should use original native get to retrieve the handler
let value = originalDescGet && originalDescGet.call(this);
if (value) {
desc !.set !.call(this, value);
if (typeof(target as any)[REMOVE_ATTRIBUTE] === 'function') {
desc!.set!.call(this, value);
if (typeof (target as any)[REMOVE_ATTRIBUTE] === 'function') {
(target as any).removeAttribute(prop);
}
return value;
@ -265,7 +265,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
obj[onPropPatchedSymbol] = true;
}
export function patchOnProperties(obj: any, properties: string[] | null, prototype?: any) {
export function patchOnProperties(obj: any, properties: string[]|null, prototype?: any) {
if (properties) {
for (let i = 0; i < properties.length; i++) {
patchProperty(obj, 'on' + properties[i], prototype);
@ -342,7 +342,9 @@ export function patchClass(className: string) {
this[originalInstanceKey][prop] = fn;
}
},
get: function() { return this[originalInstanceKey][prop]; }
get: function() {
return this[originalInstanceKey][prop];
}
});
}
}(prop));
@ -356,14 +358,16 @@ export function patchClass(className: string) {
}
export function copySymbolProperties(src: any, dest: any) {
if (typeof(Object as any).getOwnPropertySymbols !== 'function') {
if (typeof (Object as any).getOwnPropertySymbols !== 'function') {
return;
}
const symbols: any = (Object as any).getOwnPropertySymbols(src);
symbols.forEach((symbol: any) => {
const desc = Object.getOwnPropertyDescriptor(src, symbol);
Object.defineProperty(dest, symbol, {
get: function() { return src[symbol]; },
get: function() {
return src[symbol];
},
set: function(value: any) {
if (desc && (!desc.writable || typeof desc.set !== 'function')) {
// if src[symbol] is not writable or not have a setter, just return
@ -384,8 +388,9 @@ export function setShouldCopySymbolProperties(flag: boolean) {
}
export function patchMethod(
target: any, name: string, patchFn: (delegate: Function, delegateName: string, name: string) =>
(self: any, args: any[]) => any): Function|null {
target: any, name: string,
patchFn: (delegate: Function, delegateName: string, name: string) => (self: any, args: any[]) =>
any): Function|null {
let proto = target;
while (proto && !proto.hasOwnProperty(name)) {
proto = ObjectGetPrototypeOf(proto);
@ -403,8 +408,10 @@ export function patchMethod(
// some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
const desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
if (isPropertyWritable(desc)) {
const patchDelegate = patchFn(delegate !, delegateName, name);
proto[name] = function() { return patchDelegate(this, arguments as any); };
const patchDelegate = patchFn(delegate!, delegateName, name);
proto[name] = function() {
return patchDelegate(this, arguments as any);
};
attachOriginToPatched(proto[name], delegate);
if (shouldCopySymbolProperties) {
copySymbolProperties(delegate, proto[name]);
@ -428,8 +435,10 @@ export function patchMacroTask(
function scheduleTask(task: Task) {
const data = <MacroTaskMeta>task.data;
data.args[data.cbIdx] = function() { task.invoke.apply(this, arguments); };
setNative !.apply(data.target, data.args);
data.args[data.cbIdx] = function() {
task.invoke.apply(this, arguments);
};
setNative!.apply(data.target, data.args);
return task;
}
@ -457,8 +466,10 @@ export function patchMicroTask(
function scheduleTask(task: Task) {
const data = <MacroTaskMeta>task.data;
data.args[data.cbIdx] = function() { task.invoke.apply(this, arguments); };
setNative !.apply(data.target, data.args);
data.args[data.cbIdx] = function() {
task.invoke.apply(this, arguments);
};
setNative!.apply(data.target, data.args);
return task;
}

View File

@ -18,7 +18,7 @@ Zone.__load_patch('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
if (args.length > 1 && typeof args[1] === FUNCTION) {
args[1] = Zone.current.wrap(args[1], ERROR_SOURCE);
}
return nativeExec !.apply(self, args);
return nativeExec!.apply(self, args);
});
}
});
@ -31,7 +31,9 @@ Zone.__load_patch('cordova.FileReader', (global: any, Zone: ZoneType) => {
const eventNameSymbol = Zone.__symbol__('ON_PROPERTY' + prop);
Object.defineProperty(FileReader.prototype, eventNameSymbol, {
configurable: true,
get: function() { return this._realReader && this._realReader[eventNameSymbol]; }
get: function() {
return this._realReader && this._realReader[eventNameSymbol];
}
});
});
});

View File

@ -70,8 +70,10 @@ Zone.__load_patch('jsonp', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api.patchMethod(
options.jsonp, options.sendFuncName, (delegate: Function) => (self: any, args: any[]) => {
global[api.symbol('jsonpTask')] = Zone.current.scheduleMacroTask(
'jsonp', noop, {}, (task: Task) => { return delegate.apply(self, args); }, noop);
global[api.symbol('jsonpTask')] =
Zone.current.scheduleMacroTask('jsonp', noop, {}, (task: Task) => {
return delegate.apply(self, args);
}, noop);
});
};
});

View File

@ -12,7 +12,9 @@ Zone.__load_patch('socketio', (global: any, Zone: ZoneType, api: _ZonePrivate) =
useG: false,
chkDup: false,
rt: true,
diff: (task: any, delegate: any) => { return task.callback === delegate; }
diff: (task: any, delegate: any) => {
return task.callback === delegate;
}
});
// also patch io.Socket.prototype.on/off/removeListener/removeAllListeners
io.Socket.prototype.on = io.Socket.prototype.addEventListener;

View File

@ -14,7 +14,9 @@ Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
const __extends = function(d: any, b: any) {
for (const p in b)
if (b.hasOwnProperty(p)) d[p] = b[p];
function __(this: Object) { this.constructor = d; }
function __(this: Object) {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new (__ as any)());
};
// Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs
@ -126,9 +128,9 @@ Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
if (fakeAsyncZoneSpec) {
const dateTime = arguments.length > 0 ? arguments[0] : new Date();
return fakeAsyncZoneSpec.setCurrentRealTime.apply(
fakeAsyncZoneSpec, dateTime && typeof dateTime.getTime === 'function' ?
[dateTime.getTime()] :
arguments);
fakeAsyncZoneSpec,
dateTime && typeof dateTime.getTime === 'function' ? [dateTime.getTime()] :
arguments);
}
return originalMockDate.apply(this, arguments);
};
@ -163,8 +165,8 @@ Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
function runInTestZone(
testBody: Function, applyThis: any, queueRunner: QueueRunner, done?: Function) {
const isClockInstalled = !!(jasmine as any)[symbol('clockInstalled')];
const testProxyZoneSpec = queueRunner.testProxyZoneSpec !;
const testProxyZone = queueRunner.testProxyZone !;
const testProxyZoneSpec = queueRunner.testProxyZoneSpec!;
const testProxyZone = queueRunner.testProxyZone!;
let lastDelegate;
if (isClockInstalled && enableAutoFakeAsyncWhenClockPatched) {
// auto run a fakeAsync
@ -190,9 +192,9 @@ Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
// Note we have to make a function with correct number of arguments, otherwise jasmine will
// think that all functions are sync or async.
return (testBody && (testBody.length ? function(this: QueueRunnerUserContext, done: Function) {
return runInTestZone(testBody, this, this.queueRunner !, done);
return runInTestZone(testBody, this, this.queueRunner!, done);
} : function(this: QueueRunnerUserContext) {
return runInTestZone(testBody, this, this.queueRunner !);
return runInTestZone(testBody, this, this.queueRunner!);
}));
}
interface QueueRunner {

View File

@ -57,10 +57,12 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
// Note we have to make a function with correct number of arguments,
// otherwise mocha will
// think that all functions are sync or async.
args[i] = (arg.length === 0) ? syncTest(arg) : asyncTest !(arg);
args[i] = (arg.length === 0) ? syncTest(arg) : asyncTest!(arg);
// Mocha uses toString to view the test body in the result list, make sure we return the
// correct function body
args[i].toString = function() { return arg.toString(); };
args[i].toString = function() {
return arg.toString();
};
}
}
@ -69,7 +71,9 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
function wrapDescribeInZone(args: IArguments): any[] {
const syncTest: any = function(fn: Function) {
return function(this: unknown) { return syncZone.run(fn, this, arguments as any as any[]); };
return function(this: unknown) {
return syncZone.run(fn, this, arguments as any as any[]);
};
};
return modifyArguments(args, syncTest);
@ -77,11 +81,15 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
function wrapTestInZone(args: IArguments): any[] {
const asyncTest = function(fn: Function) {
return function(this: unknown, done: Function) { return testZone !.run(fn, this, [done]); };
return function(this: unknown, done: Function) {
return testZone!.run(fn, this, [done]);
};
};
const syncTest: any = function(fn: Function) {
return function(this: unknown) { return testZone !.run(fn, this); };
return function(this: unknown) {
return testZone!.run(fn, this);
};
};
return modifyArguments(args, syncTest, asyncTest);
@ -89,11 +97,15 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
function wrapSuiteInZone(args: IArguments): any[] {
const asyncTest = function(fn: Function) {
return function(this: unknown, done: Function) { return suiteZone.run(fn, this, [done]); };
return function(this: unknown, done: Function) {
return suiteZone.run(fn, this, [done]);
};
};
const syncTest: any = function(fn: Function) {
return function(this: unknown) { return suiteZone.run(fn, this); };
return function(this: unknown) {
return suiteZone.run(fn, this);
};
};
return modifyArguments(args, syncTest, asyncTest);
@ -111,8 +123,9 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
return mochaOriginal.describe.only.apply(this, wrapDescribeInZone(arguments));
};
global.it = global.specify = global.test =
Mocha.it = function() { return mochaOriginal.it.apply(this, wrapTestInZone(arguments)); };
global.it = global.specify = global.test = Mocha.it = function() {
return mochaOriginal.it.apply(this, wrapTestInZone(arguments));
};
global.xit = global.xspecify = Mocha.it.skip = function() {
return mochaOriginal.it.skip.apply(this, wrapTestInZone(arguments));
@ -140,11 +153,15 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
((originalRunTest, originalRun) => {
Mocha.Runner.prototype.runTest = function(fn: Function) {
Zone.current.scheduleMicroTask('mocha.forceTask', () => { originalRunTest.call(this, fn); });
Zone.current.scheduleMicroTask('mocha.forceTask', () => {
originalRunTest.call(this, fn);
});
};
Mocha.Runner.prototype.run = function(fn: Function) {
this.on('test', (e: any) => { testZone = rootZone.fork(new ProxyZoneSpec()); });
this.on('test', (e: any) => {
testZone = rootZone.fork(new ProxyZoneSpec());
});
this.on('fail', (test: any, err: any) => {
const proxyZoneSpec = testZone && testZone.get('ProxyZoneSpec');

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Scheduler, asapScheduler, asyncScheduler} from 'rxjs';
import {asapScheduler, asyncScheduler, Scheduler} from 'rxjs';
Zone.__load_patch('rxjs.Scheduler.now', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api.patchMethod(Scheduler, 'now', (delegate: Function) => (self: any, args: any[]) => {

View File

@ -10,7 +10,7 @@ import {Observable, Subscriber, Subscription} from 'rxjs';
type ZoneSubscriberContext = {
_zone: Zone
} & Subscriber<any>;
}&Subscriber<any>;
(Zone as any).__load_patch('rxjs', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
const symbol: (symbolString: string) => string = (Zone as any).__symbol__;
@ -31,7 +31,9 @@ type ZoneSubscriberContext = {
_zoneSubscribe: {value: null, writable: true, configurable: true},
source: {
configurable: true,
get: function(this: Observable<any>) { return (this as any)._zoneSource; },
get: function(this: Observable<any>) {
return (this as any)._zoneSource;
},
set: function(this: Observable<any>, source: any) {
(this as any)._zone = Zone.current;
(this as any)._zoneSource = source;
@ -75,7 +77,9 @@ type ZoneSubscriberContext = {
}
},
subjectFactory: {
get: function() { return (this as any)._zoneSubjectFactory; },
get: function() {
return (this as any)._zoneSubjectFactory;
},
set: function(factory: any) {
const zone = this._zone;
this._zoneSubjectFactory = function() {
@ -142,7 +146,9 @@ type ZoneSubscriberContext = {
Object.defineProperty(Subscriber.prototype, 'destination', {
configurable: true,
get: function(this: Subscriber<any>) { return (this as any)._zoneDestination; },
get: function(this: Subscriber<any>) {
return (this as any)._zoneDestination;
},
set: function(this: Subscriber<any>, destination: any) {
(this as any)._zone = Zone.current;
(this as any)._zoneDestination = destination;

View File

@ -22,7 +22,9 @@ Zone.__load_patch('asynctest', (global: any, Zone: ZoneType, api: _ZonePrivate)
// if we run beforeEach in @angular/core/testing/testing_internal then we get no done
// fake it here and assume sync.
done = function() {};
done.fail = function(e: any) { throw e; };
done.fail = function(e: any) {
throw e;
};
}
runInTestZone(fn, this, done, (err: any) => {
if (typeof err === 'string') {
@ -68,7 +70,7 @@ Zone.__load_patch('asynctest', (global: any, Zone: ZoneType, api: _ZonePrivate)
// If we do it in ProxyZone then we will get to infinite recursion.
const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
const previousDelegate = proxyZoneSpec.getDelegate();
proxyZone !.parent !.run(() => {
proxyZone!.parent!.run(() => {
const testZoneSpec: ZoneSpec = new AsyncTestZoneSpec(
() => {
// Need to restore the original zone.
@ -79,7 +81,9 @@ Zone.__load_patch('asynctest', (global: any, Zone: ZoneType, api: _ZonePrivate)
proxyZoneSpec.setDelegate(previousDelegate);
}
(testZoneSpec as any).unPatchPromiseForTest();
currentZone.run(() => { finishCallback(); });
currentZone.run(() => {
finishCallback();
});
},
(error: any) => {
// Need to restore the original zone.
@ -88,7 +92,9 @@ Zone.__load_patch('asynctest', (global: any, Zone: ZoneType, api: _ZonePrivate)
proxyZoneSpec.setDelegate(previousDelegate);
}
(testZoneSpec as any).unPatchPromiseForTest();
currentZone.run(() => { failCallback(error); });
currentZone.run(() => {
failCallback(error);
});
},
'test');
proxyZoneSpec.setDelegate(testZoneSpec);

View File

@ -131,7 +131,9 @@ Zone.__load_patch('fakeasync', (global: any, Zone: ZoneType, api: _ZonePrivate)
*
* @experimental
*/
function flush(maxTurns?: number): number { return _getFakeAsyncZoneSpec().flush(maxTurns); }
function flush(maxTurns?: number): number {
return _getFakeAsyncZoneSpec().flush(maxTurns);
}
/**
* Discard all remaining periodic tasks.
@ -149,7 +151,9 @@ Zone.__load_patch('fakeasync', (global: any, Zone: ZoneType, api: _ZonePrivate)
*
* @experimental
*/
function flushMicrotasks(): void { _getFakeAsyncZoneSpec().flushMicrotasks(); }
(Zone as any)[api.symbol('fakeAsyncTest')] = {
resetFakeAsyncZone, flushMicrotasks, discardPeriodicTasks, tick, flush, fakeAsync};
function flushMicrotasks(): void {
_getFakeAsyncZoneSpec().flushMicrotasks();
}
(Zone as any)[api.symbol('fakeAsyncTest')] =
{resetFakeAsyncZone, flushMicrotasks, discardPeriodicTasks, tick, flush, fakeAsync};
});

View File

@ -6,144 +6,144 @@
* found in the LICENSE file at https://angular.io/license
*/
(function(_global: any) {
class AsyncTestZoneSpec implements ZoneSpec {
static symbolParentUnresolved = Zone.__symbol__('parentUnresolved');
class AsyncTestZoneSpec implements ZoneSpec {
static symbolParentUnresolved = Zone.__symbol__('parentUnresolved');
_pendingMicroTasks: boolean = false;
_pendingMacroTasks: boolean = false;
_alreadyErrored: boolean = false;
_isSync: boolean = false;
runZone = Zone.current;
unresolvedChainedPromiseCount = 0;
_pendingMicroTasks: boolean = false;
_pendingMacroTasks: boolean = false;
_alreadyErrored: boolean = false;
_isSync: boolean = false;
runZone = Zone.current;
unresolvedChainedPromiseCount = 0;
supportWaitUnresolvedChainedPromise = false;
supportWaitUnresolvedChainedPromise = false;
constructor(
private finishCallback: Function, private failCallback: Function, namePrefix: string) {
this.name = 'asyncTestZone for ' + namePrefix;
this.properties = {'AsyncTestZoneSpec': this};
this.supportWaitUnresolvedChainedPromise =
_global[Zone.__symbol__('supportWaitUnResolvedChainedPromise')] === true;
constructor(
private finishCallback: Function, private failCallback: Function, namePrefix: string) {
this.name = 'asyncTestZone for ' + namePrefix;
this.properties = {'AsyncTestZoneSpec': this};
this.supportWaitUnresolvedChainedPromise =
_global[Zone.__symbol__('supportWaitUnResolvedChainedPromise')] === true;
}
isUnresolvedChainedPromisePending() {
return this.unresolvedChainedPromiseCount > 0;
}
_finishCallbackIfDone() {
if (!(this._pendingMicroTasks || this._pendingMacroTasks ||
(this.supportWaitUnresolvedChainedPromise && this.isUnresolvedChainedPromisePending()))) {
// We do this because we would like to catch unhandled rejected promises.
this.runZone.run(() => {
setTimeout(() => {
if (!this._alreadyErrored && !(this._pendingMicroTasks || this._pendingMacroTasks)) {
this.finishCallback();
}
}, 0);
});
}
}
isUnresolvedChainedPromisePending() { return this.unresolvedChainedPromiseCount > 0; }
patchPromiseForTest() {
if (!this.supportWaitUnresolvedChainedPromise) {
return;
}
const patchPromiseForTest = (Promise as any)[Zone.__symbol__('patchPromiseForTest')];
if (patchPromiseForTest) {
patchPromiseForTest();
}
}
_finishCallbackIfDone() {
if (!(this._pendingMicroTasks || this._pendingMacroTasks ||
(this.supportWaitUnresolvedChainedPromise &&
this.isUnresolvedChainedPromisePending()))) {
// We do this because we would like to catch unhandled rejected promises.
this.runZone.run(() => {
setTimeout(() => {
if (!this._alreadyErrored && !(this._pendingMicroTasks || this._pendingMacroTasks)) {
this.finishCallback();
}
}, 0);
});
unPatchPromiseForTest() {
if (!this.supportWaitUnresolvedChainedPromise) {
return;
}
const unPatchPromiseForTest = (Promise as any)[Zone.__symbol__('unPatchPromiseForTest')];
if (unPatchPromiseForTest) {
unPatchPromiseForTest();
}
}
// ZoneSpec implementation below.
name: string;
properties: {[key: string]: any};
onScheduleTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): Task {
if (task.type !== 'eventTask') {
this._isSync = false;
}
if (task.type === 'microTask' && task.data && task.data instanceof Promise) {
// check whether the promise is a chained promise
if ((task.data as any)[AsyncTestZoneSpec.symbolParentUnresolved] === true) {
// chained promise is being scheduled
this.unresolvedChainedPromiseCount--;
}
}
return delegate.scheduleTask(target, task);
}
patchPromiseForTest() {
if (!this.supportWaitUnresolvedChainedPromise) {
return;
}
const patchPromiseForTest = (Promise as any)[Zone.__symbol__('patchPromiseForTest')];
if (patchPromiseForTest) {
patchPromiseForTest();
}
onInvokeTask(
delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, applyThis: any,
applyArgs: any) {
if (task.type !== 'eventTask') {
this._isSync = false;
}
return delegate.invokeTask(target, task, applyThis, applyArgs);
}
unPatchPromiseForTest() {
if (!this.supportWaitUnresolvedChainedPromise) {
return;
}
const unPatchPromiseForTest = (Promise as any)[Zone.__symbol__('unPatchPromiseForTest')];
if (unPatchPromiseForTest) {
unPatchPromiseForTest();
}
onCancelTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task) {
if (task.type !== 'eventTask') {
this._isSync = false;
}
return delegate.cancelTask(target, task);
}
// ZoneSpec implementation below.
name: string;
properties: {[key: string]: any};
onScheduleTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): Task {
if (task.type !== 'eventTask') {
this._isSync = false;
}
if (task.type === 'microTask' && task.data && task.data instanceof Promise) {
// check whether the promise is a chained promise
if ((task.data as any)[AsyncTestZoneSpec.symbolParentUnresolved] === true) {
// chained promise is being scheduled
this.unresolvedChainedPromiseCount--;
}
}
return delegate.scheduleTask(target, task);
}
onInvokeTask(
delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, applyThis: any,
applyArgs: any) {
if (task.type !== 'eventTask') {
this._isSync = false;
}
return delegate.invokeTask(target, task, applyThis, applyArgs);
}
onCancelTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task) {
if (task.type !== 'eventTask') {
this._isSync = false;
}
return delegate.cancelTask(target, task);
}
// Note - we need to use onInvoke at the moment to call finish when a test is
// fully synchronous. TODO(juliemr): remove this when the logic for
// onHasTask changes and it calls whenever the task queues are dirty.
// updated by(JiaLiPassion), only call finish callback when no task
// was scheduled/invoked/canceled.
onInvoke(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function,
applyThis: any, applyArgs?: any[], source?: string): any {
let previousTaskCounts: any = null;
try {
this._isSync = true;
return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source);
} finally {
const afterTaskCounts: any = (parentZoneDelegate as any)._taskCounts;
if (this._isSync) {
this._finishCallbackIfDone();
}
}
}
onHandleError(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
error: any): boolean {
// Let the parent try to handle the error.
const result = parentZoneDelegate.handleError(targetZone, error);
if (result) {
this.failCallback(error);
this._alreadyErrored = true;
}
return false;
}
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) {
delegate.hasTask(target, hasTaskState);
if (hasTaskState.change == 'microTask') {
this._pendingMicroTasks = hasTaskState.microTask;
this._finishCallbackIfDone();
} else if (hasTaskState.change == 'macroTask') {
this._pendingMacroTasks = hasTaskState.macroTask;
// Note - we need to use onInvoke at the moment to call finish when a test is
// fully synchronous. TODO(juliemr): remove this when the logic for
// onHasTask changes and it calls whenever the task queues are dirty.
// updated by(JiaLiPassion), only call finish callback when no task
// was scheduled/invoked/canceled.
onInvoke(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function,
applyThis: any, applyArgs?: any[], source?: string): any {
let previousTaskCounts: any = null;
try {
this._isSync = true;
return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source);
} finally {
const afterTaskCounts: any = (parentZoneDelegate as any)._taskCounts;
if (this._isSync) {
this._finishCallbackIfDone();
}
}
}
// Export the class so that new instances can be created with proper
// constructor params.
(Zone as any)['AsyncTestZoneSpec'] = AsyncTestZoneSpec;
onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: any):
boolean {
// Let the parent try to handle the error.
const result = parentZoneDelegate.handleError(targetZone, error);
if (result) {
this.failCallback(error);
this._alreadyErrored = true;
}
return false;
}
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) {
delegate.hasTask(target, hasTaskState);
if (hasTaskState.change == 'microTask') {
this._pendingMicroTasks = hasTaskState.microTask;
this._finishCallbackIfDone();
} else if (hasTaskState.change == 'macroTask') {
this._pendingMacroTasks = hasTaskState.macroTask;
this._finishCallbackIfDone();
}
}
}
// Export the class so that new instances can be created with proper
// constructor params.
(Zone as any)['AsyncTestZoneSpec'] = AsyncTestZoneSpec;
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);

File diff suppressed because it is too large Load Diff

View File

@ -88,7 +88,7 @@ function stackTracesEnabled(): boolean {
return (Error as any).stackTraceLimit > 0;
}
type LongStackTraceZoneSpec = ZoneSpec & {longStackTraceLimit: number};
type LongStackTraceZoneSpec = ZoneSpec&{longStackTraceLimit: number};
(Zone as any)['longStackTraceZoneSpec'] = <LongStackTraceZoneSpec>{
name: 'long-stack-trace',

View File

@ -18,9 +18,13 @@ class ProxyZoneSpec implements ZoneSpec {
private tasks: Task[] = [];
static get(): ProxyZoneSpec { return Zone.current.get('ProxyZoneSpec'); }
static get(): ProxyZoneSpec {
return Zone.current.get('ProxyZoneSpec');
}
static isLoaded(): boolean { return ProxyZoneSpec.get() instanceof ProxyZoneSpec; }
static isLoaded(): boolean {
return ProxyZoneSpec.get() instanceof ProxyZoneSpec;
}
static assertPresent(): ProxyZoneSpec {
if (!ProxyZoneSpec.isLoaded()) {
@ -40,7 +44,7 @@ class ProxyZoneSpec implements ZoneSpec {
this.propertyKeys = null;
if (delegateSpec && delegateSpec.properties) {
this.propertyKeys = Object.keys(delegateSpec.properties);
this.propertyKeys.forEach((k) => this.properties[k] = delegateSpec.properties ![k]);
this.propertyKeys.forEach((k) => this.properties[k] = delegateSpec.properties![k]);
}
// if a new delegateSpec was set, check if we need to trigger hasTask
if (isNewDelegate && this.lastTaskState &&
@ -49,7 +53,9 @@ class ProxyZoneSpec implements ZoneSpec {
}
}
getDelegate() { return this._delegateSpec; }
getDelegate() {
return this._delegateSpec;
}
resetDelegate() {
@ -85,7 +91,9 @@ class ProxyZoneSpec implements ZoneSpec {
const taskInfo = this.tasks.map((task: Task) => {
const dataInfo = task.data &&
Object.keys(task.data)
.map((key: string) => { return key + ':' + (task.data as any)[key]; })
.map((key: string) => {
return key + ':' + (task.data as any)[key];
})
.join(',');
return `type: ${task.type}, source: ${task.source}, args: {${dataInfo}}`;
});

View File

@ -9,7 +9,9 @@
class SyncTestZoneSpec implements ZoneSpec {
runZone = Zone.current;
constructor(namePrefix: string) { this.name = 'syncTestZone for ' + namePrefix; }
constructor(namePrefix: string) {
this.name = 'syncTestZone for ' + namePrefix;
}
// ZoneSpec implementation below.

View File

@ -19,7 +19,9 @@ class TaskTrackingZoneSpec implements ZoneSpec {
eventTasks: Task[] = [];
properties: {[key: string]: any} = {'TaskTrackingZone': this};
static get() { return Zone.current.get('TaskTrackingZone'); }
static get() {
return Zone.current.get('TaskTrackingZone');
}
private getTasksFor(type: string): Task[] {
switch (type) {

View File

@ -11,152 +11,150 @@
*/
(function(global: any) {
interface Wtf {
trace: WtfTrace;
}
interface WtfScope {}
interface WtfRange {}
interface WtfTrace {
events: WtfEvents;
leaveScope(scope: WtfScope, returnValue?: any): void;
beginTimeRange(rangeType: string, action: string): WtfRange;
endTimeRange(range: WtfRange): void;
}
interface WtfEvents {
createScope(signature: string, flags?: any): WtfScopeFn;
createInstance(signature: string, flags?: any): WtfEventFn;
}
interface Wtf {
trace: WtfTrace;
}
interface WtfScope {}
interface WtfRange {}
interface WtfTrace {
events: WtfEvents;
leaveScope(scope: WtfScope, returnValue?: any): void;
beginTimeRange(rangeType: string, action: string): WtfRange;
endTimeRange(range: WtfRange): void;
}
interface WtfEvents {
createScope(signature: string, flags?: any): WtfScopeFn;
createInstance(signature: string, flags?: any): WtfEventFn;
}
type WtfScopeFn = (...args: any[]) => WtfScope;
type WtfEventFn = (...args: any[]) => any;
type WtfScopeFn = (...args: any[]) => WtfScope;
type WtfEventFn = (...args: any[]) => any;
// Detect and setup WTF.
let wtfTrace: WtfTrace|null = null;
let wtfEvents: WtfEvents|null = null;
const wtfEnabled: boolean = (function(): boolean {
const wtf: Wtf = global['wtf'];
if (wtf) {
wtfTrace = wtf.trace;
if (wtfTrace) {
wtfEvents = wtfTrace.events;
return true;
}
}
return false;
})();
class WtfZoneSpec implements ZoneSpec {
name: string = 'WTF';
static forkInstance =
wtfEnabled? wtfEvents !.createInstance('Zone:fork(ascii zone, ascii newZone)'): null;
static scheduleInstance: {[key: string]: WtfEventFn} = {};
static cancelInstance: {[key: string]: WtfEventFn} = {};
static invokeScope: {[key: string]: WtfEventFn} = {};
static invokeTaskScope: {[key: string]: WtfEventFn} = {};
onFork(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
zoneSpec: ZoneSpec): Zone {
const retValue = parentZoneDelegate.fork(targetZone, zoneSpec);
WtfZoneSpec.forkInstance !(zonePathName(targetZone), retValue.name);
return retValue;
}
onInvoke(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function,
applyThis: any, applyArgs?: any[], source?: string): any {
const src = source || 'unknown';
let scope = WtfZoneSpec.invokeScope[src];
if (!scope) {
scope = WtfZoneSpec.invokeScope[src] =
wtfEvents !.createScope(`Zone:invoke:${source}(ascii zone)`);
}
return wtfTrace !.leaveScope(
scope(zonePathName(targetZone)),
parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source));
}
onHandleError(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
error: any): boolean {
return parentZoneDelegate.handleError(targetZone, error);
}
onScheduleTask(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): any {
const key = task.type + ':' + task.source;
let instance = WtfZoneSpec.scheduleInstance[key];
if (!instance) {
instance = WtfZoneSpec.scheduleInstance[key] =
wtfEvents !.createInstance(`Zone:schedule:${key}(ascii zone, any data)`);
}
const retValue = parentZoneDelegate.scheduleTask(targetZone, task);
instance(zonePathName(targetZone), shallowObj(task.data, 2));
return retValue;
}
onInvokeTask(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task,
applyThis?: any, applyArgs?: any[]): any {
const source = task.source;
let scope = WtfZoneSpec.invokeTaskScope[source];
if (!scope) {
scope = WtfZoneSpec.invokeTaskScope[source] =
wtfEvents !.createScope(`Zone:invokeTask:${source}(ascii zone)`);
}
return wtfTrace !.leaveScope(
scope(zonePathName(targetZone)),
parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs));
}
onCancelTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
any {
const key = task.source;
let instance = WtfZoneSpec.cancelInstance[key];
if (!instance) {
instance = WtfZoneSpec.cancelInstance[key] =
wtfEvents !.createInstance(`Zone:cancel:${key}(ascii zone, any options)`);
}
const retValue = parentZoneDelegate.cancelTask(targetZone, task);
instance(zonePathName(targetZone), shallowObj(task.data, 2));
return retValue;
// Detect and setup WTF.
let wtfTrace: WtfTrace|null = null;
let wtfEvents: WtfEvents|null = null;
const wtfEnabled: boolean = (function(): boolean {
const wtf: Wtf = global['wtf'];
if (wtf) {
wtfTrace = wtf.trace;
if (wtfTrace) {
wtfEvents = wtfTrace.events;
return true;
}
}
return false;
})();
function shallowObj(obj: {[k: string]: any} | undefined, depth: number): any {
if (!obj || !depth) return null;
const out: {[k: string]: any} = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
// explicit : any due to https://github.com/microsoft/TypeScript/issues/33191
let value: any = obj[key];
switch (typeof value) {
case 'object':
const name = value && value.constructor && (<any>value.constructor).name;
value = name == (<any>Object).name ? shallowObj(value, depth - 1) : name;
break;
case 'function':
value = value.name || undefined;
break;
}
out[key] = value;
class WtfZoneSpec implements ZoneSpec {
name: string = 'WTF';
static forkInstance =
wtfEnabled ? wtfEvents!.createInstance('Zone:fork(ascii zone, ascii newZone)') : null;
static scheduleInstance: {[key: string]: WtfEventFn} = {};
static cancelInstance: {[key: string]: WtfEventFn} = {};
static invokeScope: {[key: string]: WtfEventFn} = {};
static invokeTaskScope: {[key: string]: WtfEventFn} = {};
onFork(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, zoneSpec: ZoneSpec):
Zone {
const retValue = parentZoneDelegate.fork(targetZone, zoneSpec);
WtfZoneSpec.forkInstance!(zonePathName(targetZone), retValue.name);
return retValue;
}
onInvoke(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function,
applyThis: any, applyArgs?: any[], source?: string): any {
const src = source || 'unknown';
let scope = WtfZoneSpec.invokeScope[src];
if (!scope) {
scope = WtfZoneSpec.invokeScope[src] =
wtfEvents!.createScope(`Zone:invoke:${source}(ascii zone)`);
}
return wtfTrace!.leaveScope(
scope(zonePathName(targetZone)),
parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source));
}
onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: any):
boolean {
return parentZoneDelegate.handleError(targetZone, error);
}
onScheduleTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
any {
const key = task.type + ':' + task.source;
let instance = WtfZoneSpec.scheduleInstance[key];
if (!instance) {
instance = WtfZoneSpec.scheduleInstance[key] =
wtfEvents!.createInstance(`Zone:schedule:${key}(ascii zone, any data)`);
}
const retValue = parentZoneDelegate.scheduleTask(targetZone, task);
instance(zonePathName(targetZone), shallowObj(task.data, 2));
return retValue;
}
onInvokeTask(
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task,
applyThis?: any, applyArgs?: any[]): any {
const source = task.source;
let scope = WtfZoneSpec.invokeTaskScope[source];
if (!scope) {
scope = WtfZoneSpec.invokeTaskScope[source] =
wtfEvents!.createScope(`Zone:invokeTask:${source}(ascii zone)`);
}
return wtfTrace!.leaveScope(
scope(zonePathName(targetZone)),
parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs));
}
onCancelTask(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
any {
const key = task.source;
let instance = WtfZoneSpec.cancelInstance[key];
if (!instance) {
instance = WtfZoneSpec.cancelInstance[key] =
wtfEvents!.createInstance(`Zone:cancel:${key}(ascii zone, any options)`);
}
const retValue = parentZoneDelegate.cancelTask(targetZone, task);
instance(zonePathName(targetZone), shallowObj(task.data, 2));
return retValue;
}
}
function shallowObj(obj: {[k: string]: any}|undefined, depth: number): any {
if (!obj || !depth) return null;
const out: {[k: string]: any} = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
// explicit : any due to https://github.com/microsoft/TypeScript/issues/33191
let value: any = obj[key];
switch (typeof value) {
case 'object':
const name = value && value.constructor && (<any>value.constructor).name;
value = name == (<any>Object).name ? shallowObj(value, depth - 1) : name;
break;
case 'function':
value = value.name || undefined;
break;
}
out[key] = value;
}
return out;
}
return out;
}
function zonePathName(zone: Zone) {
let name: string = zone.name;
let localZone = zone.parent;
while (localZone != null) {
name = localZone.name + '::' + name;
localZone = localZone.parent;
}
return name;
function zonePathName(zone: Zone) {
let name: string = zone.name;
let localZone = zone.parent;
while (localZone != null) {
name = localZone.name + '::' + name;
localZone = localZone.parent;
}
return name;
}
(Zone as any)['wtfZoneSpec'] = !wtfEnabled ? null : new WtfZoneSpec();
(Zone as any)['wtfZoneSpec'] = !wtfEnabled ? null : new WtfZoneSpec();
})(typeof window === 'object' && window || typeof self === 'object' && self || global);

View File

@ -310,9 +310,9 @@ interface ZoneType {
root: Zone;
/**
* load patch for specified native module, allow user to
* define their own patch, user can use this API after loading zone.js
*/
* load patch for specified native module, allow user to
* define their own patch, user can use this API after loading zone.js
*/
__load_patch(name: string, fn: _PatchFn): void;
/**
@ -547,12 +547,12 @@ type HasTaskState = {
/**
* Task type: `microTask`, `macroTask`, `eventTask`.
*/
type TaskType = 'microTask' | 'macroTask' | 'eventTask';
type TaskType = 'microTask'|'macroTask'|'eventTask';
/**
* Task type: `notScheduled`, `scheduling`, `scheduled`, `running`, `canceling`, 'unknown'.
*/
type TaskState = 'notScheduled' | 'scheduling' | 'scheduled' | 'running' | 'canceling' | 'unknown';
type TaskState = 'notScheduled'|'scheduling'|'scheduled'|'running'|'canceling'|'unknown';
/**
@ -684,7 +684,9 @@ declare var global: NodeJS.Global;
const Zone: ZoneType = (function(global: any) {
const performance: {mark(name: string): void; measure(name: string, label: string): void;} =
global['performance'];
function mark(name: string) { performance && performance['mark'] && performance['mark'](name); }
function mark(name: string) {
performance && performance['mark'] && performance['mark'](name);
}
function performanceMeasure(name: string, label: string) {
performance && performance['measure'] && performance['measure'](name, label);
}
@ -695,7 +697,9 @@ const Zone: ZoneType = (function(global: any) {
// symbol prefix with a custom one if needed.
const symbolPrefix = global['__Zone_symbol_prefix'] || '__zone_symbol__';
function __symbol__(name: string) { return symbolPrefix + name; }
function __symbol__(name: string) {
return symbolPrefix + name;
}
const checkDuplicate = global[__symbol__('forceDuplicateZoneCheck')] === true;
if (global['Zone']) {
@ -738,9 +742,13 @@ const Zone: ZoneType = (function(global: any) {
return zone;
}
static get current(): AmbientZone { return _currentZoneFrame.zone; }
static get current(): AmbientZone {
return _currentZoneFrame.zone;
}
static get currentTask(): Task|null { return _currentTask; }
static get currentTask(): Task|null {
return _currentTask;
}
// tslint:disable-next-line:require-internal-with-underscore
static __load_patch(name: string, fn: _PatchFn): void {
@ -756,9 +764,13 @@ const Zone: ZoneType = (function(global: any) {
}
}
public get parent(): AmbientZone|null { return this._parent; }
public get parent(): AmbientZone|null {
return this._parent;
}
public get name(): string { return this._name; }
public get name(): string {
return this._name;
}
private _parent: Zone|null;
@ -813,7 +825,7 @@ const Zone: ZoneType = (function(global: any) {
try {
return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
} finally {
_currentZoneFrame = _currentZoneFrame.parent !;
_currentZoneFrame = _currentZoneFrame.parent!;
}
}
@ -831,7 +843,7 @@ const Zone: ZoneType = (function(global: any) {
}
}
} finally {
_currentZoneFrame = _currentZoneFrame.parent !;
_currentZoneFrame = _currentZoneFrame.parent!;
}
}
@ -880,7 +892,7 @@ const Zone: ZoneType = (function(global: any) {
(task as ZoneTask<any>)._transitionTo(notScheduled, running, notScheduled);
}
}
_currentZoneFrame = _currentZoneFrame.parent !;
_currentZoneFrame = _currentZoneFrame.parent!;
_currentTask = previousTask;
}
}
@ -964,7 +976,7 @@ const Zone: ZoneType = (function(global: any) {
}
private _updateTaskCount(task: ZoneTask<any>, count: number) {
const zoneDelegates = task._zoneDelegates !;
const zoneDelegates = task._zoneDelegates!;
if (count == -1) {
task._zoneDelegates = null;
}
@ -976,23 +988,27 @@ const Zone: ZoneType = (function(global: any) {
const DELEGATE_ZS: ZoneSpec = {
name: '',
onHasTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone,
hasTaskState: HasTaskState): void => delegate.hasTask(target, hasTaskState),
onScheduleTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone,
task: Task): Task => delegate.scheduleTask(target, task),
onInvokeTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task,
applyThis: any, applyArgs: any): any =>
delegate.invokeTask(target, task, applyThis, applyArgs),
onHasTask:
(delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone,
hasTaskState: HasTaskState): void => delegate.hasTask(target, hasTaskState),
onScheduleTask:
(delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task): Task =>
delegate.scheduleTask(target, task),
onInvokeTask:
(delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task,
applyThis: any, applyArgs: any): any =>
delegate.invokeTask(target, task, applyThis, applyArgs),
onCancelTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task):
any => delegate.cancelTask(target, task)
any => delegate.cancelTask(target, task)
};
class ZoneDelegate implements AmbientZoneDelegate {
public zone: Zone;
private _taskCounts: {microTask: number,
macroTask: number,
eventTask: number} = {'microTask': 0, 'macroTask': 0, 'eventTask': 0};
private _taskCounts:
{microTask: number,
macroTask: number,
eventTask: number} = {'microTask': 0, 'macroTask': 0, 'eventTask': 0};
private _parentDelegate: ZoneDelegate|null;
@ -1033,52 +1049,51 @@ const Zone: ZoneType = (function(global: any) {
this.zone = zone;
this._parentDelegate = parentDelegate;
this._forkZS =
zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate !._forkZS);
this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate !._forkDlgt);
this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate!._forkZS);
this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate!._forkDlgt);
this._forkCurrZone =
zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate !._forkCurrZone);
zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate!._forkCurrZone);
this._interceptZS =
zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate !._interceptZS);
zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate!._interceptZS);
this._interceptDlgt =
zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate !._interceptDlgt);
zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate!._interceptDlgt);
this._interceptCurrZone =
zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate !._interceptCurrZone);
zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate!._interceptCurrZone);
this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate !._invokeZS);
this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate!._invokeZS);
this._invokeDlgt =
zoneSpec && (zoneSpec.onInvoke ? parentDelegate ! : parentDelegate !._invokeDlgt);
zoneSpec && (zoneSpec.onInvoke ? parentDelegate! : parentDelegate!._invokeDlgt);
this._invokeCurrZone =
zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate !._invokeCurrZone);
zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate!._invokeCurrZone);
this._handleErrorZS =
zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate !._handleErrorZS);
this._handleErrorDlgt = zoneSpec &&
(zoneSpec.onHandleError ? parentDelegate ! : parentDelegate !._handleErrorDlgt);
zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate!._handleErrorZS);
this._handleErrorDlgt =
zoneSpec && (zoneSpec.onHandleError ? parentDelegate! : parentDelegate!._handleErrorDlgt);
this._handleErrorCurrZone =
zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate !._handleErrorCurrZone);
zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate!._handleErrorCurrZone);
this._scheduleTaskZS =
zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate !._scheduleTaskZS);
zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate!._scheduleTaskZS);
this._scheduleTaskDlgt = zoneSpec &&
(zoneSpec.onScheduleTask ? parentDelegate ! : parentDelegate !._scheduleTaskDlgt);
this._scheduleTaskCurrZone = zoneSpec &&
(zoneSpec.onScheduleTask ? this.zone : parentDelegate !._scheduleTaskCurrZone);
(zoneSpec.onScheduleTask ? parentDelegate! : parentDelegate!._scheduleTaskDlgt);
this._scheduleTaskCurrZone =
zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate!._scheduleTaskCurrZone);
this._invokeTaskZS =
zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate !._invokeTaskZS);
zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate!._invokeTaskZS);
this._invokeTaskDlgt =
zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate ! : parentDelegate !._invokeTaskDlgt);
zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate! : parentDelegate!._invokeTaskDlgt);
this._invokeTaskCurrZone =
zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate !._invokeTaskCurrZone);
zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate!._invokeTaskCurrZone);
this._cancelTaskZS =
zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate !._cancelTaskZS);
zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate!._cancelTaskZS);
this._cancelTaskDlgt =
zoneSpec && (zoneSpec.onCancelTask ? parentDelegate ! : parentDelegate !._cancelTaskDlgt);
zoneSpec && (zoneSpec.onCancelTask ? parentDelegate! : parentDelegate!._cancelTaskDlgt);
this._cancelTaskCurrZone =
zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate !._cancelTaskCurrZone);
zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate!._cancelTaskCurrZone);
this._hasTaskZS = null;
this._hasTaskDlgt = null;
@ -1094,51 +1109,49 @@ const Zone: ZoneType = (function(global: any) {
this._hasTaskDlgt = parentDelegate;
this._hasTaskDlgtOwner = this;
this._hasTaskCurrZone = zone;
if (!zoneSpec !.onScheduleTask) {
if (!zoneSpec!.onScheduleTask) {
this._scheduleTaskZS = DELEGATE_ZS;
this._scheduleTaskDlgt = parentDelegate !;
this._scheduleTaskDlgt = parentDelegate!;
this._scheduleTaskCurrZone = this.zone;
}
if (!zoneSpec !.onInvokeTask) {
if (!zoneSpec!.onInvokeTask) {
this._invokeTaskZS = DELEGATE_ZS;
this._invokeTaskDlgt = parentDelegate !;
this._invokeTaskDlgt = parentDelegate!;
this._invokeTaskCurrZone = this.zone;
}
if (!zoneSpec !.onCancelTask) {
if (!zoneSpec!.onCancelTask) {
this._cancelTaskZS = DELEGATE_ZS;
this._cancelTaskDlgt = parentDelegate !;
this._cancelTaskDlgt = parentDelegate!;
this._cancelTaskCurrZone = this.zone;
}
}
}
fork(targetZone: Zone, zoneSpec: ZoneSpec): AmbientZone {
return this._forkZS ?
this._forkZS.onFork !(this._forkDlgt !, this.zone, targetZone, zoneSpec) :
new Zone(targetZone, zoneSpec);
return this._forkZS ? this._forkZS.onFork!(this._forkDlgt!, this.zone, targetZone, zoneSpec) :
new Zone(targetZone, zoneSpec);
}
intercept(targetZone: Zone, callback: Function, source: string): Function {
return this._interceptZS ?
this._interceptZS.onIntercept !(
this._interceptDlgt !, this._interceptCurrZone !, targetZone, callback, source) :
this._interceptZS.onIntercept!
(this._interceptDlgt!, this._interceptCurrZone!, targetZone, callback, source) :
callback;
}
invoke(
targetZone: Zone, callback: Function, applyThis: any, applyArgs?: any[],
source?: string): any {
return this._invokeZS ?
this._invokeZS.onInvoke !(
this._invokeDlgt !, this._invokeCurrZone !, targetZone, callback, applyThis,
applyArgs, source) :
callback.apply(applyThis, applyArgs);
return this._invokeZS ? this._invokeZS.onInvoke!
(this._invokeDlgt!, this._invokeCurrZone!, targetZone, callback,
applyThis, applyArgs, source) :
callback.apply(applyThis, applyArgs);
}
handleError(targetZone: Zone, error: any): boolean {
return this._handleErrorZS ?
this._handleErrorZS.onHandleError !(
this._handleErrorDlgt !, this._handleErrorCurrZone !, targetZone, error) :
this._handleErrorZS.onHandleError!
(this._handleErrorDlgt!, this._handleErrorCurrZone!, targetZone, error) :
true;
}
@ -1146,7 +1159,7 @@ const Zone: ZoneType = (function(global: any) {
let returnTask: ZoneTask<any> = task as ZoneTask<any>;
if (this._scheduleTaskZS) {
if (this._hasTaskZS) {
returnTask._zoneDelegates !.push(this._hasTaskDlgtOwner !);
returnTask._zoneDelegates!.push(this._hasTaskDlgtOwner!);
}
// clang-format off
returnTask = this._scheduleTaskZS.onScheduleTask !(
@ -1166,18 +1179,17 @@ const Zone: ZoneType = (function(global: any) {
}
invokeTask(targetZone: Zone, task: Task, applyThis: any, applyArgs?: any[]): any {
return this._invokeTaskZS ?
this._invokeTaskZS.onInvokeTask !(
this._invokeTaskDlgt !, this._invokeTaskCurrZone !, targetZone, task, applyThis,
applyArgs) :
task.callback.apply(applyThis, applyArgs);
return this._invokeTaskZS ? this._invokeTaskZS.onInvokeTask!
(this._invokeTaskDlgt!, this._invokeTaskCurrZone!, targetZone,
task, applyThis, applyArgs) :
task.callback.apply(applyThis, applyArgs);
}
cancelTask(targetZone: Zone, task: Task): any {
let value: any;
if (this._cancelTaskZS) {
value = this._cancelTaskZS.onCancelTask !(
this._cancelTaskDlgt !, this._cancelTaskCurrZone !, targetZone, task);
value = this._cancelTaskZS.onCancelTask!
(this._cancelTaskDlgt!, this._cancelTaskCurrZone!, targetZone, task);
} else {
if (!task.cancelFn) {
throw Error('Task is not cancelable');
@ -1192,8 +1204,8 @@ const Zone: ZoneType = (function(global: any) {
// can still trigger hasTask callback
try {
this._hasTaskZS &&
this._hasTaskZS.onHasTask !(
this._hasTaskDlgt !, this._hasTaskCurrZone !, targetZone, isEmpty);
this._hasTaskZS.onHasTask!
(this._hasTaskDlgt!, this._hasTaskCurrZone!, targetZone, isEmpty);
} catch (err) {
this.handleError(targetZone, err);
}
@ -1274,11 +1286,17 @@ const Zone: ZoneType = (function(global: any) {
}
}
get zone(): Zone { return this._zone !; }
get zone(): Zone {
return this._zone!;
}
get state(): TaskState { return this._state; }
get state(): TaskState {
return this._state;
}
public cancelScheduleRequest() { this._transitionTo(notScheduled, scheduling); }
public cancelScheduleRequest() {
this._transitionTo(notScheduled, scheduling);
}
// tslint:disable-next-line:require-internal-with-underscore
_transitionTo(toState: TaskState, fromState1: TaskState, fromState2?: TaskState) {