( args: Record<string, string>, script: string, isAsync = false, )
| 12 | } |
| 13 | |
| 14 | const createSandboxedFunction = function ( |
| 15 | args: Record<string, string>, |
| 16 | script: string, |
| 17 | isAsync = false, |
| 18 | ) { |
| 19 | const params = Object.getOwnPropertyNames(args); |
| 20 | |
| 21 | if (containsGeneratorFunction(script)) { |
| 22 | throw new Error('Generator functions are not supported'); |
| 23 | } |
| 24 | |
| 25 | const blacklist = [ |
| 26 | ...Object.getOwnPropertyNames(window).filter( |
| 27 | (e) => e !== 'eval' && e !== 'arguments' && e !== 'btoa' && e !== 'atob', |
| 28 | ), |
| 29 | ]; |
| 30 | |
| 31 | params.push(...blacklist); |
| 32 | if (isAsync) { |
| 33 | script = `return (async function() {${script}})()`; |
| 34 | } |
| 35 | return new Function(...params, '"use strict";' + script); |
| 36 | }; |
| 37 | |
| 38 | const sandboxedFunction = function (args: Record<string, string>, script: string) { |
| 39 | const vals = Object.values(args); |
no test coverage detected