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


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

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


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

示例1: Exception

v8::Handle<v8::String> V8::toJson(v8::Handle<v8::Value> value) {
	HandleScope scope;

	Handle<Context> context = Context::GetCurrent();
	Handle<Object> global = context->Global();

	Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
	Handle<Function> JSON_stringify = Handle<Function>::Cast(JSON->Get(String::New("stringify")));

	TryCatch exception;

	Handle<Value> argv[] = {
		value,
		v8::Null(),
		v8::String::New("\t")
	};

	if (exception.HasCaught()) {
		throw chi::Exception(chi::V8::ReportException(exception));
	}

	Handle<Value> stringified = JSON_stringify->Call(JSON_stringify, 3, argv);

	if (exception.HasCaught()) {
		throw chi::Exception(chi::V8::ReportException(exception));
	}

	return scope.Close(stringified.As<String>());
}
开发者ID:cha0s,项目名称:Worlds-Beyond,代码行数:29,代码来源:wbv8.cpp

示例2: handleScope

// Install the constructor in the global scope so Path2Ds can be constructed
// in JS.
void Path2D::AddToGlobal(Global* global) {
    gGlobal = global;

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

    Handle<Context> context = gGlobal->getContext();

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

    Local<FunctionTemplate> constructor = FunctionTemplate::New(
            gGlobal->getIsolate(), Path2D::ConstructPath);
    constructor->InstanceTemplate()->SetInternalFieldCount(1);

    ADD_METHOD("closePath", ClosePath);
    ADD_METHOD("moveTo", MoveTo);
    ADD_METHOD("lineTo", LineTo);
    ADD_METHOD("quadraticCurveTo", QuadraticCurveTo);
    ADD_METHOD("bezierCurveTo", BezierCurveTo);
    ADD_METHOD("arc", Arc);
    ADD_METHOD("rect", Rect);
    ADD_METHOD("oval", Oval);
    ADD_METHOD("conicTo", ConicTo);

    context->Global()->Set(String::NewFromUtf8(
            gGlobal->getIsolate(), "Path2D"), constructor->GetFunction());
}
开发者ID:Adenilson,项目名称:skia,代码行数:30,代码来源:Path2D.cpp

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

示例4: toJson

v8::Handle<v8::Value> toJson(v8::Handle<v8::Value> value) {
	HandleScope scope;

	Handle<Context> context = Context::GetCurrent();
	Handle<Object> global = context->Global();
	Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
	Handle<Function> JSON_stringify = Handle<Function>::Cast(JSON->Get(String::New("stringify")));

	// JSON.stringify(values, null, '\t');
	Handle<Value> argv[] = {
		value,
		Null(),
		String::New("\t")
	};

	TryCatch exception;

	Handle<Value> stringified = JSON_stringify->Call(JSON_stringify, 3, argv);

	if (exception.HasCaught()) {
		return exception.ReThrow();
	}

	return scope.Close(stringified);
}
开发者ID:cha0s,项目名称:avocado-spi-v8,代码行数:25,代码来源:avocado-v8.cpp

示例5: context_scope

void TiV8Event::fire(void* fireDataObject)
{
    HandleScope handleScope;
    if (function_.IsEmpty())
    {
        return;
    }
    Handle<Context> context = function_->CreationContext();
    Context::Scope context_scope(context);
    Handle<Value> result;
    TryCatch tryCatch;
    if (fireDataObject == NULL)
    {
        //make a function call with no arguments
        result = function_->Call(context->Global(), 0, 0);
    }
    else
    {
        Handle<Object> dataObject = *((Persistent<Object>*) fireDataObject);
        dataObject->Set(String::New("source"), source_);
        // This calls the Javascript function that handles the event. It has
        // the form of: function(e) {...}
        // The "1" in the following function refers to the number of arguments that
        // are passed the the Javascript function. In this case there is one
        // argument: "e". The argument is an object with properties relating
        // to the event that was triggered.
        result = function_->Call(source_, 1, (Handle<Value>*) &dataObject);
    }
    if (result.IsEmpty())
    {
        Ti::TiErrorScreen::ShowWithTryCatch(tryCatch);
    }
}
开发者ID:Buder,项目名称:titanium_mobile_blackberry,代码行数:33,代码来源:TiV8Event.cpp

示例6: New

 Handle<Value> SCRGetLockCursor(Local<String> propname, const AccessorInfo& info)
 {
    HandleScope handle_scope;
    Handle<Context> context = info.Holder()->CreationContext();
    Handle<Value> ih = context->Global()->Get(String::New("Input"));
    dtEntity::InputInterface* input = UnwrapInputInterface(ih);
    return Boolean::New(input->GetLockCursor());
 }
开发者ID:mathieu,项目名称:dtEntity,代码行数:8,代码来源:screenwrapper.cpp

示例7:

Handle<ObjectTemplate> TiObject::getObjectTemplateFromJsObject(Handle<Value> value)
{
    HandleScope handleScope;
    Handle<Object> obj = Handle<Object>::Cast(value);
    Handle<Context> context = obj->CreationContext();
    Handle<External> globalTemplateExternal = Handle<External>::Cast(
                context->Global()->GetHiddenValue(String::New(HIDDEN_TEMP_OBJECT_PROPERTY)));
    Handle<ObjectTemplate>temp = *((Handle<ObjectTemplate>*) globalTemplateExternal->Value());
    return handleScope.Close(temp);
}
开发者ID:saggy,项目名称:titanium_mobile_blackberry,代码行数:10,代码来源:TiObject.cpp

示例8: FetchGlobalTickFunction

   void ScriptSystem::FetchGlobalTickFunction()
   {
      HandleScope scope;
      Handle<Context> context = GetGlobalContext();

      mGlobalTickFunction.Clear();

      Handle<String> funcname = String::New("__executeTimeOuts");
      if(context->Global()->Has(funcname))
      {
         Handle<Value> func = context->Global()->Get(funcname);
         if(!func.IsEmpty())
         {
            Handle<Function> f = Handle<Function>::Cast(func);
            if(!f.IsEmpty())
            {
               mGlobalTickFunction = Persistent<Function>::New(f);
            }
         }
      }
   }
开发者ID:mathieu,项目名称:dtEntity,代码行数:21,代码来源:scriptcomponent.cpp

示例9: stringify

// TODO: move these to a util file
static Local<String> stringify(Handle<Value> object)
{
    HandleScope scope;

    Handle<Context> context = Context::GetCurrent();
    Handle<Object> global = context->Global();

    Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
    Handle<Function> JSON_stringify = Handle<Function>::Cast(JSON->Get(String::New("stringify")));

    return scope.Close(JSON_stringify->Call(JSON, 1, &object)->ToString());
}
开发者ID:adesugbaa,项目名称:titanium_mobile_blackberry,代码行数:13,代码来源:TiAppPropertiesObject.cpp

示例10: parseJson

static Local<Value> parseJson(const QString& json)
{
    Handle<Context> context = Context::GetCurrent();
    Handle<Object> global = context->Global();

    Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
    Handle<Function> JSON_parse = Handle<Function>::Cast(JSON->Get(String::New("parse")));

    Handle<Value> value = String::New(json.toUtf8());

    return JSON_parse->Call(JSON, 1, &value);
}
开发者ID:adesugbaa,项目名称:titanium_mobile_blackberry,代码行数:12,代码来源:TiAppPropertiesObject.cpp

示例11: toJsonNode

static JsonNode* toJsonNode(Handle<Value> object) {
  std::vector<char> buf;
  Handle<Context> context = Context::GetCurrent();
  Handle<Object> global = context->Global();
  Handle<Object> JSON = global->Get(String::New ("JSON"))->ToObject();
  Handle<Function> JSON_stringify = Handle<Function>::Cast(JSON->Get(String::New("stringify")));
  Handle<Value> argv[1] = {
    object
  };
  Handle<String> ret = JSON_stringify->Call(JSON, 1, argv)->ToString();

  buf.resize (ret->Utf8Length());
  ret->WriteUtf8 (buf.data());
  return json_decode (buf.data());
}
开发者ID:codius,项目名称:codius-sandbox,代码行数:15,代码来源:sandbox-node-module.cpp

示例12:

Handle<Value> V8::parseJson(Handle<String> jsonString) {
	HandleScope scope;

	Handle<Context> context = Context::GetCurrent();
	Handle<Object> global = context->Global();

	Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
	Handle<Function> JSON_parse = Handle<Function>::Cast(JSON->Get(String::New("parse")));

	// return JSON.parse.apply(JSON, jsonString);
	Handle<Value> args[] = {
		jsonString
	};
	return scope.Close(JSON_parse->Call(JSON, 1, args));
}
开发者ID:cha0s,项目名称:Worlds-Beyond,代码行数:15,代码来源:wbv8.cpp

示例13: fromJsonNode

static Handle<Value> fromJsonNode(JsonNode* node) {
  char* buf;
  Handle<Context> context = Context::GetCurrent();
  Handle<Object> global = context->Global();
  Handle<Object> JSON = global->Get(String::New ("JSON"))->ToObject();
  Handle<Function> JSON_parse = Handle<Function>::Cast(JSON->Get(String::New("parse")));

  buf = json_encode (node);
  Handle<Value> argv[1] = {
    String::New (buf)
  };
  Handle<Value> parsedObj = JSON_parse->Call(JSON, 1, argv);
  free (buf);

  return parsedObj;
}
开发者ID:codius,项目名称:codius-sandbox,代码行数:16,代码来源:sandbox-node-module.cpp

示例14: Bind

void Point::Bind( Isolate* isolate, Handle< Context > context ) {
	// Get creation scope
	HandleScope scope( isolate );

	// Create constructor function and object template
	Local< FunctionTemplate > constructor = FunctionTemplate::New( Construct );
	Local< ObjectTemplate > templ = constructor->InstanceTemplate();
	templ->SetInternalFieldCount( 1 );

	// Set properties and methods
	templ->SetAccessor( String::New( "x" ), GetX, SetX );
	templ->SetAccessor( String::New( "y" ), GetY, SetY );
	templ->Set( String::New( "print" ), FunctionTemplate::New( Print ) );

	// Register constructor
	context->Global()->Set( String::New( "Point" ), constructor->GetFunction() );
}
开发者ID:TheCodeInside,项目名称:v8-example,代码行数:17,代码来源:point.cpp

示例15: SetupContext

   void ScriptSystem::SetupContext()
   {
      HandleScope handle_scope;
      if(!mGlobalContext.IsEmpty())
      {
         mGlobalContext.Dispose();
      }

      // create a template for the global object
      Handle<ObjectTemplate> global = ObjectTemplate::New();

      // create persistent global context
      mGlobalContext = Persistent<Context>::New(Context::New(NULL, global));

      // store pointer to script system into isolate data to have it globally available in javascript
      Isolate::GetCurrent()->SetData(this);

      RegisterGlobalFunctions(this, mGlobalContext);
      RegisterPropertyFunctions(this, mGlobalContext);

      InitializeAllWrappers(GetEntityManager());

      Handle<Context> context = GetGlobalContext();
      Context::Scope context_scope(context);
      Handle<FunctionTemplate> tmplt = FunctionTemplate::New();
      tmplt->InstanceTemplate()->SetInternalFieldCount(2);

      tmplt->SetClassName(String::New("ScriptSystem"));

      context->Global()->Set(String::New("Screen"), WrapScreen(this));

      dtEntity::InputInterface* ipiface = dtEntity::GetInputInterface();
      if(ipiface)
      {
         context->Global()->Set(String::New("Input"), WrapInputInterface(GetGlobalContext(), ipiface));
         context->Global()->Set(String::New("Axis"), WrapAxes(ipiface));
         context->Global()->Set(String::New("Key"), WrapKeys(ipiface));
      }

      context->Global()->Set(String::New("TouchPhase"), WrapTouchPhases());
      context->Global()->Set(String::New("Priority"), WrapPriorities());
      context->Global()->Set(String::New("Order"), WrapPriorities());

   }
开发者ID:mathieu,项目名称:dtEntity,代码行数:44,代码来源:scriptcomponent.cpp


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