node addon 0.10 to 0.12 upgrade

37 views
Skip to first unread message

Srdjan Boskovic

unread,
Aug 28, 2015, 10:42:41 PM8/28/15
to nodejs
I need to convert one 0.10 node add-on to 0.12 and struggle with Persistent <Function> conversion.

Here are my baton structs

struct ClientBaton {
  uv_work_t request;
  Persistent<Function> callback;

  RFC_ERROR_INFO errorInfo;
  Client *wrapper;
};

struct InvokeBaton {
  uv_work_t request;
  Persistent<Function> callback;

  RFC_FUNCTION_HANDLE functionHandle;
  RFC_FUNCTION_DESC_HANDLE functionDescHandle;
  RFC_ERROR_INFO errorInfo;
  Client *wrapper;
};

and partly converted client code:

void Client::ConnectAsyncAfter(uv_work_t* req) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    ClientBaton* baton = static_cast<ClientBaton*>(req->data);
    if (baton->errorInfo.code != RFC_OK) {
        Handle<Value> argv[] = { wrapError(&baton->errorInfo) };

        TryCatch try_catch;
        baton->callback->Call(isolate->GetCurrentContext()->Global(), 1, argv);

        if (try_catch.HasCaught()) {
            node::FatalException(try_catch);
        }
    } 
    else {
        // connect
        baton->callback->Call(isolate->GetCurrentContext()->Global(), 0, NULL);
        baton->wrapper->alive = true;
    }

    baton->callback->Dispose();
    delete baton;
}

This results in following build errors:

gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory `/home/pos/src/node-rfc/build'
  CXX(target) Release/obj.target/rfc/src/Client.o
../src/Client.cc: In static member function ‘static void Client::ConnectAsyncAfter(uv_work_t*)’:
../src/Client.cc:135:24: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::Function>’
         baton->callback->Call(isolate->GetCurrentContext()->Global(), 1, argv);
                        ^
../src/Client.cc:143:24: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::Function>’
         baton->callback->Call(isolate->GetCurrentContext()->Global(), 0, NULL);
                        ^
../src/Client.cc:147:20: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::Function>’
     baton->callback->Dispose();
                    ^
../src/Client.cc: In static member function ‘static void Client::Connect(const v8::FunctionCallbackInfo<v8::Value>&)’:
../src/Client.cc:166:66: error: no matching function for call to ‘v8::Persistent<v8::Function>::New(v8::Isolate*&, v8::Local<v8::Function>&)’
     baton->callback = Persistent<Function>::New(isolate, callback);

I am not sure how Persistent <Function> should be converted and hint/example would be of a great help.





Reply all
Reply to author
Forward
0 new messages