本文整理汇总了C++中Isolate类的典型用法代码示例。如果您正苦于以下问题:C++ Isolate类的具体用法?C++ Isolate怎么用?C++ Isolate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Isolate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Move
void UiWindow::Move(const FunctionCallbackInfo<Value>& args) {
Isolate *isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() != 2 && args.Length() != 4) {
isolate->ThrowException(String::NewFromUtf8(isolate, "arg"));
return;
}
UiWindow* _this = Unwrap<UiWindow>(args.This());
WindowRect rect = _this->GetWindowRect();
if (args[0]->IsNumber()) {
rect.Left = args[0]->Int32Value();
}
if (args[1]->IsNumber()) {
rect.Top = args[1]->Int32Value();
}
if (args.Length() == 4) {
if (args[2]->IsNumber()) {
rect.Width = args[2]->Int32Value();
}
if (args[3]->IsNumber()) {
rect.Height = args[3]->Int32Value();
}
}
_this->SetWindowRect(rect);
}
示例2: clock_gettime
void Profiler::HeapSnapshotMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
struct timespec nowt;
clock_gettime(CLOCK_MONOTONIC, &nowt);
uint64_t now = (int64_t) nowt.tv_sec*1000000000LL + nowt.tv_nsec;
unsigned long sec = static_cast<unsigned long>(now / 1000000);
unsigned long usec = static_cast<unsigned long>(now % 1000000);
char filename[256];
snprintf(filename, sizeof(filename), "/sdcard/%s-heapdump-%lu.%lu.heapsnapshot", s_appName.c_str(), sec, usec);
FILE* fp = fopen(filename, "w");
if (fp == nullptr)
{
return;
}
Isolate* isolate = Isolate::GetCurrent();
const HeapSnapshot* snap = isolate->GetHeapProfiler()->TakeHeapSnapshot();
FileOutputStream stream(fp);
snap->Serialize(&stream, HeapSnapshot::kJSON);
fclose(fp);
const_cast<HeapSnapshot*>(snap)->Delete();
}
示例3: wrap
result_t SslServer::create(v8::Local<v8::Array> certs, exlib::string addr, int32_t port,
v8::Local<v8::Value> listener)
{
result_t hr;
obj_ptr<TcpServer_base> _server;
obj_ptr<SslHandler_base> _handler;
hr = SslHandler_base::_new(certs, listener, _handler);
if (hr < 0)
return hr;
hr = TcpServer_base::_new(addr, port, _handler->wrap(), _server);
if (hr < 0)
return hr;
m_server = _server;
v8::Local<v8::Object> o = wrap();
Isolate* isolate = holder();
isolate->SetPrivate(o, "handler", _handler->wrap());
isolate->SetPrivate(o, "server", _server->wrap());
return 0;
}
示例4: ParseAsync
void ParseAsync(const Nan::FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
int args_length = args.Length();
if (args_length < 2) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
Local<Value> input = args[0];
if (!ValidateInput(input, isolate)) {
return;
}
if (!args[1]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second parameter must be a callback")));
return;
}
Nan::Callback *callback = new Nan::Callback(args[1].As<Function>());
anitomyJs::Worker *worker = new anitomyJs::Worker(callback);
if (args_length >= 3) {
Local<Value> options = args[2];
if (!ValidateOptions(options, isolate) ||
!worker->GetAnitomy()->SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
return;
}
}
worker->GetAnitomy()->SetInput(input, isolate);
Nan::AsyncQueueWorker(worker);
args.GetReturnValue().Set(Nan::Undefined());
}
示例5: ParseSync
void ParseSync(const Nan::FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
int args_length = args.Length();
if (args_length < 1) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
Local<Value> input = args[0];
if (!ValidateInput(input, isolate)) {
return;
}
anitomyJs::AnitomyJs anitomy;
if (args_length >= 2) {
Local<Value> options = args[1];
if (!ValidateOptions(options, isolate) ||
!anitomy.SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
return;
}
}
anitomy.SetInput(input, isolate);
anitomy.Parse();
args.GetReturnValue().Set(anitomy.ParsedResult(isolate));
}
示例6: jsCreateMyClass
void jsCreateMyClass(const FunctionCallbackInfo<Value>& args)
{
if (args.Length() != 1)
{
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), "Bad parameters",
NewStringType::kNormal).ToLocalChecked());
return;
}
Isolate* isolate = args.GetIsolate();
Local<ObjectTemplate> myClassTemplate =
Local<ObjectTemplate>::New(isolate, gMyClassTemplate);
Local<Object> myClassObj = myClassTemplate->NewInstance(
isolate->GetCurrentContext()).ToLocalChecked();
int numValue =
args[0]->Int32Value(isolate->GetCurrentContext()).FromMaybe(0);
gMyClass = new ObjectWrap(numValue);
gMyClass->Wrap(myClassObj);
args.GetReturnValue().Set(myClassObj);
}
示例7: holder
result_t X509Crl::dump(v8::Local<v8::Array> &retVal)
{
Isolate* isolate = holder();
retVal = v8::Array::New(isolate->m_isolate);
const mbedtls_x509_crl *pCrl = &m_crl;
int32_t ret, n = 0;
exlib::string buf;
size_t olen;
while (pCrl)
{
if (pCrl->raw.len > 0)
{
buf.resize(pCrl->raw.len * 2 + 64);
ret = mbedtls_pem_write_buffer(PEM_BEGIN_CRL, PEM_END_CRL,
pCrl->raw.p, pCrl->raw.len,
(unsigned char *)&buf[0], buf.length(), &olen);
if (ret != 0)
return CHECK_ERROR(_ssl::setError(ret));
retVal->Set(n ++, isolate->NewFromUtf8(buf.c_str(), (int32_t) olen - 1));
}
pCrl = pCrl->next;
}
return 0;
}
示例8: New
void CRF::New(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
if (args.IsConstructCall()) {
// Invoked as constructor: `new CRF(...)`
CRF* obj = new CRF();
CRFPP::Tagger* tag = CRFPP::createTagger(get(args[0]));
if(!tag){
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, (const char *) CRFPP::getTaggerError())));
return;
}
v8::Local<v8::External> handle = v8::External::New(isolate, tag);
v8::Persistent<v8::External, v8::CopyablePersistentTraits<v8::External> > tagger(isolate, handle);
obj -> tagger = tagger;
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
const int argc = 1;
Local<Value> argv[argc] = { args[0] };
Local<Function> cons = Local<Function>::New(isolate, constructor);
args.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}
示例9: _jsonEncode
inline result_t _jsonEncode(v8::Local<v8::Value> data,
std::string &retVal)
{
Isolate* isolate = Isolate::current();
v8::Local<v8::Object> _json;
if (isolate->m_json.IsEmpty())
{
v8::Local<v8::Object> glob = v8::Local<v8::Object>::New(isolate->m_isolate, isolate->m_global);
_json = glob->Get(isolate->NewFromUtf8("JSON"))->ToObject();
isolate->m_json.Reset(isolate->m_isolate, _json);
isolate->m_stringify.Reset(isolate->m_isolate,
v8::Local<v8::Function>::Cast(_json->Get(isolate->NewFromUtf8("stringify"))));
} else
_json = v8::Local<v8::Object>::New(isolate->m_isolate, isolate->m_json);
TryCatch try_catch;
v8::Local<v8::Value> str = v8::Local<v8::Function>::New(isolate->m_isolate, isolate->m_stringify)->Call(_json, 1, &data);
if (try_catch.HasCaught())
return CHECK_ERROR(Runtime::setError(*v8::String::Utf8Value(try_catch.Exception())));
v8::String::Utf8Value v(str);
retVal.assign(*v, v.length());
return 0;
}
示例10: map
result_t util_base::map(v8::Local<v8::Value> list, v8::Local<v8::Function> iterator,
v8::Local<v8::Value> context, v8::Local<v8::Array> &retVal)
{
Isolate* isolate = Isolate::current();
v8::Local<v8::Array> arr = v8::Array::New(isolate->m_isolate);
if (!list->IsObject())
{
retVal = arr;
return 0;
}
v8::Local<v8::Value> args[3];
args[2] = list;
v8::Local<v8::Object> o = v8::Local<v8::Object>::Cast(list);
v8::Local<v8::Value> v = o->Get(isolate->NewFromUtf8("length"));
int32_t cnt = 0;
if (IsEmpty(v))
{
v8::Local<v8::Array> keys = o->GetPropertyNames();
int32_t len = keys->Length();
int32_t i;
for (i = 0; i < len; i ++)
{
args[1] = keys->Get(i);
args[0] = o->Get(args[1]);
v = iterator->Call(context, 3, args);
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;
arr->Set(cnt ++, v);
}
}
else
{
int32_t len = v->Int32Value();
int32_t i;
for (i = 0; i < len; i ++)
{
args[1] = v8::Int32::New(isolate->m_isolate, i);
args[0] = o->Get(args[1]);
v = iterator->Call(context, 3, args);
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;
arr->Set(cnt ++, v);
}
}
retVal = arr;
return 0;
}
示例11: Method
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
const char * cstr;
String::Utf8Value str(args[0]->ToString());
cstr = *str;
CTime curTime;
CRTime deliLimit;
vector<CDriver> drivers;
vector<CTask> tasks;
vector<CPath> paths;
vector<CScheduleItem> schedule;
schedule.clear();
if (parseInput(cstr, curTime, deliLimit, drivers, tasks, paths)) {
int ret = ALG::findScheduleGreedy(curTime, deliLimit, drivers, tasks, paths, schedule);
if (ret != E_NORMAL) {
printf("search algorithm returned %d.\n", ret);
}
}
Local<String> schd_string = String::NewFromUtf8(isolate, prepareOutput(schedule).c_str());
//args.GetReturnValue().Set(schd_string);
Local<Function> cb = Local<Function>::Cast(args[1]);
const unsigned int argc = 1;
Local<Value> argv[argc] = {schd_string};
cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}
示例12: get_env
result_t process_base::get_env(v8::Local<v8::Object>& retVal)
{
Isolate* isolate = Isolate::current();
v8::Local<v8::Object> glob = v8::Local<v8::Object>::New(isolate->m_isolate, isolate->m_global);
v8::Local<v8::Value> ev = isolate->GetPrivate(glob, "_env");
if (ev->IsUndefined())
{
v8::Local<v8::Object> o = v8::Object::New(isolate->m_isolate);
char** env = environ;
const char *p, *p1;
while ((p = *env++) != NULL)
{
p1 = qstrchr(p, '=');
if (p1)
o->Set(isolate->NewFromUtf8(p, (int32_t)(p1 - p)), isolate->NewFromUtf8(p1 + 1));
}
isolate->SetPrivate(glob, "_env", o);
retVal = o;
} else
retVal = v8::Local<v8::Object>::Cast(ev);
return 0;
}
示例13: SetLogHandler
void EModuleHelper::SetLogHandler( const FunctionCallbackInfo< Value >& args )
{
Isolate* isolate = args.GetIsolate( );
HandleScope scope( isolate );
Local< Context > context = isolate->GetCurrentContext( );
if( args[ 0 ]->IsNull( ) )
{
s_bLogEnabled = false;
}
else if( args[ 0 ]->IsFunction( ) )
{
s_bLogEnabled = true;
s_fnLogHandler.Reset( isolate, args[ 0 ].As< Function >( ) );
}
else
{
std::wostringstream stream;
{
stream << __FUNCTIONW__ << L" Invalid input type";
}
ThrowV8Exception( isolate, stream );
}
}
示例14: Serialize
void ABPFilterParserWrap::Serialize(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
ABPFilterParserWrap* obj =
ObjectWrap::Unwrap<ABPFilterParserWrap>(args.Holder());
int totalSize = 0;
// Serialize data
char* data = obj->serialize(&totalSize);
if (nullptr == data) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Could not serialize")));
return;
}
MaybeLocal<Object> buffer = node::Buffer::New(isolate, totalSize);
Local<Object> localBuffer;
if (!buffer.ToLocal(&localBuffer)) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Could not convert MaybeLocal to Local")));
return;
}
memcpy(node::Buffer::Data(localBuffer), data, totalSize);
delete[] data;
args.GetReturnValue().Set(localBuffer);
}
示例15: Lookup
void BookWrap::Lookup(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
if (args.Length() == 1) {
if (args[0]->IsString()) {
const String::Utf8Value s(args[0]->ToString());
Book* b = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book;
try {
Person* p = b->lookup(*s);
Local<Object> obj = PersonWrap::NewInstance();
PersonWrap* pw = ObjectWrap::Unwrap<PersonWrap>(obj);
pw->m_person = p;
args.GetReturnValue().Set(obj);
}
catch (...) {
isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Not found")));
args.GetReturnValue().SetUndefined();
}
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "String expected")));
args.GetReturnValue().SetUndefined();
}
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected")));
args.GetReturnValue().SetUndefined();
}
}