4 ms·
I'm currently working on a game[0] similar to Untrusted[1] and I had to use bind (among other techniques like variable shadowing) in order to "sandbox" player p
by umvi 4y ago
I'm currently working on a game[0] similar to Untrusted[1] and I had to use bind (among other techniques like variable shadowing) in order to "sandbox" player provided code from interfering with other game objects or accessing the global scope (obviously there's no perfect sandbox, but it at least it makes it more difficult for players to do naughty things). Bind is useful because you can control the meaning of "this" when evaluating user-provided code, and I use it to deny player access to the parent scope by calling bind(undefined).
[0] https://www.bryanpg.com/games/pragma_twice https://www.bryanpg.com/games/pragma_twice
[1] https://github.com/AlexNisnevich/untrusted https://github.com/AlexNisnevich/untrusted
- tim1994 4y agoHave you considered running "untrusted" code in a worker? That way the code can not interfere with the global scope.
- umvi 4y agoIndeed, however, I started this project a few years ago before I knew about workers and so it would be a lot of effort to switch now. Perhaps if I make a follow on game I'd try workers. I'd have to implement message routing in order for objects to communicate with each other and I'm not sure how much impact that would have on performance.