@@ -34,9 +34,11 @@ export function patchPrototype(prototype: any, fnNames: string[]) {
3434 const delegate = prototype [ name ] ;
3535 if ( delegate ) {
3636 prototype [ name ] = ( ( delegate : Function ) => {
37- return function ( ) {
37+ const patched : any = function ( ) {
3838 return delegate . apply ( this , bindArguments ( < any > arguments , source + '.' + name ) ) ;
3939 } ;
40+ attachOriginToPatched ( patched , delegate ) ;
41+ return patched ;
4042 } ) ( delegate ) ;
4143 }
4244 }
@@ -401,6 +403,8 @@ const originalInstanceKey = zoneSymbol('originalInstance');
401403export function patchClass ( className : string ) {
402404 const OriginalClass = _global [ className ] ;
403405 if ( ! OriginalClass ) return ;
406+ // keep original class in global
407+ _global [ zoneSymbol ( className ) ] = OriginalClass ;
404408
405409 _global [ className ] = function ( ) {
406410 const a = bindArguments ( < any > arguments , className ) ;
@@ -425,6 +429,9 @@ export function patchClass(className: string) {
425429 }
426430 } ;
427431
432+ // attach original delegate to patched function
433+ attachOriginToPatched ( _global [ className ] , OriginalClass ) ;
434+
428435 const instance = new OriginalClass ( function ( ) { } ) ;
429436
430437 let prop ;
@@ -441,6 +448,10 @@ export function patchClass(className: string) {
441448 set : function ( fn ) {
442449 if ( typeof fn === 'function' ) {
443450 this [ originalInstanceKey ] [ prop ] = Zone . current . wrap ( fn , className + '.' + prop ) ;
451+ // keep callback in wrapped function so we can
452+ // use it in Function.prototype.toString to return
453+ // the native one.
454+ attachOriginToPatched ( this [ originalInstanceKey ] [ prop ] , fn ) ;
444455 } else {
445456 this [ originalInstanceKey ] [ prop ] = fn ;
446457 }
@@ -488,6 +499,7 @@ export function patchMethod(
488499 if ( proto && ! ( delegate = proto [ delegateName ] ) ) {
489500 delegate = proto [ delegateName ] = proto [ name ] ;
490501 proto [ name ] = createNamedFn ( name , patchFn ( delegate , delegateName , name ) ) ;
502+ attachOriginToPatched ( proto [ name ] , delegate ) ;
491503 }
492504 return delegate ;
493505}
@@ -575,5 +587,9 @@ export function findEventTask(target: any, evtName: string): Task[] {
575587 return result ;
576588}
577589
590+ export function attachOriginToPatched ( patched : Function , original : any ) {
591+ ( patched as any ) [ zoneSymbol ( 'OriginalDelegate' ) ] = original ;
592+ }
593+
578594( Zone as any ) [ zoneSymbol ( 'patchEventTargetMethods' ) ] = patchEventTargetMethods ;
579595( Zone as any ) [ zoneSymbol ( 'patchOnProperties' ) ] = patchOnProperties ;
0 commit comments