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

Commit 5783663

Browse files
alexeaglemhevery
authored andcommitted
fix(patching): call native cancel method
Fixes #278 Closes #279
1 parent 44b5ee4 commit 5783663

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: lib/browser/browser.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function patchTimer(
6666
return clearNative((<TimerOptions>task.data).handleId);
6767
}
6868

69-
var setNative = patchMethod(window, setName, () => function(self: any, args: any[]) {
69+
var setNative = patchMethod(window, setName, (delegate: Function) => function(self: any, args: any[]) {
7070
if (typeof args[0] === 'function') {
7171
var zone = Zone.current;
7272
var options:TimerOptions = {
@@ -78,13 +78,18 @@ function patchTimer(
7878
return zone.scheduleMacroTask(setName, args[0], options, scheduleTask, clearTask);
7979
} else {
8080
// cause an error by calling it directly.
81-
return setNative.apply(window, args);
81+
return delegate.apply(window, args);
8282
}
8383
});
8484

85-
var clearNative = patchMethod(window, cancelName, () => function(self: any, args: any[]) {
85+
var clearNative = patchMethod(window, cancelName, (delegate: Function) => function(self: any, args: any[]) {
8686
var task: Task = args[0];
87-
task.zone.cancelTask(task);
87+
if (task && typeof task.type == 'string') {
88+
task.zone.cancelTask(task);
89+
} else {
90+
// cause an error by calling it directly.
91+
delegate.apply(window, args);
92+
}
8893
});
8994
}
9095

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

+5
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ describe('setTimeout', function () {
4040
});
4141
});
4242

43+
it('should pass invalid values through', function () {
44+
clearTimeout(null);
45+
clearTimeout(<any>{});
46+
});
47+
4348
});

0 commit comments

Comments
 (0)