From 2631c09bdbca9e79f26e1ac24cff54bf9ec89357 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Thu, 22 Jun 2023 15:49:12 +0300 Subject: [PATCH] fix globals --- src/eval.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/eval.js b/src/eval.js index 7e500ec..7c0927c 100644 --- a/src/eval.js +++ b/src/eval.js @@ -434,19 +434,18 @@ account // Workaround with statement forbidden in strict mode (imposed by ES6 modules) // Also currently try/catch is not implemented TODO - - -// TODO also create in Iframe Context? -const eval_codestring = new Function('codestring', 'scope', - // Make a copy of `scope` to not mutate it with assignments - ` - try { - return {ok: true, value: eval('with({...scope}){' + codestring + '}')} - } catch(error) { - return {ok: false, error} - } - ` -) +export const eval_codestring = (codestring, scope) => + // Note that we eval code in context of run_window + (new (globalThis.run_window.Function)('codestring', 'scope', + // Make a copy of `scope` to not mutate it with assignments + ` + try { + return {ok: true, value: eval('with({...scope}){' + codestring + '}')} + } catch(error) { + return {ok: false, error} + } + ` + ))(codestring, scope) const get_args_scope = (fn_node, args) => { const arg_names =