Skip to content

Pass function as a parameter #17

@Wansmer

Description

@Wansmer

Is your feature request related to a problem? Please describe.

Now methods of modules can work with with primitives and objects only, bun no with a functions.

Code below throw Error, because postMessage no work with function:

(async () => {
  const res = await module1.method1(x => x ** x);
  console.log({ res });
})();

Describe the solution you'd like

There an idea of implementation with vm: https://github.com/Wansmer/noroutine/pull/1

But there is open questions:

  1. Is a good approach to create new sandbox for every higher order function?
  2. Is need disable modules like os and fs for safety or user must make decision himself? (set flags in options or generate and pass own context, for example);
  3. If 'dangerous' code not expected (from end user), maybe eval in this case will be better and lighter solution instead vm.Script?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions