Merge branch 'master' into execute-script-v2

This commit is contained in:
deanhannigan 2025-02-03 09:07:04 +00:00 committed by GitHub
commit 37a544eba1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -107,4 +107,15 @@ describe("Test isolated vm directly", () => {
)
expect(result).toEqual([])
})
it("should ensure error results are cleared between runs", () => {
const context = {}
// throw error
// Ensure the first execution throws an error
expect(() => runJSWithIsolatedVM(`test.foo.bar = 123`, context)).toThrow()
// Ensure the error is not persisted across VMs
const secondResult = runJSWithIsolatedVM(`return {}`, context)
expect(secondResult).toEqual({})
})
})

View File

@ -186,6 +186,7 @@ export class IsolatedVM implements VM {
code = `
try {
results = {}
results['${this.runResultKey}']=${this.codeWrapper(code)}
} catch (e) {
results['${this.runErrorKey}']=e