1
0
Fork 0
mirror of synced 2024-08-14 17:42:01 +12:00

Avoid crossing results

This commit is contained in:
Adria Navarro 2024-02-14 11:47:34 +01:00
parent 7d6e49f8ca
commit bb6500cc91

View file

@ -26,6 +26,7 @@ export class IsolatedVM implements VM {
private codeWrapper: (code: string) => string = code => code
private readonly resultKey = "results"
private runResultKey: string
constructor({
memoryLimit,
@ -41,8 +42,9 @@ export class IsolatedVM implements VM {
this.jail = this.vm.global
this.jail.setSync("global", this.jail.derefInto())
this.runResultKey = crypto.randomUUID()
this.addToContext({
[this.resultKey]: { out: "" },
[this.resultKey]: { [this.runResultKey]: "" },
})
this.invocationTimeout = invocationTimeout
@ -163,7 +165,7 @@ export class IsolatedVM implements VM {
}
}
code = `results.out=${this.codeWrapper(code)}`
code = `results['${this.runResultKey}']=${this.codeWrapper(code)}`
const script = this.isolate.compileScriptSync(code)
@ -171,7 +173,7 @@ export class IsolatedVM implements VM {
// We can't rely on the script run result as it will not work for non-transferable values
const result = this.getFromContext(this.resultKey)
return result.out
return result[this.runResultKey]
}
private registerCallbacks(functions: Record<string, any>) {