On Tue, Sep 16, 2014 at 9:10 PM, Peter Stoyanov <[email protected]> wrote: > --corrected > > Hi Ben, > > I want to get the context after the javascript file is executed from > node::CreateEnvironment(). I am trying like this: > > 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); > > 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); > > char *argv_n[] = {(char*)"node", param, NULL}; > int argc_n = sizeof(argv_n) / sizeof(char*) - 1; > > int exec_argc = 0; > const char** exec_argv = NULL; > node::Init(&argc_n, const_cast<const char**>(argv_n), &exec_argc, > &exec_argv); > env = node::CreateEnvironment(isolate, context, argc_n, argv_n, > exec_argc, exec_argv); > > Local<Context> context2 = env->context(); > > if (context2.IsEmpty()) printf("Empty context. \n"); > context_.Reset(isolate, context2); > > Context::Scope context_scope(context2); > Handle<String> processFunctionName = String::NewFromUtf8(isolate, > "stateInit"); > Handle<Value> processFunctionValue = > context2->Global()->Get(processFunctionName); > > > if (!processFunctionValue->IsFunction()) > { > LOG4CXX_ERROR(logger, "Function " << "stateInit" << " not found!"); > exit(1); > } > > Local<Function> processFunction = > Handle<Function>::Cast(processFunctionValue); > stateInitFunctionJS.Reset(isolate, processFunction); > > And then the ouput is "Function stateInit not found. "param" is my > javascript file and I don't know in which context of node.js is executed. > Or may be my mistake is at: > Handle<Value> processFunctionValue = > context2->Global()->Get(processFunctionName); > How can I cat the name of the function from node.js?
How and where is that function stateInit() defined? -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAHQurc_Rj8-muLnU6mLoPAjbK7PBSv4F88%2BsQKyhRaSTn9H%3Dag%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
