@@ -1664,7 +1664,6 @@ const Zone: ZoneType = (function(global: any) {
1664
1664
case FrameType . transition :
1665
1665
if ( zoneFrame . parent ) {
1666
1666
// This is the special frame where zone changed. Print and process it accordingly
1667
- // frames[i] += ` [${zoneFrame.parent.zone.name} => ${zoneFrame.zone.name}]`;
1668
1667
zoneFrame = zoneFrame . parent ;
1669
1668
} else {
1670
1669
zoneFrame = null ;
@@ -1777,17 +1776,11 @@ const Zone: ZoneType = (function(global: any) {
1777
1776
} ) ;
1778
1777
1779
1778
// Now we need to populate the `blacklistedStackFrames` as well as find the
1780
- // run/runGuraded /runTask frames. This is done by creating a detect zone and then threading
1779
+ // run/runGuarded /runTask frames. This is done by creating a detect zone and then threading
1781
1780
// the execution through all of the above methods so that we can look at the stack trace and
1782
1781
// find the frames of interest.
1783
1782
let detectZone : Zone = Zone . current . fork ( {
1784
1783
name : 'detect' ,
1785
- onInvoke : function (
1786
- parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , delegate : Function ,
1787
- applyThis : any , applyArgs : any [ ] , source : string ) : any {
1788
- // Here only so that it will show up in the stack frame so that it can be black listed.
1789
- return parentZoneDelegate . invoke ( targetZone , delegate , applyThis , applyArgs , source ) ;
1790
- } ,
1791
1784
onHandleError : function ( parentZD : ZoneDelegate , current : Zone , target : Zone , error : any ) :
1792
1785
boolean {
1793
1786
if ( error . originalStack && Error === ZoneAwareError ) {
@@ -1836,8 +1829,7 @@ const Zone: ZoneType = (function(global: any) {
1836
1829
// carefully constructor a stack frame which contains all of the frames of interest which
1837
1830
// need to be detected and blacklisted.
1838
1831
1839
- const parentDetectSpec = { name : 'parent' } ;
1840
- const childDetectZone = Zone . current . fork ( parentDetectSpec ) . fork ( {
1832
+ const childDetectZone = detectZone . fork ( {
1841
1833
name : 'child' ,
1842
1834
onScheduleTask : function ( delegate , curr , target , task ) {
1843
1835
return delegate . scheduleTask ( target , task ) ;
@@ -1853,26 +1845,28 @@ const Zone: ZoneType = (function(global: any) {
1853
1845
}
1854
1846
} ) ;
1855
1847
1848
+ // we need to detect all zone related frames, it will
1849
+ // exceed default stackTraceLimit, so we set it to
1850
+ // larger number here, and restore it after detect finish.
1851
+ const originalStackTraceLimit = Error . stackTraceLimit ;
1856
1852
Error . stackTraceLimit = 100 ;
1853
+ // we schedule event/micro/macro task, and invoke them
1854
+ // when onSchedule, so we can get all stack traces for
1855
+ // all kinds of tasks with one error thrown.
1857
1856
childDetectZone . run ( ( ) => {
1858
1857
childDetectZone . runGuarded ( ( ) => {
1859
1858
const fakeTransitionTo =
1860
1859
( toState : TaskState , fromState1 : TaskState , fromState2 : TaskState ) => { } ;
1861
1860
childDetectZone . scheduleEventTask (
1862
- 'detect' ,
1861
+ blacklistedStackFramesSymbol ,
1863
1862
( ) => {
1864
1863
childDetectZone . scheduleMacroTask (
1865
- 'detect' ,
1864
+ blacklistedStackFramesSymbol ,
1866
1865
( ) => {
1867
1866
childDetectZone . scheduleMicroTask (
1868
- 'detect' ,
1867
+ blacklistedStackFramesSymbol ,
1869
1868
( ) => {
1870
- const error = new Error ( 'detect' ) ;
1871
- const frames = error . stack . split ( '\n' ) ;
1872
- while ( frames . length ) {
1873
- let frame = frames . shift ( ) ;
1874
- blackListedStackFrames [ frame ] = FrameType . blackList ;
1875
- }
1869
+ throw new ( ZoneAwareError as any ) ( ZoneAwareError , NativeError ) ;
1876
1870
} ,
1877
1871
null ,
1878
1872
( t : Task ) => {
@@ -1895,19 +1889,7 @@ const Zone: ZoneType = (function(global: any) {
1895
1889
( ) => { } ) ;
1896
1890
} ) ;
1897
1891
} ) ;
1898
- Error . stackTraceLimit = 15 ;
1899
-
1900
- // carefully constructor a stack frame which contains all of the frames of interest which
1901
- // need to be detected and blacklisted.
1902
- let detectRunFn = ( ) => {
1903
- detectZone . run ( ( ) => {
1904
- detectZone . runGuarded ( ( ) => {
1905
- throw new ( ZoneAwareError as any ) ( ZoneAwareError , NativeError ) ;
1906
- } ) ;
1907
- } ) ;
1908
- } ;
1909
- // Cause the error to extract the stack frames.
1910
- detectZone . runTask ( detectZone . scheduleMacroTask ( 'detect' , detectRunFn , null , ( ) => null , null ) ) ;
1892
+ Error . stackTraceLimit = originalStackTraceLimit ;
1911
1893
1912
1894
return global [ 'Zone' ] = Zone ;
1913
1895
} ) ( typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global ) ;
0 commit comments