Skip to content

Commit

Permalink
fix(engine): expression can not return right value in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
towersxu authored and boyongjiong committed Aug 21, 2023
1 parent a907c87 commit 9ef9f2e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/engine/src/expression/browserVm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const createContext = (globalData) => {
if (!document || !document.body) {
console.error(getErrorMsg(ErrorCode.NO_DOCUMENT_BODY));
}
document.body.appendChild(iframe);
const iframeWindow = iframe.contentWindow as any;
iframeWindow.parent = null;
Object.keys(globalData).forEach((key) => {
Expand All @@ -22,6 +23,9 @@ const runInContext = (code, context) => {
try {
const iframeEval = context.eval;
iframeEval.call(context, code);
if (context.frameElement) {
document.body.removeChild(context.frameElement);
}
} catch (e) {
console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), { code, context, e });
}
Expand Down

0 comments on commit 9ef9f2e

Please sign in to comment.