|
57 | 57 |
|
58 | 58 | v8::Local<v8::String> baseMethodName = Nan::New<v8::String>(methodNameStr.c_str()).ToLocalChecked(); |
59 | 59 |
|
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(); |
61 | 62 | v8::Local<v8::FunctionTemplate> methodCallTemplate = Nan::New<v8::FunctionTemplate>(methodCall, baseMethodName); |
62 | | - funcTemplate->PrototypeTemplate()->Set(methodNameAsync, methodCallTemplate->GetFunction()); |
| 63 | + Nan::SetPrototypeTemplate(funcTemplate, methodNameAsync, methodCallTemplate); |
63 | 64 |
|
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(); |
65 | 67 | v8::Local<v8::FunctionTemplate> methodCallSyncTemplate = Nan::New<v8::FunctionTemplate>(methodCallSync, baseMethodName); |
66 | | - funcTemplate->PrototypeTemplate()->Set(methodNameSync, methodCallSyncTemplate->GetFunction()); |
| 68 | + Nan::SetPrototypeTemplate(funcTemplate, methodNameSync, methodCallSyncTemplate); |
67 | 69 |
|
68 | 70 | if (java->DoPromise()) { |
69 | 71 | v8::Local<v8::Object> recv = Nan::New<v8::Object>(); |
|
74 | 76 | assert(result->IsFunction()); |
75 | 77 | } |
76 | 78 | 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); |
79 | 83 | } |
80 | 84 | } |
81 | 85 |
|
@@ -202,6 +206,21 @@ NAN_METHOD(JavaObject::methodCallSync) { |
202 | 206 | info.GetReturnValue().Set(result); |
203 | 207 | } |
204 | 208 |
|
| 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 | + |
205 | 224 | NAN_GETTER(JavaObject::fieldGetter) { |
206 | 225 | Nan::HandleScope scope; |
207 | 226 | JavaObject* self = Nan::ObjectWrap::Unwrap<JavaObject>(info.This()); |
@@ -317,9 +336,7 @@ NAN_INDEX_GETTER(JavaObject::indexGetter) { |
317 | 336 | t->InstanceTemplate()->SetInternalFieldCount(1); |
318 | 337 | t->SetClassName(Nan::New<v8::String>("NodeDynamicProxy").ToLocalChecked()); |
319 | 338 |
|
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)); |
323 | 340 |
|
324 | 341 | v8::Local<v8::String> fieldName = Nan::New<v8::String>("invocationHandler").ToLocalChecked(); |
325 | 342 | Nan::SetAccessor(t->InstanceTemplate(), fieldName, invocationHandlerGetter); |
|
0 commit comments