void Grid::EIO_AfterEncode(uv_work_t* req) { NanScope(); encode_grid_baton_t *closure = static_cast<encode_grid_baton_t *>(req->data); if (closure->error) { // There is no known ways to throw errors in the processing prior // so simply removing the following from coverage /* LCOV_EXCL_START */ Local<Value> argv[1] = { NanError(closure->error_name.c_str()) }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { // convert key order to proper javascript array Local<Array> keys_a = NanNew<Array>(closure->key_order.size()); std::vector<std::string>::iterator it; unsigned int i; for (it = closure->key_order.begin(), i = 0; it < closure->key_order.end(); ++it, ++i) { keys_a->Set(i, NanNew((*it).c_str())); } mapnik::grid const& grid_type = *closure->g->get(); // gather feature data Local<Object> feature_data = NanNew<Object>(); if (closure->add_features) { node_mapnik::write_features<mapnik::grid>(grid_type, feature_data, closure->key_order); } // Create the return hash. Local<Object> json = NanNew<Object>(); Local<Array> grid_array = NanNew<Array>(closure->lines.size()); unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(closure->resolution)); for (unsigned j=0;j<closure->lines.size();++j) { node_mapnik::grid_line_type const & line = closure->lines[j]; grid_array->Set(j, NanNew<String>(line.get(),array_size)); } json->Set(NanNew("grid"), grid_array); json->Set(NanNew("keys"), keys_a); json->Set(NanNew("data"), feature_data); Local<Value> argv[2] = { NanNull(), NanNew(json) }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); } closure->g->Unref(); NanDisposePersistent(closure->cb); delete closure; }
static void DNSSD_API OnServiceChanged(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char * serviceName, const char * serviceType, const char * replyDomain, void * context) { NanScope(); ServiceRef * serviceRef = static_cast<ServiceRef*>(context); Handle<Function> callback = serviceRef->GetCallback(); Handle<Object> this_ = serviceRef->GetThis(); const size_t argc(8); Local<Value> args[argc]; args[0] = NanObjectWrapHandle(serviceRef); args[1] = NanNew<Integer>(flags); args[2] = NanNew<Uint32>(interfaceIndex); args[3] = NanNew<Integer>(errorCode); args[4] = stringOrUndefined(serviceName); args[5] = stringOrUndefined(serviceType); args[6] = stringOrUndefined(replyDomain); if (serviceRef->GetContext().IsEmpty()) { args[7] = NanUndefined(); } else { args[7] = NanNew<Value>(serviceRef->GetContext()); } NanMakeCallback(this_, callback, argc, args); }
static void DNSSD_API OnServiceRegistered(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char * name, const char * serviceType, const char * domain, void * context) { if ( ! context) return; NanScope(); ServiceRef * serviceRef = static_cast<ServiceRef*>(context); Handle<Function> callback = serviceRef->GetCallback(); Handle<Object> this_ = serviceRef->GetThis(); if ( ! callback.IsEmpty() && ! this_.IsEmpty()) { const size_t argc(7); Local<Value> args[argc]; args[0] = NanObjectWrapHandle(serviceRef); args[1] = NanNew<Integer>(flags); args[2] = NanNew<Integer>(errorCode); args[3] = stringOrUndefined(name); args[4] = stringOrUndefined(serviceType); args[5] = stringOrUndefined(domain); if (serviceRef->GetContext().IsEmpty()) { args[6] = NanUndefined(); } else { args[6] = NanNew<Value>(serviceRef->GetContext()); } NanMakeCallback(this_, callback, argc, args); } }
void DNSSD_API OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char * fullname, const char * hosttarget, uint16_t port, uint16_t txtLen, const unsigned char * txtRecord, void * context) { NanScope(); ServiceRef * serviceRef = static_cast<ServiceRef*>(context); Handle<Function> callback = serviceRef->GetCallback(); Handle<Object> this_ = serviceRef->GetThis(); const size_t argc(9); Local<Value> args[argc]; args[0] = NanObjectWrapHandle(serviceRef); args[1] = NanNew<Integer>(flags); args[2] = NanNew<Uint32>(interfaceIndex); args[3] = NanNew<Integer>(errorCode); args[4] = stringOrUndefined(fullname); args[5] = stringOrUndefined(hosttarget); args[6] = NanNew<Integer>( ntohs(port) ); Local<Object> buffer = NanNewBufferHandle(txtLen); memcpy(Buffer::Data(buffer), txtRecord, txtLen); args[7] = buffer; if (serviceRef->GetContext().IsEmpty()) { args[8] = NanUndefined(); } else { args[8] = NanNew<Value>(serviceRef->GetContext()); } NanMakeCallback(this_, callback, argc, args); }
/* DESCRIPTION Callback function of Get Connection method PARAMETERS: UV queue work block NOTES: Connection handle is formed and handed over to JS. */ void Oracledb::Async_AfterGetConnection (uv_work_t *req) { NanScope(); connectionBaton *connBaton = (connectionBaton*)req->data; v8::TryCatch tc; Handle<Value> argv[2]; if( !(connBaton->error).empty() ) { argv[0] = v8::Exception::Error(NanNew<v8::String>( (connBaton->error).c_str() )); argv[1] = NanNull(); } else { argv[0] = NanUndefined(); Local<FunctionTemplate> lft = NanNew(Connection::connectionTemplate_s); Handle<Object> connection = lft->GetFunction()-> NewInstance(); (ObjectWrap::Unwrap<Connection> (connection))-> setConnection( connBaton->dpiconn, connBaton->oracledb ); argv[1] = connection; } Local<Function> callback = NanNew(connBaton->cb); delete connBaton; NanMakeCallback( NanGetCurrentContext()->Global(), callback, 2, argv ); if(tc.HasCaught()) node::FatalException(tc); }
void Grid::EIO_AfterClear(uv_work_t* req) { NanScope(); clear_grid_baton_t *closure = static_cast<clear_grid_baton_t *>(req->data); if (closure->error) { Local<Value> argv[1] = { NanError(closure->error_name.c_str()) }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); } else { Local<Value> argv[2] = { NanNull() }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); } closure->g->Unref(); NanDisposePersistent(closure->cb); delete closure; }
Local<Function> Cache::exitCallback() { NanEscapableScope(); Local<Function> unboundExitCallback(NanNew<FunctionTemplate>(Cache::Close)->GetFunction()); static const int argc = 1; Handle<Value> argv[argc] = { NanObjectWrapHandle(this) }; Local<Function> boundExitCallback( NanMakeCallback(unboundExitCallback, "bind", argc, argv).As<Function>()); return NanEscapeScope(boundExitCallback); }
void Grid::EIO_AfterClear(uv_work_t* req) { NanScope(); clear_grid_baton_t *closure = static_cast<clear_grid_baton_t *>(req->data); if (closure->error) { // There seems to be no possible way for the exception to be thrown in the previous // process and therefore not possible to have an error here so removing it from code // coverage /* LCOV_EXCL_START */ Local<Value> argv[1] = { NanError(closure->error_name.c_str()) }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { Local<Value> argv[2] = { NanNull(), NanObjectWrapHandle(closure->g) }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); } closure->g->Unref(); NanDisposePersistent(closure->cb); delete closure; }
void DNSSD_API OnEnumeration(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char * replyDomain, void * context) { Nan::HandleScope scope; ServiceRef * serviceRef = static_cast<ServiceRef*>(context); Handle<Function> callback = serviceRef->GetCallback(); Handle<Object> this_ = serviceRef->GetThis(); const size_t argc(6); Local<Value> args[argc]; args[0] = NanObjectWrapHandle(serviceRef); args[1] = NanNew<Integer>(flags); args[2] = NanNew<Uint32>(interfaceIndex); args[3] = NanNew<Integer>(errorCode); args[4] = stringOrUndefined(replyDomain); args[5] = NanNew<Value>(serviceRef->GetContext()); NanMakeCallback(this_, callback, argc, args); }
void NodeFileSource::processAdd(mbgl::Request *req) { NanScope(); // Make sure the loop stays alive as long as request is pending. if (pending.empty()) { queue->ref(); } auto handle = NanObjectWrapHandle(this); auto requestHandle = NanNew<v8::Object>(NodeRequest::Create(handle, req)); #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) const v8::UniquePersistent<v8::Object> requestPersistent(v8::Isolate::GetCurrent(), requestHandle); #else v8::Persistent<v8::Object> requestPersistent; NanAssignPersistent(requestPersistent, requestHandle); #endif pending.emplace(req, std::move(requestPersistent)); v8::Local<v8::Value> argv[] = { requestHandle }; NanMakeCallback(handle, NanNew("request"), 1, argv); }
void OracleClient::EIO_AfterConnect(uv_work_t* req, int status) { UNI_SCOPE(scope); ConnectBaton* baton = static_cast<ConnectBaton*>(req->data); baton->client->Unref(); Handle<Value> argv[2]; if(baton->error) { argv[0] = Exception::Error(NanNew<String>(baton->error->c_str())); argv[1] = NanUndefined(); } else { argv[0] = NanUndefined(); Handle<Object> connection = uni::Deref(Connection::constructorTemplate)->GetFunction()->NewInstance(); (node::ObjectWrap::Unwrap<Connection>(connection))->setConnection(baton->client->m_environment, baton->connection); argv[1] = connection; } NanMakeCallback(NanGetCurrentContext()->Global(), uni::Deref(baton->callback), 2, argv); delete baton; delete req; }
void NodeFileSource::processCancel(mbgl::Request *req) { NanScope(); auto it = pending.find(req); if (it == pending.end()) { // The response callback was already fired. There is no point in calling the cancelation // callback because the request is already completed. } else { #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) auto requestHandle = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), it->second); #else auto requestHandle = NanNew<v8::Object>(it->second); #endif // Dispose and remove the persistent handle #if (NODE_MODULE_VERSION <= NODE_0_10_MODULE_VERSION) NanDisposePersistent(it->second); #endif pending.erase(it); // Make sure the the loop can exit when there are no pending requests. if (pending.empty()) { queue->unref(); } auto handle = NanObjectWrapHandle(this); if (handle->Has(NanNew("cancel"))) { v8::Local<v8::Value> argv[] = { requestHandle }; NanMakeCallback(handle, NanNew("cancel"), 1, argv); } // Set the request handle in the request wrapper handle to null ObjectWrap::Unwrap<NodeRequest>(requestHandle)->cancel(); } // Finally, destruct the request object req->destruct(); }
void NodeFileSource::processAdd(const mbgl::Resource& resource) { NanScope(); // Make sure the loop stays alive as long as request is pending. if (pending.empty()) { queue->ref(); } auto requestHandle = NanNew<v8::Object>(NodeRequest::Create(this, resource)); v8::Persistent<v8::Object> requestPersistent; NanAssignPersistent(requestPersistent, requestHandle); pending.emplace(resource, std::move(requestPersistent)); #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) auto requestFunction = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), options)->Get(NanNew("request")).As<v8::Function>(); #else auto requestFunction = options->Get(NanNew("request")).As<v8::Function>(); #endif v8::Local<v8::Value> argv[] = { requestHandle }; NanMakeCallback(NanGetCurrentContext()->Global(), requestFunction, 1, argv); }
/* DESCRIPTION Worker Function of CreatePool. PARAMETERS: UV queue work block NOTES: Pool handle is created and handed over to JS. */ void Oracledb::Async_AfterCreatePool (uv_work_t *req) { NanScope() ; connectionBaton *poolBaton = (connectionBaton *)req->data; v8::TryCatch tc; Handle<Value> argv[2]; if (!poolBaton->error.empty()) { argv[0] = v8::Exception::Error(NanNew<v8::String>(( poolBaton->error).c_str() )); argv[1] = NanUndefined(); } else { argv[0] = NanUndefined (); Handle<Object> njsPool = NanNew(Pool::poolTemplate_s)-> GetFunction() ->NewInstance(); (ObjectWrap::Unwrap<Pool> (njsPool))-> setPool ( poolBaton->dpipool, poolBaton->oracledb, poolBaton->poolMax, poolBaton->poolMin, poolBaton->poolIncrement, poolBaton->poolTimeout, poolBaton->stmtCacheSize, poolBaton->lobPrefetchSize); argv[1] = njsPool; } Local<Function> callback = NanNew(poolBaton->cb); delete poolBaton; NanMakeCallback ( NanGetCurrentContext()->Global(), callback, 2, argv); if(tc.HasCaught()) { node::FatalException (tc); } }
static NAUV_WORK_CB(EmitMessage) { NanScope(); NodeMidiInput *input = static_cast<NodeMidiInput*>(async->data); uv_mutex_lock(&input->message_mutex); v8::Local<v8::Function> emitFunction = NanObjectWrapHandle(input)->Get(NanNew<v8::String>(symbol_emit)).As<v8::Function>(); while (!input->message_queue.empty()) { MidiMessage* message = input->message_queue.front(); v8::Local<v8::Value> args[3]; args[0] = NanNew<v8::String>(symbol_message); args[1] = NanNew<v8::Number>(message->deltaTime); int32_t count = (int32_t)message->message.size(); v8::Local<v8::Array> data = NanNew<v8::Array>(count); for (int32_t i = 0; i < count; ++i) { data->Set(NanNew<v8::Number>(i), NanNew<v8::Integer>(message->message[i])); } args[2] = data; NanMakeCallback(NanObjectWrapHandle(input), emitFunction, 3, args); input->message_queue.pop(); delete message; } uv_mutex_unlock(&input->message_mutex); }
void NodeFileSource::processCancel(const mbgl::Resource& resource) { NanScope(); auto it = pending.find(resource); if (it == pending.end()) { // The response callback was already fired. There is no point in calling the cancelation // callback because the request is already completed. } else { #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) auto requestHandle = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), it->second); it->second.Reset(); #else auto requestHandle = NanNew<v8::Object>(it->second); NanDisposePersistent(it->second); #endif pending.erase(it); // Make sure the the loop can exit when there are no pending requests. if (pending.empty()) { queue->unref(); } #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) auto optionsObject = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), options); if (optionsObject->Has(NanNew("cancel"))) { auto cancelFunction = optionsObject->Get(NanNew("cancel")).As<v8::Function>(); #else if (options->Has(NanNew("cancel"))) { auto cancelFunction = options->Get(NanNew("cancel")).As<v8::Function>(); #endif v8::Local<v8::Value> argv[] = { requestHandle }; NanMakeCallback(NanGetCurrentContext()->Global(), cancelFunction, 1, argv); } // Set the request handle in the request wrapper handle to null node::ObjectWrap::Unwrap<NodeRequest>(requestHandle)->cancel(); } } void NodeFileSource::notify(const mbgl::Resource& resource, const std::shared_ptr<const mbgl::Response>& response) { // First, remove the request, since it might be destructed at any point now. auto it = pending.find(resource); if (it != pending.end()) { #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) it->second.Reset(); #else NanDisposePersistent(it->second); #endif pending.erase(it); // Make sure the the loop can exit when there are no pending requests. if (pending.empty()) { queue->unref(); } } std::lock_guard<std::mutex> lock(observersMutex); auto observersIt = observers.find(resource); if (observersIt == observers.end()) { return; } observersIt->second->notify(response); observers.erase(observersIt); }