本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例11: NanScope
void PasteWorker::HandleOKCallback () {
NanScope();
Local<Value> argv[] = {
NanNull()
};
callback->Call(1, argv);
}
示例12: HandleOKCallback
void HandleOKCallback () {
NanScope();
v8::Local<v8::Object> handle = GetFromPersistent("buffer");
v8::Local<v8::Value> argv[] = { handle };
callback->Call(1, argv);
}
示例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()
);
}
示例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);
}
示例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;
}