@ -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();
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user