当前位置: 首页>>代码示例>>C++>>正文


C++ NanScope函数代码示例

本文整理汇总了C++中NanScope函数的典型用法代码示例。如果您正苦于以下问题:C++ NanScope函数的具体用法?C++ NanScope怎么用?C++ NanScope使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NanScope函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EIO_AfterClose

void EIO_AfterClose(uv_work_t* req) {
  NanScope();

  CloseBaton* data = static_cast<CloseBaton*>(req->data);

  v8::Handle<v8::Value> argv[1];
  if(data->errorString[0]) {
    argv[0] = v8::Exception::Error(NanNew<v8::String>(data->errorString));
  } else {
    argv[0] = NanUndefined();

    // We don't have an error, so clean up the write queue for that fd

    _WriteQueue *q = qForFD(data->fd);
    if (q) {
      q->lock();
      QueuedWrite &write_queue = q->get();
      while (!write_queue.empty()) {
        QueuedWrite *del_q = write_queue.next;
        NanDisposePersistent(del_q->baton->buffer);
        del_q->remove();
      }
      q->unlock();

      deleteQForFD(data->fd);
    }

  }
  data->callback->Call(1, argv);

  delete data->callback;
  delete data;
  delete req;
}
开发者ID:AJRdev,项目名称:myo_sphero,代码行数:34,代码来源:serialport.cpp

示例2: OnResolve

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);
}
开发者ID:KxT-cs,项目名称:node_mdns,代码行数:32,代码来源:dns_service_resolve.cpp

示例3: NanScope

Image *Image::New(FIBITMAP* dib) {
  NanScope();

  Local<Value> arg = NanNew<Integer>(0);
  Local<Object> obj = NanNew<FunctionTemplate>(constructor_template)->GetFunction()->NewInstance(1, &arg);

  Image *image = ObjectWrap::Unwrap<Image>(obj);

  int w,h,pitch;
  FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib);

  obj->SetInternalField(0, NanNew<External>(dib));
  obj->Set(NanNew<String>("width"), NanNew<Integer>(w=FreeImage_GetWidth(dib)));
  obj->Set(NanNew<String>("height"), NanNew<Integer>(h=FreeImage_GetHeight(dib)));
  obj->Set(NanNew<String>("bpp"), NanNew<Integer>((int)FreeImage_GetBPP(dib)));
  obj->Set(NanNew<String>("pitch"), NanNew<Integer>(pitch=FreeImage_GetPitch(dib)));
  obj->Set(NanNew<String>("type"), NanNew<Integer>(type));
  obj->Set(NanNew<String>("redMask"), NanNew<Integer>((int)FreeImage_GetRedMask(dib)));
  obj->Set(NanNew<String>("greenMask"), NanNew<Integer>((int)FreeImage_GetGreenMask(dib)));
  obj->Set(NanNew<String>("blueMask"), NanNew<Integer>((int)FreeImage_GetBlueMask(dib)));

  BYTE *bits = FreeImage_GetBits(dib);
  obj->Set(NanNew<String>("buffer"), NanNewBufferHandle((char*) bits, h * pitch));

  return image;
}
开发者ID:luismreis,项目名称:node-image,代码行数:26,代码来源:Image.cpp

示例4: EIO_AfterList

void EIO_AfterList(uv_work_t* req) {
  NanScope();

  ListBaton* data = static_cast<ListBaton*>(req->data);

  v8::Handle<v8::Value> argv[2];
  if(data->errorString[0]) {
    argv[0] = v8::Exception::Error(v8::String::New(data->errorString));
    argv[1] = v8::Undefined();
  } else {
    v8::Local<v8::Array> results = v8::Array::New();
    int i = 0;
    for(std::list<ListResultItem*>::iterator it = data->results.begin(); it != data->results.end(); ++it, i++) {
      v8::Local<v8::Object> item = v8::Object::New();
      item->Set(v8::String::New("comName"), v8::String::New((*it)->comName.c_str()));
      item->Set(v8::String::New("manufacturer"), v8::String::New((*it)->manufacturer.c_str()));
      item->Set(v8::String::New("serialNumber"), v8::String::New((*it)->serialNumber.c_str()));
      item->Set(v8::String::New("pnpId"), v8::String::New((*it)->pnpId.c_str()));
      item->Set(v8::String::New("locationId"), v8::String::New((*it)->locationId.c_str()));
      item->Set(v8::String::New("vendorId"), v8::String::New((*it)->vendorId.c_str()));
      item->Set(v8::String::New("productId"), v8::String::New((*it)->productId.c_str()));
      results->Set(i, item);
    }
    argv[0] = v8::Undefined();
    argv[1] = results;
  }
  data->callback->Call(2, argv);

  delete data->callback;
  for(std::list<ListResultItem*>::iterator it = data->results.begin(); it != data->results.end(); ++it) {
    delete *it;
  }
  delete data;
  delete req;
}
开发者ID:ognjenm,项目名称:node-twain-dll,代码行数:35,代码来源:twainDll.cpp

示例5: EIO_AfterOpen

void EIO_AfterOpen(uv_work_t* req) {
  NanScope();

  OpenBaton* data = static_cast<OpenBaton*>(req->data);

  v8::Handle<v8::Value> argv[2];
  if(data->errorString[0]) {
    argv[0] = v8::Exception::Error(v8::String::New(data->errorString));
    argv[1] = v8::Undefined();
    // not needed for AfterOpenSuccess
    delete data->dataCallback;
    delete data->errorCallback;
    delete data->disconnectedCallback;
  } else {
    argv[0] = v8::Undefined();
    argv[1] = v8::Int32::New(data->result);
    AfterOpenSuccess(data->result, data->dataCallback, data->disconnectedCallback, data->errorCallback);
  }

  data->callback->Call(2, argv);

  delete data->callback;
  delete data;
  delete req;
}
开发者ID:ognjenm,项目名称:node-twain-dll,代码行数:25,代码来源:twainDll.cpp

示例6: NanScope

void DecodeBufferWorker::HandleOKCallback () {
    NanScope();

    Local<v8::Primitive> metadata;
    if (_metadata == NULL) {
        metadata = NanNull();
    } else {
        metadata = NanNew<String>(_metadata);
    }

    Local<Value> argv[] = {
        NanNull(),
        NanBufferUse(
            (char *) _pixbuf,
            _width * _height * _channels
        ),
        NanNew<Number>(_width),
        NanNew<Number>(_height),
        NanNew<Number>(_channels),
        NanNew<Boolean>(_trans),
        metadata
    };

    callback->Call(7, argv);
}
开发者ID:neophob,项目名称:lwip,代码行数:25,代码来源:buffer_worker.cpp

示例7: EIO_AfterWatchPort

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] = v8::Exception::Error(v8::String::New(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;
}
开发者ID:AlisamfP,项目名称:NodeBots,代码行数:31,代码来源:serialport_win.cpp

示例8: OnServiceRegistered

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);
    }
}
开发者ID:KxT-cs,项目名称:node_mdns,代码行数:31,代码来源:dns_service_register.cpp

示例9: NanScope

// Sets up everything for the Logger object when the addon is initialized
void Logger::Initialize(Handle<Object> target) {
    NanScope();

    Local<FunctionTemplate> lcons = NanNew<FunctionTemplate>(Logger::New);
    lcons->InstanceTemplate()->SetInternalFieldCount(1);
    lcons->SetClassName(NanNew("Logger"));

    // Static methods
    NODE_SET_METHOD(lcons->GetFunction(), "getSeverity", Logger::get_severity);
    NODE_SET_METHOD(lcons->GetFunction(), "setSeverity", Logger::set_severity);

    // Constants
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"NONE",mapnik::logger::severity_type::none);
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"ERROR",mapnik::logger::severity_type::error);
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"DEBUG",mapnik::logger::severity_type::debug);
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"WARN",mapnik::logger::severity_type::warn);

    // What about booleans like:
    // ENABLE_STATS
    // ENABLE_LOG
    // DEFAULT_LOG_SEVERITY
    // RENDERING_STATS
    // DEBUG

    // Not sure if needed...
    target->Set(NanNew("Logger"),lcons->GetFunction());
    NanAssignPersistent(constructor, lcons);

}
开发者ID:cuulee,项目名称:self-hosted-vector-tiles,代码行数:30,代码来源:mapnik_logger.cpp

示例10: NanScope

/*
   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);
}
开发者ID:rafaelqm,项目名称:node-oracledb,代码行数:40,代码来源:njsOracle.cpp

示例11: NanScope

void PasteWorker::HandleOKCallback () {
    NanScope();
    Local<Value> argv[] = {
        NanNull()
    };
    callback->Call(1, argv);
}
开发者ID:Acro,项目名称:lwip,代码行数:7,代码来源:paste_worker.cpp

示例12: HandleOKCallback

  void HandleOKCallback () {
    NanScope();

    v8::Local<v8::Object> handle = GetFromPersistent("buffer");
    v8::Local<v8::Value> argv[] = { handle };
    callback->Call(1, argv);
  }
开发者ID:rohiniwork,项目名称:nan,代码行数:7,代码来源:bufferworkerpersistent.cpp

示例13: Init

void Init (v8::Handle<v8::Object> target) {
  NanScope();

  v8::Local<v8::FunctionTemplate> returnString = v8::FunctionTemplate::New(ReturnString);
  NanAssignPersistent(v8::FunctionTemplate, returnString_persistent, returnString);
  target->Set(
      NanSymbol("returnString")
    , returnString->GetFunction()
  );
  v8::Local<v8::FunctionTemplate> returnCString = v8::FunctionTemplate::New(ReturnCString);
  NanAssignPersistent(v8::FunctionTemplate, returnCString_persistent, returnCString);
  target->Set(
      NanSymbol("returnCString")
    , returnCString->GetFunction()
  );
  v8::Local<v8::FunctionTemplate> compareCStringToBuffer = v8::FunctionTemplate::New(CompareCStringToBuffer);
  NanAssignPersistent(v8::FunctionTemplate, compareCStringToBuffer_persistent, compareCStringToBuffer);
  target->Set(
      NanSymbol("compareCStringToBuffer")
    , compareCStringToBuffer->GetFunction()
  );
  v8::Local<v8::FunctionTemplate> compareRawStringToBuffer = v8::FunctionTemplate::New(CompareRawStringToBuffer);
  NanAssignPersistent(v8::FunctionTemplate, compareRawStringToBuffer_persistent, compareRawStringToBuffer);
  target->Set(
      NanSymbol("compareRawStringToBuffer")
    , compareRawStringToBuffer->GetFunction()
  );
}
开发者ID:kofd,项目名称:nan,代码行数:28,代码来源:fromv8string.cpp

示例14: OnServiceChanged

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);
}
开发者ID:KxT-cs,项目名称:node_mdns,代码行数:29,代码来源:dns_service_browse.cpp

示例15: EIO_AfterUpdate

void EIO_AfterUpdate(uv_work_t* req) {
  NanScope();

  OpenBaton* data = static_cast<OpenBaton*>(req->data);

  v8::Handle<v8::Value> argv[2];
  if(data->errorString[0]) {
    argv[0] = v8::Exception::Error(NanNew<v8::String>(data->errorString));
    argv[1] = NanUndefined();
    // not needed for AfterOpenSuccess
    delete data->dataCallback;
    delete data->errorCallback;
    delete data->disconnectedCallback;
  } else {
    argv[0] = NanUndefined();
    argv[1] = NanNew<v8::Int32>(data->result);

    int fd = argv[1]->ToInt32()->Int32Value();
    newQForFD(fd);

    AfterOpenSuccess(data->result, data->dataCallback, data->disconnectedCallback, data->errorCallback);
  }

  data->callback->Call(2, argv);

  delete data->platformOptions;
  delete data->callback;
  delete data;
  delete req;
}
开发者ID:AJRdev,项目名称:myo_sphero,代码行数:30,代码来源:serialport.cpp


注:本文中的NanScope函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。