Skip to content

Commit

Permalink
fix: avoid syntax collision with self-invoking function
Browse files Browse the repository at this point in the history
  • Loading branch information
aaa123eee committed Aug 8, 2024
1 parent b292a14 commit 21bc821
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/web-worker/worker-exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ export const run = (env: WebWorkerEnvironment, scriptContent: string, scriptUrl?
env.$runWindowLoadEvent$ = 1;

// First we want to replace all `this` symbols
let sourceWithReplacedThis = replaceThisInSource(scriptContent, '(thi$(this)?window:this)');
let sourceWithReplacedThis = replaceThisInSource(scriptContent, 'getThi$(this)');

scriptContent =
`with(this){${sourceWithReplacedThis.replace(
/\/\/# so/g,
'//Xso'
)}\n;function thi$(t){return t===this}};${(webWorkerCtx.$config$.globalFns || [])
)}\n;function getThi$(t){return t===this?window:this}};${(webWorkerCtx.$config$.globalFns || [])
.filter((globalFnName) => /[a-zA-Z_$][0-9a-zA-Z_$]*/.test(globalFnName))
.map((g) => `(typeof ${g}=='function'&&(this.${g}=${g}))`)
.join(';')};` + (scriptUrl ? '\n//# sourceURL=' + scriptUrl : '');
Expand Down

0 comments on commit 21bc821

Please sign in to comment.