aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/php/exec.mjs
blob: 7403dfcc12d69c0811f9d2fdcfb9ea573606297c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { buildResult, createIOCallbacks, preprocessCode } from "./lib.mjs";
import PHPWasm from "./php-wasm.js";

process.once("message", async ({ code: originalCode, input }) => {
	const code = preprocessCode(originalCode);
	const io = createIOCallbacks(input);

	const { ccall } = await PHPWasm({
		stdin: io.stdin,
		stdout: io.stdout,
		stderr: io.stderr,
	});

	let err;
	let result;
	try {
		result = ccall("php_wasm_run", "number", ["string"], [code]);
	} catch (e) {
		err = e;
	}

	process.send(buildResult(err, result, io.getStdout, io.getStderr));
});