Some PR comments/build issue.
This commit is contained in:
parent
3e21d97c47
commit
285916d0bf
|
@ -15,6 +15,17 @@ export class BuiltInVM implements VM {
|
||||||
this.span = span
|
this.span = span
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withContext<T>(context: Record<string, any>, executeWithContext: () => T): T {
|
||||||
|
this.ctx = vm.createContext(context)
|
||||||
|
try {
|
||||||
|
return executeWithContext()
|
||||||
|
} finally {
|
||||||
|
for (const key in context) {
|
||||||
|
delete this.ctx[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
execute(code: string) {
|
execute(code: string) {
|
||||||
const perRequestLimit = env.JS_PER_REQUEST_TIMEOUT_MS
|
const perRequestLimit = env.JS_PER_REQUEST_TIMEOUT_MS
|
||||||
let track: TrackerFn = f => f()
|
let track: TrackerFn = f => f()
|
||||||
|
|
|
@ -97,11 +97,11 @@ export class IsolatedVM implements VM {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext<T>(context: Record<string, any>, f: () => T) {
|
withContext<T>(context: Record<string, any>, executeWithContext: () => T) {
|
||||||
this.addToContext(context)
|
this.addToContext(context)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return f()
|
return executeWithContext()
|
||||||
} finally {
|
} finally {
|
||||||
this.removeFromContext(Object.keys(context))
|
this.removeFromContext(Object.keys(context))
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@ export class VM2 implements VM {
|
||||||
this.vm.setGlobal("results", this.results)
|
this.vm.setGlobal("results", this.results)
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext<T>(context: Record<string, any>, fn: () => T): T {
|
withContext<T>(context: Record<string, any>, executeWithContext: () => T): T {
|
||||||
this.vm.setGlobals(context)
|
this.vm.setGlobals(context)
|
||||||
try {
|
try {
|
||||||
return fn()
|
return executeWithContext()
|
||||||
} finally {
|
} finally {
|
||||||
for (const key in context) {
|
for (const key in context) {
|
||||||
this.vm.setGlobal(key, undefined)
|
this.vm.setGlobal(key, undefined)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export interface VM {
|
export interface VM {
|
||||||
execute(code: string): any
|
execute(code: string): any
|
||||||
withContext<T>(context: Record<string, any>, fn: () => T): T
|
withContext<T>(context: Record<string, any>, executeWithContext: () => T): T
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue