From 39e6c0e3a6bd39a6f7510d991f2a2a12706aa6e2 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Mon, 11 Jan 2016 13:36:06 -0800 Subject: [PATCH] fix(Immediate): update setImmediate compatibility on IE closes #1163 --- spec/util/Immediate-spec.js | 20 ++++++++++++++++---- src/util/Immediate.ts | 6 +++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/spec/util/Immediate-spec.js b/spec/util/Immediate-spec.js index 40417baeb8..8696f9e40a 100644 --- a/spec/util/Immediate-spec.js +++ b/spec/util/Immediate-spec.js @@ -10,13 +10,25 @@ describe('ImmediateDefinition', function () { describe('when setImmediate exists on root', function () { it('should use the setImmediate and clearImmediate methods from root', function () { + var setImmediateCalled = false; + var clearImmediateCalled = false; + var root = { - setImmediate: function () {}, - clearImmediate: function () {} + setImmediate: function () { + setImmediateCalled = true; + }, + clearImmediate: function () { + clearImmediateCalled = true; + } }; + var result = new ImmediateDefinition(root); - expect(result.setImmediate).toBe(root.setImmediate); - expect(result.clearImmediate).toBe(root.clearImmediate); + + result.setImmediate(function () {}); + result.clearImmediate(); + + expect(setImmediateCalled).toBeTruthy(); + expect(clearImmediateCalled).toBeTruthy(); }); }); diff --git a/src/util/Immediate.ts b/src/util/Immediate.ts index 2606df17db..2406bcbe49 100644 --- a/src/util/Immediate.ts +++ b/src/util/Immediate.ts @@ -20,9 +20,9 @@ export class ImmediateDefinition { currentlyRunningATask: boolean; constructor(private root: any) { - if (root.setImmediate) { - this.setImmediate = root.setImmediate; - this.clearImmediate = root.clearImmediate; + if (root.setImmediate && typeof root.setImmediate === 'function') { + this.setImmediate = root.setImmediate.bind(root); + this.clearImmediate = root.clearImmediate.bind(root); } else { this.nextHandle = 1; this.tasksByHandle = {};