Skip to content

Commit

Permalink
capricorn86#948@patch: Use macro task timing for postmessage api.
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Jun 8, 2023
1 parent f1987a9 commit e6d3b1a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/happy-dom/src/window/Window.ts
Expand Up @@ -806,14 +806,22 @@ export default class Window extends EventTarget implements IWindow {
);
}

this.dispatchEvent(
new MessageEvent('message', {
data: message,
origin: this.parent.location.origin,
source: this.parent,
lastEventId: ''
})
);
const setImmediate =
globalThis.setImmediate || <typeof globalThis.setImmediate>(<unknown>setTimeout);
const clearImmediate =
globalThis.clearImmediate || <typeof globalThis.clearImmediate>(<unknown>clearTimeout);
const taskId = this.happyDOM.asyncTaskManager.startTask(() => clearImmediate(immediateId));
const immediateId = setImmediate(() => {
this.happyDOM.asyncTaskManager.endTask(taskId);
this.dispatchEvent(
new MessageEvent('message', {
data: message,
origin: this.parent.location.origin,
source: this.parent,
lastEventId: ''
})
);
});
}

/**
Expand Down

0 comments on commit e6d3b1a

Please sign in to comment.