I am reorganizing my V8 with an OpenGL implementation and run into a problem in the execution context.
The concept is this:
V8GL::initialize()
This method initializes the context and global template. It also uses context for glut because there are several loops that are also subject to JS context. (e.g. glut.mainLoop())
V8GL::execute(context, source, url)
This method basically executes the string inside the given context. I think it should be for the subsequent use of isolates at intervals / timeouts.
What does not work:
V8GL::initialize()also attaches embedded JavaScript files and executes them. It works great.
Simplified code:
V8GL::initialize(...) {
v8::Persistent<v8::Context> context = v8::Context::New(NULL, globalTemplate);
v8::Context::Scope context_scope(context);
GlutFactory::context_ = v8::Persistent<v8::Context>::New(context);
execute(context, v8::String::New(...script content...), v8::String::New(...script url path to show for exception stacktraces...);
v8gl::global = v8::Persistent<v8::Object>::New(context->Global());
context->DetachGlobal();
context.Dispose();
}
V8GL::execute(context, source, filename) {
v8::HandleScope scope;
v8::Local<v8::Script> script = v8::Script::Compile(source, filename);
}
Problem:
. , JavaScript. , . main.cpp main() .
int main(...) {
v8gl::V8GL::initialize(&argc, argv);
v8::HandleScope scope;
v8::Context::New(NULL, v8::ObjectTemplate::New(), v8gl::global);
v8gl::V8GL::execute(context, source, filepath);
}
:
- objectTemplate
v8::Context::New()? - global_object ?
- ?
DetachGlobal() ReattachGlobal() , . .