-
If I create a new const compartment = new Compartment({ foo: 1, bar: 2 });
export class Compartment {
// ...
get globalThis(): Record<PropertyKey, any>; My use case is I have a number of constants which may change every time a program is executed within the compartment. Rather than constructing a new |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
The chief consideration needed to answer this question is whether each program is running on the behalf of the same agent. If the global is mutable, each process (evaluation of a program) has an opportunity to interfere with every subsequent process by modifying or even freezing the environment. If the parameters are communicated as properties of a mutable global object, they can interfere by setting and then freezing the global object. You can make a single compartment safe for multiple agents by freezing compartment.evaluate(`(params) => {}`)(params); You can also provide parameters as lexical bindings with a confined new compartment.globalThis.Function(...Object.keys(params), program)(...Object.values(params)) You can also preserve a But, each new |
Beta Was this translation helpful? Give feedback.
I have found I can simply use the following to update globals available within SES:
I had assumed I could not do this because
globalThis
is a getter but I'm glad it works!