Avoid crossing results
This commit is contained in:
parent
7d6e49f8ca
commit
bb6500cc91
1 changed files with 5 additions and 3 deletions
|
@ -26,6 +26,7 @@ export class IsolatedVM implements VM {
|
||||||
private codeWrapper: (code: string) => string = code => code
|
private codeWrapper: (code: string) => string = code => code
|
||||||
|
|
||||||
private readonly resultKey = "results"
|
private readonly resultKey = "results"
|
||||||
|
private runResultKey: string
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
memoryLimit,
|
memoryLimit,
|
||||||
|
@ -41,8 +42,9 @@ export class IsolatedVM implements VM {
|
||||||
this.jail = this.vm.global
|
this.jail = this.vm.global
|
||||||
this.jail.setSync("global", this.jail.derefInto())
|
this.jail.setSync("global", this.jail.derefInto())
|
||||||
|
|
||||||
|
this.runResultKey = crypto.randomUUID()
|
||||||
this.addToContext({
|
this.addToContext({
|
||||||
[this.resultKey]: { out: "" },
|
[this.resultKey]: { [this.runResultKey]: "" },
|
||||||
})
|
})
|
||||||
|
|
||||||
this.invocationTimeout = invocationTimeout
|
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)
|
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
|
// We can't rely on the script run result as it will not work for non-transferable values
|
||||||
const result = this.getFromContext(this.resultKey)
|
const result = this.getFromContext(this.resultKey)
|
||||||
return result.out
|
return result[this.runResultKey]
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerCallbacks(functions: Record<string, any>) {
|
private registerCallbacks(functions: Record<string, any>) {
|
||||||
|
|
Loading…
Reference in a new issue