简体   繁体   中英

Node Addons and v8 GlobalTemplate

I am building node addon with node 0.10.17 and in one of my class i am making a context of v8. I have this code :

v8::Locker locker;
v8::HandleScope handle_scope;
v8::Handle<v8::ObjectTemplate> globalTemplate;

// vvv--------------- Exception here at ->Set()
globalTemplate->Set(v8::String::New("version"), v8::FunctionTemplate::New(NodeVersion));
context = v8::Context::New(NULL, globalTemplate);
if (context.IsEmpty()) {
      fprintf(stderr, "Error creating context\n");
}

This is giving me exception in ->Set() function call. The application is just breaking.

What should i do ?

Your globalTemplate pointer is null, since you only created a null v8::Handle.

You should do something like this:

v8::Handle<v8::ObjectTemplate> globalTemplate = v8::ObjectTemplate::New();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM