当前位置: 首页>>代码示例>>C++>>正文


C++ Local::Call方法代码示例

本文整理汇总了C++中Local::Call方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::Call方法的具体用法?C++ Local::Call怎么用?C++ Local::Call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Local的用法示例。


在下文中一共展示了Local::Call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FireEvent

void Server::FireEvent(std::string name, const int argc, Local<Value> argv[] ){
	Locker v8Locker(isolate);
	Isolate::Scope isoscope(isolate);
	HandleScope hs(isolate);
	Local<Context> ctx = Local<Context>::New(isolate, context);
	Context::Scope cs(ctx);
	TryCatch try_catch;

	JS_Object global(ctx->Global());

	Local<Object> serverjs = global.getObject("$server");
	Local<Value> fire = serverjs->Get(String::NewFromUtf8(isolate, "fire"));
	Local<Function> fn = Local<Function>::Cast(fire);

	if (name == "ScriptInit"){
		Local<Value> check = serverjs->Get(String::NewFromUtf8(isolate, "checkPlayers"));
		Local<Function> cpfn = Local<Function>::Cast(check);
		cpfn->Call(serverjs, 0, NULL);
	}
	Local<Value> *args = new Local<Value>[argc + 1];
	args[0] = String::NewFromUtf8(isolate, name.c_str());
	if (argc > 0){
		for (int i = 0; i < argc; i++){
			args[i + 1] = argv[i];
		}
	}
	fn->Call(serverjs, argc + 1, args);

	delete[] args;

	if (try_catch.HasCaught()){
		Utils::PrintException(&try_catch);
	}
}
开发者ID:steilman,项目名称:samp.js,代码行数:34,代码来源:Server.cpp

示例2: ConnectAsync

void MySQL::ConnectAsync(int id, string host, string user, string password, string database, Persistent<Function, CopyablePersistentTraits<Function>> callback){
	//connections[id]->mysql = mysql_init(NULL);
	if (mysql_real_connect(
		connections[id]->mysql,
		host.c_str(),
		user.c_str(),
		password.c_str(),
		database.c_str(),
		0,
		NULL,
		0) == NULL){
		V8PCONTEXT(isolate, context);
		Local<Function> func = Local<Function>::New(isolate, callback);
		sjs::logger::debug("Could not connect");
		Local<String> err = String::NewFromUtf8(isolate, mysql_error(connections[id]->mysql));
		Local<Value> argv[1] = { err };
		func->Call(func, 1, argv );
		sjs::logger::debug("Called Function");
		return;
	}
	
	V8PCONTEXT(isolate, context);
	Local<Function> func = Local<Function>::New(isolate, callback);
	func->Call(func, 0, NULL);
}
开发者ID:steilman,项目名称:samp.js,代码行数:25,代码来源:MySQL.cpp

示例3: callCallback

void JsVlcPlayer::callCallback( Callbacks_e callback,
                                std::initializer_list<v8::Local<v8::Value> > list )
{
    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );

    std::vector<v8::Local<v8::Value> > argList;
    argList.reserve( list.size() );
    argList.push_back(
        String::NewFromUtf8( isolate,
                             callbackNames[callback],
                             v8::String::kInternalizedString ) );
    if( list.size() > 0 )
        argList.insert( argList.end(), list );

    if( !_jsCallbacks[callback].IsEmpty() ) {
        Local<Function> callbackFunc =
            Local<Function>::New( isolate, _jsCallbacks[callback] );

        callbackFunc->Call( handle(), argList.size() - 1, argList.data() + 1 );
    }

    Local<Object> eventEmitter = getEventEmitter();
    Local<Function> emitFunction =
        v8::Local<v8::Function>::Cast(
            eventEmitter->Get(
                String::NewFromUtf8( isolate, "emit", v8::String::kInternalizedString ) ) );

    emitFunction->Call( eventEmitter, argList.size(), argList.data() );
}
开发者ID:EdZava,项目名称:WebChimera.js,代码行数:32,代码来源:JsVlcPlayer.cpp

示例4: _mouseMoved

void ScriptGame::_mouseMoved( const float x, const float y )
{
	HandleScope hs;
	PersistentContext ctx = MagnetiteCore::Singleton->getScriptManager()->getContext();
	Context::Scope scope( ctx );
	
	bool eval = false;
	if( !mScriptObject.IsEmpty() && mScriptObject->Has( String::New("mouseMoved") ) )
	{
		Local<Value> onLoadVal = mScriptObject->Get( String::New("mouseMoved") );
		if( onLoadVal->IsFunction() )
		{
			TryCatch ct;
			Local<Function> onLoad = Local<Function>::Cast( onLoadVal );
			Handle<Value> args[2];
			args[0] = Number::New(x);
			args[1] = Number::New(y);
			auto r = onLoad->Call( mScriptObject, 2, args );
			if( r.IsEmpty() ) {
				Util::log(strize(ct.StackTrace()));
			}
			else 
			{
				eval = r->BooleanValue();
			}
		}
	}
	if(!eval && getLocalPlayer() ) {
		mPlayer->getCamera()->pitch( y );
		mPlayer->getCamera()->yaw( x );
	}
}
开发者ID:zuzak,项目名称:Magnetite,代码行数:32,代码来源:ScriptGame.cpp

示例5: operator

            void operator()() {
                V8Scope* scope = config_._scope.get();
                v8::Isolate::Scope iscope(scope->getIsolate());
                v8::Locker l(scope->getIsolate());
                HandleScope handle_scope;
                Context::Scope context_scope( scope->getContext() );

                BSONObj args = config_.args_;
                Local< v8::Function > f = v8::Function::Cast( *(scope->mongoToV8Element(args.firstElement(), true)) );
                int argc = args.nFields() - 1;

                boost::scoped_array< Local< Value > > argv( new Local< Value >[ argc ] );
                BSONObjIterator it(args);
                it.next();
                for( int i = 0; i < argc; ++i ) {
                    argv[ i ] = Local< Value >::New( scope->mongoToV8Element(*it, true) );
                    it.next();
                }
                TryCatch try_catch;
                Handle< Value > ret = f->Call( scope->getContext()->Global(), argc, argv.get() );
                if ( ret.IsEmpty() ) {
                    string e = toSTLString( &try_catch );
                    log() << "js thread raised exception: " << e << endl;
                    // v8 probably does something sane if ret is empty, but not going to assume that for now
                    ret = v8::Undefined();
                }
                // ret is translated to BSON to switch isolate
                BSONObjBuilder b;
                scope->v8ToMongoElement(b, "ret", ret);
                config_.returnData_ = b.obj();
            }
开发者ID:89snake89,项目名称:mongo,代码行数:31,代码来源:v8_utils.cpp

示例6: scope

static gboolean
gum_v8_exception_handler_on_exception (GumExceptionDetails * details,
                                       gpointer user_data)
{
  GumV8ExceptionHandler * handler = (GumV8ExceptionHandler *) user_data;
  GumV8Core * core = handler->core;

  ScriptScope scope (core->script);
  Isolate * isolate = core->isolate;

  Local<Function> callback (Local<Function>::New (isolate, *handler->callback));

  Local<Object> ex, context;
  _gum_v8_parse_exception_details (details, ex, context, core);

  Handle<Value> argv[] = { ex };
  Local<Value> result = callback->Call (Null (isolate), 1, argv);

  _gum_v8_cpu_context_free_later (
      new GumPersistent<Object>::type (isolate, context),
      core);

  if (!result.IsEmpty () && result->IsBoolean ())
  {
    bool handled = result.As<Boolean> ()->Value ();
    return handled ? TRUE : FALSE;
  }

  return FALSE;
}
开发者ID:terry2012,项目名称:frida-gum,代码行数:30,代码来源:gumv8process.cpp

示例7:

extern "C" void
init(Handle<Object> target)
{
    HandleScope scope;
    Local<FunctionTemplate> logFunction = FunctionTemplate::New(LogWrapper);
    target->Set(String::NewSymbol("_logString"), logFunction->GetFunction());
    Local<FunctionTemplate> logKeyValueFunction = FunctionTemplate::New(LogKeyValueWrapper);
    target->Set(String::NewSymbol("_logKeyValueString"), logKeyValueFunction->GetFunction());
    target->Set(String::NewSymbol("LOG_CRITICAL"), Integer::New(kPmLogLevel_Critical));
    target->Set(String::NewSymbol("LOG_ERR"), Integer::New(kPmLogLevel_Error));
    target->Set(String::NewSymbol("LOG_WARNING"), Integer::New(kPmLogLevel_Warning));
    target->Set(String::NewSymbol("LOG_INFO"), Integer::New(kPmLogLevel_Info));
    target->Set(String::NewSymbol("LOG_DEBUG"), Integer::New(kPmLogLevel_Debug));
    Local<String> scriptText = String::New((const char*)pmloglib_js, pmloglib_js_len);
    Local<Script> script = Script::New(scriptText, String::New("pmloglib.js"));
    if (!script.IsEmpty()) {
        Local<Value> v = script->Run();
        Local<Function> f = Local<Function>::Cast(v);
        Local<Context> current = Context::GetCurrent();
        Handle<Value> argv[1];
        argv[0] = target;
        f->Call(current->Global(), 1, &argv[0]);
    } else {
        cerr << "Script was empty." << endl;
    }
}
开发者ID:Andolamin,项目名称:nodejs-module-webos-pmlog,代码行数:26,代码来源:pmloglib.cpp

示例8: wWinMain

int __stdcall wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow){
	int rt = -1;
	initContext();
	HandleScope store;
	runJSRes(IDR_JS_STRUCT,L"app.lib");
	Handle<Value> result = runJSFile(L"main.js",L"utf-8");
	if(!result.IsEmpty()){//只有出错的时候才会返回Empty, 否则即使没有返回值, result仍然是Undefined.
		Local<Object> gObj = getGlobal();
		Local<Function> main = GetJSVariant<Function>(gObj,L"main");
		if(main.IsEmpty()){
			//InnerMsg(L"没有发现 main 函数",MT_ERROR);
		}else if(!main->IsFunction()){
			//InnerMsg(L"main 不是函数",MT_ERROR);
		}else{
			TryCatch err;
			Handle<Value> args[1];
			args[0] = String::New((uint16_t*)lpCmdLine);
			Local<Value> r = main->Call(gObj,1,args);
			if(!err.Exception().IsEmpty()){
				ReportError(err);
			}else
				rt = r->Int32Value();
		}
	}
	releaseContext();
	return rt;
}
开发者ID:pgmsoul,项目名称:JSApp,代码行数:27,代码来源:main.cpp

示例9: locker

extern "C" void Java_io_neft_Native_renderer_1callAnimationFrame(JNIEnv * env, jobject obj) {
    using namespace renderer;

    // enter isolate
    Isolate* isolate = JS::GetIsolate();
    Locker locker(isolate);
    Isolate::Scope isolate_scope(isolate);
    HandleScope handle_scope(isolate);

    // get local context and enter it
    Local<Context> context = Local<Context>::New(isolate, JS::GetContext());
    Context::Scope context_scope(context);

    // call all registered functions
    const int length = animationFrameCalls.size();
    for (int i = 0; i < length; i++){
        Persistent<Function, CopyablePersistentTraits<Function>> func = animationFrameCalls[i];

        // get local function
        Local<Function> localFunc = Local<Function>::New(isolate, func);

        // call function
        localFunc->Call(context->Global(), 0, NULL);

        // clear persistent
        func.Reset();
    }

    // remove called functions
    animationFrameCalls.erase(animationFrameCalls.begin(), animationFrameCalls.begin() + length);
}
开发者ID:Neft-io,项目名称:neft,代码行数:31,代码来源:renderer.cpp

示例10: operator

            void operator()() {
                config_._scope.reset( dynamic_cast< V8Scope * >( globalScriptEngine->newScope() ) );
                v8::Locker v8lock(config_._scope->getIsolate());
                v8::Isolate::Scope iscope(config_._scope->getIsolate());
                HandleScope handle_scope;
                Context::Scope context_scope(config_._scope->getContext());

                BSONObj args = config_.args_;
                Local< v8::Function > f = v8::Function::Cast( *(config_._scope->mongoToV8Element(args.firstElement(), true)) );
                int argc = args.nFields() - 1;

                // TODO SERVER-8016: properly allocate handles on the stack
                Local<Value> argv[24];
                BSONObjIterator it(args);
                it.next();
                for(int i = 0; i < argc && i < 24; ++i) {
                    argv[i] = Local< Value >::New(config_._scope->mongoToV8Element(*it, true));
                    it.next();
                }
                TryCatch try_catch;
                Handle<Value> ret = f->Call(config_._scope->getContext()->Global(), argc, argv);
                if (ret.IsEmpty() || try_catch.HasCaught()) {
                    string e = toSTLString( &try_catch );
                    log() << "js thread raised exception: " << e << endl;
                    // v8 probably does something sane if ret is empty, but not going to assume that for now
                    ret = v8::Undefined();
                }
                // ret is translated to BSON to switch isolate
                BSONObjBuilder b;
                config_._scope->v8ToMongoElement(b, "ret", ret);
                config_.returnData_ = b.obj();
            }
开发者ID:ahopedog,项目名称:mongo,代码行数:32,代码来源:v8_utils.cpp

示例11: InvokeProperty

jsvalue JsContext::InvokeProperty(Persistent<Object>* obj, const uint16_t* name, jsvalue args)
{
    jsvalue v;

    Locker locker(isolate_);
    Isolate::Scope isolate_scope(isolate_);
    (*context_)->Enter();
        
    HandleScope scope;    
    TryCatch trycatch;
        
    Local<Value> prop = (*obj)->Get(String::New(name));
    if (prop.IsEmpty() || !prop->IsFunction()) {
        v = engine_->StringFromV8(String::New("property not found or isn't a function"));
        v.type = JSVALUE_TYPE_STRING_ERROR;   
    }
    else {
        std::vector<Local<Value> > argv(args.length);
        engine_->ArrayToV8Args(args, id_, &argv[0]);
        // TODO: Check ArrayToV8Args return value (but right now can't fail, right?)                   
        Local<Function> func = Local<Function>::Cast(prop);
        Local<Value> value = func->Call(*obj, args.length, &argv[0]);
        if (!value.IsEmpty()) {
            v = engine_->AnyFromV8(value);        
        }
        else {
            v = engine_->ErrorFromV8(trycatch);
        }         
    }
    
    (*context_)->Exit();
    
    return v;
}
开发者ID:killf,项目名称:V8Net,代码行数:34,代码来源:jscontext.cpp

示例12: handle_scope

// メソッド呼び出し共通処理
tjs_error
TJSInstance::callMethod(Isolate *isolate, Local<Object> &obj, const tjs_char *membername, tTJSVariant *result, tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis)
{
	HandleScope handle_scope(isolate);
	Context::Scope context_scope(getContext());
	TryCatch try_catch;

	Local<Object> context = membername ? obj : objthis ? toJSValue(isolate, tTJSVariant(objthis))->ToObject() : getContext()->Global();
	Local<Object> method  = membername ? obj->Get(String::NewFromTwoByte(isolate, membername))->ToObject() : obj;

	if (!method->IsFunction()) {
		return TJS_E_NOTIMPL;
	}
	
	// 関数抽出
	Local<Function> func = Local<Function>::Cast(method);
	// 引数
	Handle<Value> *argv = new Handle<Value>[numparams];
	for (int i=0;i<numparams;i++) {
		argv[i] = toJSValue(isolate, *param[i]);
	}
	Local<Value> ret = func->Call(context, numparams, argv);
	delete argv;
	
	if (ret.IsEmpty()) {
		JSEXCEPTION(isolate, &try_catch);
	} else {
		if (result) {
			*result = toVariant(isolate, ret);
		}
	}
	return TJS_S_OK;
}
开发者ID:xmoeproject,项目名称:X-moe,代码行数:34,代码来源:tjsinstance.cpp

示例13: 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);
}
开发者ID:ace68723,项目名称:smart,代码行数:27,代码来源:wrapper.cpp

示例14: Each

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;
            
    }
}
开发者ID:kneth,项目名称:DemoNodeExtension,代码行数:30,代码来源:book_wrap.cpp

示例15: ThrowException

Handle<Value> parseHandler(const Arguments& args) {
    HandleScope scope;

	bool validArguments = 
		args[0]->IsString() &&
		args[1]->IsString() && 
		args[2]->IsNumber() && 
		args[3]->IsFunction();

	if (!validArguments) {
        return ThrowException(Exception::TypeError(
			String::New("Invalid arguments! Pass the arguments in the following order: {string} text, {string} title, {int} outputlength, {function} callback.")));
    }

	Local<Array> nodes = Parser(std::string(*String::Utf8Value(args[0]->ToString())),
								std::string(*String::Utf8Value(args[1]->ToString())), 
								int(args[2]->Int32Value()),
								false);

	const unsigned argc = 2;
	Local<Value> argv[argc] = {
		Local<Value>::New(Null()),
		nodes
	};

	Local<Function> callback = Local<Function>::Cast(args[3]);

	callback->Call(Context::GetCurrent()->Global(), argc, argv);

    return Undefined();
}
开发者ID:deepsyx,项目名称:text-resume-analyzer,代码行数:31,代码来源:handler.cpp


注:本文中的Local::Call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。