Skip to content

Commit 3e67132

Browse files
committed
Upgrade Nan to 2.3.2 to support node v6.
1 parent 75969b8 commit 3e67132

10 files changed

Lines changed: 55 additions & 44 deletions

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"url": "https://github.com/joeferner/node-java.git"
2727
},
2828
"dependencies": {
29-
"async": "0.9.0",
29+
"async": "1.5.2",
3030
"find-java-home": "0.1.2",
31-
"glob": "5.0.5",
32-
"lodash": "3.7.0",
33-
"nan": "2.0.9"
31+
"glob": "7.0.3",
32+
"lodash": "4.11.1",
33+
"nan": "2.3.2"
3434
},
3535
"devDependencies": {
3636
"chalk": "1.0.0",

src/javaObject.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@
5757

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

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

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

6870
if (java->DoPromise()) {
6971
v8::Local<v8::Object> recv = Nan::New<v8::Object>();
@@ -74,8 +76,10 @@
7476
assert(result->IsFunction());
7577
}
7678
v8::Local<v8::Function> promFunction = result.As<v8::Function>();
77-
v8::Local<v8::String> methodNamePromise = Nan::New<v8::String>((methodNameStr + java->PromiseSuffix()).c_str()).ToLocalChecked();
78-
funcTemplate->PrototypeTemplate()->Set(methodNamePromise, promFunction);
79+
v8::Local<v8::FunctionTemplate> promFunctionTemplate = Nan::New<v8::FunctionTemplate>(methodCallPromise, promFunction);
80+
std::string methodNamePromiseStr = methodNameStr;
81+
const char* methodNamePromise = methodNamePromiseStr.append(java->PromiseSuffix()).c_str();
82+
Nan::SetPrototypeTemplate(funcTemplate, methodNamePromise, promFunctionTemplate);
7983
}
8084
}
8185

@@ -202,6 +206,21 @@ NAN_METHOD(JavaObject::methodCallSync) {
202206
info.GetReturnValue().Set(result);
203207
}
204208

209+
NAN_METHOD(JavaObject::methodCallPromise) {
210+
Nan::HandleScope scope;
211+
v8::Local<v8::Function> fn = info.Data().As<v8::Function>();
212+
v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[info.Length()];
213+
for (int i = 0 ; i < info.Length(); i++) {
214+
argv[i] = info[i];
215+
}
216+
217+
v8::Local<v8::Value> result = fn->Call(info.This(), info.Length(), argv);
218+
219+
delete[] argv;
220+
221+
info.GetReturnValue().Set(result);
222+
}
223+
205224
NAN_GETTER(JavaObject::fieldGetter) {
206225
Nan::HandleScope scope;
207226
JavaObject* self = Nan::ObjectWrap::Unwrap<JavaObject>(info.This());
@@ -317,9 +336,7 @@ NAN_INDEX_GETTER(JavaObject::indexGetter) {
317336
t->InstanceTemplate()->SetInternalFieldCount(1);
318337
t->SetClassName(Nan::New<v8::String>("NodeDynamicProxy").ToLocalChecked());
319338

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

324341
v8::Local<v8::String> fieldName = Nan::New<v8::String>("invocationHandler").ToLocalChecked();
325342
Nan::SetAccessor(t->InstanceTemplate(), fieldName, invocationHandlerGetter);

src/javaObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class JavaObject : public Nan::ObjectWrap {
3030
private:
3131
static NAN_METHOD(methodCall);
3232
static NAN_METHOD(methodCallSync);
33+
static NAN_METHOD(methodCallPromise);
3334
static NAN_GETTER(fieldGetter);
3435
static NAN_SETTER(fieldSetter);
3536
static NAN_INDEX_GETTER(indexGetter);

testAsyncOptions/testAllThreeSuffix.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ module.exports = {
2020
test.ok(arrayList);
2121
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));
2222

23-
var api = _.functions(arrayList);
24-
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
25-
test.ok(_.includes(api, 'addAsync'), 'Expected `addAsync` to be present, but it is NOT.');
26-
test.ok(_.includes(api, 'addPromise'), 'Expected addPromise to be present, but it is NOT.');
27-
test.ok(!_.includes(api, 'add'), 'Expected add to NOT be present, but it is.');
23+
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
24+
test.ok(!_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to be present, but it is NOT.');
25+
test.ok(!_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to be present, but it is NOT.');
26+
test.ok(_.isUndefined(arrayList.add), 'Expected `add` to NOT be present, but it is.');
2827
test.done();
2928
},
3029

testAsyncOptions/testAsyncSuffixSyncDefault.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ module.exports = {
4141
test.ok(arrayList);
4242
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));
4343

44-
var api = _.functions(arrayList);
45-
test.ok(_.includes(api, 'addAsync'), 'Expected `addAsync` to be present, but it is NOT.');
46-
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
47-
test.ok(!_.includes(api, 'addPromise'), 'Expected addPromise to NOT be present, but it is.');
44+
test.ok(!_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to be present, but it is NOT.');
45+
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
46+
test.ok(_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to NOT be present, but it is.');
4847
test.done();
4948
},
5049

testAsyncOptions/testDefacto.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ module.exports = {
4949
test.ok(arrayList);
5050
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));
5151

52-
var api = _.functions(arrayList);
53-
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
54-
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
55-
test.ok(!_.includes(api, 'addPromise'), 'Expected addPromise to NOT be present, but it is.');
52+
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
53+
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
54+
test.ok(_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to NOT be present, but it is.');
5655
test.done();
5756
},
5857

testAsyncOptions/testDefactoPlusPromise.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ module.exports = {
4646
test.ok(arrayList);
4747
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));
4848

49-
var api = _.functions(arrayList);
50-
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
51-
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
52-
test.ok(_.includes(api, 'addPromise'), 'Expected `addPromise` to be present, but it is NOT.');
49+
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
50+
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
51+
test.ok(!_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to be present, but it is NOT.');
5352
test.done();
5453
},
5554

testAsyncOptions/testDefault.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ module.exports = {
1616
test.ok(arrayList);
1717
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));
1818

19-
var api = _.functions(arrayList);
20-
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
21-
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
22-
test.ok(!_.includes(api, 'addPromise'), 'Expected addPromise to NOT be present, but it is.');
19+
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
20+
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
21+
test.ok(_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to NOT be present, but it is.');
2322
test.done();
2423
},
2524

testAsyncOptions/testNoAsync.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ module.exports = {
5252
test.ok(arrayList);
5353
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));
5454

55-
var api = _.functions(arrayList);
56-
test.ok(_.includes(api, 'addSync'), 'Expected `addSync` to be present, but it is NOT.');
57-
test.ok(_.includes(api, 'addPromise'), 'Expected `addPromise` to be present, but it is NOT.');
58-
test.ok(!_.includes(api, 'add'), 'Expected `add` to NOT be present, but it is.');
59-
test.ok(!_.includes(api, 'addAsync'), 'Expected `addAsync` to NOT be present, but it is.');
55+
test.ok(!_.isUndefined(arrayList.addSync), 'Expected `addSync` to be present, but it is NOT.');
56+
test.ok(!_.isUndefined(arrayList.addPromise), 'Expected `addPromise` to be present, but it is NOT.');
57+
test.ok(_.isUndefined(arrayList.add), 'Expected `add` to NOT be present, but it is.');
58+
test.ok(_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to NOT be present, but it is.');
6059
test.done();
6160
},
6261

testAsyncOptions/testSyncDefaultPlusPromise.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ module.exports = {
2020
test.ok(arrayList);
2121
test.ok(java.instanceOf(arrayList, "java.util.ArrayList"));
2222

23-
var api = _.functions(arrayList);
24-
test.ok(_.includes(api, 'add'), 'Expected `add` to be present, but it is NOT.');
25-
test.ok(_.includes(api, 'addP'), 'Expected `addP` to be present, but it is NOT.');
26-
test.ok(!_.includes(api, 'addSync'), 'Expected `addSync` to NOT be present, but it is.');
27-
test.ok(!_.includes(api, 'addAsync'), 'Expected `addAsync` to NOT be present, but it is.');
23+
test.ok(!_.isUndefined(arrayList.add), 'Expected `add` to be present, but it is NOT.');
24+
test.ok(!_.isUndefined(arrayList.addP), 'Expected `addP` to be present, but it is NOT.');
25+
test.ok(_.isUndefined(arrayList.addSync), 'Expected `addSync` to NOT be present, but it is.');
26+
test.ok(_.isUndefined(arrayList.addAsync), 'Expected `addAsync` to NOT be present, but it is.');
2827
test.done();
2928
},
3029

0 commit comments

Comments
 (0)