Template Upload
This commit is contained in:
96
node_modules/zone.js/lib/zone-spec/async-test.ts
generated
vendored
Normal file
96
node_modules/zone.js/lib/zone-spec/async-test.ts
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
(function() {
|
||||
class AsyncTestZoneSpec implements ZoneSpec {
|
||||
_finishCallback: Function;
|
||||
_failCallback: Function;
|
||||
_pendingMicroTasks: boolean = false;
|
||||
_pendingMacroTasks: boolean = false;
|
||||
_alreadyErrored: boolean = false;
|
||||
runZone = Zone.current;
|
||||
|
||||
constructor(finishCallback: Function, failCallback: Function, namePrefix: string) {
|
||||
this._finishCallback = finishCallback;
|
||||
this._failCallback = failCallback;
|
||||
this.name = 'asyncTestZone for ' + namePrefix;
|
||||
}
|
||||
|
||||
_finishCallbackIfDone() {
|
||||
if (!(this._pendingMicroTasks || this._pendingMacroTasks)) {
|
||||
// We do this because we would like to catch unhandled rejected promises.
|
||||
// To do this quickly when there are native promises, we must run using an unwrapped
|
||||
// promise implementation.
|
||||
var symbol = (<any>Zone).__symbol__;
|
||||
var NativePromise: typeof Promise = <any>window[symbol('Promise')];
|
||||
if (NativePromise) {
|
||||
NativePromise.resolve(true)[symbol('then')](() => {
|
||||
if (!this._alreadyErrored) {
|
||||
this.runZone.run(this._finishCallback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// For implementations which do not have nativePromise, use setTimeout(0). This is slower,
|
||||
// but it also works because Zones will handle errors when rejected promises have no
|
||||
// listeners after one macrotask.
|
||||
this.runZone.run(() => {
|
||||
setTimeout(() => {
|
||||
if (!this._alreadyErrored) {
|
||||
this._finishCallback();
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ZoneSpec implementation below.
|
||||
|
||||
name: string;
|
||||
|
||||
// Note - we need to use onInvoke at the moment to call finish when a test is
|
||||
// fully synchronous. TODO(juliemr): remove this when the logic for
|
||||
// onHasTask changes and it calls whenever the task queues are dirty.
|
||||
onInvoke(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
|
||||
delegate: Function, applyThis: any, applyArgs: any[], source: string): any {
|
||||
try {
|
||||
return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source);
|
||||
} finally {
|
||||
this._finishCallbackIfDone();
|
||||
}
|
||||
}
|
||||
|
||||
onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
|
||||
error: any): boolean {
|
||||
// Let the parent try to handle the error.
|
||||
var result = parentZoneDelegate.handleError(targetZone, error);
|
||||
if (result) {
|
||||
this._failCallback(error.message ? error.message : 'unknown error');
|
||||
this._alreadyErrored = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
onScheduleTask(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): Task {
|
||||
if (task.type == 'macroTask' && task.source == 'setInterval') {
|
||||
this._failCallback('Cannot use setInterval from within an async zone test.');
|
||||
return;
|
||||
}
|
||||
|
||||
return delegate.scheduleTask(targetZone, task);
|
||||
}
|
||||
|
||||
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) {
|
||||
delegate.hasTask(target, hasTaskState);
|
||||
|
||||
if (hasTaskState.change == 'microTask') {
|
||||
this._pendingMicroTasks = hasTaskState.microTask;
|
||||
this._finishCallbackIfDone();
|
||||
} else if (hasTaskState.change == 'macroTask') {
|
||||
this._pendingMacroTasks = hasTaskState.macroTask;
|
||||
this._finishCallbackIfDone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export the class so that new instances can be created with proper
|
||||
// constructor params.
|
||||
Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec;
|
||||
})();
|
134
node_modules/zone.js/lib/zone-spec/long-stack-trace.ts
generated
vendored
Normal file
134
node_modules/zone.js/lib/zone-spec/long-stack-trace.ts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
'use strict';
|
||||
(function() {
|
||||
const NEWLINE = '\n';
|
||||
const SEP = ' ------------- ';
|
||||
const IGNORE_FRAMES = [];
|
||||
const creationTrace = '__creationTrace__';
|
||||
|
||||
class LongStackTrace {
|
||||
error: Error = getStacktrace();
|
||||
timestamp: Date = new Date();
|
||||
|
||||
}
|
||||
|
||||
function getStacktraceWithUncaughtError (): Error {
|
||||
return new Error('STACKTRACE TRACKING');
|
||||
}
|
||||
|
||||
function getStacktraceWithCaughtError(): Error {
|
||||
try {
|
||||
throw getStacktraceWithUncaughtError();
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
// Some implementations of exception handling don't create a stack trace if the exception
|
||||
// isn't thrown, however it's faster not to actually throw the exception.
|
||||
var error = getStacktraceWithUncaughtError();
|
||||
var coughtError = getStacktraceWithCaughtError();
|
||||
var getStacktrace = error.stack
|
||||
? getStacktraceWithUncaughtError
|
||||
: (coughtError.stack ? getStacktraceWithCaughtError: getStacktraceWithUncaughtError);
|
||||
|
||||
function getFrames(error: Error): string[] {
|
||||
return error.stack ? error.stack.split(NEWLINE) : [];
|
||||
}
|
||||
|
||||
function addErrorStack(lines:string[], error:Error):void {
|
||||
var trace: string[];
|
||||
trace = getFrames(error);
|
||||
for (var i = 0; i < trace.length; i++) {
|
||||
var frame = trace[i];
|
||||
// Filter out the Frames which are part of stack capturing.
|
||||
if (! (i < IGNORE_FRAMES.length && IGNORE_FRAMES[i] === frame)) {
|
||||
lines.push(trace[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderLongStackTrace(frames: LongStackTrace[], stack: string): string {
|
||||
var longTrace: string[] = [stack];
|
||||
|
||||
if (frames) {
|
||||
var timestamp = new Date().getTime();
|
||||
for (var i = 0; i < frames.length; i++) {
|
||||
var traceFrames: LongStackTrace = frames[i];
|
||||
var lastTime = traceFrames.timestamp;
|
||||
longTrace.push(`${SEP} Elapsed: ${timestamp - lastTime.getTime()} ms; At: ${lastTime} ${SEP}`);
|
||||
addErrorStack(longTrace, traceFrames.error);
|
||||
|
||||
timestamp = lastTime.getTime();
|
||||
}
|
||||
}
|
||||
|
||||
return longTrace.join(NEWLINE);
|
||||
}
|
||||
|
||||
Zone['longStackTraceZoneSpec'] = <ZoneSpec>{
|
||||
name: 'long-stack-trace',
|
||||
longStackTraceLimit: 10, // Max number of task to keep the stack trace for.
|
||||
|
||||
onScheduleTask: function(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
|
||||
task: Task): any
|
||||
{
|
||||
var currentTask = Zone.currentTask;
|
||||
var trace = currentTask && currentTask.data && currentTask.data[creationTrace] || [];
|
||||
trace = [new LongStackTrace()].concat(trace);
|
||||
if (trace.length > this.longStackTraceLimit) {
|
||||
trace.length = this.longStackTraceLimit;
|
||||
}
|
||||
if (!task.data) task.data = {};
|
||||
task.data[creationTrace] = trace;
|
||||
return parentZoneDelegate.scheduleTask(targetZone, task);
|
||||
},
|
||||
|
||||
onHandleError: function(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
|
||||
error: any): any
|
||||
{
|
||||
var parentTask = Zone.currentTask;
|
||||
if (error instanceof Error && parentTask) {
|
||||
var descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
||||
if (descriptor) {
|
||||
var delegateGet = descriptor.get;
|
||||
var value = descriptor.value;
|
||||
descriptor = {
|
||||
get: function() {
|
||||
return renderLongStackTrace(parentTask.data && parentTask.data[creationTrace],
|
||||
delegateGet ? delegateGet.apply(this): value);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(error, 'stack', descriptor);
|
||||
} else {
|
||||
error.stack = renderLongStackTrace(parentTask.data && parentTask.data[creationTrace],
|
||||
error.stack);
|
||||
}
|
||||
}
|
||||
return parentZoneDelegate.handleError(targetZone, error);
|
||||
}
|
||||
};
|
||||
|
||||
function captureStackTraces(stackTraces: string[][], count: number): void {
|
||||
if (count > 0) {
|
||||
stackTraces.push(getFrames((new LongStackTrace()).error));
|
||||
captureStackTraces(stackTraces, count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
function computeIgnoreFrames() {
|
||||
var frames: string[][] = [];
|
||||
captureStackTraces(frames, 2);
|
||||
var frames1 = frames[0];
|
||||
var frames2 = frames[1];
|
||||
for (var i = 0; i < frames1.length; i++) {
|
||||
var frame1 = frames1[i];
|
||||
var frame2 = frames2[i];
|
||||
if (frame1 === frame2) {
|
||||
IGNORE_FRAMES.push(frame1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
computeIgnoreFrames();
|
||||
})();
|
29
node_modules/zone.js/lib/zone-spec/sync-test.ts
generated
vendored
Normal file
29
node_modules/zone.js/lib/zone-spec/sync-test.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
(function() {
|
||||
class SyncTestZoneSpec implements ZoneSpec {
|
||||
runZone = Zone.current;
|
||||
|
||||
constructor(namePrefix: string) {
|
||||
this.name = 'syncTestZone for ' + namePrefix;
|
||||
}
|
||||
|
||||
// ZoneSpec implementation below.
|
||||
|
||||
name: string;
|
||||
|
||||
onScheduleTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): Task {
|
||||
switch (task.type) {
|
||||
case 'microTask':
|
||||
case 'macroTask':
|
||||
throw new Error(`Cannot call ${task.source} from within a sync test.`);
|
||||
case 'eventTask':
|
||||
task = delegate.scheduleTask(target, task);
|
||||
break;
|
||||
}
|
||||
return task;
|
||||
}
|
||||
}
|
||||
|
||||
// Export the class so that new instances can be created with proper
|
||||
// constructor params.
|
||||
Zone['SyncTestZoneSpec'] = SyncTestZoneSpec;
|
||||
})();
|
140
node_modules/zone.js/lib/zone-spec/wtf.ts
generated
vendored
Normal file
140
node_modules/zone.js/lib/zone-spec/wtf.ts
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
(function(global) {
|
||||
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) => WtfScope;
|
||||
type WtfEventFn = (...args) => any;
|
||||
|
||||
// Detect and setup WTF.
|
||||
var wtfTrace: WtfTrace = null;
|
||||
var wtfEvents: WtfEvents = null;
|
||||
var wtfEnabled: boolean = (function (): boolean {
|
||||
var 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)');
|
||||
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 {
|
||||
var 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 {
|
||||
var scope = WtfZoneSpec.invokeScope[source];
|
||||
if (!scope) {
|
||||
scope = WtfZoneSpec.invokeScope[source]
|
||||
= 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 {
|
||||
var key = task.type + ':' + task.source;
|
||||
var instance = WtfZoneSpec.scheduleInstance[key];
|
||||
if (!instance) {
|
||||
instance = WtfZoneSpec.scheduleInstance[key]
|
||||
= wtfEvents.createInstance(`Zone:schedule:${key}(ascii zone, any data)`);
|
||||
}
|
||||
var 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
|
||||
{
|
||||
var source = task.source;
|
||||
var 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 {
|
||||
var key = task.source;
|
||||
var instance = WtfZoneSpec.cancelInstance[key];
|
||||
if (!instance) {
|
||||
instance = WtfZoneSpec.cancelInstance[key]
|
||||
= wtfEvents.createInstance(`Zone:cancel:${key}(ascii zone, any options)`);
|
||||
}
|
||||
var retValue = parentZoneDelegate.cancelTask(targetZone, task);
|
||||
instance(zonePathName(targetZone), shallowObj(task.data, 2));
|
||||
return retValue;
|
||||
};
|
||||
}
|
||||
|
||||
function shallowObj(obj: any, depth: number): any {
|
||||
if (!depth) return null;
|
||||
var out = {};
|
||||
for(var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
var value = obj[key];
|
||||
switch (typeof value) {
|
||||
case 'object':
|
||||
var 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;
|
||||
}
|
||||
|
||||
function zonePathName(zone: Zone) {
|
||||
var name: string = zone.name;
|
||||
zone = zone.parent;
|
||||
while(zone != null) {
|
||||
name = zone.name + '::' + name;
|
||||
zone = zone.parent;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
Zone['wtfZoneSpec'] = !wtfEnabled ? null : new WtfZoneSpec();
|
||||
})(typeof window == 'undefined' ? global : window);
|
Reference in New Issue
Block a user