本文整理汇总了C++中NanScope函数的典型用法代码示例。如果您正苦于以下问题:C++ NanScope函数的具体用法?C++ NanScope怎么用?C++ NanScope使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NanScope函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: SerializePart
int SerializePart(google::protobuf::Message *message, Handle<Object> subj) {
NanScope();
// get a reflection
const Reflection *r = message->GetReflection();
const Descriptor *d = message->GetDescriptor();
// build a list of required properties
vector<string> required;
for (int i = 0; i < d->field_count(); i++) {
const FieldDescriptor *field = d->field(i);
if (field->is_required())
required.push_back(field->name());
}
// build a reflection
// get properties of passed object
Local<Array> properties = subj->GetPropertyNames();
uint32_t len = properties->Length();
// check that all required properties are present
for (uint32_t i = 0; i < required.size(); i++) {
Handle<String> key = String::New(required.at(i).c_str());
if (!subj->Has(key))
return -1;
}
for (uint32_t i = 0; i < len; i++) {
Local<Value> property = properties->Get(i);
Local<String> property_s = property->ToString();
if (*property_s == NULL)
continue;
String::Utf8Value temp(property);
std::string propertyName = std::string(*temp);
const FieldDescriptor *field = d->FindFieldByName(propertyName);
if (field == NULL) continue;
Local<Value> val = subj->Get(property);
if (field->is_repeated()) {
if (!val->IsArray())
continue;
Handle<Array> array = val.As<Array>();
int len = array->Length();
for (int i = 0; i < len; i++)
SerializeField(message, r, field, array->Get(i));
} else {
SerializeField(message, r, field, val);
}
}
return 0;
}
开发者ID:cleverca22,项目名称:node-protobuf,代码行数:59,代码来源:serialize.cpp
示例17: HandleProgressCallback
void HandleProgressCallback(const char *data, size_t size) {
NanScope();
v8::Local<v8::Value> argv[] = {
NanNew<v8::Integer>(*reinterpret_cast<int*>(const_cast<char*>(data)))
};
progress->Call(1, argv);
}
开发者ID:az7arul,项目名称:nan,代码行数:8,代码来源:asyncprogressworker.cpp
示例18: NanScope
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;
}
开发者ID:cuulee,项目名称:self-hosted-vector-tiles,代码行数:58,代码来源:mapnik_grid.cpp
示例19: ParsePlatformOptions
OpenBatonPlatformOptions* ParsePlatformOptions(const v8::Local<v8::Object>& options) {
NanScope();
UnixPlatformOptions* result = new UnixPlatformOptions();
result->vmin = options->Get(NanNew<v8::String>("vmin"))->ToInt32()->Int32Value();
result->vtime = options->Get(NanNew<v8::String>("vtime"))->ToInt32()->Int32Value();
return result;
}
开发者ID:Adeboye,项目名称:Nellcor-600x,代码行数:9,代码来源:serialport_unix.cpp
示例20: NAN_METHOD
static inline NAN_METHOD(register_fonts)
{
NanScope();
try
{
if (args.Length() == 0 || !args[0]->IsString())
{
NanThrowTypeError("first argument must be a path to a directory of fonts");
NanReturnUndefined();
}
bool found = false;
std::vector<std::string> const names_before = mapnik::freetype_engine::face_names();
// option hash
if (args.Length() == 2){
if (!args[1]->IsObject())
{
NanThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse:Boolean }");
NanReturnUndefined();
}
Local<Object> options = args[1].As<Object>();
if (options->Has(NanNew("recurse")))
{
Local<Value> recurse_opt = options->Get(NanNew("recurse"));
if (!recurse_opt->IsBoolean())
{
NanThrowTypeError("'recurse' must be a Boolean");
NanReturnUndefined();
}
bool recurse = recurse_opt->BooleanValue();
std::string path = TOSTR(args[0]);
found = mapnik::freetype_engine::register_fonts(path,recurse);
}
}
else
{
std::string path = TOSTR(args[0]);
found = mapnik::freetype_engine::register_fonts(path);
}
std::vector<std::string> const& names_after = mapnik::freetype_engine::face_names();
if (names_after.size() == names_before.size())
found = false;
NanReturnValue(NanNew(found));
}
catch (std::exception const& ex)
{
NanThrowError(ex.what());
NanReturnUndefined();
}
}
开发者ID:ReclaimSoftware,项目名称:rs-upstream,代码行数:57,代码来源:mapnik_fonts.hpp
注:本文中的NanScope函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论