diff --git a/lib/zone.ts b/lib/zone.ts index c7cbe663b..75c68b12b 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -395,6 +395,11 @@ interface TaskData { * Delay in milliseconds when the Task will run. */ delay?: number; + + /** + * identifier returned by the native setTimeout. + */ + handleId?: number; } /** @@ -819,6 +824,14 @@ const Zone: ZoneType = (function(global: any) { } }; } + + public toString() { + if (this.data && typeof this.data.handleId !== 'undefined') { + return this.data.handleId; + } else { + return this.toString(); + } + } } interface UncaughtPromiseError extends Error { diff --git a/test/common/setTimeout.spec.ts b/test/common/setTimeout.spec.ts index 213eb390a..0119eea62 100644 --- a/test/common/setTimeout.spec.ts +++ b/test/common/setTimeout.spec.ts @@ -88,6 +88,12 @@ describe('setTimeout', function () { }); }); + it('should return the timeout Id through toString', function () { + var cancelId = setTimeout(() => { + }, 0); + expect(typeof (cancelId.toString())).toBe('number'); + }) + it('should pass invalid values through', function () { clearTimeout(null); clearTimeout({});