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 out is Empty context. and segfault. "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?

-- 
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/a5a9447f-c89d-4377-ac8b-408dc42df02b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to