UNPKG

@logicflow/engine

Version:

a process engine for javascript

66 lines 2.02 kB
// import { // ErrorCode, // getErrorMsg, // getWarningMsg, // WarningCode, // } from '../../constant/logCode' // // const createContext = (globalData: Record<string, unknown>) => { // const iframe = document.createElement('iframe') // iframe.style.display = 'none' // if (!document || !document.body) { // console.error(getErrorMsg(ErrorCode.NO_DOCUMENT_BODY)) // } // document.body.appendChild(iframe) // const iframeWindow = iframe.contentWindow // if (iframeWindow) { // // TODO: 确认是否需要该代码,parent 置为空是为了解决什么问题 // // @ts-ignore // ;(iframeWindow!.parent as any) = null // Object.keys(globalData).forEach((key) => { // iframeWindow[key] = globalData[key] // }) // } // return iframeWindow // } // // const runInContext = (code: string, context: any) => { // try { // const iframeEval = context.eval // iframeEval.call(context, code) // console.log('context --->>> ===>>>', context) // if (context.frameElement) { // document.body.removeChild(context.frameElement) // } // } catch (e) { // console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), { // code, // context, // e, // }) // } // } // // const runInBrowserContext = async ( // code: string, // globalData = {}, // ): Promise<any> => { // const context = createContext(globalData) // runInContext(code, context) // return context // } // // export { createContext, runInContext, runInBrowserContext } import { __awaiter } from "tslib"; import Sandbox from '@nyariv/sandboxjs'; export const runInBrowserContext = (code_1, ...args_1) => __awaiter(void 0, [code_1, ...args_1], void 0, function* (code, globalData = {}) { try { const sandbox = new Sandbox(); const exec = sandbox.compile(code); return yield exec(globalData).run(); } catch (e) { console.log('runInBrowserContext error --->>>', e); } }); //# sourceMappingURL=browserVm.js.map