mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-09-24 17:11:00 +00:00
17 lines
458 B
TypeScript
17 lines
458 B
TypeScript
import type { PluginAPI } from "./types";
|
|
export class PluginSandbox {
|
|
static evaluate(api: PluginAPI, code: string): void {
|
|
const fn = new Function("api", code);
|
|
fn(api);
|
|
}
|
|
|
|
static evaluateAsync(api: PluginAPI, code: string): Promise<void> {
|
|
try {
|
|
const asyncFn = new Function("api", `return (async () => { ${code} })()`);
|
|
return Promise.resolve(asyncFn(api));
|
|
} catch (err) {
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
}
|