For starters, I want two things:
- Have a JS file with global functions to use in my application. I already the global object set with the C++ functions, but also need to mix the JS ones since it's a lot faster sometimes.
- Have a module system akin to Node.js/CommonJS and load JS files from the file system.
Also, I want both of those things to work across multiple contexts, since each script in my application runs in a different context and I have a bunch of scripts.
So, I expected that it would be possible to pre-compile a script in one temporary context then run it in each of the other contexts to add the global functions. It turned out that none of my tests to do so worked (and I really don't understand the cryptic error messages I get, something like that == 0 || (*reinterpret_cast<v8::internal::Object* const*>(that))->IsJSFunction() and similar stuff). Tried to use the same security token in both contexts, use ScriptCompiler::CompileUnbound() and Script::GetUnboundScript() (those failed when using BindToCurrentContext() later).
Maybe there's a better way to do this, but I am completely thrown off by the absence of documentation and reference material (or my inability to find them, though I accomplished quite a lot until now without needing to ask). Anyway, if there's some easy and fast way to do both of my points above without context-switching then please point me the way.
My main question that (I think) will solve my problem: How to share a compiled script between different contexts?
Thanks in advance.