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


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

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


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

示例1: main

int main(int argc, char** argv) {
	signal(SIGSEGV, AnsiSignalHandler);
//    printf("SILK V0.1\n");
    if (argc < 2) {
		printf("usage: %s file.js\n", argv[0]);
		exit(1);
    }
	
	char *startup = readFile(argv[1]);
	if (!startup) {
		printf("%s not found\n", argv[1]);
		exit(1);
	}
	if (startup[0] == '#' && startup[1] == '!') {
		startup[0] = startup[1] = '/';
	}
	init_global_object();
	{
		HandleScope scope;
		context = Persistent<Context>::New(Context::New(NULL, globalObject));
		Context::Scope context_scope(context);

//		Debug::EnableAgent("silkjs", 9222);
//		Debug::SetDebugMessageDispatchHandler(debugger, true);

		Handle<Script>init = Script::New(String::New("global=this;"), String::New("builtin"));
		init->Run();
		
		mainScript = Persistent<Script>::New(Script::Compile(String::New(startup), String::New(argv[1])));
		mainScript->Run();
		Handle<String> process_name = String::New("main");
		Handle<Value> process_val = context->Global()->Get(process_name);
		Handle<Function> process_fun = Handle<Function>::Cast(process_val);
		mainFunc = Persistent<Function>::New(process_fun);
		const int ac = argc-2;
		Handle<Value>av[ac];
		for (int i=2; i<argc; i++) {
			av[i-2] = String::New(argv[i]);
		}
//		printf("SILKJS running %s\n", argv[1]);
		mainFunc->Call(context->Global(), ac, av);
	}
}
开发者ID:sequoiar,项目名称:SilkJS,代码行数:43,代码来源:main.cpp

示例2: main

int main (int argc, char** argv) {
    signal(SIGSEGV, AnsiSignalHandler);
    //    printf("SILK V0.1\n");
    char *startup;
    const char *progName;
    signal(SIGSEGV, AnsiSignalHandler);
    signal(SIGINT, AnsiSignalHandler);

    if (argc < 2) {
        startup = readFile("/usr/local/silkjs/builtin/interpreter.js");
        if (!startup) {
            startup = readFile("/usr/share/silkjs/builtin/interpreter.js");
        }
        progName = "interpreter";
    }
    else {
        startup = readFile(argv[1]);
        progName = argv[1];
    }
    if (!startup) {
        printf("%s not found\n", argv[1]);
        exit(1);
    }
    if (startup[0] == '#' && startup[1] == '!') {
        startup[0] = startup[1] = '/';
    }
    
    // v8 command line switches
    const char *switches = "--harmony";
    V8::SetFlagsFromString(switches, strlen(switches));
    
    {
        //		Isolate *isolate = Isolate::New();
        //		isolate->Enter();
        //		Locker lock(isolate);
        Locker locker;
        HandleScope scope;

        init_global_object();
        V8::SetCaptureStackTraceForUncaughtExceptions(true, 50); // , StackTrace::kDetailed);
        context = Context::New(NULL, globalObject);
        Context::Scope context_scope(context);
        {
            Locker locker;
            //			Debug::SetDebugMessageDispatchHandler(debugger, true);
            //			Debug::EnableAgent("silkjs", 5858);

            Handle<Script>init = Script::New(String::New("global=this; module = {}; include('builtin/all.js');"), String::New("builtin"));
            init->Run();
            V8::SetCaptureStackTraceForUncaughtExceptions(true, 50, StackTrace::kDetailed);
            TryCatch tryCatch;
            mainScript = Persistent<Script>::New(Script::Compile(String::New(startup), String::New(progName)));
            if (mainScript.IsEmpty()) {
                ReportException(&tryCatch);
                exit(1);
            }
            Handle<Value>v = mainScript->Run();
            if (v.IsEmpty()) {
                ReportException(&tryCatch);
                exit(1);
            }
            Handle<String> process_name = String::New("main");
            Handle<Value> process_val = context->Global()->Get(process_name);
            if (!process_val.IsEmpty() && process_val->IsFunction()) {
                Handle<Function> process_fun = Handle<Function>::Cast(process_val);
                mainFunc = Persistent<Function>::New(process_fun);
                int ac = argc - 2;
                if (ac < 0) {
                    ac = 0;
                }
                Handle<Value>av[ac];
                for (int i = 2; i < argc; i++) {
                    av[i - 2] = String::New(argv[i]);
                }
                v = mainFunc->Call(context->Global(), ac, av);
                if (v.IsEmpty()) {
                    ReportException(&tryCatch);
                    exit(1);
                }
            }
        }
        context.Dispose();
    }
}
开发者ID:amigrave,项目名称:SilkJS,代码行数:84,代码来源:main.cpp


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