Bromeon/js-sandbox

Question: define function in Rust and expose it to javascript?

JasonMiesionczek opened this issue · 3 comments

Just wondering if it's possible, as I didn't see this particular example, to define a function in Rust code and allow it to be called from the JavaScript code directly? I see there are plenty of examples of calling functions defined in JS from Rust, but I need the opposite. Thanks.

So far, js-sandbox only supports unidirectional data flow (Rust invokes JS, data needs to be returned via function return values). I'm a bit conflicted about adding JS->Rust calls -- they're handy for simple use cases, but make it harder to completely isolate code security-wise, and add new issues like re-entrancy.

This is however exactly what the underlying library deno_core does: running JS code with hooks to Rust code -- so-called "ops". I actually misuse that mechanism to emulate the other way 🙂

Another project that might be interesting for you could be MiniV8. The ReadMe example // Rust functions can be passed into JavaScript. could be a starting point.

Awesome, thanks for the links, appreciate your time.

Closing as answered.