Skip to content

Commit

Permalink
Async function argument
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurweinmann committed Jan 29, 2024
1 parent 96bc8d8 commit 2438a68
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import puppeteer from "puppeteer";
import {KnownDevices} from "puppeteer";
import path from 'path';

const AsyncFunction = async function () {}.constructor; // AsyncFunction constructor working in the same way as `new Function`

var command_line_args = { verbose: true, newheadless: false }; // defaults
for (let i = 2; i < Bun.argv.length; i++) {
if (!Bun.argv[i].startsWith("--")) {
Expand Down Expand Up @@ -332,6 +334,18 @@ Bun.serve({
}

body.calls[i].parameters[p] = new Function(...args);
} else if (body.calls[i].parameters[p].startsWith("async function(")) {
body.calls[i].parameters[p] = body.calls[i].parameters[p].slice("async function(".length);
let argend = body.calls[i].parameters[p].indexOf(")");
let args = body.calls[i].parameters[p].slice(0, argend).trim().split(",").map(v => v.trim());
body.calls[i].parameters[p] = body.calls[i].parameters[p].slice(argend + 1).trim();
args.push(body.calls[i].parameters[p].slice(1, body.calls[i].parameters[p].length - 2).trim()); // remove { }

if (verbose) {
console.log("creating new async Function with arguments", args);
}

body.calls[i].parameters[p] = new AsyncFunction(...args);
}
}
}
Expand Down

0 comments on commit 2438a68

Please sign in to comment.