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


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

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


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

示例1: scope

JNIEXPORT jobject JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeEvalString
	(JNIEnv *env, jobject self, jstring source, jstring filename)
{
	HandleScope scope(V8Runtime::v8_isolate);
	titanium::JNIScope jniScope(env);

	Local<Value> jsSource = TypeConverter::javaStringToJsString(V8Runtime::v8_isolate, env, source);
	if (jsSource.IsEmpty() || !jsSource->IsString()) {
		LOGE(TAG, "Error converting Javascript string, aborting evalString");
		return NULL;
	}

	Local<Value> jsFilename = TypeConverter::javaStringToJsString(V8Runtime::v8_isolate, env, filename);

	TryCatch tryCatch(V8Runtime::v8_isolate);
	Local<Script> script = Script::Compile(jsSource.As<String>(), jsFilename.As<String>());
	Local<Value> result = script->Run();

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(V8Runtime::v8_isolate, tryCatch);
		V8Util::reportException(V8Runtime::v8_isolate, tryCatch, true);
		return NULL;
	}

	return TypeConverter::jsValueToJavaObject(V8Runtime::v8_isolate, env, result);
}
开发者ID:chmiiller,项目名称:titanium_mobile,代码行数:26,代码来源:V8Runtime.cpp

示例2: exec

void exec(Isolate *isolate){
    Isolate::Scope isolate_scope(isolate);

    // Create a stack-allocated handle scope.
    HandleScope handle_scope(isolate);

    // Create a new context.
    Local<Context> context = Context::New(isolate);

    // Enter the context for compiling and running the hello world script.
    Context::Scope context_scope(context);

    // Create a string containing the JavaScript source code.
    Local<String> source =
        String::NewFromUtf8(isolate, "'Hello' + ', World!'",
                            NewStringType::kNormal).ToLocalChecked();

    // Compile the source code.
    Local<Script> script = Script::Compile(context, source).ToLocalChecked();

    // Run the script to get the result.
    Local<Value> result = script->Run(context).ToLocalChecked();

    // Convert the result to an UTF8 string and print it.
    String::Utf8Value utf8(result);
    Print(" result --->", *utf8);
}
开发者ID:cesarvr,项目名称:v8-hacking,代码行数:27,代码来源:main.cpp

示例3:

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

示例4: v8test_eval

bool v8test_eval()
{
    BEGINTEST();

    HandleScope handle_scope;
    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);

    Local<Object> qmlglobal = Object::New();
    qmlglobal->Set(String::New("a"), Integer::New(1922));

    Local<Script> script = Script::Compile(String::New("eval(\"a\")"), NULL, NULL, 
                                           Handle<String>(), Script::QmlMode);
    
    TryCatch tc;
    Local<Value> result = script->Run(qmlglobal);

    VERIFY(!tc.HasCaught());
    VERIFY(result->Int32Value() == 1922);

cleanup:
    context.Dispose();

    ENDTEST();
}
开发者ID:yinyunqiao,项目名称:qtdeclarative,代码行数:25,代码来源:v8test.cpp

示例5: origin

ScriptValuePtr V8Engine::runScript(std::string script, std::string identifier)
{
    HandleScope handleScope;
    TryCatch tc;

    Local<String> source = String::New(script.c_str());

    // Build data

    ScriptOrigin origin(String::New(identifier.c_str()));

    // Compile the source code.

    Local<Script> code = Script::Compile(source, &origin);
    if (code.IsEmpty())
        handleException(tc);
  
    // Run the script to get the result.

    Local<Value> result = code->Run();
    if (result.IsEmpty())
        handleException(tc);

    return ScriptValuePtr( new V8Value(this, result) );
}
开发者ID:Amplifying,项目名称:intensityengine,代码行数:25,代码来源:script_engine_v8.cpp

示例6: ExecuteReturnString

stdext::ustring JavaScriptContext::ExecuteReturnString(const stdext::ustring & source, const stdext::ustring & name, stdext::ustring & error)
{
	stdext::ustring resultString;
	error = wstringToUstring(L"");
	Locker locker(m_isolate); 
	Isolate::Scope isolate_scope(m_isolate);
	{
		Context::Scope contextScope(*m_ctx);
		HandleScope scope;
		Local<String> scriptSource = String::New(reinterpret_cast<const uint16_t *>(source.c_str()));
		Local<String> scriptName = String::New(reinterpret_cast<const uint16_t *>(name.c_str()));
		Local<Script> script = Script::New(scriptSource, scriptName);
		Local<Value> result;
		{
			TryCatch tryCatch;
			result = script->Run();
			if (!result.IsEmpty())
			{
				String::Value value(result);
				resultString.append(reinterpret_cast<const char16_t *>(*value));
			}

			if (tryCatch.HasCaught())
			{
				error.append(wstringToUstring(L"Error running script: "));
				error.append(name);
				error.append(wstringToUstring(L" - "));
				String::Value stackTrace(tryCatch.StackTrace());
				error.append(reinterpret_cast<const char16_t*>(*stackTrace));
			}
		}
	}

	return resultString;
}
开发者ID:LogosBible,项目名称:V8Helper,代码行数:35,代码来源:JavascriptContext.cpp

示例7: newFunction

 Local< v8::Value > newFunction( const char *code ) {
     stringstream codeSS;
     codeSS << "____MontoToV8_newFunction_temp = " << code;
     string codeStr = codeSS.str();
     Local< Script > compiled = Script::New( v8::String::New( codeStr.c_str() ) );
     Local< Value > ret = compiled->Run();
     return ret;
 }
开发者ID:IlyaM,项目名称:mongo,代码行数:8,代码来源:v8_wrapper.cpp

示例8: ScriptValuePtr

void V8Engine::init()
{
    Logging::log(Logging::DEBUG, "V8Engine::init:\r\n");
    INDENT_LOG(Logging::DEBUG);

    HandleScope handleScope;

    // Create a template for the global object.
    Logging::log(Logging::DEBUG, "Creating global\r\n");

//    _global = ObjectTemplate::New();

    Logging::log(Logging::DEBUG, "Creating context\r\n");

    context = Context::New(); //NULL, _global);

    context->Enter();

    // Create our internal wrappers

    Logging::log(Logging::DEBUG, "Creating wrapper for global\r\n");

    globalValue = ScriptValuePtr(new V8Value(this, context->Global()));

#if 0
    // Setup debugger, if required - XXX Doesn't work

//    Debug::SetDebugEventListener(debuggerListener);
//    runFile("src/thirdparty/v8/src/debug-delay.js"); // FIXME: remove hardcoded src/..
    runFile("src/javascript/intensity/V8Debugger.js"); // FIXME: remove hardcoded src/javascript
             
    v8::Handle<v8::Value> result =
        ((V8Value*)(getGlobal()->getProperty("__debuggerListener").get()))->value;
    assert(result->IsObject());
    Local<Object> debuggerListener = result->ToObject();
    assert(debuggerListener->IsFunction());

    Debug::SetDebugEventListener(debuggerListener);

    runScript("Debug.setBrzzzzzzzzzeakOnException()");

    Local<String> source = String::New(
        "temp = function () { Debug.setBreakOnException(); return 5098; } "
    );
    Local<Script> code = Script::Compile(source);
    Local<Value> result2 = code->Run();
    printV8Value(result2, true);
    assert(result2->IsObject());
    Local<Object> obj = result2->ToObject();
    assert(obj->IsFunction());
    Local<Function> func = Function::Cast(*obj);
    Handle<Value> output = Debug::Call(func);
    printV8Value(output, true);
assert(0);
#endif

    Logging::log(Logging::DEBUG, "V8Engine::init complete.\r\n");
}
开发者ID:Amplifying,项目名称:intensityengine,代码行数:58,代码来源:script_engine_v8.cpp

示例9: Init

void Module::Init(Isolate *isolate)
{
	JEnv env;

	MODULE_CLASS = env.FindClass("com/tns/Module");
	assert(MODULE_CLASS != nullptr);

	RESOLVE_PATH_METHOD_ID = env.GetStaticMethodID(MODULE_CLASS, "resolvePath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
	assert(RESOLVE_PATH_METHOD_ID != nullptr);

	string requireFactoryScript =
	"(function () { "
	"	function require_factory(requireInternal, dirName) { "
	"		return function require(modulePath) { "
	"			if(global.__requireOverride) { "
	"				var result = global.__requireOverride(modulePath, dirName); "
	"				if(result) { "
	"					return result; "
	"				} "
	"			} "
	"			return requireInternal(modulePath, dirName); "
	"		} "
	"	} "
	"	return require_factory; "
	"})()";

	auto source = ConvertToV8String(requireFactoryScript);
	auto context = isolate->GetCurrentContext();

	Local<Script> script;
	auto maybeScript = Script::Compile(context, source).ToLocal(&script);

	assert(!script.IsEmpty());

	Local<Value> result;
	auto maybeResult = script->Run(context).ToLocal(&result);

	assert(!result.IsEmpty() && result->IsFunction());

	auto requireFactoryFunction = result.As<Function>();

	auto cache = GetCache(isolate);

	cache->RequireFactoryFunction = new Persistent<Function>(isolate, requireFactoryFunction);

	auto requireFuncTemplate = FunctionTemplate::New(isolate, RequireCallback);
	auto requireFunc = requireFuncTemplate->GetFunction();
	cache->RequireFunction = new Persistent<Function>(isolate, requireFunc);

	auto global = isolate->GetCurrentContext()->Global();
	auto globalRequire = GetRequireFunction(isolate, Constants::APP_ROOT_FOLDER_PATH);
	global->Set(ConvertToV8String("require"), globalRequire);
}
开发者ID:NathanaelA,项目名称:android-runtime,代码行数:53,代码来源:Module.cpp

示例10: RunScript

jobject NativePlatform::RunScript(JNIEnv *_env, jobject obj, jstring scriptFile)
{
	JEnv env(_env);
	jobject res = nullptr;

	auto isolate = g_isolate;
	Isolate::Scope isolate_scope(isolate);
	HandleScope handleScope(isolate);
	auto context = isolate->GetCurrentContext();

	auto filename = ArgConverter::jstringToString(scriptFile);
	auto src = File::ReadText(filename);
	auto source = ConvertToV8String(src);

	TryCatch tc;

	Local<Script> script;
	ScriptOrigin origin(ConvertToV8String(filename));
	auto maybeScript = Script::Compile(context, source, &origin).ToLocal(&script);

	if(tc.HasCaught()) {
		throw NativeScriptException(tc, "Script " + filename + " contains compilation errors!");
	}

	if (!script.IsEmpty())
	{
		Local<Value> result;
		auto maybeResult = script->Run(context).ToLocal(&result);

		if(tc.HasCaught()) {
			throw NativeScriptException(tc, "Error running script " + filename);
		}
		if (!result.IsEmpty())
		{
			res = ConvertJsValueToJavaObject(env, result, static_cast<int>(Type::Null));
		}
		else
		{
			DEBUG_WRITE(">>runScript maybeResult is empty");
		}
	}
	else
	{
		DEBUG_WRITE(">>runScript maybeScript is empty");
	}

	return res;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:48,代码来源:NativePlatform.cpp

示例11: execute

bool JSWrapper::execute( const char *scr, JSWrapperData *data, const char *fileName )
{
    HandleScope handle_scope( m_isolate );

    Local<String> source = String::NewFromUtf8( m_isolate, scr, NewStringType::kNormal ).ToLocalChecked();

    ScriptOrigin origin( v8::String::NewFromUtf8( m_isolate, fileName ? fileName : "Unknown" ) );
    MaybeLocal<Script> maybeScript = Script::Compile( m_context, source, &origin );

    bool success=false;

    if ( !maybeScript.IsEmpty() )
    {
        Local<Script> script = maybeScript.ToLocalChecked();        
        MaybeLocal<Value> maybeResult = script->Run(m_context);

        if ( !maybeResult.IsEmpty() )
        {
            Local<Value> result = maybeResult.ToLocalChecked();

            if ( data )
            {
                if ( result->IsNumber() )
                    data->setNumber( result->ToNumber()->Value() );
                else
                if ( result->IsString() )
                {
                    String::Utf8Value utf8( result );
                    data->setString( *utf8 );
                } else
                if ( result->IsBoolean() )
                    data->setBoolean( result->ToBoolean()->Value() );
                else                
                if ( result->IsObject() )
                    data->setObject( new JSWrapperObject( m_isolate, result->ToObject() ) );
                else
                if ( result->IsNull() )
                    data->setNull();
                else data->setUndefined();
            }

            success=true;
        } 
    }

    return success;
}
开发者ID:markusmoenig,项目名称:jsenginewrapper,代码行数:47,代码来源:jswrapper_v8.cpp

示例12: ExecuteString

	Local<Value> ExecuteString(Handle<String> source, Handle<Value> filename) {
		HandleScope scope;
		TryCatch tryCatch;
		
		Local<Script> script = Script::Compile(source, filename);
		if (script.IsEmpty()) {
			ReportException(&tryCatch);
			exit(1);
		}
		
		Local<Value> result = script->Run();
		if (result.IsEmpty()) {
			ReportException(&tryCatch);
			exit(1);
		}
		
		return scope.Close(result);
	} // ExecuteString
开发者ID:pablosole,项目名称:pet,代码行数:18,代码来源:sorrow.cpp

示例13: Undefined

	//C++版本的loadJSCode
	Handle<Value> LoadJsCode(LPCWSTR cjs,LPCWSTR fn){
		if(cjs==0) return Undefined();
		if(fn==0) fn = NULL_STR;
		HandleScope store;
		Handle<String> js = String::New((uint16_t*)cjs);
		Handle<Value> name = String::New((uint16_t*)fn);
		TryCatch err;

		Local<Script> script = Script::Compile(js,name);
		while(!script.IsEmpty()){
			Local<Value> result = script->Run(); 
			if(err.HasCaught()) break;//这两种判断方式可能是等价的。
			//if(result.IsEmpty()) break;
			return store.Close(result);
		}
		ReportError(err);
		return Undefined();
	}
开发者ID:pgmsoul,项目名称:GitLib,代码行数:19,代码来源:v8base.cpp

示例14: debuggerListener

void debuggerListener(DebugEvent event,
                       Handle<Object> exec_state,
                       Handle<Object> event_data,
                       Handle<Value> data)
{
    printf("************************ V8 debugger ***********************\r\n");

    HandleScope handleScope;

    Local<String> source = String::New(
        "temp = function (exec_state) { "
        "   log(WARNING, 'halp now'); "
        "   return serializeJSON(exec_state); "
        "} "
    );
    Local<Script> code = Script::Compile(source);
    Local<Value> result = code->Run();
//    printV8Value(result, true);
    assert(result->IsObject());
    Local<Object> obj = result->ToObject();
    assert(obj->IsFunction());
    Local<Function> func = Function::Cast(*obj);
    Handle<Value> output = Debug::Call(func, exec_state);
    printV8Value(output, true);


    printV8Value(exec_state, true);
    printV8Value(event_data, true);
    printV8Value(data, true);

/*

    Local<Object> _func = obj->Get(String::New(funcName.c_str()))->ToObject();
    assert(_func->IsFunction());

    Local<Function> func = Function::Cast(*_func);
*/


    assert(0);
}
开发者ID:Amplifying,项目名称:intensityengine,代码行数:41,代码来源:script_engine_v8.cpp

示例15: Undefined

Handle<Value> V8Util::executeString(Handle<String> source, Handle<Value> filename)
{
	HandleScope scope;
	TryCatch tryCatch;

	Local<Script> script = Script::Compile(source, filename);
	if (script.IsEmpty()) {
		LOGF(TAG, "Script source is empty");
		reportException(tryCatch, true);
		return Undefined();
	}

	Local<Value> result = script->Run();
	if (result.IsEmpty()) {
		LOGF(TAG, "Script result is empty");
		reportException(tryCatch, true);
		return Undefined();
	}

	return scope.Close(result);
}
开发者ID:1rp,项目名称:titanium_mobile,代码行数:21,代码来源:V8Util.cpp


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