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)); } }
/** * 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)); }
/* * 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 (); } }
void ETW::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.IsConstructCall()) { if (args[0]->IsUndefined()) { Nan::ThrowTypeError("Session name is required."); return; } int wchars_num = MultiByteToWideChar(CP_UTF8 , 0 , *String::Utf8Value(args[0]), -1, NULL , 0 ); wchar_t* szSessionName = new wchar_t[wchars_num]; MultiByteToWideChar(CP_UTF8, 0, *String::Utf8Value(args[0]), -1, szSessionName, wchars_num); // Invoked as constructor: `new ETW(...)` ETW* obj = new ETW(szSessionName); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { // Invoked as plain function `ETW(...)`, turn into construct call. 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 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; } }
void ConsoleInterfaces::Assert(const FunctionCallbackInfo<Value>& args) { Handle<External> ext = Handle<External>::Cast(args.Data()); Flathead *pFH = (Flathead *)ext->Value(); int counter = 0; if (args.Length() == 0) { pFH->GetConfiguration()->LoggingFn()(LogLevels::Assert, ""); return; } Local<Value> value = args[0]; if (value->IsTrue()) { args.GetReturnValue().Set(counter); return; } if (pFH->GetConfiguration()->LoggingFn() != NULL) { for (int i = 1; i < args.Length(); i++) { Local<Value> value = args[i]; String::Utf8Value outputString(value); pFH->GetConfiguration()->LoggingFn()(LogLevels::Assert, *outputString); counter++; } } args.GetReturnValue().Set(counter); }
void IdPool::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); if (args.IsConstructCall()) { // Invoked as constructor: `new IdPool(...)` double value = args[0]->IsUndefined() || !args[0]->IsNumber()? 0 : args[0]->NumberValue() / 8; if (value > DEFAULT_CTOR_MAX_POSSIBLE_SIZE) { JS_THROW(isolate, "Size too large"); return; } // ceil size_t poolSize = value + (size_t)((size_t)value != value); try { IdPool* obj = new IdPool(poolSize); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } catch (std::Exception e) { JS_THROW(isolate, e.what()); return; } } else { // Invoked as plain function `IdPool(...)`, turn into construct call. 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 WeakRef::GettertCallback(const FunctionCallbackInfo<Value>& args) { try { auto holder = args.This(); auto poTarget = reinterpret_cast<Persistent<Object>*>(holder->GetHiddenValue(V8StringConstants::GetTarget()).As<External>()->Value()); auto isolate = args.GetIsolate(); if (poTarget != nullptr) { auto target = Local<Object>::New(isolate, *poTarget); args.GetReturnValue().Set(target); } else { args.GetReturnValue().Set(Null(isolate)); } } catch (NativeScriptException& e) { e.ReThrowToV8(); } catch (std::exception e) { stringstream ss; ss << "Error: c++ exception: " << e.what() << endl; NativeScriptException nsEx(ss.str()); nsEx.ReThrowToV8(); } catch (...) { NativeScriptException nsEx(std::string("Error: c++ exception!")); nsEx.ReThrowToV8(); } }
void get_game_player_sync_buffer(const FunctionCallbackInfo<Value>& args){ Block_Buffer *buf = MASTER_MANAGER->pop_master_player_sync_data(); if (buf) { args.GetReturnValue().Set(wrap_buffer(args.GetIsolate(), buf)); } else { //设置对象为空 args.GetReturnValue().SetNull(); } }
void pop_sync_master_data_buffer(const FunctionCallbackInfo<Value>& args) { Block_Buffer *buf = GAME_MANAGER->pop_sync_master_data_buffer(); if (buf) { args.GetReturnValue().Set(wrap_buffer(args.GetIsolate(), buf)); } else { //设置对象为空 args.GetReturnValue().SetNull(); } }
void pop_game_buffer(const FunctionCallbackInfo<Value>& args) { Block_Buffer *buf = GAME_MANAGER->pop_block_buffer(); if (buf) { buf->reset(); args.GetReturnValue().Set(wrap_buffer(args.GetIsolate(), buf)); } else { //设置对象为空 args.GetReturnValue().SetNull(); } }
void MySQL::JS_Escape(const FunctionCallbackInfo<Value> & args){ if (args[0]->IsString()){ string str = JS2STRING(args[0]); char* tmp = new char[str.length() * 2 + 1]; mysql_escape_string(tmp, str.c_str(),str.length()); args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), tmp)); } else { args.GetReturnValue().Set(args[0]); } }
/** * TJSオブジェクトの有効確認 * @param args 引数 * @return 結果 */ void TJSInstance::tjsIsValid(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant instance; if (getVariant(isolate, instance, args.This())) { args.GetReturnValue().Set(Boolean::New(isolate, instance.AsObjectClosureNoAddRef().IsValid(0, NULL, NULL, NULL) == TJS_S_TRUE)); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
/* * Prototype: * Module.findExportByName(module_name, symbol_name) * * Docs: * TBW * * Example: * TBW */ static void gum_v8_module_on_find_export_by_name ( 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]; gchar * module_name; if (module_name_val->IsString ()) { String::Utf8Value module_name_utf8 (module_name_val); module_name = g_strdup (*module_name_utf8); } else if (module_name_val->IsNull ()) { module_name = NULL; } else { isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Module.findExportByName: first argument must be a string " "specifying module name, or null"))); return; } Local<Value> symbol_name_val = info[1]; if (!symbol_name_val->IsString ()) { g_free (module_name); isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, "Module.findExportByName: second argument must be a string " "specifying name of exported symbol"))); return; } String::Utf8Value symbol_name (symbol_name_val); GumAddress raw_address = gum_module_find_export_by_name (module_name, *symbol_name); if (raw_address != 0) { info.GetReturnValue ().Set ( _gum_v8_native_pointer_new (GSIZE_TO_POINTER (raw_address), self->core)); } else { info.GetReturnValue ().SetNull (); } g_free (module_name); }
/** * TJSオブジェクトのコンストラクタ */ void TJSInstance::tjsConstructor(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant classObj; if (getVariant(isolate, classObj, args.Data()->ToObject())) { CreateInfo info(classObj, args); args.GetReturnValue().Set(info.create()); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
// メソッドの呼び出し void TJSObject::caller(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant self; if (getVariant(isolate, self, args.This())) { Local<Value> ret; // 引数変換 tjs_int argc = args.Length(); tTJSVariant **argv = new tTJSVariant*[argc]; for (tjs_int i=0;i<argc;i++) { argv[i] = new tTJSVariant(); *argv[i] = toVariant(isolate, args[i]); } if (self.AsObjectClosureNoAddRef().IsInstanceOf(0, NULL, NULL, L"Class", NULL) == TJS_S_TRUE) { // クラスオブジェクトならコンストラクタ呼び出し iTJSDispatch2 *instance = NULL; tjs_error error; if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().CreateNew(0, NULL, NULL, &instance, argc, argv, NULL))) { ret = toJSValue(isolate, tTJSVariant(instance, instance)); instance->Release(); } else { ret = ERROR_KRKR(isolate, error); } } else { // メソッド呼び出し tTJSVariant result; tjs_error error; if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().FuncCall(0, NULL, NULL, &result, argc, argv, NULL))) { ret = toJSValue(isolate, result); } else { ret = ERROR_KRKR(isolate, error); } } // 引数解放 if (argv) { for (int i=0;i<argc;i++) { delete argv[i]; } delete[] argv; } args.GetReturnValue().Set(ret); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
void Buffer::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); HandleScope handle_scope(isolate); if (args.IsConstructCall()) { Buffer* obj = new Buffer(args); args.GetReturnValue().Set(args.This()); } else { std::array<Local<Value>, 1> argv{ args[0] }; Local<Function> cons = Local<Function>::New(isolate, constructor.Get(isolate)); args.GetReturnValue().Set(cons->NewInstance(SafeInt<int>(argv.size()), argv.data())); } }
/** * TJSオブジェクト用のメソッド * @param args 引数 * @return 結果 */ void TJSInstance::tjsInvoker(const FunctionCallbackInfo<Value>& args) { Isolate *isolate = args.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant instance; tTJSVariant method; if (getVariant(isolate, instance, args.This()) && getVariant(isolate, method, args.Data()->ToObject())) { FuncInfo info(instance, method, args); args.GetReturnValue().Set(info.exec()); return; } args.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
void MyObject::close(const FunctionCallbackInfo<Value>& args) { Isolate* isolate=Isolate::GetCurrent(); HandleScope scope(isolate); MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder()); if(obj->leftPort.close() && obj->rightPort.close()) { args.GetReturnValue().Set(String::NewFromUtf8(isolate, "OK")); } else args.GetReturnValue().Set(String::NewFromUtf8(isolate, "ERROR - OPENING")); }
void ModuleInterfaces::Exists(const FunctionCallbackInfo<Value>& args) { struct stat buf; // Filename if (args.Length() != 1) { args.GetReturnValue().SetUndefined(); return; // invalid arguments } v8::String::Utf8Value Filename(args[0]); args.GetReturnValue().Set(0 == stat(*Filename, &buf)); }
void DeviceNode::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); if (args.IsConstructCall()) { // Invoked as constructor: `new DeviceNode()` DeviceNode* obj = new DeviceNode(); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { // Invoked as plain function `DeviceNode(...)`, turn into construct call. Local<Function> cons = Local<Function>::New(isolate, constructor); args.GetReturnValue().Set(cons->NewInstance()); } }
void GeometryFactory::GetPrecisionModel(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); GeometryFactory *factory = ObjectWrap::Unwrap<GeometryFactory>(args.This()); args.GetReturnValue().Set(PrecisionModel::New(factory->_factory->getPrecisionModel())); }
void PrecisionModel::GetOffsetX(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); PrecisionModel *model = ObjectWrap::Unwrap<PrecisionModel>(args.This()); args.GetReturnValue().Set(Number::New(isolate, model->_model->getOffsetX())); }
void PrecisionModel::New(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); PrecisionModel *model; if (args.Length() == 0) { model = new PrecisionModel(); } else { if (args[0]->IsString()) { //type if(args[0]->ToString()->Equals(String::NewFromUtf8(isolate, "FIXED"))) { model = new PrecisionModel(geos::geom::PrecisionModel::FIXED); } else if (args[0]->ToString()->Equals(String::NewFromUtf8(isolate, "FLOATING"))) { model = new PrecisionModel(geos::geom::PrecisionModel::FLOATING); } else { model = new PrecisionModel(geos::geom::PrecisionModel::FLOATING_SINGLE); } } else { //double model = new PrecisionModel(args[0]->NumberValue()); } } model->Wrap(args.This()); args.GetReturnValue().Set(args.This()); }
void PrecisionModel::IsFloating(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); PrecisionModel *model = ObjectWrap::Unwrap<PrecisionModel>(args.This()); args.GetReturnValue().Set(model->_model->isFloating() ? True(isolate) : False(isolate)); }
void PrecisionModel::ToString(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); PrecisionModel *model = ObjectWrap::Unwrap<PrecisionModel>(args.This()); args.GetReturnValue().Set(String::NewFromUtf8(isolate, model->_model->toString().data())); }
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); }
static void gum_script_process_on_is_debugger_attached ( const FunctionCallbackInfo<Value> & info) { info.GetReturnValue ().Set ( gum_process_is_debugger_attached () ? true : false); }
//! \verbatim //! String Quaternion.toString //! \endverbatim void Quaternion::jsToString( const FunctionCallbackInfo<v8::Value>& args ) { Quaternion* ptr = unwrap( args.Holder() ); char result[128]; sprintf_s<128>( result, "Quaternion[%f,%f,%f,%f]", ptr->w, ptr->x, ptr->y, ptr->z ); args.GetReturnValue().Set( Util::allocString( result ) ); }
static void gum_script_process_on_get_current_thread_id ( const FunctionCallbackInfo<Value> & info) { info.GetReturnValue ().Set (static_cast<uint32_t> ( gum_process_get_current_thread_id ())); }