Skip to content

Revert "fix: keep this in parse expression function" #3027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/renderer-core/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,22 @@ function parseExpression(a: any, b?: any, c = false) {
thisRequired = c;
}
try {
const contextArr = ['"use strict";', 'var __self = arguments[0];'];
contextArr.push('return ');
let tarStr: string;

tarStr = (str.value || '').trim();

let code = `"use strict"; function __wrapper(){ return ${tarStr}} return __wrapper.call(arguments[0])`;
// NOTE: use __self replace 'this' in the original function str
// may be wrong in extreme case which contains '__self' already
tarStr = tarStr.replace(/this(\W|$)/g, (_a: any, b: any) => `__self${b}`);
tarStr = contextArr.join('\n') + tarStr;

// 默认调用顶层窗口的parseObj, 保障new Function的window对象是顶层的window对象
if (inSameDomain() && (window.parent as any).__newFunc) {
return (window.parent as any).__newFunc(code)(self);
}
if (!thisRequired) {
code = `with($scope){${code}}`;
return (window.parent as any).__newFunc(tarStr)(self);
}
const code = `with(${thisRequired ? '{}' : '$scope || {}'}) { ${tarStr} }`;
return new Function('$scope', code)(self);
} catch (err) {
logger.error(`${logScope || ''} parseExpression.error`, err, str, self?.__self ?? self);
Expand Down
Loading