open window to run code

This commit is contained in:
Dmitry Vasilev
2022-10-26 01:05:52 +08:00
parent 9ab8ddec68
commit 30e318a2c4
4 changed files with 36 additions and 13 deletions

View File

@@ -57,15 +57,16 @@ type Node = ToplevelCall | Call
*/
// TODO just export const Iframe_Function?
const make_function = globalThis.process != null
// Tests are run in Node.js, no iframe
? (...args) => new Function(...args)
// Browser context, run code in iframe
: (...args) => {
/* access window object for iframe */
const fn_constructor = globalThis.run_code.contentWindow.Function
return new fn_constructor(...args)
}
const make_function = (...args) => {
if(globalThis.run_window == null) {
// Tests are run in Node.js or user have not opened run_window
return new Function(...args)
} else {
// Code run in browser and user opened run_window
const fn_constructor = globalThis.run_window.Function
return new fn_constructor(...args)
}
}
const codegen_function_expr = (node, cxt, name) => {
const do_codegen = n => codegen(n, cxt)