0

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 
ZachB
  • 13,051
  • 4
  • 61
  • 89
Royal Pinto
  • 2,869
  • 8
  • 27
  • 39

1 Answers1

3

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();
mscdex
  • 104,356
  • 15
  • 192
  • 153
  • Thanks for the example and link. with string I am facing following issue: `static Persistent oncomplete_sym;` `oncomplete_sym.Reset(Nan::New("oncomplete").ToLocalChecked());` It says No matching member function to call Reset. It expects 2 parameters and only I am passing only one as mentioned in the document. For `Object`s i will try soon. – Royal Pinto Feb 15 '16 at 08:21
  • I am using `Nan` `2.2.0` version. – Royal Pinto Feb 15 '16 at 08:25
  • For string it worked for me after adding isolate as the first parameter. `oncomplete_sym.Reset(v8::Isolate::GetCurrent(), Nan::New("oncomplete").ToLocalChecked());` – Royal Pinto Feb 15 '16 at 08:57
  • If you have to deal with isolates explicitly that means you're not using the `Nan::` primitives/methods. Use `Nan::Persistent<..>` instead of `v8::Persistent<...>`. – mscdex Feb 15 '16 at 09:12
  • Awesome, changed from Persistent from v8 to NaN and everything is working fine now (even for objects). thanks a lot :) – Royal Pinto Feb 15 '16 at 09:46