Clean code
This commit is contained in:
parent
8dfcc3aeb1
commit
75f8b40cc4
|
@ -25,14 +25,14 @@ class ScriptRunner {
|
||||||
class IsolatedVM {
|
class IsolatedVM {
|
||||||
isolate: ivm.Isolate
|
isolate: ivm.Isolate
|
||||||
vm: ivm.Context
|
vm: ivm.Context
|
||||||
jail: ivm.Reference
|
#jail: ivm.Reference
|
||||||
script: any
|
script: any
|
||||||
|
|
||||||
constructor({ memoryLimit }: { memoryLimit: number }) {
|
constructor({ memoryLimit }: { memoryLimit: number }) {
|
||||||
this.isolate = new ivm.Isolate({ memoryLimit })
|
this.isolate = new ivm.Isolate({ memoryLimit })
|
||||||
this.vm = this.isolate.createContextSync()
|
this.vm = this.isolate.createContextSync()
|
||||||
this.jail = this.vm.global
|
this.#jail = this.vm.global
|
||||||
this.jail.setSync("global", this.jail.derefInto())
|
this.#jail.setSync("global", this.#jail.derefInto())
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue(key: string) {
|
getValue(key: string) {
|
||||||
|
@ -44,7 +44,7 @@ class IsolatedVM {
|
||||||
|
|
||||||
set context(context: Record<string, any>) {
|
set context(context: Record<string, any>) {
|
||||||
for (let key in context) {
|
for (let key in context) {
|
||||||
this.jail.setSync(key, this.copyRefToVm(context[key]))
|
this.#jail.setSync(key, this.copyRefToVm(context[key]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue