Skip to content

Commit

Permalink
Upgrade Nan to 2.3.2 to support node v6.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeferner committed May 1, 2016
1 parent 75969b8 commit 3e67132
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 44 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"url": "https://github.com/joeferner/node-java.git"
},
"dependencies": {
"async": "0.9.0",
"async": "1.5.2",
"find-java-home": "0.1.2",
"glob": "5.0.5",
"lodash": "3.7.0",
"nan": "2.0.9"
"glob": "7.0.3",
"lodash": "4.11.1",
"nan": "2.3.2"
},
"devDependencies": {
"chalk": "1.0.0",
Expand Down
35 changes: 26 additions & 9 deletions src/javaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@

v8::Local<v8::String> baseMethodName = Nan::New<v8::String>(methodNameStr.c_str()).ToLocalChecked();

v8::Local<v8::String> methodNameAsync = Nan::New<v8::String>((methodNameStr + java->AsyncSuffix()).c_str()).ToLocalChecked();
std::string methodNameAsyncStr = methodNameStr;
const char* methodNameAsync = methodNameAsyncStr.append(java->AsyncSuffix()).c_str();
v8::Local<v8::FunctionTemplate> methodCallTemplate = Nan::New<v8::FunctionTemplate>(methodCall, baseMethodName);
funcTemplate->PrototypeTemplate()->Set(methodNameAsync, methodCallTemplate->GetFunction());
Nan::SetPrototypeTemplate(funcTemplate, methodNameAsync, methodCallTemplate);

v8::Local<v8::String> methodNameSync = Nan::New<v8::String>((methodNameStr + java->SyncSuffix()).c_str()).ToLocalChecked();
std::string methodNameSyncStr = methodNameStr;
const char* methodNameSync = methodNameSyncStr.append(java->SyncSuffix()).c_str();
v8::Local<v8::FunctionTemplate> methodCallSyncTemplate = Nan::New<v8::FunctionTemplate>(methodCallSync, baseMethodName);
funcTemplate->PrototypeTemplate()->Set(methodNameSync, methodCallSyncTemplate->GetFunction());
Nan::SetPrototypeTemplate(funcTemplate, methodNameSync, methodCallSyncTemplate);

if (java->DoPromise()) {
v8::Local<v8::Object> recv = Nan::New<v8::Object>();
Expand All @@ -74,8 +76,10 @@
assert(result->IsFunction());
}
v8::Local<v8::Function> promFunction = result.As<v8::Function>();
v8::Local<v8::String> methodNamePromise = Nan::New<v8::String>((methodNameStr + java->PromiseSuffix()).c_str()).ToLocalChecked();
funcTemplate->PrototypeTemplate()->Set(methodNamePromise, promFunction);
v8::Local<v8::FunctionTemplate> promFunctionTemplate = Nan::New<v8::FunctionTemplate>(methodCallPromise, promFunction);
std::string methodNamePromiseStr = methodNameStr;
const char* methodNamePromise = methodNamePromiseStr.append(java->PromiseSuffix()).c_str();
Nan::SetPrototypeTemplate(funcTemplate, methodNamePromise, promFunctionTemplate);
}
}

Expand Down Expand Up @@ -202,6 +206,21 @@ NAN_METHOD(JavaObject::methodCallSync) {
info.GetReturnValue().Set(result);
}

NAN_METHOD(JavaObject::methodCallPromise) {
Nan::HandleScope scope;
v8::Local<v8::Function> fn = info.Data().As<v8::Function>();
v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[info.Length()];
for (int i = 0 ; i < info.Length(); i++) {
argv[i] = info[i];
}

v8::Local<v8::Value> result = fn->Call(info.This(), info.Length(), argv);

delete[] argv;

info.GetReturnValue().Set(result);
}

NAN_GETTER(JavaObject::fieldGetter) {
Nan::HandleScope scope;
JavaObject* self = Nan::ObjectWrap::Unwrap<JavaObject>(info.This());
Expand Down Expand Up @@ -317,9 +336,7 @@ NAN_INDEX_GETTER(JavaObject::indexGetter) {
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(Nan::New<v8::String>("NodeDynamicProxy").ToLocalChecked());

v8::Local<v8::String> methodName = Nan::New<v8::String>("unref").ToLocalChecked();
v8::Local<v8::FunctionTemplate> methodCallTemplate = Nan::New<v8::FunctionTemplate>(doUnref);
t->PrototypeTemplate()->Set(methodName, methodCallTemplate->GetFunction());
Nan::SetPrototypeTemplate(t, "unref", Nan::New<v8::FunctionTemplate>(doUnref));

v8::Local<v8::String> fieldName = Nan::New<v8::String>("invocationHandler").ToLocalChecked();
Nan::SetAccessor(t->InstanceTemplate(), fieldName, invocationHandlerGetter);
Expand Down
1 change: 1 addition & 0 deletions src/javaObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class JavaObject : public Nan::ObjectWrap {
private:
static NAN_METHOD(methodCall);
static NAN_METHOD(methodCallSync);
static NAN_METHOD(methodCallPromise);
static NAN_GETTER(fieldGetter);
static NAN_SETTER(fieldSetter);
static NAN_INDEX_GETTER(indexGetter);
Expand Down
9 changes: 4 additions & 5 deletions testAsyncOptions/testAllThreeSuffix.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ module.exports = {
test.ok(arrayList);
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));

var api = _.functions(arrayList);
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
test.ok(_.includes(api, 'addAsync'), 'Expected `addAsync` to be present, but it is NOT.');
test.ok(_.includes(api, 'addPromise'), 'Expected addPromise to be present, but it is NOT.');
test.ok(!_.includes(api, 'add'), 'Expected add to NOT be present, but it is.');
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to be present, but it is NOT.');
test.ok(_.isUndefined(arrayList.add), 'Expected `add` to NOT be present, but it is.');
test.done();
},

Expand Down
7 changes: 3 additions & 4 deletions testAsyncOptions/testAsyncSuffixSyncDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ module.exports = {
test.ok(arrayList);
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));

var api = _.functions(arrayList);
test.ok(_.includes(api, 'addAsync'), 'Expected `addAsync` to be present, but it is NOT.');
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
test.ok(!_.includes(api, 'addPromise'), 'Expected addPromise to NOT be present, but it is.');
test.ok(!_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
test.ok(_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to NOT be present, but it is.');
test.done();
},

Expand Down
7 changes: 3 additions & 4 deletions testAsyncOptions/testDefacto.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ module.exports = {
test.ok(arrayList);
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));

var api = _.functions(arrayList);
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
test.ok(!_.includes(api, 'addPromise'), 'Expected addPromise to NOT be present, but it is.');
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
test.ok(_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to NOT be present, but it is.');
test.done();
},

Expand Down
7 changes: 3 additions & 4 deletions testAsyncOptions/testDefactoPlusPromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ module.exports = {
test.ok(arrayList);
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));

var api = _.functions(arrayList);
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
test.ok(_.includes(api, 'addPromise'), 'Expected `addPromise` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to be present, but it is NOT.');
test.done();
},

Expand Down
7 changes: 3 additions & 4 deletions testAsyncOptions/testDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ module.exports = {
test.ok(arrayList);
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));

var api = _.functions(arrayList);
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
test.ok(!_.includes(api, 'addPromise'), 'Expected addPromise to NOT be present, but it is.');
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
test.ok(_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to NOT be present, but it is.');
test.done();
},

Expand Down
9 changes: 4 additions & 5 deletions testAsyncOptions/testNoAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ module.exports = {
test.ok(arrayList);
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));

var api = _.functions(arrayList);
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
test.ok(_.includes(api, 'addPromise'), 'Expected `addPromise` to be present, but it is NOT.');
test.ok(!_.includes(api, 'add'), 'Expected `add` to NOT be present, but it is.');
test.ok(!_.includes(api, 'addAsync'), 'Expected `addAsync` to NOT be present, but it is.');
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to be present, but it is NOT.');
test.ok(_.isUndefined(arrayList.add), 'Expected `add` to NOT be present, but it is.');
test.ok(_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to NOT be present, but it is.');
test.done();
},

Expand Down
9 changes: 4 additions & 5 deletions testAsyncOptions/testSyncDefaultPlusPromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ module.exports = {
test.ok(arrayList);
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));

var api = _.functions(arrayList);
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
test.ok(_.includes(api, 'addP'), 'Expected `addP` to be present, but it is NOT.');
test.ok(!_.includes(api, 'addSync'), 'Expected `addSync` to NOT be present, but it is.');
test.ok(!_.includes(api, 'addAsync'), 'Expected `addAsync` to NOT be present, but it is.');
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
test.ok(!_.isUndefined(arrayList.addP), 'Expected `addP` to be present, but it is NOT.');
test.ok(_.isUndefined(arrayList.addSync), 'Expected `addSync` to NOT be present, but it is.');
test.ok(_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to NOT be present, but it is.');
test.done();
},

Expand Down

0 comments on commit 3e67132

Please sign in to comment.