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


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

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


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

示例1: initialize

// Fetch the onDraw function from the global context.
bool JsContext::initialize() {

    // Create a stack-allocated handle scope.
    HandleScope handleScope(fGlobal->getIsolate());

    // Create a local context from our global context.
    Local<Context> context = fGlobal->getContext();

    // Enter the scope so all operations take place in the scope.
    Context::Scope contextScope(context);

    v8::TryCatch try_catch;

    Handle<String> fn_name = String::NewFromUtf8(
        fGlobal->getIsolate(), "onDraw");
    Handle<Value> fn_val = context->Global()->Get(fn_name);

    if (!fn_val->IsFunction()) {
        printf("Not a function.\n");
        return false;
    }

    // It is a function; cast it to a Function.
    Handle<Function> fn_fun = Handle<Function>::Cast(fn_val);

    // Store the function in a Persistent handle, since we also want that to
    // remain after this call returns.
    fOnDraw.Reset(fGlobal->getIsolate(), fn_fun);

    return true;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:32,代码来源:JsContext.cpp

示例2: 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

示例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: CallJSFunction

void CallJSFunction(JavaScriptCompiler &jsc,  
		    JavaScriptSource *source,
		    const char *name)
{
	HandleScope scope(jsc.GetIsolate());
	Local<Context> ctx = Local<Context>::New(jsc.GetIsolate(), source->ctx_);
	Context::Scope context_scope(ctx);
	Handle<Value> rewriteFuncValue = ctx->Global()->Get(String::NewSymbol(name));
	if (!rewriteFuncValue.IsEmpty() && rewriteFuncValue->IsFunction()) {
		const int argc = 0;
		Handle<Function> initFunc = Handle<Function>::Cast(rewriteFuncValue);
		Handle<Value> ret = initFunc->Call(ctx->Global(), argc, NULL);
		String::AsciiValue ascii(ret);
		ASSERT_STREQ("OK", *ascii);
	}
}
开发者ID:Nightaway,项目名称:dragon,代码行数:16,代码来源:testJavaScriptCompiler.cpp

示例5: handle_scope

 TEST_F(JSDeviceTest, createTemplate) {
     HandleScope handle_scope(isolate);
     Local<Context> context = Context::New(isolate, nullptr);
     Context::Scope context_scope(context);
     Handle<Object> global = context->Global();
     jsDevice->initJsObjectsTemplate(isolate, global);
 }
开发者ID:paoloach,项目名称:zdomus,代码行数:7,代码来源:JSDeviceTest.cpp

示例6: Init

void Server::Init(Local<Context> ctx){
	isolate = ctx->GetIsolate();
	context.Reset(ctx->GetIsolate(), ctx);


	ifstream serverFile("js/samp.js/Server.js", std::ios::in);
	if (!serverFile){
		sjs::logger::error("Missing required file Server.js");
		SAMPJS::Shutdown();
	}
	std::string serverSource((std::istreambuf_iterator<char>(serverFile)), std::istreambuf_iterator<char>());
	SAMPJS::ExecuteCode(ctx, "Server.js", serverSource);

	SAMPJS::ExecuteCode(ctx, "$server", "var $server = new Server();");

	JS_Object global(ctx->Global());

	global.Set("CallNative", Server::JS_CallNative);

	JS_Object server(global.getObject("$server"));

	JS_Object memory(server.getObject("memory"));

	memory.Set("current", Server::JS_CurrentMemory);
	memory.Set("peak", Server::JS_PeakMemory);
	
	server.Set("Debug", Utils::JS_Debug);

	
}
开发者ID:steilman,项目名称:samp.js,代码行数:30,代码来源:Server.cpp

示例7: 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

示例8: tryCatch

/* static */
void V8Runtime::bootstrap(Local<Context> context)
{
	Isolate* isolate = context->GetIsolate();
	EventEmitter::initTemplate(context);

	Local<Object> kroll = Object::New(isolate);
	krollGlobalObject.Reset(isolate, kroll);
	Local<Array> mc = Array::New(isolate);
	moduleContexts.Reset(isolate, mc);

	KrollBindings::initFunctions(kroll, context);

	SetMethod(isolate, kroll, "log", krollLog);
	// Move this into the EventEmitter::initTemplate call?
	Local<FunctionTemplate> eect = Local<FunctionTemplate>::New(isolate, EventEmitter::constructorTemplate);
	{
		v8::TryCatch tryCatch(isolate);
		Local<Function> eventEmitterConstructor;
		MaybeLocal<Function> maybeEventEmitterConstructor = eect->GetFunction(context);
		if (!maybeEventEmitterConstructor.ToLocal(&eventEmitterConstructor)) {
			titanium::V8Util::fatalException(isolate, tryCatch);
			return;
		}
		kroll->Set(NEW_SYMBOL(isolate, "EventEmitter"), eventEmitterConstructor);
	}

	kroll->Set(NEW_SYMBOL(isolate, "runtime"), STRING_NEW(isolate, "v8"));
	kroll->Set(NEW_SYMBOL(isolate, "DBG"), v8::Boolean::New(isolate, V8Runtime::DBG));
	kroll->Set(NEW_SYMBOL(isolate, "moduleContexts"), mc);

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

	TryCatch tryCatch(isolate);
	Local<Value> result = V8Util::executeString(isolate, KrollBindings::getMainSource(isolate), STRING_NEW(isolate, "ti:/kroll.js"));

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

	// Add a reference to the global object
	Local<Object> global = context->Global();

	// Expose the global object as a property on itself
	// (Allows you to set stuff on `global` from anywhere in JavaScript.)
	global->Set(NEW_SYMBOL(isolate, "global"), global);

	Local<Function> mainFunction = result.As<Function>();
	Local<Value> args[] = { kroll };
	mainFunction->Call(context, global, 1, args);

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

示例9: createTemplateTest

        void JSAttributeTest::createTemplateTest(std::shared_ptr<JSZAttribute> &jsZAttribute) {
            HandleScope handle_scope(isolate);
            Local<Context> context = Context::New(isolate, nullptr);
            Context::Scope context_scope(context);

            Handle<Object> global = context->Global();
            jsZAttribute->initJsObjectsTemplate(isolate, global);
        }
开发者ID:paoloach,项目名称:zdomus,代码行数:8,代码来源:JSAttributeTest.cpp

示例10: process_events

void process_events( jsBrowser* js_exec, base_entity_ptr entity, bool is_jquery )
{
    /* simplest variant - recursive descent through DOM-tree */
    Local<Context> ctx = Context::GetCurrent();
    std::string src;
    std::string name;
    // get on... events
    LOG4CXX_INFO(iLogger::GetLogger(), _T("jsWindow::process_events entity = ") << entity->Name());

    AttrMap::iterator attrib = entity->attr_list().begin();

    while(attrib != entity->attr_list().end() ) {
        name = (*attrib).first;
        src = (*attrib).second;

        Local<Object> obj = Local<Object>::New(v8_wrapper::wrap_entity(boost::shared_dynamic_cast<html_entity>(entity))->m_this);
        ctx->Global()->Set(String::New("__evt_target__"), obj);
        if (boost::istarts_with(name, "on")) {
            // attribute name started with "on*" - this is the event
            LOG4CXX_INFO(iLogger::GetLogger(), _T("audit_jscript::process_events - ") << name << _T(" source = ") << src);
            boost::trim(src);
            if (! boost::istarts_with(src, "function")) {
                src = "__evt_target__.__event__" + name + "=function(){" + src + "}";
            } else {
                src = "__evt_target__.__event__" + name + "=" + src;
            }
            js_exec->execute_string(src, "", true, true);
            js_exec->execute_string("__evt_target__.__event__" + name + "()", "", true, true);
        }
        if (boost::istarts_with(src, "javascript:")) {
            LOG4CXX_INFO(iLogger::GetLogger(), _T("jsWindow::process_events (proto) - ") << name << _T(" source = ") << src);
            src = src.substr(11); // skip "javascript:"
            src = "__evt_target__.__event__=function(){ " + src + " }";
            js_exec->execute_string(src, "", true, true);
            js_exec->execute_string("__evt_target__.__event__()", "", true, true);
        }


        ++attrib;
    }

    if (is_jquery) {
        js_exec->execute_string("RunJqueryEvents(__evt_target__)", "", true, true);
    }

    // and process all children
    entity_list chld = entity->Children();
    entity_list::iterator  it;

    for(size_t i = 0; i < chld.size(); i++) {
        std::string nm = chld[i]->Name();
        if (nm != "#text" && nm != "#comment") {
            process_events(js_exec, chld[i], is_jquery);
        }
    }
    // all results will be processed in the caller parse_scripts function
}
开发者ID:abhishekbhalani,项目名称:webapptools,代码行数:57,代码来源:jsWindow.cpp

示例11: scope

TEST(JavaScriptCompiler, Load) {
	JavaScriptCompiler jsc;
	jsc.Load(DRAGON_TEST_PATH, "testJavaScriptCompiler/subdir");
        SourceMap &source= jsc.GetSource();
        JavaScriptSource *source1 = source["1"];

	HandleScope scope(jsc.GetIsolate());
	Local<Context> ctx = Local<Context>::New(jsc.GetIsolate(), source1->ctx_);
	Context::Scope context_scope(ctx);
	Handle<Value> rewriteFuncValue = ctx->Global()->Get(String::NewSymbol("test1"));
	if (!rewriteFuncValue.IsEmpty() && rewriteFuncValue->IsFunction()) {
		const int argc = 0;
		Handle<Function> initFunc = Handle<Function>::Cast(rewriteFuncValue);
		Handle<Value> ret = initFunc->Call(ctx->Global(), argc, NULL);
		String::AsciiValue ascii(ret);
		ASSERT_STREQ("OK1", *ascii);
	}
}
开发者ID:Nightaway,项目名称:dragon,代码行数:18,代码来源:testJavaScriptCompiler.cpp

示例12:

shared_ptr<Server> Server::GetInstance(Local<Context> context){
	sjs::logger::debug("Getting Instance");
	Local<Object> self = Local<Object>::Cast(context->Global()->Get(STRING2JS(context->GetIsolate(), "$sampjs")));
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
	Server* server = static_cast<Server*>(ptr);
	sjs::logger::debug("Casting");
	return make_shared<Server>(*server);
}
开发者ID:damospiderman,项目名称:samp.js,代码行数:9,代码来源:Server.cpp

示例13: handle_scope

TEST_F( JSRowTest, createTemplate) {
	JSRow jsRow;
	HandleScope handle_scope(isolate);
	Local<Context> context = Context::New(isolate, nullptr);
	Context::Scope context_scope(context);

	Handle<Object> global = context->Global();
	jsRow.initJsObjectsTemplate(isolate, global);
	jsRow.resetPersistences();
}
开发者ID:paoloach,项目名称:zdomus,代码行数:10,代码来源:JSRowTest.cpp

示例14: handle_scope

/* for geomtransform, we don't have the mapObj */
shapeObj *msV8TransformShape(shapeObj *shape, const char* filename)
{
  TryCatch try_catch;
  Isolate *isolate = Isolate::GetCurrent();
  V8Context *v8context = (V8Context*)isolate->GetData();

  HandleScope handle_scope(v8context->isolate);

  /* execution context */
  Local<Context> context = Local<Context>::New(v8context->isolate, v8context->context);
  Context::Scope context_scope(context);
  Handle<Object> global = context->Global();

  Shape* shape_ = new Shape(shape);
  shape_->setLayer(v8context->layer);
  shape_->disableMemoryHandler();
  Handle<Value> ext = External::New(shape_);
  global->Set(String::New("shape"),
              Shape::Constructor()->NewInstance(1, &ext));

  msV8ExecuteScript(filename);
  Handle<Value> value = global->Get(String::New("geomtransform"));
  if (value->IsUndefined()) {
    msDebug("msV8TransformShape: Function 'geomtransform' is missing.\n");
    return NULL;
  }
  Handle<Function> func = Handle<Function>::Cast(value);
  Handle<Value> result = func->Call(global, 0, 0);
  if (result.IsEmpty() && try_catch.HasCaught()) {
    msV8ReportException(&try_catch);
  }

  if (!result.IsEmpty() && result->IsObject()) {
    Handle<Object> obj = result->ToObject();
    if (obj->GetConstructorName()->Equals(String::New("shapeObj"))) {
      Shape* new_shape = ObjectWrap::Unwrap<Shape>(result->ToObject());
      if (shape == new_shape->get()) {
        shapeObj *new_shape_ = (shapeObj *)msSmallMalloc(sizeof(shapeObj));
        msInitShape(new_shape_);
        msCopyShape(shape, new_shape_);
        return new_shape_;
      }
      else {
        new_shape->disableMemoryHandler();
        return new_shape->get();
      }
    }
  }

  return NULL;
}
开发者ID:BentleySystems,项目名称:mapserver,代码行数:52,代码来源:mapv8.cpp

示例15: registerGlobalV8Function

void registerGlobalV8Function(const char * name, F function)
{
    using namespace v8;

    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    HandleScope handle_scope(isolate);
    Q_UNUSED(handle_scope);

    Local<Context> ctx = isolate->GetCurrentContext();
    Local<Object> global( ctx->Global() );
    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, function);
    v8::Local<v8::Function> fn = t->GetFunction();
    v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
    fn->SetName(fn_name);
    global->Set(fn_name, fn);
}
开发者ID:robxu9,项目名称:qtjs-generator,代码行数:16,代码来源:cpgfApi.cpp


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