Skip to content

[api-minor] Remove support for synchronous event dispatching in LoopbackPort #12999

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

Merged
merged 1 commit into from
Feb 17, 2021
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
21 changes: 7 additions & 14 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,9 +1624,8 @@ class PDFPageProxy {
}

class LoopbackPort {
constructor(defer = true) {
constructor() {
this._listeners = [];
this._defer = defer;
this._deferred = Promise.resolve(undefined);
}

Expand Down Expand Up @@ -1670,7 +1669,7 @@ class LoopbackPort {
continue;
}
if (typeof desc.value === "function") {
if (value.hasOwnProperty && value.hasOwnProperty(i)) {
if (value.hasOwnProperty?.(i)) {
throw new Error(
`LoopbackPort.postMessage - cannot clone: ${value[i]}`
);
Expand All @@ -1682,19 +1681,13 @@ class LoopbackPort {
return result;
}

if (!this._defer) {
this._listeners.forEach(listener => {
listener.call(this, { data: obj });
});
return;
}

const cloned = new WeakMap();
const e = { data: cloneValue(obj) };
const event = { data: cloneValue(obj) };

this._deferred.then(() => {
this._listeners.forEach(listener => {
listener.call(this, e);
});
for (const listener of this._listeners) {
listener.call(this, event);
}
});
}

Expand Down