@@ -67,19 +67,40 @@ function canPatchViaPropertyDescriptor() {
67
67
// by default XMLHttpRequest.prototype.onreadystatechange is undefined
68
68
// without adding enumerable and configurable will cause onreadystatechange
69
69
// non-configurable
70
- Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange' , {
71
- enumerable : true ,
72
- configurable : true ,
73
- get : function ( ) {
74
- return true ;
75
- }
76
- } ) ;
77
- const req = new XMLHttpRequest ( ) ;
78
- const result = ! ! req . onreadystatechange ;
79
- // restore original desc
80
- Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange' , xhrDesc || { } ) ;
81
- return result ;
82
- }
70
+ // and if XMLHttpRequest.prototype.onreadystatechange is undefined,
71
+ // we should set a real desc instead a fake one
72
+ if ( xhrDesc ) {
73
+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange' , {
74
+ enumerable : true ,
75
+ configurable : true ,
76
+ get : function ( ) {
77
+ return true ;
78
+ }
79
+ } ) ;
80
+ const req = new XMLHttpRequest ( ) ;
81
+ const result = ! ! req . onreadystatechange ;
82
+ // restore original desc
83
+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange' , xhrDesc || { } ) ;
84
+ return result ;
85
+ } else {
86
+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange' , {
87
+ enumerable : true ,
88
+ configurable : true ,
89
+ get : function ( ) {
90
+ return this [ zoneSymbol ( 'fakeonreadystatechange' ) ] ;
91
+ } ,
92
+ set : function ( value ) {
93
+ this [ zoneSymbol ( 'fakeonreadystatechange' ) ] = value ;
94
+ }
95
+ } ) ;
96
+ const req = new XMLHttpRequest ( ) ;
97
+ const detectFunc = ( ) => { } ;
98
+ req . onreadystatechange = detectFunc ;
99
+ const result = ( req as any ) [ zoneSymbol ( 'fakeonreadystatechange' ) ] === detectFunc ;
100
+ req . onreadystatechange = null ;
101
+ return result ;
102
+ }
103
+ } ;
83
104
84
105
const unboundKey = zoneSymbol ( 'unbound' ) ;
85
106
0 commit comments