mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 23:28:18 -05:00
fix(web/worker) define event handlers in DOM order (#8334)
This commit is contained in:
parent
97a9620a01
commit
b255a05f18
2 changed files with 29 additions and 10 deletions
|
@ -4,6 +4,7 @@
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const { Window } = window.__bootstrap.globalInterfaces;
|
const { Window } = window.__bootstrap.globalInterfaces;
|
||||||
const { log } = window.__bootstrap.util;
|
const { log } = window.__bootstrap.util;
|
||||||
|
const { defineEventHandler } = window.__bootstrap.webUtil;
|
||||||
|
|
||||||
function createWorker(
|
function createWorker(
|
||||||
specifier,
|
specifier,
|
||||||
|
@ -87,9 +88,6 @@
|
||||||
cancelable: false,
|
cancelable: false,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
if (this.onmessageerror) {
|
|
||||||
this.onmessageerror(msgErrorEvent);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +96,6 @@
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.onmessage) {
|
|
||||||
this.onmessage(msgEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dispatchEvent(msgEvent);
|
this.dispatchEvent(msgEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,9 +110,6 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
if (this.onerror) {
|
|
||||||
this.onerror(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dispatchEvent(event);
|
this.dispatchEvent(event);
|
||||||
if (event.defaultPrevented) {
|
if (event.defaultPrevented) {
|
||||||
|
@ -205,6 +196,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineEventHandler(Worker.prototype, "error");
|
||||||
|
defineEventHandler(Worker.prototype, "message");
|
||||||
|
defineEventHandler(Worker.prototype, "messageerror");
|
||||||
|
|
||||||
window.__bootstrap.worker = {
|
window.__bootstrap.worker = {
|
||||||
Worker,
|
Worker,
|
||||||
};
|
};
|
||||||
|
|
|
@ -334,3 +334,27 @@ Deno.test({
|
||||||
w.terminate();
|
w.terminate();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "Worker event handler order",
|
||||||
|
fn: async function (): Promise<void> {
|
||||||
|
const promise = createResolvable();
|
||||||
|
const w = new Worker(
|
||||||
|
new URL("subdir/test_worker.ts", import.meta.url).href,
|
||||||
|
{ type: "module", name: "tsWorker" },
|
||||||
|
);
|
||||||
|
const arr: number[] = [];
|
||||||
|
w.addEventListener("message", () => arr.push(1));
|
||||||
|
w.onmessage = (e): void => {
|
||||||
|
arr.push(2);
|
||||||
|
};
|
||||||
|
w.addEventListener("message", () => arr.push(3));
|
||||||
|
w.addEventListener("message", () => {
|
||||||
|
assertEquals(arr, [1, 2, 3]);
|
||||||
|
promise.resolve();
|
||||||
|
});
|
||||||
|
w.postMessage("Hello World");
|
||||||
|
await promise;
|
||||||
|
w.terminate();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue