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

Commit

Permalink
fix(patching): call native cancel method
Browse files Browse the repository at this point in the history
Fixes #278

Closes #279
  • Loading branch information
alexeagle authored and mhevery committed Mar 17, 2016
1 parent 44b5ee4 commit 5783663
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function patchTimer(
return clearNative((<TimerOptions>task.data).handleId);
}

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

var clearNative = patchMethod(window, cancelName, () => function(self: any, args: any[]) {
var clearNative = patchMethod(window, cancelName, (delegate: Function) => function(self: any, args: any[]) {
var task: Task = args[0];
task.zone.cancelTask(task);
if (task && typeof task.type == 'string') {
task.zone.cancelTask(task);
} else {
// cause an error by calling it directly.
delegate.apply(window, args);
}
});
}

5 changes: 5 additions & 0 deletions test/browser/setTimeout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ describe('setTimeout', function () {
});
});

it('should pass invalid values through', function () {
clearTimeout(null);
clearTimeout(<any>{});
});

});

0 comments on commit 5783663

Please sign in to comment.