Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit d4e5ae8

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(patch): patchOnProperty getter should return original listener (#887)
1 parent 874bfdc commit d4e5ae8

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Diff for: lib/common/utils.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
170170
if (!target) {
171171
return null;
172172
}
173-
if (target[eventNameSymbol]) {
174-
return wrapFn;
173+
const listener = target[eventNameSymbol];
174+
if (listener) {
175+
return listener;
175176
} else if (originalDescGet) {
176177
// result will be null when use inline event attribute,
177178
// such as <button onclick="func();">OK</button>

Diff for: test/browser/XMLHttpRequest.spec.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ifEnvSupports, supportPatchXHROnProperty} from '../test-util';
9+
import {ifEnvSupports, ifEnvSupportsWithDone, supportPatchXHROnProperty} from '../test-util';
1010

1111
describe('XMLHttpRequest', function() {
1212
let testZone: Zone;
@@ -280,4 +280,27 @@ describe('XMLHttpRequest', function() {
280280
req.send();
281281
});
282282
});
283+
284+
it('should return origin listener when call xhr.onreadystatechange',
285+
ifEnvSupportsWithDone(supportPatchXHROnProperty, function(done: Function) {
286+
testZone.run(function() {
287+
// sometimes this case will cause timeout
288+
// so we set it longer
289+
const req = new XMLHttpRequest();
290+
req.open('get', '/', true);
291+
const interval = (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL;
292+
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 5000;
293+
const listener = req.onreadystatechange = function() {
294+
if (req.readyState === 4) {
295+
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = interval;
296+
done();
297+
}
298+
};
299+
expect(req.onreadystatechange).toBe(listener);
300+
req.onreadystatechange = function() {
301+
return listener.apply(this, arguments);
302+
};
303+
req.send();
304+
});
305+
}));
283306
});

0 commit comments

Comments
 (0)