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)); } }
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); }
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(); }
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); }
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; }
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()); }
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)); }
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; }
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; }
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; }
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); }
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; }
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 ); } }
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); }
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(); } }
result_t CustomExtLoader::compile(SandBox::Context* ctx, Buffer_base* src, exlib::string name, exlib::string arg_names, v8::Local<v8::Script>& script) { Isolate* isolate = ctx->m_sb->holder(); v8::Local<v8::Value> require_fn = ctx->m_sb->GetPrivate(SandBox::_get_extloader_pname(m_ext)); exlib::string strScript; // read filecontent and compile to strScript :start v8::Local<v8::Value> transpileArgs[2]; src->valueOf(transpileArgs[0]); v8::Local<v8::Object> requireInfo = v8::Object::New(isolate->m_isolate); transpileArgs[1] = requireInfo; requireInfo->Set(isolate->NewString("filename"), isolate->NewString(name)); v8::Local<v8::Value> fileContent = v8::Local<v8::Function>::Cast(require_fn)->Call(v8::Undefined(isolate->m_isolate), 2, transpileArgs); if (fileContent.IsEmpty()) return CALL_E_JAVASCRIPT; result_t hr = GetArgumentValue(fileContent, strScript, true); if (hr < 0) return CHECK_ERROR(hr); // read filecontent and compile to strScript :end obj_ptr<Buffer_base> buf = new Buffer(strScript); return JsLoader::compile(ctx, buf, name, arg_names, script); }
int main(){ // Initialize V8. V8::InitializeICU(); //V8::InitializeExternalStartupData(argv[0]); Platform* platform = platform::CreateDefaultPlatform(); V8::InitializePlatform(platform); V8::Initialize(); // Create a new Isolate and make it the current one. ArrayBufferAllocator allocator; Isolate::CreateParams create_params; create_params.array_buffer_allocator = &allocator; Isolate* isolate = Isolate::New(create_params); exec(isolate); // Dispose the isolate and tear down V8. isolate->Dispose(); V8::Dispose(); V8::ShutdownPlatform(); delete platform; return 0; }
// DISCONNECT SYNC void disconnectSync(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); SQLRETURN retcode; // define callback Local<Function> cb = Local<Function>::Cast(args[0]); // Free handles // Statement if (hstmt != SQL_NULL_HSTMT) SQLFreeHandle(SQL_HANDLE_STMT, hstmt); // Connection retcode = SQLDisconnect(hdbc); if(!SQL_SUCCEEDED(retcode)){ printf("ERROR AT SQLDISCONNECT\n"); extract_error(hdbc, SQL_HANDLE_DBC); } SQLFreeHandle(SQL_HANDLE_DBC, hdbc); /* // Environment if (henv != SQL_NULL_HENV) SQLFreeHandle(SQL_HANDLE_ENV, henv); */ Local<Value> argv[1] = { Number::New(isolate, retcode)}; cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); }
/* * Class: org_appcelerator_kroll_runtime_v8_V8Runtime * Method: nativeInit * Signature: (Lorg/appcelerator/kroll/runtime/v8/V8Runtime;)J */ JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeInit(JNIEnv *env, jobject self, jboolean useGlobalRefs, jobject debugger, jboolean DBG, jboolean profilerEnabled) { if (!V8Runtime::initialized) { // Initialize V8. V8::InitializeICU(); // TODO Enable this when we use snapshots? //V8::InitializeExternalStartupData(argv[0]); V8Runtime::platform = platform::CreateDefaultPlatform(); V8::InitializePlatform(V8Runtime::platform); V8::Initialize(); V8Runtime::initialized = true; } if (profilerEnabled) { char* argv[] = { const_cast<char*>(""), const_cast<char*>("--expose-gc") }; int argc = sizeof(argv)/sizeof(*argv); V8::SetFlagsFromCommandLine(&argc, argv, false); } titanium::JNIScope jniScope(env); JavaObject::useGlobalRefs = useGlobalRefs; V8Runtime::DBG = DBG; V8Runtime::javaInstance = env->NewGlobalRef(self); JNIUtil::initCache(); Isolate* isolate; if (V8Runtime::v8_isolate == nullptr) { // Create a new Isolate and make it the current one. Isolate::CreateParams create_params; create_params.array_buffer_allocator = &allocator; isolate = Isolate::New(create_params); isolate->Enter(); V8Runtime::v8_isolate = isolate; // Log all uncaught V8 exceptions. V8::AddMessageListener(&logV8Exception); V8::SetCaptureStackTraceForUncaughtExceptions(true); } else { isolate = V8Runtime::v8_isolate; isolate->Enter(); } HandleScope scope(isolate); Local<Context> context = Context::New(isolate); context->Enter(); V8Runtime::globalContext.Reset(isolate, context); JSDebugger::init(env, isolate, debugger); if (debugger != nullptr) { V8Runtime::debuggerEnabled = true; } V8Runtime::bootstrap(context); LOG_HEAP_STATS(isolate, TAG); }
/* * Prototype: * Stalker.addCallProbe(target_address, callback) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_stalker_on_add_call_probe (const FunctionCallbackInfo<Value> & info) { GumV8Stalker * self = static_cast<GumV8Stalker *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); GumV8CallProbe * probe; GumProbeId id; gpointer target_address; if (!_gum_v8_native_pointer_get (info[0], &target_address, self->core)) return; Local<Value> callback_value = info[1]; if (!callback_value->IsFunction ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Stalker.addCallProbe: second argument must be a function"))); return; } Local<Function> callback = Local<Function>::Cast (callback_value); probe = g_slice_new (GumV8CallProbe); probe->parent = self; probe->callback = new GumPersistent<Function>::type (isolate, callback); probe->receiver = new GumPersistent<Value>::type (isolate, info.This ()); id = gum_stalker_add_call_probe (_gum_v8_stalker_get (self), target_address, gum_v8_call_probe_fire, probe, reinterpret_cast<GDestroyNotify> (gum_v8_call_probe_free)); info.GetReturnValue ().Set (id); }
Handle<Value> VException(const char *msg) { Isolate *isolate = Isolate::GetCurrent(); HandleScope scope(isolate); return isolate->ThrowException(ErrorException(msg)); }
Handle<Value> ManagedRef::SetPropertyValue(Local<String> name, Local<Value> value) { Handle<Value> res; String::Value s(name); #ifdef DEBUG_TRACE_API std::cout << "SetPropertyValue" << std::endl; #endif Isolate* isolate = Isolate::GetCurrent(); jsvalue v = engine_->AnyFromV8(value); jsvalue r = engine_->CallSetPropertyValue(contextId_, id_, *s, v); if (r.type == JSVALUE_TYPE_MANAGED_ERROR) isolate->ThrowException(engine_->AnyToV8(r, contextId_));//0.12.x //res = ThrowException(engine_->AnyToV8(r, contextId_));//0.10.x else res = engine_->AnyToV8(r, contextId_); #ifdef DEBUG_TRACE_API std::cout << "cleaning up result from setproperty value" << std::endl; #endif // We don't need the jsvalues anymore and the CLR side never reuse them. jsvalue_dispose(v); jsvalue_dispose(r); return res; }
/** * TJSオブジェクトのオーバライド処理 * @param args 引数 * @return 結果 */ void TJSInstance::tjsOverride(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant instance; if (getVariant(isolate, instance, args.This())) { if (args.Length() > 0) { Local<Value> func = args.Length() > 1 ? args[1] : args.This()->Get(args[0]); if (func->IsFunction()) { tTJSVariant value = toVariant(isolate, func->ToObject(), args.This()); String::Value methodName(args[0]); tjs_error error; if (TJS_FAILED(error = instance.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *methodName, NULL, &value, NULL))) { args.GetReturnValue().Set(ERROR_KRKR(isolate, error)); return; } args.GetReturnValue().Set(Undefined(isolate)); return; } } args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "not function"))); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
void BookWrap::Each(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); Book* book = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book; if (args.Length() == 1) { if (args[0]->IsFunction()) { Local<Function> fun = Local<Function>::Cast(args[0]); for(uint32_t i = 0; i < book->size(); ++i) { Local<Object> pw = PersonWrap::New(isolate, book, i); Local<Value> argv[1] = { pw }; fun->Call(Null(isolate), 1, argv); } args.GetReturnValue().SetUndefined(); return; } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Function expected"))); args.GetReturnValue().SetUndefined(); return; } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected"))); args.GetReturnValue().SetUndefined(); return; } }
/* * Prototype: * Module.findBaseAddress(module_name) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_module_on_find_base_address ( const FunctionCallbackInfo<Value> & info) { GumV8Module * self = static_cast<GumV8Module *> ( info.Data ().As<External> ()->Value ()); Isolate * isolate = info.GetIsolate (); Local<Value> module_name_val = info[0]; if (!module_name_val->IsString ()) { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Module.findBaseAddress: argument must be a string " "specifying module name"))); return; } String::Utf8Value module_name (module_name_val); GumAddress raw_address = gum_module_find_base_address (*module_name); if (raw_address != 0) { info.GetReturnValue ().Set ( _gum_v8_native_pointer_new (GSIZE_TO_POINTER (raw_address), self->core)); } else { info.GetReturnValue ().SetNull (); } }
result_t BufferedStream::readLines(int32_t maxlines, v8::Local<v8::Array> &retVal) { result_t hr = 0; std::string str; int32_t n = 0; Isolate* isolate = holder(); retVal = v8::Array::New(isolate->m_isolate); if (maxlines == 0) return 0; while (true) { hr = ac_readLine(-1, str); if (hr < 0) return hr; if (hr > 0) return 0; retVal->Set(n ++, isolate->NewFromUtf8(str)); if (maxlines > 0) { maxlines --; if (maxlines == 0) break; } } return 0; }
result_t HttpsServer::create(v8::Local<v8::Array> certs, const char *addr, int32_t port, v8::Local<v8::Value> hdlr) { result_t hr; obj_ptr<SslServer_base> _server; obj_ptr<HttpHandler_base> _handler; hr = HttpHandler_base::_new(hdlr, _handler); if (hr < 0) return hr; hr = SslServer_base::_new(certs, addr, port, _handler->wrap(), _server); if (hr < 0) return hr; v8::Local<v8::Object> o = wrap(); Isolate* isolate = holder(); m_handler = _handler; o->SetHiddenValue(isolate->NewFromUtf8("handler"), _handler->wrap()); m_server = _server; o->SetHiddenValue(isolate->NewFromUtf8("server"), _server->wrap()); return 0; }
static void gum_v8_script_backend_emit_debug_message (const Debug::Message & message) { Isolate * isolate = message.GetIsolate (); GumV8ScriptBackend * self = GUM_V8_SCRIPT_BACKEND (isolate->GetData (0)); GumV8ScriptBackendPrivate * priv = self->priv; HandleScope scope (isolate); Local<String> json = message.GetJSON (); String::Utf8Value json_str (json); GUM_V8_SCRIPT_BACKEND_LOCK (); GMainContext * context = (priv->debug_handler_context != NULL) ? g_main_context_ref (priv->debug_handler_context) : NULL; GUM_V8_SCRIPT_BACKEND_UNLOCK (); if (context == NULL) return; GumEmitDebugMessageData * d = g_slice_new (GumEmitDebugMessageData); d->backend = self; g_object_ref (self); d->message = g_strdup (*json_str); GSource * source = g_idle_source_new (); g_source_set_callback (source, (GSourceFunc) gum_v8_script_backend_do_emit_debug_message, d, (GDestroyNotify) gum_emit_debug_message_data_free); g_source_attach (source, context); g_source_unref (source); g_main_context_unref (context); }
bool V8::Initialize() { Isolate *isolate = Isolate::New(); isolate->Enter(); atexit([]() { Isolate::GetCurrent()->Dispose(); }); return true; }
result_t MongoCollection::update(v8::Local<v8::Object> query, v8::Local<v8::Object> document, v8::Local<v8::Object> options) { Isolate* isolate = holder(); return update(query, document, options->Get(isolate->NewString("upsert", 6))->BooleanValue(), options->Get(isolate->NewString("multi", 5))->BooleanValue()); }