From 72a8e084ce62bf03e4b5ade26fc27c5aeb4e316c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Tue, 16 Jul 2024 15:21:34 +0200 Subject: [PATCH] fix: plugins can't execute plugins --- src/routes/sandbox/+page.svelte | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/routes/sandbox/+page.svelte b/src/routes/sandbox/+page.svelte index 1d6254f9..8994f875 100644 --- a/src/routes/sandbox/+page.svelte +++ b/src/routes/sandbox/+page.svelte @@ -5,6 +5,8 @@ let resolveRequest: ((data: unknown) => void) | undefined = undefined; let source: MessageEventSource | undefined = undefined; + const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; + async function post(channel: string, args: unknown[]) { while (ongoingRequest) { await ongoingRequest; @@ -35,15 +37,18 @@ ), ); - new Function("Action", "Chara", event.data.script)( - Action, - Object.fromEntries( - event.data.charaChannels.map((name) => [ - name, - (...args: unknown[]) => post(name, args), - ]), - ), + const Chara = Object.fromEntries( + event.data.charaChannels.map((name) => [ + name, + (...args: unknown[]) => post(name, args), + ]), ); + + AsyncFunction( + "Action", + "Chara", + '"use strict"\n' + event.data.script, + )(Action, Chara); } }