mirror of
https://github.com/koush/scrypted.git
synced 2026-03-14 14:22:13 +00:00
server: fix closure capture
This commit is contained in:
@@ -7,9 +7,12 @@ export interface CompileFunctionOptions {
|
||||
function compileFunction(): any {
|
||||
// this is a hacky way of preventing the closure from capturing the code variable which may be a large blob.
|
||||
try {
|
||||
// "new Function" can't be used because it injects newlines per parameter.
|
||||
// this causes source mapping to get misaligned.
|
||||
return eval((globalThis as any).compileFunctionShim);
|
||||
// "new Function" can't be used directly because it injects newlines per parameter,
|
||||
// which causes source mapping to get misaligned.
|
||||
// However, using eval inside a function works, because there are no parameters,
|
||||
// and the "new Function" addresses the closure capture issue.
|
||||
const f = new Function('return eval(globalThis.compileFunctionShim)');
|
||||
return f();
|
||||
}
|
||||
finally {
|
||||
delete (globalThis as any).compileFunctionShim;
|
||||
|
||||
Reference in New Issue
Block a user