Run JavaScript

js.eval(source, options) runs a short JavaScript snippet in an isolated environment. Java passes options and reads results as JSON strings; Python uses self.js.eval and QuickJS uses await js.eval.

Options

OptionPurpose
globalsJSON variables exposed to the script under the same names.
timeoutPositive integer in milliseconds, 5000 by default.

md5X is built in. The result is the JSON value of the last expression; promises are not accepted. The environment provides no networking, DOM or module imports, and is disposed after completion, timeout or cancellation. All three languages need the QuickJS module.

Samples

# Python: compute a signature
sign = self.js.eval(
    "md5X(seed + path + salt)",
    {"globals": {"seed": "demo", "path": "/api/list", "salt": "demo-salt"}}
)
// Java: options and result are both JSON strings
String sign = js.eval("md5X(seed + path + salt)",
        "{\"globals\":{\"seed\":\"demo\",\"path\":\"/api/list\",\"salt\":\"demo-salt\"}}");
Tip

Use this for signatures, decryption or short parsing snippets. When you need full Node.js packages, use Node.js loading.