Skip to content

Commit 2fe2aaf

Browse files
committed
Merge pull request #116 from Sage/node-11
Node 11
2 parents 59cd72c + 498b3b0 commit 2fe2aaf

File tree

10 files changed

+177
-126
lines changed

10 files changed

+177
-126
lines changed

src/commitBaton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class CommitBaton {
88
public:
99
CommitBaton(Connection* connection, v8::Handle<v8::Function>* callback) {
1010
this->connection = connection;
11-
this->callback = Persistent<Function>::New(*callback);
11+
uni::Reset(this->callback, *callback);
1212
}
1313
~CommitBaton() {
1414
callback.Dispose();

src/connection.cpp

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "commitBaton.h"
55
#include "rollbackBaton.h"
66
#include "outParam.h"
7-
#include "node_buffer.h"
87
#include <vector>
98
#include <node_version.h>
109
#include <iostream>
@@ -13,31 +12,31 @@ using namespace std;
1312
Persistent<FunctionTemplate> Connection::constructorTemplate;
1413

1514
void Connection::Init(Handle<Object> target) {
16-
HandleScope scope;
15+
UNI_SCOPE(scope);
1716

1817
Local<FunctionTemplate> t = FunctionTemplate::New(New);
19-
constructorTemplate = Persistent<FunctionTemplate>::New(t);
20-
constructorTemplate->InstanceTemplate()->SetInternalFieldCount(1);
21-
constructorTemplate->SetClassName(String::NewSymbol("Connection"));
22-
23-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "execute", Execute);
24-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "executeSync", ExecuteSync);
25-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "close", Close);
26-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "isConnected", IsConnected);
27-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "setAutoCommit", SetAutoCommit);
28-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "setPrefetchRowCount", SetPrefetchRowCount);
29-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "commit", Commit);
30-
NODE_SET_PROTOTYPE_METHOD(constructorTemplate, "rollback", Rollback);
31-
32-
target->Set(String::NewSymbol("Connection"), constructorTemplate->GetFunction());
18+
uni::Reset(constructorTemplate, t);
19+
uni::Deref(constructorTemplate)->InstanceTemplate()->SetInternalFieldCount(1);
20+
uni::Deref(constructorTemplate)->SetClassName(String::NewSymbol("Connection"));
21+
22+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "execute", Execute);
23+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "executeSync", ExecuteSync);
24+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "close", Close);
25+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "isConnected", IsConnected);
26+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "setAutoCommit", SetAutoCommit);
27+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "setPrefetchRowCount", SetPrefetchRowCount);
28+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "commit", Commit);
29+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "rollback", Rollback);
30+
31+
target->Set(String::NewSymbol("Connection"), uni::Deref(constructorTemplate)->GetFunction());
3332
}
3433

35-
Handle<Value> Connection::New(const Arguments& args) {
36-
HandleScope scope;
34+
uni::CallbackType Connection::New(const uni::FunctionCallbackInfo& args) {
35+
UNI_SCOPE(scope);
3736

3837
Connection *connection = new Connection();
3938
connection->Wrap(args.This());
40-
return scope.Close(args.This());
39+
UNI_RETURN(scope, args, args.This());
4140
}
4241

4342
Connection::Connection():m_connection(NULL), m_environment(NULL), m_autoCommit(true), m_prefetchRowCount(0) {
@@ -47,8 +46,8 @@ Connection::~Connection() {
4746
closeConnection();
4847
}
4948

50-
Handle<Value> Connection::Execute(const Arguments& args) {
51-
HandleScope scope;
49+
uni::CallbackType Connection::Execute(const uni::FunctionCallbackInfo& args) {
50+
UNI_SCOPE(scope);
5251
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
5352

5453
REQ_STRING_ARG(0, sql);
@@ -61,7 +60,7 @@ Handle<Value> Connection::Execute(const Arguments& args) {
6160
if (baton->error) {
6261
Local<String> message = String::New(baton->error->c_str());
6362
delete baton;
64-
return scope.Close(ThrowException(Exception::Error(message)));
63+
UNI_THROW(Exception::Error(message));
6564
}
6665

6766
uv_work_t* req = new uv_work_t();
@@ -70,34 +69,34 @@ Handle<Value> Connection::Execute(const Arguments& args) {
7069

7170
connection->Ref();
7271

73-
return scope.Close(Undefined());
72+
UNI_RETURN(scope, args, Undefined());
7473
}
7574

76-
Handle<Value> Connection::Close(const Arguments& args) {
77-
HandleScope scope;
75+
uni::CallbackType Connection::Close(const uni::FunctionCallbackInfo& args) {
76+
UNI_SCOPE(scope);
7877
try {
7978
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
8079
connection->closeConnection();
8180

82-
return scope.Close(Undefined());
81+
UNI_RETURN(scope, args, Undefined());
8382
} catch (const exception& ex) {
84-
return scope.Close(ThrowException(Exception::Error(String::New(ex.what()))));
83+
UNI_THROW(Exception::Error(String::New(ex.what())));
8584
}
8685
}
8786

88-
Handle<Value> Connection::IsConnected(const Arguments& args) {
89-
HandleScope scope;
87+
uni::CallbackType Connection::IsConnected(const uni::FunctionCallbackInfo& args) {
88+
UNI_SCOPE(scope);
9089
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
9190

9291
if(connection && connection->m_connection) {
93-
return scope.Close(Boolean::New(true));
92+
UNI_RETURN(scope, args, Boolean::New(true));
9493
} else {
95-
return scope.Close(Boolean::New(false));
94+
UNI_RETURN(scope, args, Boolean::New(false));
9695
}
9796
}
9897

99-
Handle<Value> Connection::Commit(const Arguments& args) {
100-
HandleScope scope;
98+
uni::CallbackType Connection::Commit(const uni::FunctionCallbackInfo& args) {
99+
UNI_SCOPE(scope);
101100
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
102101

103102
REQ_FUN_ARG(0, callback);
@@ -110,11 +109,11 @@ Handle<Value> Connection::Commit(const Arguments& args) {
110109

111110
connection->Ref();
112111

113-
return scope.Close(Undefined());
112+
UNI_RETURN(scope, args, Undefined());
114113
}
115114

116-
Handle<Value> Connection::Rollback(const Arguments& args) {
117-
HandleScope scope;
115+
uni::CallbackType Connection::Rollback(const uni::FunctionCallbackInfo& args) {
116+
UNI_SCOPE(scope);
118117
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
119118

120119
REQ_FUN_ARG(0, callback);
@@ -127,23 +126,23 @@ Handle<Value> Connection::Rollback(const Arguments& args) {
127126

128127
connection->Ref();
129128

130-
return scope.Close(Undefined());
129+
UNI_RETURN(scope, args, Undefined());
131130
}
132131

133-
Handle<Value> Connection::SetAutoCommit(const Arguments& args) {
134-
HandleScope scope;
132+
uni::CallbackType Connection::SetAutoCommit(const uni::FunctionCallbackInfo& args) {
133+
UNI_SCOPE(scope);
135134
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
136135
REQ_BOOL_ARG(0, autoCommit);
137136
connection->m_autoCommit = autoCommit;
138-
return scope.Close(Undefined());
137+
UNI_RETURN(scope, args, Undefined());
139138
}
140139

141-
Handle<Value> Connection::SetPrefetchRowCount(const Arguments& args) {
142-
HandleScope scope;
140+
uni::CallbackType Connection::SetPrefetchRowCount(const uni::FunctionCallbackInfo& args) {
141+
UNI_SCOPE(scope);
143142
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
144143
REQ_INT_ARG(0, prefetchRowCount);
145144
connection->m_prefetchRowCount = prefetchRowCount;
146-
return scope.Close(Undefined());
145+
UNI_RETURN(scope, args, Undefined());
147146
}
148147

149148
void Connection::closeConnection() {
@@ -354,14 +353,14 @@ void Connection::EIO_Commit(uv_work_t* req) {
354353
}
355354

356355
void Connection::EIO_AfterCommit(uv_work_t* req, int status) {
357-
HandleScope scope;
356+
UNI_SCOPE(scope);
358357
CommitBaton* baton = static_cast<CommitBaton*>(req->data);
359358

360359
baton->connection->Unref();
361360

362361
Handle<Value> argv[2];
363362
argv[0] = Undefined();
364-
node::MakeCallback(Context::GetCurrent()->Global(), baton->callback, 2, argv);
363+
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv);
365364
delete baton;
366365

367366
}
@@ -373,14 +372,14 @@ void Connection::EIO_Rollback(uv_work_t* req) {
373372
}
374373

375374
void Connection::EIO_AfterRollback(uv_work_t* req, int status) {
376-
HandleScope scope;
375+
UNI_SCOPE(scope);
377376
RollbackBaton* baton = static_cast<RollbackBaton*>(req->data);
378377

379378
baton->connection->Unref();
380379

381380
Handle<Value> argv[2];
382381
argv[0] = Undefined();
383-
node::MakeCallback(Context::GetCurrent()->Global(), baton->callback, 2, argv);
382+
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv);
384383
delete baton;
385384

386385
}
@@ -502,7 +501,7 @@ Local<Date> OracleDateToV8Date(oracle::occi::Date* d) {
502501
int year;
503502
unsigned int month, day, hour, min, sec;
504503
d->getDate(year, month, day, hour, min, sec);
505-
Local<Date> date = Date::Cast(*Date::New(0.0));
504+
Local<Date> date = uni::DateCast(Date::New(0.0));
506505
CallDateMethod(date, "setUTCMilliseconds", 0);
507506
CallDateMethod(date, "setUTCSeconds", sec);
508507
CallDateMethod(date, "setUTCMinutes", min);
@@ -518,10 +517,10 @@ Local<Date> OracleTimestampToV8Date(oracle::occi::Timestamp* d) {
518517
unsigned int month, day, hour, min, sec, fs, ms;
519518
d->getDate(year, month, day);
520519
d->getTime(hour, min, sec, fs);
521-
Local<Date> date = Date::Cast(*Date::New(0.0));
522520
//occi always returns nanoseconds, regardless of precision set on timestamp column
523521
ms = (fs / 1000000.0) + 0.5; // add 0.5 to round to nearest millisecond
524522

523+
Local<Date> date = uni::DateCast(Date::New(0.0));
525524
CallDateMethod(date, "setUTCMilliseconds", ms);
526525
CallDateMethod(date, "setUTCSeconds", sec);
527526
CallDateMethod(date, "setUTCMinutes", min);
@@ -624,10 +623,10 @@ Local<Object> Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, vector<colu
624623
v->close();
625624

626625
// convert to V8 buffer
627-
node::Buffer *nodeBuff = node::Buffer::New(buffer, blobLength, RandomBytesFree, NULL);
626+
uni::BufferType nodeBuff = node::Buffer::New(buffer, blobLength, RandomBytesFree, NULL);
628627
v8::Local<v8::Object> globalObj = v8::Context::GetCurrent()->Global();
629628
v8::Local<v8::Function> bufferConstructor = v8::Local<v8::Function>::Cast(globalObj->Get(v8::String::New("Buffer")));
630-
v8::Handle<v8::Value> constructorArgs[3] = { nodeBuff->handle_, v8::Integer::New(blobLength), v8::Integer::New(0) };
629+
v8::Handle<v8::Value> constructorArgs[3] = { uni::BufferToHandle(nodeBuff), v8::Integer::New(blobLength), v8::Integer::New(0) };
631630
v8::Local<v8::Object> v8Buffer = bufferConstructor->NewInstance(3, constructorArgs);
632631
obj->Set(String::New(col->name.c_str()), v8Buffer);
633632
delete v;
@@ -661,19 +660,19 @@ Local<Array> Connection::CreateV8ArrayFromRows(ExecuteBaton* baton, vector<colum
661660

662661
void Connection::EIO_AfterExecute(uv_work_t* req, int status) {
663662

664-
HandleScope scope;
663+
UNI_SCOPE(scope);
665664
ExecuteBaton* baton = static_cast<ExecuteBaton*>(req->data);
666665

667666
baton->connection->Unref();
668667
try {
669668
Handle<Value> argv[2];
670669
handleResult(baton, argv);
671-
node::MakeCallback(Context::GetCurrent()->Global(), baton->callback, 2, argv);
670+
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv);
672671
} catch(const exception &ex) {
673672
Handle<Value> argv[2];
674673
argv[0] = Exception::Error(String::New(ex.what()));
675674
argv[1] = Undefined();
676-
node::MakeCallback(Context::GetCurrent()->Global(), baton->callback, 2, argv);
675+
node::MakeCallback(Context::GetCurrent()->Global(), uni::Deref(baton->callback), 2, argv);
677676
}
678677

679678
delete baton;
@@ -747,10 +746,10 @@ void Connection::handleResult(ExecuteBaton* baton, Handle<Value> (&argv)[2]) {
747746
output->blobVal.close();
748747

749748
// convert to V8 buffer
750-
node::Buffer *nodeBuff = node::Buffer::New(buffer, lobLength, RandomBytesFree, NULL);
749+
uni::BufferType nodeBuff = node::Buffer::New(buffer, lobLength, RandomBytesFree, NULL);
751750
v8::Local<v8::Object> globalObj = v8::Context::GetCurrent()->Global();
752751
v8::Local<v8::Function> bufferConstructor = v8::Local<v8::Function>::Cast(globalObj->Get(v8::String::New("Buffer")));
753-
v8::Handle<v8::Value> constructorArgs[3] = { nodeBuff->handle_, v8::Integer::New(lobLength), v8::Integer::New(0) };
752+
v8::Handle<v8::Value> constructorArgs[3] = { uni::BufferToHandle(nodeBuff), v8::Integer::New(lobLength), v8::Integer::New(0) };
754753
v8::Local<v8::Object> v8Buffer = bufferConstructor->NewInstance(3, constructorArgs);
755754
obj->Set(String::New(returnParam.c_str()), v8Buffer);
756755
delete [] buffer;
@@ -784,8 +783,8 @@ void Connection::setConnection(oracle::occi::Environment* environment, oracle::o
784783
m_connection = connection;
785784
}
786785

787-
Handle<Value> Connection::ExecuteSync(const Arguments& args) {
788-
HandleScope scope;
786+
uni::CallbackType Connection::ExecuteSync(const uni::FunctionCallbackInfo& args) {
787+
UNI_SCOPE(scope);
789788
Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
790789

791790
REQ_STRING_ARG(0, sql);
@@ -797,7 +796,7 @@ Handle<Value> Connection::ExecuteSync(const Arguments& args) {
797796
if (baton->error) {
798797
Local<String> message = String::New(baton->error->c_str());
799798
delete baton;
800-
return scope.Close(ThrowException(Exception::Error(message)));
799+
UNI_THROW(Exception::Error(message));
801800
}
802801

803802
uv_work_t* req = new uv_work_t();
@@ -811,9 +810,9 @@ Handle<Value> Connection::ExecuteSync(const Arguments& args) {
811810

812811
if(baton->error) {
813812
delete baton;
814-
return scope.Close(ThrowException(argv[0]));
813+
UNI_THROW(argv[0]);
815814
}
816815

817816
delete baton;
818-
return scope.Close(argv[1]);
817+
UNI_RETURN(scope, args, argv[1]);
819818
}

0 commit comments

Comments
 (0)