Thanks Ben,
I posted it here because I think I have a context problem.
I use the latest v.011 and node::Init() and node::CreateEnvironment() are
available. So i modified the code, but it is still not working:
void init(char* param)
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Handle<String> source = readFile(isolate, param);
if (source.IsEmpty())
{
LOG4CXX_ERROR(logger, "Error reading: " << param);
return;
}
Handle<ObjectTemplate> global = ObjectTemplate::New(isolate);
//Log
global->Set(String::NewFromUtf8(isolate, "log"),
FunctionTemplate::New(isolate, LogCallback));
Handle<Context> context = Context::New(isolate, NULL, global);
context_.Reset(isolate, context);
Context::Scope contextScope(context);
// if (!executeScript(source)) return; //if I use this, wich includes
Compile and Run, it's working
char *argv_n[] = {(char*)"node", param, NULL};
int argc_n = sizeof(argv_n) / sizeof(char*) - 1;
int exec_argc;
const char** exec_argv;
node::Init(&argc_n, const_cast<const char**>(argv_n), &exec_argc,
&exec_argv);
Environment* env = node::CreateEnvironment(isolate, context, argc_n,
argv_n, exec_argc, exec_argv);
stateInitFunctionJS.Reset(isolate, registerFunction((char*)"stateInit"))
return;
}
Handle<Function> registerFunction(char* name)
{
Isolate* isolate = Isolate::GetCurrent();
EscapableHandleScope handleScope(isolate);
Local<Context> context = Local<Context>::New(isolate, context_);
Context::Scope contextScope(context);
Handle<String> processFunctionName = String::NewFromUtf8(isolate,
name);
Handle<Value> processFunctionValue =
context->Global()->Get(processFunctionName);
if (!processFunctionValue->IsFunction())
{
LOG4CXX_ERROR(logger, "Function " << name << " not found!");
exit(1);
}
Local<Function> processFunction =
Handle<Function>::Cast(processFunctionValue);
return handleScope.Escape(processFunction);
}
context_ ist persistent context and stateInitFunctionJS is persistent
function.
And then I have: Function stateInit not found!
I think when the execution comes back from node.js the context is lost and
the JavaScript code is no longer visible to my program and i can't run the
functions from C++.
When I use the function executeScript(the commented line), which includes
Compile and Run like in the process.cc example in V8, it's ok.
So how can I keep, copy or use the context form node.js so it's visible to
the main program, if this is the correct question? May be is helpful if you
see how CreateEnvironment() uses the context. I tried to use
GetCurrentContext and GetEnteredContext on different places but it didn't
work.
--
--
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.