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


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

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


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

示例1: cfg

	//*,{
	//	"type":"function",
	//	"name":"setConfig(callback,[filename])",
	//	"text":"读取或设置配置文件,配置文件是一个 Json 格式的文本文件,可以是 utf-8 获取 ansi 编码。",
	//	"param":[
	//		{
	//			"type":"function",
	//			"name":"callback(cfg)",
	//			"text":"setConfig 函数如果成功,会触发这个回调函数,cfg 是一个对象,它的属性就是配置内容,对这个对象的任何更改最后都会作为 Json 格式保存到配置文件。"
	//		},
	//		{
	//			"type":"string",
	//			"name":"[filename]",
	//			"text":"配置文件名,缺省是和脚本同路径同名的一个后缀为“.json”的文本文件,如果指定了文件名,则读取和保存对应的文件。"
	//		}
	//	],
	//	"return":{
	//		"type":"boolean",
	//		"text":"如果成功打开了配置文件,函数返回 true,否则返回 undefined。"
	//	}
	//}//*
	Handle<Value> setConfig(const Arguments& args){
		HandleScope stack;
		while(true){
			if(args.Length()<1) break;
			if(!args[0]->IsFunction()) break;
			cs::String file;
			if(args.Length()>1)
				GetString(args[1],file);
			cs::Config cfg(file);
			cs::Json* json = cfg.Lock();
			if(!json) break;

			json->ToString(file,false);
			Handle<Object> glb = GetGlobal();
			Handle<Object> JSON = glb->Get(NEW_STR(JSON))->ToObject();
			Handle<Function> parse = Handle<Function>::Cast(JSON->Get(NEW_STR(parse)));
			Handle<Function> stringify = Handle<Function>::Cast(JSON->Get(NEW_STR(stringify)));
			Handle<Function> callback = Handle<Function>::Cast(args[0]);
			Handle<Value> argv[3];
			argv[0] = NEW_WSTR(file.Handle());
			Handle<Value> v = parse->Call(JSON,1,argv);
			if(v.IsEmpty()||!v->IsObject()) v = Object::New();
			argv[0] = v;
			CallFunc(glb,callback,1,argv);
			v = stringify->Call(JSON,1,argv);
			GetString(v,file);
			json->Parse(file);
			return True();
		}
		return Undefined();
	}
开发者ID:pgmsoul,项目名称:GitLib,代码行数:52,代码来源:v8base.cpp

示例2: jniScope

JNIEXPORT jboolean JNICALL
Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeFireEvent
	(JNIEnv *env, jobject jEmitter, jlong ptr, jstring event, jobject data)
{
	ENTER_V8(V8Runtime::globalContext);
	JNIScope jniScope(env);

	Handle<Value> jsEvent = TypeConverter::javaStringToJsString(event);

#ifdef TI_DEBUG
	String::Utf8Value eventName(jsEvent);
	LOGV(TAG, "firing event \"%s\"", *eventName);
#endif

	Handle<Object> emitter;
	if (ptr != 0) {
		emitter = Persistent<Object>((Object *) ptr);
	} else {
		emitter = TypeConverter::javaObjectToJsValue(jEmitter)->ToObject();
	}

	Handle<Value> fireEventValue = emitter->Get(EventEmitter::emitSymbol);
	if (!fireEventValue->IsFunction()) {
		return JNI_FALSE;
	}

	Handle<Function> fireEvent = Handle<Function>::Cast(fireEventValue->ToObject());

	Handle<Value> jsData = TypeConverter::javaObjectToJsValue(data);
	Handle<Value> result;

	TryCatch tryCatch;
	if (jsData->IsNull()) {
		Handle<Value> args[] = { jsEvent };
		result = fireEvent->Call(emitter, 1, args);
	} else {
		Handle<Value> args[] = { jsEvent, jsData };
		result = fireEvent->Call(emitter, 2, args);
	}

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(tryCatch);
		V8Util::reportException(tryCatch);
	} else if (result->IsTrue()) {
		return JNI_TRUE;
	}
	return JNI_FALSE;
}
开发者ID:AppceleratorCasts,项目名称:titanium_mobile,代码行数:48,代码来源:V8Object.cpp

示例3: isMatchCandidate

  bool isMatchCandidate(ConstElementPtr e)
  {
    Context::Scope context_scope(_script->getContext());
    HandleScope handleScope;
    Persistent<Object> plugin = getPlugin();
    Handle<String> isMatchCandidateStr = String::New("isMatchCandidate");
    if (plugin->Has(isMatchCandidateStr) == false)
    {
      throw HootException("Error finding 'isMatchCandidate' function.");
    }
    Handle<v8::Value> value = plugin->Get(isMatchCandidateStr);
    if (value->IsFunction() == false)
    {
      throw HootException("isMatchCandidate is not a function.");
    }
    Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value);
    Handle<Value> jsArgs[2];

    int argc = 0;
    jsArgs[argc++] = OsmMapJs::create(_map);
    jsArgs[argc++] = ElementJs::New(e);

    Handle<Value> f = func->Call(plugin, argc, jsArgs);

    return f->BooleanValue();
  }
开发者ID:mitulvpatel,项目名称:hootenanny,代码行数:26,代码来源:ScriptMatchCreator.cpp

示例4: argc

static
void
DNSSD_API
OnServiceRegistered(DNSServiceRef sdRef, DNSServiceFlags flags,
                    DNSServiceErrorType errorCode, const char * name,
                    const char * serviceType, const char * domain, void * context)
{
    if ( ! context) return;

    HandleScope scope;
    ServiceRef * serviceRef = static_cast<ServiceRef*>(context);
    Handle<Function> callback = serviceRef->GetCallback();
    Handle<Object> this_ = serviceRef->GetThis();

    if ( ! callback.IsEmpty() && ! this_.IsEmpty()) {
        const size_t argc(7);
        Local<Value> args[argc];
        args[0] = Local<Object>::New(serviceRef->handle_);
        args[1] = Integer::New(flags);
        args[2] = Integer::New(errorCode);
        args[3] = stringOrUndefined(name);
        args[4] = stringOrUndefined(serviceType);
        args[5] = stringOrUndefined(domain);
        if (serviceRef->GetContext().IsEmpty()) {
            args[6] = Local<Value>::New(Undefined());
        } else {
            args[6] = Local<Value>::New(serviceRef->GetContext());
        }
        callback->Call(this_, argc, args);
    }
}
开发者ID:node-migrator-bot,项目名称:node_mdns,代码行数:31,代码来源:dns_service_register.cpp

示例5: TargetCallback

void TargetCallback(Isolate* isolate, Persistent<Object>* target, WeakRef* arg) {
    HandleScope scope;
    if(!arg->target.IsNearDeath()) {
        return;
    }

    Local<Object> fnthis = Local<Object>::New(Isolate::GetCurrent(), arg->target);
    Handle<Value> argv[1];
    argv[0] = fnthis;

    // invoke any listening callbacks
    Local<Array> callbacks = Local<Array>::New(Isolate::GetCurrent(), arg->callbacks);
    uint32_t len = callbacks->Length();
    for (uint32_t i = 0; i < len; i++) {
        Handle<Function> cb = Handle<Function>::Cast(callbacks->Get(i));
        TryCatch try_catch;
        cb->Call(fnthis, 1, argv);
        if (try_catch.HasCaught()) {
            ThrowException(String::New("TargetCallback"));
        }
    }

    arg->target.Dispose();
    arg->target.Clear();
    arg->callbacks.Dispose();
    arg->callbacks.Clear();
}
开发者ID:hurry07,项目名称:v8,代码行数:27,代码来源:WeakRef.cpp

示例6: operator

 void operator()() {
     Locker l;
     HandleScope handle_scope;
     Handle< Context > context;
     Handle< v8::Function > fun;
     auto_ptr< V8Scope > scope;
     if ( config_.newScope_ ) {
         scope.reset( dynamic_cast< V8Scope * >( globalScriptEngine->newScope() ) );
         context = scope->context();
         // A v8::Function tracks the context in which it was created, so we have to
         // create a new function in the new context.
         Context::Scope baseScope( baseContext_ );
         string fCode = toSTLString( config_.f_->ToString() );
         Context::Scope context_scope( context );
         fun = scope->__createFunction( fCode.c_str() );
     } else {
         context = baseContext_;
         Context::Scope context_scope( context );
         fun = config_.f_;
     }
     Context::Scope context_scope( context );
     boost::scoped_array< Local< Value > > argv( new Local< Value >[ config_.args_.size() ] );
     for( unsigned int i = 0; i < config_.args_.size(); ++i )
         argv[ i ] = Local< Value >::New( config_.args_[ i ] );
     TryCatch try_catch;
     Handle< Value > ret = fun->Call( context->Global(), config_.args_.size(), 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();
     }
     config_.returnData_ = Persistent< Value >::New( ret );
 }
开发者ID:IlyaM,项目名称:mongo,代码行数:34,代码来源:v8_utils.cpp

示例7:

/* static */
void V8Runtime::bootstrap(Local<Object> global)
{
	EventEmitter::Initialize();
	krollGlobalObject = Persistent<Object>::New(Object::New());

	DEFINE_METHOD(krollGlobalObject, "log", krollLog);
	DEFINE_METHOD(krollGlobalObject, "binding", KrollBindings::getBinding);
	DEFINE_TEMPLATE(krollGlobalObject, "EventEmitter", EventEmitter::constructorTemplate);

	krollGlobalObject->Set(String::NewSymbol("runtime"), String::New("v8"));

	LOG_TIMER(TAG, "Executing kroll.js");

	TryCatch tryCatch;
	Handle<Value> result = V8Util::executeString(KrollBindings::getMainSource(), String::New("kroll.js"));

	if (tryCatch.HasCaught()) {
		V8Util::reportException(tryCatch, true);
	}
	if (!result->IsFunction()) {
		LOGF(TAG, "kroll.js result is not a function");
		V8Util::reportException(tryCatch, true);
	}

	Handle<Function> mainFunction = Handle<Function>::Cast(result);
	Local<Value> args[] = { Local<Value>::New(krollGlobalObject) };
	mainFunction->Call(global, 1, args);

	if (tryCatch.HasCaught()) {
		V8Util::reportException(tryCatch, true);
		LOGE(TAG, "Caught exception while bootstrapping Kroll");
	}
}
开发者ID:b0morris,项目名称:titanium_mobile,代码行数:34,代码来源:V8Runtime.cpp

示例8: Write

IOBasicTypes::LongBufferSizeType ObjectByteWriterWithPosition::Write(const IOBasicTypes::Byte* inBuffer,IOBasicTypes::LongBufferSizeType inBufferSize)
{
    HandleScope handle;
    
    Handle<Object> anArray = Array::New((int)inBufferSize);
    for(int i=0;i<(int)inBufferSize;++i)
        anArray->Set(Number::New(i),Number::New(inBuffer[i]));
    
    Handle<Value> value = mObject->Get(String::New("write"));
    if(value->IsUndefined() || !value->IsFunction())
    {
		ThrowException(Exception::TypeError(String::New("write is not a function, it should be you know...")));
        return 0;
    }
    Handle<Function> func = Handle<Function>::Cast(value);
    
    Handle<Value> args[1];
    args[0] = anArray;
    
    Handle<Value> result = func->Call(mObject, 1, args);
    if(result.IsEmpty())
    {
		ThrowException(Exception::TypeError(String::New("wrong return value. it's empty. return the number of written characters")));
		return 0;
    }
    else if(result->IsNumber())
    {
        return result->ToNumber()->Uint32Value();
    }
    else
    {
		ThrowException(Exception::TypeError(String::New("wrong return value. write should return the number of written characters")));
		return 0;
    }
}
开发者ID:abyr,项目名称:HummusJS,代码行数:35,代码来源:ObjectByteWriterWithPosition.cpp

示例9: context_scope

Handle<Value> ScriptMatch::_call(const ConstOsmMapPtr& map, Handle<Object> plugin)
{
  HandleScope handleScope;
  Context::Scope context_scope(_script->getContext());

  plugin =
    Handle<Object>::Cast(_script->getContext()->Global()->Get(String::New("plugin")));
  Handle<v8::Value> value = plugin->Get(String::New("matchScore"));
  Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value);
  Handle<Value> jsArgs[3];

  if (func.IsEmpty() || func->IsFunction() == false)
  {
    throw IllegalArgumentException("matchScore must be a valid function.");
  }

  Handle<Object> mapObj = OsmMapJs::create(map);

  int argc = 0;
  jsArgs[argc++] = mapObj;
  jsArgs[argc++] = ElementJs::New(map->getElement(_eid1));
  jsArgs[argc++] = ElementJs::New(map->getElement(_eid2));

  TryCatch trycatch;
  Handle<Value> result = func->Call(plugin, argc, jsArgs);
  HootExceptionJs::checkV8Exception(result, trycatch);

  return handleScope.Close(result);
}
开发者ID:Nanonid,项目名称:hootenanny,代码行数:29,代码来源:ScriptMatch.cpp

示例10: ThrowException

v8::Handle<v8::Value> V8::parseJsonConfigurationFile(const v8::Arguments &args) {
	if (args.Length() < 1) return v8::Undefined();

	HandleScope scope;

	std::string filename = System::resourceLocation() + V8::StringToStdString(
		args[0]->ToString()
	);
	if (!boost::filesystem::exists(boost::filesystem3::path(filename))) {

		return ThrowException(
			String::New(("parseJsonConfigurationFile(): " + filename + " doesn't exist!").c_str())
		);
	}

	Handle<Value> callbackArgs[] = {
		parseJson(v8::String::New(System::fileToString(filename).c_str()))
	};

	Handle<Function> callback = args[1].As<Function>();

	callback->Call(Context::GetCurrent()->Global(), 1, callbackArgs);

	return Undefined();
}
开发者ID:cha0s,项目名称:Worlds-Beyond,代码行数:25,代码来源:wbv8.cpp

示例11: customScriptInit

  /*
   * This is meant to run one time when the match creator is initialized.
   */
  void customScriptInit()
  {
    Context::Scope context_scope(_script->getContext());
    HandleScope handleScope;

    Persistent<Object> plugin = getPlugin();
    Handle<String> initStr = String::New("init");
    if (plugin->Has(initStr) == false)
    {
      throw HootException("Error finding 'init' function.");
    }
    Handle<v8::Value> value = plugin->Get(initStr);
    if (value->IsFunction() == false)
    {
      throw HootException("init is not a function.");
    }

    Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value);
    Handle<Value> jsArgs[1];
    int argc = 0;
    HandleScope scope;
    assert(_map.get());
    OsmMapPtr copiedMap(new OsmMap(_map));
    jsArgs[argc++] = OsmMapJs::create(copiedMap);

    func->Call(plugin, argc, jsArgs);

    //this is meant to have been set externally in a js rules file
    _searchRadius = getNumber(plugin, "searchRadius", -1.0, 15.0);
  }
开发者ID:mitulvpatel,项目名称:hootenanny,代码行数:33,代码来源:ScriptMatchCreator.cpp

示例12: argc

void
OnEnumeration(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
        DNSServiceErrorType errorCode, const char * replyDomain, void * context)
{
    if ( ! context) return;

    HandleScope scope;
    ServiceRef * serviceRef = static_cast<ServiceRef*>(context);
    Handle<Function> callback = serviceRef->GetCallback();
    Handle<Object> this_ = serviceRef->GetThis();

    const size_t argc(6);
    Local<Value> args[argc];
    args[0] = Local<Object>::New(serviceRef->handle_);
    args[1] = Integer::New(flags);
    args[2] = Integer::New(interfaceIndex);
    args[3] = Integer::New(errorCode);
    args[4] = String::New(replyDomain);
    if (serviceRef->GetContext().IsEmpty()) {
        args[5] = Local<Value>::New(Null());
    } else {
        args[5] = Local<Value>::New(serviceRef->GetContext());
    }
    callback->Call(this_, argc, args);
}
开发者ID:baiyunping333,项目名称:node_mdns,代码行数:25,代码来源:dns_service_enumerate_domains.cpp

示例13: command

static Handle<Value> NodePopen(const Arguments& args) {
  
  HandleScope scope;
  
  int length = args.Length();
  
  // Expect a callback function for stdout
  Handle<String> Command = Handle<String  >::Cast(args[0]);
  Handle<Function> cbout = Handle<Function>::Cast(args[1]);
  
  // Get Command
  char* command( *v8::String::Utf8Value(Command) );
  
  char buffer[MAX_BUFFER];
  
  FILE *stream = popen( command, "r" );
  
  Handle<Value> argv[1];
  while ( std::fgets(buffer, MAX_BUFFER, stream) != NULL )
  {
    // Do callback here!
    argv[0] = String::New( buffer );
    if(length>1)
      cbout->Call(Context::GetCurrent()->Global(), 1, argv);
  }
  
  int code = pclose(stream);
  
  return scope.Close(Integer::New(code));
}
开发者ID:groundwater,项目名称:node-allsync,代码行数:30,代码来源:main.cpp

示例14: jniScope

JNIEXPORT void JNICALL
Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeSetWindow
	(JNIEnv *env, jobject javaKrollWindow, jlong ptr, jobject javaWindow)
{
	ENTER_V8(V8Runtime::globalContext);
	titanium::JNIScope jniScope(env);

	Handle<Object> jsKrollWindow;
	if (ptr != 0) {
		jsKrollWindow = Persistent<Object>((Object *) ptr);
	} else {
		jsKrollWindow = TypeConverter::javaObjectToJsValue(env, javaKrollWindow)->ToObject();
	}

	Handle<Value> setWindowValue = jsKrollWindow->Get(String::New("setWindow"));
	if (!setWindowValue->IsFunction()) {
		return;
	}

	Handle<Function> setWindow = Handle<Function>::Cast(setWindowValue->ToObject());

	Handle<Value> jsWindow = TypeConverter::javaObjectToJsValue(env, javaWindow);

	TryCatch tryCatch;
	if (!jsWindow->IsNull()) {
		Handle<Value> args[] = { jsWindow };
		setWindow->Call(jsKrollWindow, 1, args);
	}

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(tryCatch);
		V8Util::reportException(tryCatch);
	}
}
开发者ID:mohdaminyuddin,项目名称:titanium_mobile,代码行数:34,代码来源:V8Object.cpp

示例15: Null

Handle<Value> CursorWrap::getCommon(const Arguments& args, MDB_cursor_op op, void (*setKey)(const Arguments& args, MDB_val&), Handle<Value> (*convertFunc)(MDB_val &data)) {
    int al = args.Length();
    CursorWrap *cw = ObjectWrap::Unwrap<CursorWrap>(args.This());
    MDB_val key, data;
    
    if (setKey) {
        setKey(args, key);
    }
    
    int rc = mdb_cursor_get(cw->cursor, &key, &data, op);
    
    if (rc == MDB_NOTFOUND) {
        return Null();
    }
    else if (rc != 0) {
        ThrowException(Exception::Error(String::New(mdb_strerror(rc))));
        return Undefined();
    }
    
    if (convertFunc && al > 0 && args[al - 1]->IsFunction()) {
        // In this case, we expect the key/data pair to be correctly filled
        const unsigned argc = 2;
        Handle<Value> argv[argc] = { keyToHandle(key), convertFunc(data) };
        Handle<Function> callback = Handle<Function>::Cast(args[args.Length() - 1]);
        return callback->Call(Context::GetCurrent()->Global(), argc, argv);
    }
    
    return Undefined();
}
开发者ID:jahewson,项目名称:node-lmdb,代码行数:29,代码来源:cursor.cpp


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