Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Immediate): set immediate should no longer throw in Chrome #694

Merged
merged 1 commit into from
Nov 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/util/Immediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (<any>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));
}
};
(<any>onGlobalMessage).instance = this;

root.addEventListener('message', onGlobalMessage, false);

Expand Down Expand Up @@ -198,7 +199,7 @@ export class ImmediateDefinition {
createReadyStateChangeSetImmediate() {
let fn = function setImmediate() {
const instance = (<any>setImmediate).instance;
const { root, runIfPresent } = instance;
const root = instance.root;
const doc = root.document;
const html = doc.documentElement;

Expand All @@ -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;
Expand Down