本文整理汇总了C++中context_scope函数的典型用法代码示例。如果您正苦于以下问题:C++ context_scope函数的具体用法?C++ context_scope怎么用?C++ context_scope使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了context_scope函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: msV8CreateContext
/* Create and return a v8 context. Thread safe. */
void msV8CreateContext(mapObj *map)
{
Isolate *isolate = Isolate::GetCurrent();
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);
V8Context *v8context = new V8Context(isolate);
Handle<ObjectTemplate> global_templ = ObjectTemplate::New();
global_templ->Set(String::New("require"), FunctionTemplate::New(msV8Require));
global_templ->Set(String::New("print"), FunctionTemplate::New(msV8Print));
global_templ->Set(String::New("alert"), FunctionTemplate::New(msV8Print));
Handle<Context> context_ = Context::New(v8context->isolate, NULL, global_templ);
v8context->context.Reset(v8context->isolate, context_);
/* we have to enter the context before getting global instance */
Context::Scope context_scope(context_);
Handle<Object> global = context_->Global();
Shape::Initialize(global);
Point::Initialize(global);
Line::Initialize(global);
v8context->paths.push(map->mappath);
v8context->isolate->SetData(v8context);
v8context->layer = NULL;
map->v8context = (void*)v8context;
}
开发者ID:BentleySystems,项目名称:mapserver,代码行数:31,代码来源:mapv8.cpp
示例3: main
int main() {
flusspferd::current_context_scope context_scope(
flusspferd::context::create());
flusspferd::object g = flusspferd::global();
// Create a method of the global object (= global function) with name print
// that calls print().
flusspferd::create_native_function(g, "print", &print);
// Create a global function that calls exp_i().
flusspferd::create_native_function(g, "exp", &exp_i);
flusspferd::object p = flusspferd::evaluate("Object.prototype").to_object();
// Create a method of Object.prototype that calls print_object().
// The difference between create_native_function and create_native_method is
// that the latter passes Javascript's 'this' as parameter to the function.
//
// (Note that every normal object ultimately has as prototype the value of
// Object.prototype. However create_native_method and create_native_function
// create the properties with dont_enum, so doing this is safe.)
flusspferd::create_native_method(p, "print", &print_object);
// Print e.
// (Note that 1.2 is rounded down to 1.)
flusspferd::evaluate("print(exp(1.2))");
// Print the contents of a literal object.
flusspferd::evaluate("({a:1, b:2}).print()");
}
开发者ID:ngoyal,项目名称:flusspferd,代码行数:31,代码来源:functions1.cpp
示例4: InitMapSystemWrapper
void InitMapSystemWrapper(ScriptSystem* ss)
{
HandleScope scope;
Context::Scope context_scope(ss->GetGlobalContext());
Handle<FunctionTemplate> templt= FunctionTemplate::New();
templt->SetClassName(String::New("MapSystem"));
templt->InstanceTemplate()->SetInternalFieldCount(1);
Handle<ObjectTemplate> proto = templt->PrototypeTemplate();
proto->Set("addEmptyMap", FunctionTemplate::New(MSAddEmptyMap));
proto->Set("getEntityIdByUniqueId", FunctionTemplate::New(MSGetEntityIdByUniqueId));
proto->Set("isSpawnOf", FunctionTemplate::New(MSIsSpawnOf));
proto->Set("toString", FunctionTemplate::New(MSToString));
proto->Set("loadMap", FunctionTemplate::New(MSLoadMap));
proto->Set("loadScene", FunctionTemplate::New(MSLoadScene));
proto->Set("unloadScene", FunctionTemplate::New(MSUnloadScene));
proto->Set("saveScene", FunctionTemplate::New(MSSaveScene));
proto->Set("unloadMap", FunctionTemplate::New(MSUnloadMap));
proto->Set("getLoadedMaps", FunctionTemplate::New(MSGetLoadedMaps));
proto->Set("spawn", FunctionTemplate::New(MSSpawn));
proto->Set("deleteEntitiesByMap", FunctionTemplate::New(MSDeleteEntitiesByMap));
proto->Set("addSpawner", FunctionTemplate::New(MSAddSpawner));
proto->Set("addToScene", FunctionTemplate::New(MSAddToScene));
proto->Set("deleteSpawner", FunctionTemplate::New(MSDeleteSpawner));
proto->Set("getSpawner", FunctionTemplate::New(MSGetSpawner));
proto->Set("MSGetSpawnerComponents", FunctionTemplate::New(MSGetSpawnerComponents));
proto->Set("getSpawnerCreatedEntities", FunctionTemplate::New(MSGetSpawnerCreatedEntities));
proto->Set("getAllSpawnerNames", FunctionTemplate::New(MSGetAllSpawnerNames));
proto->Set("getEntitiesInMap", FunctionTemplate::New(MSGetEntitiesInMap));
proto->Set("removeFromScene", FunctionTemplate::New(MSRemoveFromScene));
RegisterEntitySystempWrapper(ss, dtEntity::MapComponent::TYPE, templt);
}
开发者ID:flyskyosg,项目名称:dtentity,代码行数:35,代码来源:mapsystemwrapper.cpp
示例5: operator
void operator()() {
_config._scope.reset(static_cast<V8Scope*>(globalScriptEngine->newScope()));
v8::Locker v8lock(_config._scope->getIsolate());
v8::Isolate::Scope iscope(_config._scope->getIsolate());
v8::HandleScope handle_scope;
v8::Context::Scope context_scope(_config._scope->getContext());
BSONObj args = _config._args;
v8::Local<v8::Function> f = v8::Function::Cast(
*(_config._scope->mongoToV8Element(args.firstElement(), true)));
int argc = args.nFields() - 1;
// TODO SERVER-8016: properly allocate handles on the stack
v8::Local<v8::Value> argv[24];
BSONObjIterator it(args);
it.next();
for(int i = 0; i < argc && i < 24; ++i) {
argv[i] = v8::Local<v8::Value>::New(
_config._scope->mongoToV8Element(*it, true));
it.next();
}
v8::TryCatch try_catch;
v8::Handle<v8::Value> ret =
f->Call(_config._scope->getContext()->Global(), argc, argv);
if (ret.IsEmpty() || try_catch.HasCaught()) {
string e = _config._scope->v8ExceptionToSTLString(&try_catch);
log() << "js thread raised exception: " << e << endl;
ret = v8::Undefined();
}
// ret is translated to BSON to switch isolate
BSONObjBuilder b;
_config._scope->v8ToMongoElement(b, "ret", ret);
_config._returnData = b.obj();
}
开发者ID:10genReviews,项目名称:mongo,代码行数:34,代码来源:v8_utils.cpp
示例6: handle_scope
// コンストラクタ呼び出し共通処理
tjs_error
TJSInstance::createMethod(Isolate *isolate, Local<Object> &obj, const tjs_char *membername, iTJSDispatch2 **result, tjs_int numparams, tTJSVariant **param)
{
if (membername) {
return TJS_E_MEMBERNOTFOUND;
}
HandleScope handle_scope(isolate);
Context::Scope context_scope(getContext());
TryCatch try_catch;
if (!obj->IsFunction()) {
return TJS_E_NOTIMPL;
}
// 関数抽出
Local<Function> func = Local<Function>::Cast(obj->ToObject());
// 引数
Handle<Value> *argv = new Handle<Value>[numparams];
for (int i=0;i<numparams;i++) {
argv[i] = toJSValue(isolate, *param[i]);
}
Local<Object> ret = func->NewInstance(numparams, argv);
delete argv;
if (ret.IsEmpty()) {
JSEXCEPTION(isolate, &try_catch);
} else {
if (result) {
*result = toVariant(isolate, ret);
}
}
return TJS_S_OK;
}
开发者ID:xmoeproject,项目名称:X-moe,代码行数:35,代码来源:tjsinstance.cpp
示例7: script
MatchCreator::Description ScriptMatchCreator::_getScriptDescription(QString path) const
{
MatchCreator::Description result;
result.experimental = true;
shared_ptr<PluginContext> script(new PluginContext());
HandleScope handleScope;
Context::Scope context_scope(script->getContext());
script->loadScript(path, "plugin");
Persistent<Object> plugin = ScriptMatchVisitor::getPlugin(script);
Handle<String> descriptionStr = String::New("description");
if (plugin->Has(descriptionStr))
{
Handle<v8::Value> value = plugin->Get(descriptionStr);
result.description = toCpp<QString>(value);
}
Handle<String> experimentalStr = String::New("experimental");
if (plugin->Has(experimentalStr))
{
Handle<v8::Value> value = plugin->Get(experimentalStr);
result.experimental = toCpp<bool>(value);
}
QFileInfo fi(path);
result.className = (QString::fromStdString(className()) + "," + fi.fileName()).toStdString();
return result;
}
开发者ID:mitulvpatel,项目名称:hootenanny,代码行数:29,代码来源:ScriptMatchCreator.cpp
示例8: 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
示例9: load
//loads a js file
Handle<Value> load(const Arguments& args) {
//if less that nbr of formal parameters then do nothing
int len = args.Length();
int i;
if (len < 1) return v8::Undefined();
//define handle scope
HandleScope scope;
// Enter the new context so all the following operations take place
// within it.
Context::Scope context_scope(V8GL::context);
for (i = 0; i < len; ++i) {
//get argument
String::Utf8Value value0(args[i]);
char* arg0 = *value0;
char* filepath = V8GLUtils::getRealPath(arg0);
char *old_path = V8GLUtils::pushRootPath(filepath);
bool success = exec(string(filepath));
V8GLUtils::popRootPath(old_path);
if(!success) {
fprintf(stderr, "Error reading '%s'.\n", arg0);
return ThrowException(String::New("Failed to load script"));
}
}
return v8::Undefined();
}
开发者ID:cscott,项目名称:v8-gl,代码行数:32,代码来源:v8-gl.cpp
示例10: JS_ReleaseRuntime
void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8PersistentContext)
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, v8PersistentContext);
v8::Context::Scope context_scope(context);
CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
if(!pArray) return ;
for(int i=0; i<pArray->GetSize(); i++)
{
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
if(!pObjDef->m_StaticObj.IsEmpty())
{
v8::Local<v8::Object> pObj = v8::Local<v8::Object>::New(isolate, pObjDef->m_StaticObj);
if(pObjDef->m_pDestructor)
pObjDef->m_pDestructor(pObj);
JS_FreePrivate(pObj);
}
delete pObjDef;
}
delete pArray;
isolate->SetData(0,NULL);
}
开发者ID:mcanthony,项目名称:libpdf,代码行数:26,代码来源:fxjs_v8.cpp
示例11: context_scope
Status ModuleScript::try_run()
{
v8::Context::Scope context_scope(get_context());
module_object.reset();
if (prelude != NULL)
if (!prelude->enter_cancellable_region())
return S_TERMINATED;
v8::Handle<v8::Value> result = run_script(get_context());
if (prelude != NULL)
if (!prelude->exit_cancellable_region())
return S_TERMINATED;
if (result->IsObject())
{
module_object = std::shared_ptr<v8::Persistent<v8::Object>>(
new v8::Persistent<v8::Object>(v8::Isolate::GetCurrent(), result.As<v8::Object>()));
}
else
{
set_last_error("Module script must return an object");
return S_ERROR;
}
return S_OK;
}
开发者ID:18098924759,项目名称:EventStore,代码行数:25,代码来源:ModuleScript.cpp
示例12: D
JNIEXPORT void JNICALL Java_org_adblockplus_android_JSEngine_nativeCallback
(JNIEnv *pEnv, jobject pObj, jlong pCallback, jobjectArray pParams, jlong pContext)
{
D(D_WARN, "nativeCallback()");
v8::HandleScope handle_scope;
v8::Persistent<v8::Context> context((v8::Context *) pContext);
v8::Context::Scope context_scope(context);
v8::Persistent<v8::Function> callback((v8::Function *) pCallback);
jsize pnum = pEnv->GetArrayLength(pParams);
v8::Handle<v8::Value> *args = new v8::Handle<v8::Value>[pnum];
for (int i = 0; i < pnum; i++)
{
jobject param = pEnv->GetObjectArrayElement(pParams, i);
args[i] = wrapJavaObject(pEnv, param);
pEnv->DeleteLocalRef(param);
}
{
v8::TryCatch try_catch;
callback->Call(context->Global(), pnum, args);
callback.Dispose();
delete [] args;
if (try_catch.HasCaught())
reportException(&try_catch);
}
}
开发者ID:aster-anto,项目名称:adblockplusandroid,代码行数:30,代码来源:jsEngine.cpp
示例13: test_obj_setprop
void
test_obj_setprop()
{
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Handle<Object> obj = Object::New();
Handle<String> k = String::New("someprop");
Handle<String> v = String::New("somevalue");
obj->Set(k, v);
Handle<Value> v2 = obj->Get(k);
String::AsciiValue vs(v);
String::AsciiValue vs2(v2);
do_check_eq(vs.length(), vs2.length());
do_check_eq(0, strcmp(*vs,*vs2));
context.Dispose();
}
开发者ID:mmmulani,项目名称:v8monkey,代码行数:26,代码来源:test_objprop.cpp
示例14: handle_scope
bool SMJS_Plugin::RunString(const char* name, const char *source, bool asGlobal){
HandleScope handle_scope(isolate);
Context::Scope context_scope(context);
TryCatch try_catch;
v8::ScriptOrigin origin(String::New(name), v8::Integer::New(0), v8::Integer::New(0));
Handle<Script> script;
if(asGlobal){
script = Script::Compile(v8::String::New(source), &origin);
}else{
char *buffer = new char[strlen(source) + 100];
strcpy(buffer, "(function(global){");
strcat(buffer, source);
strcat(buffer, "})(this);");
script = Script::Compile(v8::String::New(buffer), &origin);
delete buffer;
}
if(script.IsEmpty()) {
// Print errors that happened during compilation.
ReportException(&try_catch);
return false;
} else {
Handle<Value> result = script->Run();
if (result.IsEmpty()) {
ReportException(&try_catch);
return false;
}
return true;
}
}
开发者ID:joeystandrew,项目名称:SourceMod.js,代码行数:32,代码来源:SMJS_Plugin.cpp
示例15: 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
示例16: test_WriteAscii
void
test_WriteAscii()
{
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
char TEST_STRING[] = "this is a UTF-8 test! This is pi: π";
int TEST_LENGTH = strlen(TEST_STRING);
Handle<String> str = String::New(TEST_STRING);
char* buf = new char[TEST_LENGTH * 2];
// Iterate over the entire string and use it as the start.
int EXPECTED_LENGTH = TEST_LENGTH - 1; // We should drop the UTF-8 char.
for (int start = 0; start < TEST_LENGTH; start++) {
// Fill the buffer with 'a' to ensure there are no NULLs to start with.
fill_string(buf, 'a', TEST_LENGTH * 2);
int copied = str->WriteAscii(buf, start, TEST_LENGTH * 2);
do_check_eq(copied, EXPECTED_LENGTH - start);
do_check_eq(strlen(buf), EXPECTED_LENGTH - start);
}
delete[] buf;
context.Dispose();
}
开发者ID:bjonreyes,项目名称:spidernode,代码行数:25,代码来源:test_String.cpp
示例17: context_scope
void ScriptSystem::Tick(const dtEntity::Message& m)
{
if(mGlobalTickFunction.IsEmpty())
{
return;
}
HandleScope scope;
Context::Scope context_scope(GetGlobalContext());
const dtEntity::TickMessage& msg = static_cast<const dtEntity::TickMessage&>(m);
TryCatch try_catch;
Handle<Value> argv[3] = {
Number::New(msg.GetDeltaSimTime()),
Number::New(msg.GetSimulationTime()),
Uint32::New(osg::Timer::instance()->time_m())
};
Handle<Value> ret = mGlobalTickFunction->Call(mGlobalTickFunction, 3, argv);
if(ret.IsEmpty())
{
ReportException(&try_catch);
}
}
开发者ID:mathieu,项目名称:dtEntity,代码行数:27,代码来源:scriptcomponent.cpp
示例18: TEST_F
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
示例19: 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
示例20: isolate_scope
int Fragment::Script::ScriptEngine::Init(int argc, char* argv[]) {
v8::V8::InitializeICU();
v8::V8::InitializeExternalStartupData(argv[0]);
v8::Platform *platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
v8::V8::Initialize();
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
ShellArrayBufferAllocator array_buffer_allocator;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &array_buffer_allocator;
v8::Isolate *isolate = v8::Isolate::New(create_params);
run_shell = (argc == 1);
int result;
{
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = CreateShellContext(isolate);
if (context.IsEmpty()) {
fprintf(stderr, "Error creating context\n");
return 1;
}
v8::Context::Scope context_scope(context);
result = RunMain(isolate, platform, argc, argv);
if (run_shell) RunShell(context, platform);
}
isolate->Dispose();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
return result;
}
开发者ID:fragment-engine,项目名称:Fragment,代码行数:33,代码来源:ScriptEngine.cpp
注:本文中的context_scope函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论