fix(zone.js): don't rely on global node typings outside of node/ directory (#31783)
PR Close #31783
This commit is contained in:

committed by
Andrew Kushnir

parent
3479fddf68
commit
5c9a8961da
@ -78,6 +78,16 @@ function renderLongStackTrace(frames: LongStackTrace[], stack?: string): string
|
||||
return longTrace.join(NEWLINE);
|
||||
}
|
||||
|
||||
// if Error.stackTraceLimit is 0, means stack trace
|
||||
// is disabled, so we don't need to generate long stack trace
|
||||
// this will improve performance in some test(some test will
|
||||
// set stackTraceLimit to 0, https://github.com/angular/zone.js/issues/698
|
||||
function stackTracesEnabled(): boolean {
|
||||
// Cast through any since this property only exists on Error in the nodejs
|
||||
// typings.
|
||||
return (Error as any).stackTraceLimit > 0;
|
||||
}
|
||||
|
||||
type LongStackTraceZoneSpec = ZoneSpec & {longStackTraceLimit: number};
|
||||
|
||||
(Zone as any)['longStackTraceZoneSpec'] = <LongStackTraceZoneSpec>{
|
||||
@ -99,11 +109,7 @@ type LongStackTraceZoneSpec = ZoneSpec & {longStackTraceLimit: number};
|
||||
|
||||
onScheduleTask: function(
|
||||
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): any {
|
||||
if (Error.stackTraceLimit > 0) {
|
||||
// if Error.stackTraceLimit is 0, means stack trace
|
||||
// is disabled, so we don't need to generate long stack trace
|
||||
// this will improve performance in some test(some test will
|
||||
// set stackTraceLimit to 0, https://github.com/angular/zone.js/issues/698
|
||||
if (stackTracesEnabled()) {
|
||||
const currentTask = Zone.currentTask;
|
||||
let trace = currentTask && currentTask.data && (currentTask.data as any)[creationTrace] || [];
|
||||
trace = [new LongStackTrace()].concat(trace);
|
||||
@ -127,11 +133,7 @@ type LongStackTraceZoneSpec = ZoneSpec & {longStackTraceLimit: number};
|
||||
|
||||
onHandleError: function(
|
||||
parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: any): boolean {
|
||||
if (Error.stackTraceLimit > 0) {
|
||||
// if Error.stackTraceLimit is 0, means stack trace
|
||||
// is disabled, so we don't need to generate long stack trace
|
||||
// this will improve performance in some test(some test will
|
||||
// set stackTraceLimit to 0, https://github.com/angular/zone.js/issues/698
|
||||
if (stackTracesEnabled()) {
|
||||
const parentTask = Zone.currentTask || error.task;
|
||||
if (error instanceof Error && parentTask) {
|
||||
const longStack =
|
||||
@ -154,7 +156,7 @@ function captureStackTraces(stackTraces: string[][], count: number): void {
|
||||
}
|
||||
|
||||
function computeIgnoreFrames() {
|
||||
if (Error.stackTraceLimit <= 0) {
|
||||
if (!stackTracesEnabled()) {
|
||||
return;
|
||||
}
|
||||
const frames: string[][] = [];
|
||||
|
Reference in New Issue
Block a user