On Thu, Aug 28, 2014 at 11:18 PM, Alex Barry <[email protected]> wrote: > Hi, > > I'm new to embedding v8 in C++, but haven't tried to do more low-level > javascript processing. > > So, to explain what I want to do, I'm developing a game where the user > interface uses javascript extensively to communicate to a server, but I want > to intentionally throttle how much gets executed per cycle, where the player > can upgrade this feature to get more commands executed per cycle. The > players will be able to create custom javascript functions, as well, so I > can't just limit this in javascript itself, since they would be able to > circumvent this, so I know I have to do this in C++ instead. > > Is this possible? Any examples I've seen of libv8 seem to be very > high-level, and don't expose some of the low-level control of how often the > javascript is executed per cycle. > > Also, if possible I want to be able to guarantee that timeout/time specific > functions still work as expected, so I know it's not just an issue of > limiting the number of steps per delta time of execution, since this will > cause the timing functions in JS to be at least inaccurate, if not > completely wrong. > > So, I guess there are a few things I could try (not sure how to do all of > them, though): > > 1. Limit the number of executions per cycle, which may compromise any > javascript timing functions. > 2. Attempt to queue javascript lines of code as they are executed. > 3. Limit the javascript vm's resouces so it forcibly chokes itself out, and > adjust this as the player upgrades himself in the game. > > I'm not sure which of these are possible, if any at all. > > Any insight or suggestions would be great! > > Thanks, > -Alex
I don't think what you want is possible as such. V8 has an API for interrupting executing JS code called v8::Isolate::RequestInterrupt() that you could abuse to suspend running code but your other requirement, that timers keep working, seems pretty much impossible. Imagine a script that executes `for (;;);`. An infinite loop never yields control back to the embedding application so there is no opportunity to process expired timers. You can forcibly interrupt the script from another thread using the aforementioned API but it's not safe to call into the VM again when it's interrupted. -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
