PlugOS refactor and other tweaks (#631)
* Prep for in-process plug loading (e.g. for CF workers, Deno Deploy) * Prototype of fixed in-process loading plugs * Fix: buttons not to scroll with content * Better positioning of modal especially on mobile * Move query caching outside query * Fix annoying mouse behavior when filter box appears * Page navigator search tweaks
This commit is contained in:
+33
-11
@@ -1,20 +1,25 @@
|
||||
import { createSandbox } from "./sandboxes/deno_worker_sandbox.ts";
|
||||
import { System } from "./system.ts";
|
||||
import { assertEquals } from "../test_deps.ts";
|
||||
import { assert, assertEquals } from "../test_deps.ts";
|
||||
import { compileManifest } from "./compile.ts";
|
||||
import { esbuild } from "./deps.ts";
|
||||
import {
|
||||
createSandbox as createNoSandbox,
|
||||
runWithSystemLock,
|
||||
} from "./sandboxes/no_sandbox.ts";
|
||||
import { sleep } from "$sb/lib/async.ts";
|
||||
import { SysCallMapping } from "./system.ts";
|
||||
|
||||
Deno.test("Run a deno sandbox", async () => {
|
||||
const system = new System("server");
|
||||
system.registerSyscalls([], {
|
||||
addNumbers: (_ctx, a, b) => {
|
||||
console.log("This is the context", _ctx.plug.name);
|
||||
return a + b;
|
||||
},
|
||||
failingSyscall: () => {
|
||||
throw new Error("#fail");
|
||||
},
|
||||
});
|
||||
} as SysCallMapping);
|
||||
system.registerSyscalls(["restricted"], {
|
||||
restrictedSyscall: () => {
|
||||
return "restricted";
|
||||
@@ -34,10 +39,8 @@ Deno.test("Run a deno sandbox", async () => {
|
||||
);
|
||||
|
||||
const plug = await system.load(
|
||||
new URL(`file://${workerPath}`),
|
||||
"test",
|
||||
0,
|
||||
createSandbox,
|
||||
createSandbox(new URL(`file://${workerPath}`)),
|
||||
);
|
||||
|
||||
assertEquals({
|
||||
@@ -52,12 +55,31 @@ Deno.test("Run a deno sandbox", async () => {
|
||||
`file://${workerPath}`
|
||||
);
|
||||
|
||||
const plug2 = await system.loadNoSandbox("test", plugExport);
|
||||
const plug2 = await system.load("test", createNoSandbox(plugExport));
|
||||
|
||||
assertEquals({
|
||||
addedNumbers: 3,
|
||||
yamlMessage: "hello: world\n",
|
||||
}, await plug2.invoke("boot", []));
|
||||
let running = false;
|
||||
await Promise.all([
|
||||
runWithSystemLock(system, async () => {
|
||||
console.log("Starting first run");
|
||||
running = true;
|
||||
await sleep(5);
|
||||
assertEquals({
|
||||
addedNumbers: 3,
|
||||
yamlMessage: "hello: world\n",
|
||||
}, await plug2.invoke("boot", []));
|
||||
console.log("Done first run");
|
||||
running = false;
|
||||
}),
|
||||
runWithSystemLock(system, async () => {
|
||||
assert(!running);
|
||||
console.log("Starting second run");
|
||||
assertEquals({
|
||||
addedNumbers: 3,
|
||||
yamlMessage: "hello: world\n",
|
||||
}, await plug2.invoke("boot", []));
|
||||
console.log("Done second run");
|
||||
}),
|
||||
]);
|
||||
|
||||
await system.unloadAll();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user