本文整理汇总了C++中HandleScope函数的典型用法代码示例。如果您正苦于以下问题:C++ HandleScope函数的具体用法?C++ HandleScope怎么用?C++ HandleScope使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HandleScope函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleScope
void CJSKadID::FxToString(const v8::FunctionCallbackInfo<v8::Value> &args)
{
v8::HandleScope HandleScope(v8::Isolate::GetCurrent());
CJSKadID* jKadID = GetJSObject<CJSKadID>(args.Holder());
args.GetReturnValue().Set(v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), V8STR(jKadID->m_pKadID->m_Value.ToHex().c_str())));
}
示例2: HandleScope
/** toString:
* convert the buffer into a hex encoded string
*
* @return string
* Hex Encoded buffer content
*/
void CJSBuffer::FxToString(const v8::FunctionCallbackInfo<v8::Value> &args)
{
v8::HandleScope HandleScope(v8::Isolate::GetCurrent());
CBufferObj* pBuffer = GetCObject<CBufferObj>(args.Holder());
args.GetReturnValue().Set(v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), V8STR(ToHex(pBuffer->GetBuffer(), pBuffer->GetSize()).c_str())));
}
示例3: HandleScope
PJsonVal TNodeJsStreamAggr::SaveJson(const int& Limit) const {
if (!SaveJsonFun.IsEmpty()) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
v8::Local<v8::Function> Callback = v8::Local<v8::Function>::New(Isolate, SaveJsonFun);
v8::Local<v8::Object> GlobalContext = Isolate->GetCurrentContext()->Global();
const unsigned Argc = 1;
v8::Local<v8::Value> ArgV[Argc] = { v8::Number::New(Isolate, Limit) };
v8::TryCatch TryCatch;
v8::Local<v8::Value> ReturnVal = Callback->Call(GlobalContext, Argc, ArgV);
if (TryCatch.HasCaught()) {
TryCatch.ReThrow();
return TJsonVal::NewObj();
}
QmAssertR(ReturnVal->IsObject(), "Stream aggr JS callback: saveJson didn't return an object.");
PJsonVal Res = TNodeJsUtil::GetObjJson(ReturnVal->ToObject());
QmAssertR(Res->IsDef(), "Stream aggr JS callback: saveJson didn't return a valid JSON.");
return Res;
}
else {
return TJsonVal::NewObj();
}
}
示例4: HandleScope
void TNodeJsFIn::Init(v8::Handle<v8::Object> exports) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
// template for creating function from javascript using "new", uses _NewJs callback
v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(Isolate, TNodeJsUtil::_NewJs<TNodeJsFIn>);
// child will have the same properties and methods, but a different callback: _NewCpp
v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(Isolate, TNodeJsUtil::_NewCpp<TNodeJsFIn>);
child->Inherit(tpl);
child->SetClassName(v8::String::NewFromUtf8(Isolate, GetClassId().CStr()));
// ObjectWrap uses the first internal field to store the wrapped pointer
child->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(v8::String::NewFromUtf8(Isolate, GetClassId().CStr()));
// ObjectWrap uses the first internal field to store the wrapped pointer
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// Add all prototype methods, getters and setters here
NODE_SET_PROTOTYPE_METHOD(tpl, "peekCh", _peekCh);
NODE_SET_PROTOTYPE_METHOD(tpl, "getCh", _getCh);
NODE_SET_PROTOTYPE_METHOD(tpl, "readLine", _readLine);
NODE_SET_PROTOTYPE_METHOD(tpl, "readJson", _readJson);
NODE_SET_PROTOTYPE_METHOD(tpl, "readAll", _readAll);
// Add properties
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(Isolate, "eof"), _eof);
tpl->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(Isolate, "length"), _length);
// This has to be last, otherwise the properties won't show up on the object in JavaScript
// Constructor is used when creating the object from C++
Constructor.Reset(Isolate, child->GetFunction());
// we need to export the class for calling using "new FIn(...)"
exports->Set(v8::String::NewFromUtf8(Isolate, GetClassId().CStr()),
tpl->GetFunction());
}
示例5: HandleScope
void TNodeJsFIn::New(const v8::FunctionCallbackInfo<v8::Value>& Args) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
if (Args.IsConstructCall()) {
EAssertR(Args.Length() == 1 && Args[0]->IsString(),
"Expected a file path.");
TStr FNm(*v8::String::Utf8Value(Args[0]->ToString()));
EAssertR(TFile::Exists(FNm), "File does not exist.");
TNodeJsFIn* JsFIn = new TNodeJsFIn(FNm);
v8::Local<v8::Object> Instance = Args.This();
v8::Handle<v8::String> key = v8::String::NewFromUtf8(Isolate, "class");
v8::Handle<v8::String> value = v8::String::NewFromUtf8(Isolate, ClassId.CStr());
Instance->SetHiddenValue(key, value);
JsFIn->Wrap(Instance);
Args.GetReturnValue().Set(Instance);
} else {
const int Argc = 1;
v8::Local<v8::Value> Argv[Argc] = { Args[0] };
v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(Isolate, constructor);
v8::Local<v8::Object> Instance = cons->NewInstance(Argc, Argv);
Args.GetReturnValue().Set(Instance);
}
}
示例6: HandleScope
TNodeJsRf24Radio* TNodeJsRf24Radio::NewFromArgs(const v8::FunctionCallbackInfo<v8::Value>& Args) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
PJsonVal ParamJson = TNodeJsUtil::GetArgJson(Args, 0);
const int PinCE = ParamJson->GetObjInt("pinCE");
const int PinCSN = ParamJson->GetObjInt("pinCSN");
const uint16 MyId = (uint16) ParamJson->GetObjInt("id");
const PJsonVal SensorJsonV = ParamJson->GetObjKey("sensors");
const bool Verbose = ParamJson->GetObjBool("verbose", false);
const PNotify Notify = Verbose ? TNotify::StdNotify : TNotify::NullNotify;
Notify->OnNotify(TNotifyType::ntInfo, "Parsing configuration ...");
TStrIntH SensorNmIdH;
TStrIntH SensorIdNodeIdH;
for (int SensorN = 0; SensorN < SensorJsonV->GetArrVals(); SensorN++) {
const PJsonVal SensorJson = SensorJsonV->GetArrVal(SensorN);
const TStr& SensorId = SensorJson->GetObjStr("id");
SensorNmIdH.AddDat(SensorId, SensorJson->GetObjInt("internalId"));
SensorIdNodeIdH.AddDat(SensorId, SensorJson->GetObjInt("nodeId"));
}
Notify->OnNotify(TNotifyType::ntInfo, "Calling cpp constructor ...");
return new TNodeJsRf24Radio(MyId, PinCE, PinCSN, SensorNmIdH, SensorIdNodeIdH, Notify);
}
示例7: TNodeTask
TNodejsDHT11Sensor::TReadTask::TReadTask(const v8::FunctionCallbackInfo<v8::Value>& Args):
TNodeTask(Args),
JsSensor(nullptr) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
JsSensor = ObjectWrap::Unwrap<TNodejsDHT11Sensor>(Args.Holder());
}
示例8: HandleScope
void TNodeTask::AfterRunSync(const v8::FunctionCallbackInfo<v8::Value>& Args) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
if (!Except.Empty()) { throw Except; }
Args.GetReturnValue().Set(WrapResult());
}