From 2cdc6d8cefbb2e0873836aca259dbd1f5f34ac6a Mon Sep 17 00:00:00 2001 From: Eric Waldheim Date: Mon, 20 Oct 2014 14:58:32 -0600 Subject: [PATCH 1/2] Compile on node 11.14 using nan v1.3.0 --- binding.gyp | 2 +- package.json | 1 + src/commitBaton.h | 2 +- src/connection.cpp | 116 ++++++++++++++++++++-------------------- src/connection.h | 6 +-- src/executeBaton.cpp | 6 +-- src/oracle_bindings.cpp | 22 ++++---- src/outParam.cpp | 10 ++-- src/reader.cpp | 18 +++---- src/rollbackBaton.h | 3 +- src/statement.cpp | 18 +++---- src/utils.h | 17 +++--- 12 files changed, 112 insertions(+), 109 deletions(-) diff --git a/binding.gyp b/binding.gyp index 4c5849c..a9c6991 100644 --- a/binding.gyp +++ b/binding.gyp @@ -50,7 +50,7 @@ "link_settings": {"libraries": [ '<(oci_lib_dir)\oraocci<(oci_version).lib'] } }] ], - "include_dirs": [ "<(oci_include_dir)" ], + "include_dirs": [ "<(oci_include_dir)", '0.8.0" diff --git a/src/commitBaton.h b/src/commitBaton.h index 5dd9c17..14915af 100644 --- a/src/commitBaton.h +++ b/src/commitBaton.h @@ -11,7 +11,7 @@ class CommitBaton { uni::Reset(this->callback, *callback); } ~CommitBaton() { - callback.Dispose(); + NanDisposePersistent(callback); } Connection *connection; diff --git a/src/connection.cpp b/src/connection.cpp index d061fbe..aee383d 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -16,10 +16,10 @@ Persistent Connection::constructorTemplate; void Connection::Init(Handle target) { UNI_SCOPE(scope); - Local t = FunctionTemplate::New(New); + Local t = NanNew(New); uni::Reset(constructorTemplate, t); uni::Deref(constructorTemplate)->InstanceTemplate()->SetInternalFieldCount(1); - uni::Deref(constructorTemplate)->SetClassName(String::NewSymbol("Connection")); + uni::Deref(constructorTemplate)->SetClassName(NanNew("Connection")); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "execute", Execute); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "executeSync", ExecuteSync); @@ -32,7 +32,7 @@ void Connection::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "commit", Commit); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "rollback", Rollback); - target->Set(String::NewSymbol("Connection"), uni::Deref(constructorTemplate)->GetFunction()); + target->Set(NanNew("Connection"), uni::Deref(constructorTemplate)->GetFunction()); } uni::CallbackType Connection::New(const uni::FunctionCallbackInfo& args) { @@ -62,7 +62,7 @@ uni::CallbackType Connection::Execute(const uni::FunctionCallbackInfo& args) { ExecuteBaton* baton = new ExecuteBaton(connection, *sqlVal, &values, &callback); if (baton->error) { - Local message = String::New(baton->error->c_str()); + Local message = NanNew(baton->error->c_str()); delete baton; UNI_THROW(Exception::Error(message)); } @@ -73,7 +73,7 @@ uni::CallbackType Connection::Execute(const uni::FunctionCallbackInfo& args) { connection->Ref(); - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } uni::CallbackType Connection::Prepare(const uni::FunctionCallbackInfo& args) { @@ -117,9 +117,9 @@ uni::CallbackType Connection::Close(const uni::FunctionCallbackInfo& args) { Connection* connection = ObjectWrap::Unwrap(args.This()); connection->closeConnection(); - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } catch (const exception& ex) { - UNI_THROW(Exception::Error(String::New(ex.what()))); + UNI_THROW(Exception::Error(NanNew(ex.what()))); } } @@ -128,9 +128,9 @@ uni::CallbackType Connection::IsConnected(const uni::FunctionCallbackInfo& args) Connection* connection = ObjectWrap::Unwrap(args.This()); if(connection && connection->m_connection) { - UNI_RETURN(scope, args, Boolean::New(true)); + UNI_RETURN(scope, args, NanTrue()); } else { - UNI_RETURN(scope, args, Boolean::New(false)); + UNI_RETURN(scope, args, NanFalse()); } } @@ -148,7 +148,7 @@ uni::CallbackType Connection::Commit(const uni::FunctionCallbackInfo& args) { connection->Ref(); - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } uni::CallbackType Connection::Rollback(const uni::FunctionCallbackInfo& args) { @@ -165,7 +165,7 @@ uni::CallbackType Connection::Rollback(const uni::FunctionCallbackInfo& args) { connection->Ref(); - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } uni::CallbackType Connection::SetAutoCommit(const uni::FunctionCallbackInfo& args) { @@ -173,7 +173,7 @@ uni::CallbackType Connection::SetAutoCommit(const uni::FunctionCallbackInfo& arg Connection* connection = ObjectWrap::Unwrap(args.This()); REQ_BOOL_ARG(0, autoCommit); connection->m_autoCommit = autoCommit; - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } uni::CallbackType Connection::SetPrefetchRowCount(const uni::FunctionCallbackInfo& args) { @@ -181,7 +181,7 @@ uni::CallbackType Connection::SetPrefetchRowCount(const uni::FunctionCallbackInf Connection* connection = ObjectWrap::Unwrap(args.This()); REQ_INT_ARG(0, prefetchRowCount); connection->m_prefetchRowCount = prefetchRowCount; - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } void Connection::closeConnection() { @@ -413,9 +413,9 @@ void Connection::EIO_AfterCommit(uv_work_t* req, int status) { baton->connection->Unref(); Handle argv[2]; - argv[0] = Undefined(); - argv[1] = Undefined(); - node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv); + argv[0] = NanUndefined(); + argv[1] = NanUndefined(); + NanMakeCallback(NanGetCurrentContext()->Global(), uni::Deref(baton->callback), 2, argv); delete baton; delete req; } @@ -433,9 +433,9 @@ void Connection::EIO_AfterRollback(uv_work_t* req, int status) { baton->connection->Unref(); Handle argv[2]; - argv[0] = Undefined(); - argv[1] = Undefined(); - node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv); + argv[0] = NanUndefined(); + argv[1] = NanUndefined(); + NanMakeCallback(NanGetCurrentContext()->Global(), uni::Deref(baton->callback), 2, argv); delete baton; delete req; } @@ -568,15 +568,15 @@ void Connection::EIO_Execute(uv_work_t* req) { void CallDateMethod(v8::Local date, const char* methodName, int val) { Handle args[1]; - args[0] = Number::New(val); - Local::Cast(date->Get(String::New(methodName)))->Call(date, 1, args); + args[0] = NanNew(val); + Local::Cast(date->Get(NanNew(methodName)))->Call(date, 1, args); } Local OracleDateToV8Date(oracle::occi::Date* d) { int year; unsigned int month, day, hour, min, sec; d->getDate(year, month, day, hour, min, sec); - Local date = uni::DateCast(Date::New(0.0)); + Local date = uni::DateCast(NanNew(0.0)); CallDateMethod(date, "setUTCMilliseconds", 0); CallDateMethod(date, "setUTCSeconds", sec); CallDateMethod(date, "setUTCMinutes", min); @@ -595,7 +595,7 @@ Local OracleTimestampToV8Date(oracle::occi::Timestamp* d) { //occi always returns nanoseconds, regardless of precision set on timestamp column ms = (fs / 1000000.0) + 0.5; // add 0.5 to round to nearest millisecond - Local date = uni::DateCast(Date::New(0.0)); + Local date = uni::DateCast(NanNew(0.0)); CallDateMethod(date, "setUTCMilliseconds", ms); CallDateMethod(date, "setUTCSeconds", sec); CallDateMethod(date, "setUTCMinutes", min); @@ -607,40 +607,40 @@ Local OracleTimestampToV8Date(oracle::occi::Timestamp* d) { } Local Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, vector columns, row_t* currentRow) { - Local obj = Object::New(); + Local obj = NanNew(); uint32_t colIndex = 0; for (vector::iterator iterator = columns.begin(), end = columns.end(); iterator != end; ++iterator, colIndex++) { column_t* col = *iterator; void* val = currentRow->values[colIndex]; if(val == NULL) { - obj->Set(String::New(col->name.c_str()), Null()); + obj->Set(NanNew(col->name.c_str()), NanNull()); } else { switch(col->type) { case VALUE_TYPE_STRING: { string* v = (string*)val; - obj->Set(String::New(col->name.c_str()), String::New(v->c_str())); + obj->Set(NanNew(col->name.c_str()), NanNew(v->c_str())); delete v; } break; case VALUE_TYPE_NUMBER: { oracle::occi::Number* v = (oracle::occi::Number*)val; - obj->Set(String::New(col->name.c_str()), Number::New((double)(*v))); + obj->Set(NanNew(col->name.c_str()), NanNew((double)(*v))); delete v; } break; case VALUE_TYPE_DATE: { oracle::occi::Date* v = (oracle::occi::Date*)val; - obj->Set(String::New(col->name.c_str()), OracleDateToV8Date(v)); + obj->Set(NanNew(col->name.c_str()), OracleDateToV8Date(v)); delete v; } break; case VALUE_TYPE_TIMESTAMP: { oracle::occi::Timestamp* v = (oracle::occi::Timestamp*)val; - obj->Set(String::New(col->name.c_str()), OracleTimestampToV8Date(v)); + obj->Set(NanNew(col->name.c_str()), OracleTimestampToV8Date(v)); delete v; } break; @@ -680,7 +680,7 @@ Local Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, vectorcloseStream(instream); v->close(); - obj->Set(String::New(col->name.c_str()), String::New(columnVal.c_str(), totalBytesRead)); + obj->Set(NanNew(col->name.c_str()), NanNew(columnVal.c_str(), totalBytesRead)); delete v; delete [] buffer; } @@ -699,11 +699,11 @@ Local Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, vector globalObj = v8::Context::GetCurrent()->Global(); - v8::Local bufferConstructor = v8::Local::Cast(globalObj->Get(v8::String::New("Buffer"))); - v8::Handle constructorArgs[3] = { uni::BufferToHandle(nodeBuff), v8::Integer::New(blobLength), v8::Integer::New(0) }; + v8::Local globalObj = NanGetCurrentContext()->Global(); + v8::Local bufferConstructor = v8::Local::Cast(globalObj->Get(NanNew("Buffer"))); + v8::Handle constructorArgs[3] = { uni::BufferToHandle(nodeBuff), NanNew(blobLength), NanNew(0) }; v8::Local v8Buffer = bufferConstructor->NewInstance(3, constructorArgs); - obj->Set(String::New(col->name.c_str()), v8Buffer); + obj->Set(NanNew(col->name.c_str()), v8Buffer); delete v; break; } @@ -721,7 +721,7 @@ Local Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, vector Connection::CreateV8ArrayFromRows(ExecuteBaton* baton, vector columns, vector* rows) { size_t totalRows = rows->size(); - Local retRows = Array::New(totalRows); + Local retRows = NanNew(totalRows); uint32_t index = 0; for (vector::iterator iterator = rows->begin(), end = rows->end(); iterator != end; ++iterator, index++) { row_t* currentRow = *iterator; @@ -741,12 +741,12 @@ void Connection::EIO_AfterExecute(uv_work_t* req, int status) { try { Handle argv[2]; handleResult(baton, argv); - node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv); + NanMakeCallback(NanGetCurrentContext()->Global(), uni::Deref(baton->callback), 2, argv); } catch(const exception &ex) { Handle argv[2]; - argv[0] = Exception::Error(String::New(ex.what())); - argv[1] = Undefined(); - node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv); + argv[0] = Exception::Error(NanNew(ex.what())); + argv[1] = NanUndefined(); + NanMakeCallback(NanGetCurrentContext()->Global(), uni::Deref(baton->callback), 2, argv); } delete baton; @@ -756,16 +756,16 @@ void Connection::EIO_AfterExecute(uv_work_t* req, int status) { void Connection::handleResult(ExecuteBaton* baton, Handle (&argv)[2]) { if(baton->error) { failed: - argv[0] = Exception::Error(String::New(baton->error->c_str())); - argv[1] = Undefined(); + argv[0] = Exception::Error(NanNew(baton->error->c_str())); + argv[1] = NanUndefined(); } else { - argv[0] = Undefined(); + argv[0] = NanUndefined(); if(baton->rows) { argv[1] = CreateV8ArrayFromRows(baton, baton->columns, baton->rows); if (baton->error) goto failed; // delete argv[1] ?? } else { - Local obj = Object::New(); - obj->Set(String::New("updateCount"), Integer::New(baton->updateCount)); + Local obj = NanNew(); + obj->Set(NanNew("updateCount"), NanNew(baton->updateCount)); /* Note: attempt to keep backward compatability here: existing users of this library will have code that expects a single out param called 'returnParam'. For multiple out params, the first output will continue to be called 'returnParam' and subsequent outputs @@ -780,19 +780,19 @@ void Connection::handleResult(ExecuteBaton* baton, Handle (&argv)[2]) { string returnParam(ss.str()); switch(output->type) { case OutParam::OCCIINT: - obj->Set(String::New(returnParam.c_str()), Integer::New(output->intVal)); + obj->Set(NanNew(returnParam.c_str()), NanNew(output->intVal)); break; case OutParam::OCCISTRING: - obj->Set(String::New(returnParam.c_str()), String::New(output->strVal.c_str())); + obj->Set(NanNew(returnParam.c_str()), NanNew(output->strVal.c_str())); break; case OutParam::OCCIDOUBLE: - obj->Set(String::New(returnParam.c_str()), Number::New(output->doubleVal)); + obj->Set(NanNew(returnParam.c_str()), NanNew(output->doubleVal)); break; case OutParam::OCCIFLOAT: - obj->Set(String::New(returnParam.c_str()), Number::New(output->floatVal)); + obj->Set(NanNew(returnParam.c_str()), NanNew(output->floatVal)); break; case OutParam::OCCICURSOR: - obj->Set(String::New(returnParam.c_str()), CreateV8ArrayFromRows(baton, output->columns, output->rows)); + obj->Set(NanNew(returnParam.c_str()), CreateV8ArrayFromRows(baton, output->columns, output->rows)); if (baton->error) goto failed; break; case OutParam::OCCICLOB: @@ -812,7 +812,7 @@ void Connection::handleResult(ExecuteBaton* baton, Handle (&argv)[2]) { } output->clobVal.closeStream(instream); output->clobVal.close(); - obj->Set(String::New(returnParam.c_str()), String::New(clobVal.c_str(), totalBytesRead)); + obj->Set(NanNew(returnParam.c_str()), NanNew(clobVal.c_str(), totalBytesRead)); delete [] buffer; break; } @@ -829,21 +829,21 @@ void Connection::handleResult(ExecuteBaton* baton, Handle (&argv)[2]) { // convert to V8 buffer uni::BufferType nodeBuff = node::Buffer::New(buffer, lobLength, RandomBytesFree, NULL); - v8::Local globalObj = v8::Context::GetCurrent()->Global(); - v8::Local bufferConstructor = v8::Local::Cast(globalObj->Get(v8::String::New("Buffer"))); - v8::Handle constructorArgs[3] = { uni::BufferToHandle(nodeBuff), v8::Integer::New(lobLength), v8::Integer::New(0) }; + v8::Local globalObj = NanGetCurrentContext()->Global(); + v8::Local bufferConstructor = v8::Local::Cast(globalObj->Get(NanNew("Buffer"))); + v8::Handle constructorArgs[3] = { uni::BufferToHandle(nodeBuff), NanNew(lobLength), NanNew(0) }; v8::Local v8Buffer = bufferConstructor->NewInstance(3, constructorArgs); - obj->Set(String::New(returnParam.c_str()), v8Buffer); + obj->Set(NanNew(returnParam.c_str()), v8Buffer); break; } case OutParam::OCCIDATE: - obj->Set(String::New(returnParam.c_str()), OracleDateToV8Date(&output->dateVal)); + obj->Set(NanNew(returnParam.c_str()), OracleDateToV8Date(&output->dateVal)); break; case OutParam::OCCITIMESTAMP: - obj->Set(String::New(returnParam.c_str()), OracleTimestampToV8Date(&output->timestampVal)); + obj->Set(NanNew(returnParam.c_str()), OracleTimestampToV8Date(&output->timestampVal)); break; case OutParam::OCCINUMBER: - obj->Set(String::New(returnParam.c_str()), Number::New(output->numberVal)); + obj->Set(NanNew(returnParam.c_str()), NanNew(output->numberVal)); break; default: { @@ -875,7 +875,7 @@ uni::CallbackType Connection::ExecuteSync(const uni::FunctionCallbackInfo& args) ExecuteBaton* baton = new ExecuteBaton(connection, *sqlVal, &values, NULL); if (baton->error) { - Local message = String::New(baton->error->c_str()); + Local message = NanNew(baton->error->c_str()); delete baton; UNI_THROW(Exception::Error(message)); } diff --git a/src/connection.h b/src/connection.h index b59d5be..d42a47e 100644 --- a/src/connection.h +++ b/src/connection.h @@ -26,7 +26,7 @@ namespace uni { typedef v8::FunctionCallbackInfo FunctionCallbackInfo; typedef v8::Local BufferType; # define UNI_RETURN(scope, args, res) { args.GetReturnValue().Set(res); return; } -# define UNI_THROW(ex) { ThrowException(ex); return; } +# define UNI_THROW(ex) { NanThrowError(ex); return; } # define UNI_SCOPE(scope) HandleScope scope(Isolate::GetCurrent()) template void Reset(Persistent& persistent, Handle handle) { @@ -34,7 +34,7 @@ namespace uni { } template Handle Deref(Persistent& handle) { - return Handle::New(Isolate::GetCurrent(), handle); + return Local::New(Isolate::GetCurrent(), handle); } template Local HandleToLocal(Handle handle) { @@ -51,7 +51,7 @@ namespace uni { typedef Arguments FunctionCallbackInfo; typedef node::Buffer* BufferType; # define UNI_RETURN(scope, args, res) return scope.Close(res) -# define UNI_THROW(ex) return ThrowException(ex) +# define UNI_THROW(ex) return NanThrowError(ex) # define UNI_SCOPE(scope) HandleScope scope template void Reset(Persistent& persistent, Handle handle) { diff --git a/src/executeBaton.cpp b/src/executeBaton.cpp index 558bd64..647e438 100644 --- a/src/executeBaton.cpp +++ b/src/executeBaton.cpp @@ -20,7 +20,7 @@ ExecuteBaton::ExecuteBaton(Connection* connection, const char* sql, v8::Local::iterator iterator = columns.begin(), end = columns.end(); iterator != end; ++iterator) { column_t* col = *iterator; @@ -97,7 +97,7 @@ void ExecuteBaton::ResetError() { double CallDateMethod(v8::Local date, const char* methodName) { Handle args[1]; // should be zero but on windows the compiler will not allow a zero length array - Local result = Local::Cast(date->Get(String::New(methodName)))->Call(date, 0, args); + Local result = Local::Cast(date->Get(NanNew(methodName)))->Call(date, 0, args); return Local::Cast(result)->Value(); } @@ -160,7 +160,7 @@ void ExecuteBaton::CopyValuesToBaton(ExecuteBaton* baton, v8::Local* } // output - else if(val->IsObject() && val->ToObject()->FindInstanceInPrototypeChain(uni::Deref(OutParam::constructorTemplate)) != v8::Null()) { + else if(val->IsObject() && val->ToObject()->FindInstanceInPrototypeChain(uni::Deref(OutParam::constructorTemplate)) != NanNull()) { OutParam* op = node::ObjectWrap::Unwrap(val->ToObject()); // [rfeng] The OutParam object will be destructed. We need to create a new copy. diff --git a/src/oracle_bindings.cpp b/src/oracle_bindings.cpp index e3aac8a..b152967 100644 --- a/src/oracle_bindings.cpp +++ b/src/oracle_bindings.cpp @@ -26,7 +26,7 @@ ConnectBaton::ConnectBaton(OracleClient* client, oracle::occi::Environment* envi } ConnectBaton::~ConnectBaton() { - callback.Dispose(); + NanDisposePersistent(callback); if(error) { delete error; } @@ -35,15 +35,15 @@ ConnectBaton::~ConnectBaton() { void OracleClient::Init(Handle target) { UNI_SCOPE(scope); - Local t = FunctionTemplate::New(New); + Local t = NanNew(New); uni::Reset(s_ct, t); uni::Deref(s_ct)->InstanceTemplate()->SetInternalFieldCount(1); - uni::Deref(s_ct)->SetClassName(String::NewSymbol("OracleClient")); + uni::Deref(s_ct)->SetClassName(NanNew("OracleClient")); NODE_SET_PROTOTYPE_METHOD(uni::Deref(s_ct), "connect", Connect); NODE_SET_PROTOTYPE_METHOD(uni::Deref(s_ct), "connectSync", ConnectSync); - target->Set(String::NewSymbol("OracleClient"), uni::Deref(s_ct)->GetFunction()); + target->Set(NanNew("OracleClient"), uni::Deref(s_ct)->GetFunction()); } uni::CallbackType OracleClient::New(const uni::FunctionCallbackInfo& args) { @@ -109,7 +109,7 @@ uni::CallbackType OracleClient::Connect(const uni::FunctionCallbackInfo& args) { req->data = baton; uv_queue_work(uv_default_loop(), req, EIO_Connect, (uv_after_work_cb)EIO_AfterConnect); - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } void OracleClient::EIO_Connect(uv_work_t* req) { @@ -140,16 +140,16 @@ void OracleClient::EIO_AfterConnect(uv_work_t* req, int status) { Handle argv[2]; if(baton->error) { - argv[0] = Exception::Error(String::New(baton->error->c_str())); - argv[1] = Undefined(); + argv[0] = Exception::Error(NanNew(baton->error->c_str())); + argv[1] = NanUndefined(); } else { - argv[0] = Undefined(); + argv[0] = NanUndefined(); Handle connection = uni::Deref(Connection::constructorTemplate)->GetFunction()->NewInstance(); (node::ObjectWrap::Unwrap(connection))->setConnection(baton->client->m_environment, baton->connection); argv[1] = connection; } - node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv); + NanMakeCallback(NanGetCurrentContext()->Global(), uni::Deref(baton->callback), 2, argv); delete baton; delete req; @@ -174,9 +174,9 @@ uni::CallbackType OracleClient::ConnectSync(const uni::FunctionCallbackInfo& arg baton.connection = baton.environment->createConnection(baton.user, baton.password, connectionStr.str()); } catch(oracle::occi::SQLException &ex) { baton.error = new std::string(ex.getMessage()); - UNI_THROW(Exception::Error(String::New(baton.error->c_str()))); + UNI_THROW(Exception::Error(NanNew(baton.error->c_str()))); } catch (const std::exception& ex) { - UNI_THROW(Exception::Error(String::New(ex.what()))); + UNI_THROW(Exception::Error(NanNew(ex.what()))); } Handle connection = uni::Deref(Connection::constructorTemplate)->GetFunction()->NewInstance(); diff --git a/src/outParam.cpp b/src/outParam.cpp index 69f98eb..fbfa4d0 100644 --- a/src/outParam.cpp +++ b/src/outParam.cpp @@ -15,11 +15,11 @@ Persistent OutParam::constructorTemplate; void OutParam::Init(Handle target) { UNI_SCOPE(scope); - Local t = FunctionTemplate::New(New); + Local t = NanNew(New); uni::Reset(constructorTemplate, t); uni::Deref(constructorTemplate)->InstanceTemplate()->SetInternalFieldCount(1); - uni::Deref(constructorTemplate)->SetClassName(String::NewSymbol("OutParam")); - target->Set(String::NewSymbol("OutParam"), uni::Deref(constructorTemplate)->GetFunction()); + uni::Deref(constructorTemplate)->SetClassName(NanNew("OutParam")); + target->Set(NanNew("OutParam"), uni::Deref(constructorTemplate)->GetFunction()); } uni::CallbackType OutParam::New(const uni::FunctionCallbackInfo& args) { @@ -37,7 +37,7 @@ uni::CallbackType OutParam::New(const uni::FunctionCallbackInfo& args) { OBJ_GET_NUMBER(opts, "size", outParam->_size, 200); // check if there's an 'in' param - if (opts->Has(String::New("in"))) { + if (opts->Has(NanNew("in"))) { outParam->_inOut.hasInParam = true; switch(outParam->_type) { case OutParam::OCCIINT: { @@ -61,7 +61,7 @@ uni::CallbackType OutParam::New(const uni::FunctionCallbackInfo& args) { break; } default: - UNI_THROW(Exception::Error(String::New("Unhandled OutPram type!"))); + UNI_THROW(Exception::Error(NanNew("Unhandled OutPram type!"))); } } } diff --git a/src/reader.cpp b/src/reader.cpp index 192aff0..3f99a32 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -10,13 +10,13 @@ Persistent Reader::constructorTemplate; void Reader::Init(Handle target) { UNI_SCOPE(scope); - Local t = FunctionTemplate::New(New); + Local t = NanNew(New); uni::Reset(constructorTemplate, t); uni::Deref(constructorTemplate)->InstanceTemplate()->SetInternalFieldCount(1); - uni::Deref(constructorTemplate)->SetClassName(String::NewSymbol("Reader")); + uni::Deref(constructorTemplate)->SetClassName(NanNew("Reader")); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "nextRows", NextRows); - target->Set(String::NewSymbol("Reader"), uni::Deref(constructorTemplate)->GetFunction()); + target->Set(NanNew("Reader"), uni::Deref(constructorTemplate)->GetFunction()); } Reader::Reader(): ObjectWrap() { @@ -45,11 +45,11 @@ uni::CallbackType Reader::NextRows(const uni::FunctionCallbackInfo& args) { Reader* reader = ObjectWrap::Unwrap(args.This()); ReaderBaton* baton = reader->m_baton; if (baton->error) { - Local message = String::New(baton->error->c_str()); + Local message = NanNew(baton->error->c_str()); UNI_THROW(Exception::Error(message)); } if (baton->busy) { - UNI_THROW(Exception::Error(String::New("invalid state: reader is busy with another nextRows call"))); + UNI_THROW(Exception::Error(NanNew("invalid state: reader is busy with another nextRows call"))); } baton->busy = true; @@ -70,7 +70,7 @@ uni::CallbackType Reader::NextRows(const uni::FunctionCallbackInfo& args) { uv_queue_work(uv_default_loop(), req, EIO_NextRows, (uv_after_work_cb)EIO_AfterNextRows); baton->connection->Ref(); - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } void Reader::EIO_NextRows(uv_work_t* req) { @@ -120,8 +120,8 @@ void Reader::EIO_AfterNextRows(uv_work_t* req, int status) { baton->connection->Unref(); // transfer callback to local and dispose persistent handle Local cb = uni::HandleToLocal(uni::Deref(baton->callback)); - baton->callback.Dispose(); - baton->callback.Clear(); + NanDisposePersistent(baton->callback); + // baton->callback.Clear(); Handle argv[2]; Connection::handleResult(baton, argv); @@ -135,6 +135,6 @@ void Reader::EIO_AfterNextRows(uv_work_t* req, int status) { delete req; // invoke callback at the very end because callback may re-enter nextRows. - node::MakeCallback(Context::GetCurrent()->Global(), cb, 2, argv); + NanMakeCallback(NanGetCurrentContext()->Global(), cb, 2, argv); } diff --git a/src/rollbackBaton.h b/src/rollbackBaton.h index 5e2349c..d5e8787 100644 --- a/src/rollbackBaton.h +++ b/src/rollbackBaton.h @@ -3,6 +3,7 @@ #define _rollback_baton_h_ #include "connection.h" +#include "nan.h" class RollbackBaton { public: @@ -11,7 +12,7 @@ class RollbackBaton { uni::Reset(this->callback, *callback); } ~RollbackBaton() { - callback.Dispose(); + NanDisposePersistent(callback); } Connection *connection; diff --git a/src/statement.cpp b/src/statement.cpp index 97f18b9..691c4f5 100644 --- a/src/statement.cpp +++ b/src/statement.cpp @@ -10,13 +10,13 @@ Persistent Statement::constructorTemplate; void Statement::Init(Handle target) { UNI_SCOPE(scope); - Local t = FunctionTemplate::New(New); + Local t = NanNew(New); uni::Reset(constructorTemplate, t); uni::Deref(constructorTemplate)->InstanceTemplate()->SetInternalFieldCount(1); - uni::Deref(constructorTemplate)->SetClassName(String::NewSymbol("Statement")); + uni::Deref(constructorTemplate)->SetClassName(NanNew("Statement")); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "execute", Execute); - target->Set(String::NewSymbol("Statement"), uni::Deref(constructorTemplate)->GetFunction()); + target->Set(NanNew("Statement"), uni::Deref(constructorTemplate)->GetFunction()); } Statement::Statement(): ObjectWrap() { @@ -51,12 +51,12 @@ uni::CallbackType Statement::Execute(const uni::FunctionCallbackInfo& args) { ExecuteBaton::CopyValuesToBaton(baton, &values); if (baton->error) { - Local message = String::New(baton->error->c_str()); + Local message = NanNew(baton->error->c_str()); UNI_THROW(Exception::Error(message)); } if (baton->busy) { - UNI_THROW(Exception::Error(String::New("invalid state: statement is busy with another execute call"))); + UNI_THROW(Exception::Error(NanNew("invalid state: statement is busy with another execute call"))); } baton->busy = true; @@ -65,7 +65,7 @@ uni::CallbackType Statement::Execute(const uni::FunctionCallbackInfo& args) { uv_queue_work(uv_default_loop(), req, EIO_Execute, (uv_after_work_cb)EIO_AfterExecute); baton->connection->Ref(); - UNI_RETURN(scope, args, Undefined()); + UNI_RETURN(scope, args, NanUndefined()); } void Statement::EIO_Execute(uv_work_t* req) { @@ -90,8 +90,8 @@ void Statement::EIO_AfterExecute(uv_work_t* req, int status) { baton->connection->Unref(); // transfer callback to local and dispose persistent handle Local cb = uni::HandleToLocal(uni::Deref(baton->callback)); - baton->callback.Dispose(); - baton->callback.Clear(); + NanDisposePersistent(baton->callback); + // baton->callback.Clear(); Handle argv[2]; Connection::handleResult(baton, argv); @@ -103,6 +103,6 @@ void Statement::EIO_AfterExecute(uv_work_t* req, int status) { delete req; // invoke callback at the very end because callback may re-enter execute. - node::MakeCallback(Context::GetCurrent()->Global(), cb, 2, argv); + NanMakeCallback(NanGetCurrentContext()->Global(), cb, 2, argv); } diff --git a/src/utils.h b/src/utils.h index c75bbcf..ad6751b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -6,40 +6,41 @@ #include #include #include +#include "nan.h" #define REQ_BOOL_ARG(I, VAR) \ if (args.Length() <= (I) || !args[I]->IsBoolean()) \ - UNI_THROW(Exception::TypeError(String::New("Argument " #I " must be a bool"))); \ + UNI_THROW(Exception::TypeError(NanNew("Argument " #I " must be a bool"))); \ bool VAR = args[I]->IsTrue(); #define REQ_INT_ARG(I, VAR) \ if (args.Length() <= (I) || !args[I]->IsNumber()) \ - UNI_THROW(Exception::TypeError(String::New("Argument " #I " must be an integer"))); \ + UNI_THROW(Exception::TypeError(NanNew("Argument " #I " must be an integer"))); \ int VAR = args[I]->NumberValue(); #define REQ_STRING_ARG(I, VAR) \ if (args.Length() <= (I) || !args[I]->IsString()) \ - UNI_THROW(Exception::TypeError(String::New("Argument " #I " must be a string"))); \ + UNI_THROW(Exception::TypeError(NanNew("Argument " #I " must be a string"))); \ Local VAR = Local::Cast(args[I]); #define REQ_ARRAY_ARG(I, VAR) \ if (args.Length() <= (I) || !args[I]->IsArray()) \ - UNI_THROW(Exception::TypeError(String::New("Argument " #I " must be an array"))); \ + UNI_THROW(Exception::TypeError(NanNew("Argument " #I " must be an array"))); \ Local VAR = Local::Cast(args[I]); #define REQ_FUN_ARG(I, VAR) \ if (args.Length() <= (I) || !args[I]->IsFunction()) \ - UNI_THROW(Exception::TypeError(String::New("Argument " #I " must be a function"))); \ + UNI_THROW(Exception::TypeError(NanNew("Argument " #I " must be a function"))); \ Local VAR = Local::Cast(args[I]); #define REQ_OBJECT_ARG(I, VAR) \ if (args.Length() <= (I) || !args[I]->IsObject()) \ - UNI_THROW(Exception::TypeError(String::New("Argument " #I " must be an object"))); \ + UNI_THROW(Exception::TypeError(NanNew("Argument " #I " must be an object"))); \ Local VAR = Local::Cast(args[I]); #define OBJ_GET_STRING(OBJ, KEY, VAR) \ { \ - Local __val = OBJ->Get(String::New(KEY)); \ + Local __val = OBJ->Get(NanNew(KEY)); \ if(__val->IsString()) { \ String::Utf8Value __utf8Val(__val); \ VAR = *__utf8Val; \ @@ -48,7 +49,7 @@ #define OBJ_GET_NUMBER(OBJ, KEY, VAR, DEFAULT) \ { \ - Local __val = OBJ->Get(String::New(KEY)); \ + Local __val = OBJ->Get(NanNew(KEY)); \ if(__val->IsNumber()) { \ VAR = __val->ToNumber()->Value(); \ } \ From 8b38c3b9e5fdc6aaab9b1971bb260823bcbc993c Mon Sep 17 00:00:00 2001 From: Eric Waldheim Date: Tue, 21 Oct 2014 14:02:12 -0600 Subject: [PATCH 2/2] remove commented out Clear calls handled by NanDisposePersistent --- src/reader.cpp | 1 - src/statement.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 3f99a32..d56433f 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -121,7 +121,6 @@ void Reader::EIO_AfterNextRows(uv_work_t* req, int status) { // transfer callback to local and dispose persistent handle Local cb = uni::HandleToLocal(uni::Deref(baton->callback)); NanDisposePersistent(baton->callback); - // baton->callback.Clear(); Handle argv[2]; Connection::handleResult(baton, argv); diff --git a/src/statement.cpp b/src/statement.cpp index 691c4f5..c292f5b 100644 --- a/src/statement.cpp +++ b/src/statement.cpp @@ -91,7 +91,6 @@ void Statement::EIO_AfterExecute(uv_work_t* req, int status) { // transfer callback to local and dispose persistent handle Local cb = uni::HandleToLocal(uni::Deref(baton->callback)); NanDisposePersistent(baton->callback); - // baton->callback.Clear(); Handle argv[2]; Connection::handleResult(baton, argv);