Royal Pinto Royal Pinto - 2 months ago 25
Node.js Question

How to use new version of Node Nan Persistent

With new version of

Nan
what would be the equivalent code for following:
The following code works with 0.12.* but not on 4.3.0 and later.

//1)
//This is my object_
Persistent<Object> object_;

Local<Object> obj = Nan::New<Object>();
NanAssignPersistent(object_, obj); //Don't know what to replace with here


//2)
NanDisposePersistent(object_); //Don't know what to replace with here

Answer

The nan documentation shows how to deal with Persistents here. It may also be useful to look at the nan tests for Persistent.

Example:

Local<Object> obj;
Local<Object> obj2;

// Create a persistent
Nan::Persistent<v8::Object> persistent(obj);

// Get a local handle to the persisted object
v8::Local<v8::Object> orig_obj = Nan::New(persistent);

// Change the persistent reference
persistent.Reset(obj2);

// Dispose of the persistent
persistent.Reset();