From a3de7d9bc38e789a069f862d4cb5927593dbbaae Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 10 Nov 2015 13:53:45 -0800 Subject: [PATCH] fix(Immediate): set immediate should no longer throw in Chrome closes #690 --- src/util/Immediate.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/Immediate.ts b/src/util/Immediate.ts index b26e07d306..aacb6bcdc9 100644 --- a/src/util/Immediate.ts +++ b/src/util/Immediate.ts @@ -128,16 +128,17 @@ export class ImmediateDefinition { // * https://developer.mozilla.org/en/DOM/window.postMessage // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages const root = this.root; - const runIfPresent = this.runIfPresent; let messagePrefix = 'setImmediate$' + root.Math.random() + '$'; - let onGlobalMessage = function (event) { + let onGlobalMessage = function globalMessageHandler(event) { + const instance = (globalMessageHandler).instance; if (event.source === root && typeof event.data === 'string' && event.data.indexOf(messagePrefix) === 0) { - runIfPresent(+event.data.slice(messagePrefix.length)); + instance.runIfPresent(+event.data.slice(messagePrefix.length)); } }; + (onGlobalMessage).instance = this; root.addEventListener('message', onGlobalMessage, false); @@ -198,7 +199,7 @@ export class ImmediateDefinition { createReadyStateChangeSetImmediate() { let fn = function setImmediate() { const instance = (setImmediate).instance; - const { root, runIfPresent } = instance; + const root = instance.root; const doc = root.document; const html = doc.documentElement; @@ -207,7 +208,7 @@ export class ImmediateDefinition { // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called. let script = doc.createElement('script'); script.onreadystatechange = () => { - runIfPresent(handle); + instance.runIfPresent(handle); script.onreadystatechange = null; html.removeChild(script); script = null;