vlocode-project - v1.40.0-beta-4
    Preparing search index...

    Function compileFunction

    • Compiles the specified code as sandboxed function. The compiled function can be executed with a context object. Optionally the context object can be mutable, allowing the compiled code to modify the context object.

      Parameters

      • code: string
      • Optionaloptions: { mode: "vm" | "sandbox" }

      Returns (context?: object, options?: ExecuteOptions) => any

      const context = { counter: 0 };
      const code = 'return context.coounter++;';
      const compiledFn = compileFunction(code, { mode: 'sandbox' });
      expect(compiledFn(context, true)).toBe(1);
      expect(context.counter).toBe(1);

      @param code JS code @param options specifies how to compile the function @returns