示例#1
0
        static EOS_OPERATION_CONSTRUCTOR(New, Statement) {
            EOS_DEBUG_METHOD();

            if (args.Length() < 6)
                return NanError("Too few arguments");

            auto columnNumber = args[1]->Int32Value();
            auto sqlType = args[2]->Int32Value();

            if (!args[1]->IsUint32() || columnNumber > USHRT_MAX)
                return NanError("Column number must be an integer from 0 to 65535");

            if (!args[2]->IsInt32() || sqlType < SHRT_MIN || sqlType > SHRT_MAX)
                return NanError("Target type is out of range");

            Handle<Object> bufferHandle;
            SQLPOINTER buffer;
            SQLLEN bufferLength;
            bool raw;
            bool ownBuffer;

#if !defined(NODE_12)
            if (args[3]->IsObject() && args[3].As<Object>()->GetConstructor()->Equals(JSBuffer::Constructor())) {
                bufferHandle = args[3].As<Object>();
                
                auto msg = JSBuffer::Unwrap(bufferHandle, buffer, bufferLength);
                if (msg)
                    return NanError(msg);
            } else 
#endif
            if (args[3]->IsObject() && Buffer::HasInstance(args[3])) {
                buffer = Buffer::Data(args[3]);
                bufferLength = Buffer::Length(args[3]);
                ownBuffer = false;
            } else {
                if (!args[3]->IsUndefined() && !args[3]->IsNull())
                    return NanError("Unknown buffer type (pass null to have a buffer created automatically)");

                // The operation can choose to allocate a buffer if it decides it necessary
                // based on targetType.
                buffer = nullptr;
                bufferLength = 0;
            }
            
            raw = args[4]->BooleanValue();

            (new GetDataOperation(
                columnNumber, 
                sqlType, 
                buffer, bufferLength, bufferHandle,
                raw))->Wrap(args.Holder());

            EOS_OPERATION_CONSTRUCTOR_RETURN();
        }
void EIO_AfterWatchPort(uv_work_t* req) {
  NanScope();

  WatchPortBaton* data = static_cast<WatchPortBaton*>(req->data);
  if(data->disconnected) {
    data->disconnectedCallback->Call(0, NULL);
    DisposeWatchPortCallbacks(data);
    goto cleanup;
  }

  if(data->bytesRead > 0) {
    v8::Handle<v8::Value> argv[1];
    argv[0] = NanNewBufferHandle(data->buffer, data->bytesRead);
    data->dataCallback->Call(1, argv);
  } else if(data->errorCode > 0) {
    if(data->errorCode == ERROR_INVALID_HANDLE && IsClosingHandle((int)data->fd)) {
      DisposeWatchPortCallbacks(data);
      goto cleanup;
    } else {
      v8::Handle<v8::Value> argv[1];
      argv[0] = NanError(data->errorString);
      data->errorCallback->Call(1, argv);
      Sleep(100); // prevent the errors from occurring too fast
    }
  }
  AfterOpenSuccess((int)data->fd, data->dataCallback, data->disconnectedCallback, data->errorCallback);

cleanup:
  delete data;
  delete req;
}
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;
}
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;
}
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;
}