fix: plugins can't execute plugins

This commit is contained in:
2024-07-16 15:21:34 +02:00
parent 989e844190
commit 72a8e084ce

View File

@@ -5,6 +5,8 @@
let resolveRequest: ((data: unknown) => void) | undefined = undefined; let resolveRequest: ((data: unknown) => void) | undefined = undefined;
let source: MessageEventSource | undefined = undefined; let source: MessageEventSource | undefined = undefined;
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
async function post(channel: string, args: unknown[]) { async function post(channel: string, args: unknown[]) {
while (ongoingRequest) { while (ongoingRequest) {
await ongoingRequest; await ongoingRequest;
@@ -35,15 +37,18 @@
), ),
); );
new Function("Action", "Chara", event.data.script)( const Chara = Object.fromEntries(
Action,
Object.fromEntries(
event.data.charaChannels.map((name) => [ event.data.charaChannels.map((name) => [
name, name,
(...args: unknown[]) => post(name, args), (...args: unknown[]) => post(name, args),
]), ]),
),
); );
AsyncFunction(
"Action",
"Chara",
'"use strict"\n' + event.data.script,
)(Action, Chara);
} }
} }
</script> </script>