mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
open window to run code
This commit is contained in:
19
src/eval.js
19
src/eval.js
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user