本文整理汇总了C++中Persistent::Global方法的典型用法代码示例。如果您正苦于以下问题:C++ Persistent::Global方法的具体用法?C++ Persistent::Global怎么用?C++ Persistent::Global使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Persistent
的用法示例。
在下文中一共展示了Persistent::Global方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cm_script_GetGeometrySize
void cm_script_GetGeometrySize(cm_script* Script, int* x, int* y, int* z)
{
// Thread protection
v8::Locker Locker;
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Get the latest geometry
v8::Local<v8::Function> FunctionName = v8::Local<v8::Function>::Cast(context->Global()->Get(v8::String::New("cm_GetGeometry")));
v8::Handle<v8::Value> args[] = { };
v8::Local<v8::Value> Result = FunctionName->Call(FunctionName, 0, args);
// If we got back an array
if(Result->IsArray())
{
// Turn into array
v8::Handle<v8::Array> Array0 = v8::Handle<v8::Array>::Cast(Result);
*z = Array0->Length();
v8::Handle<v8::Array> Array1 = v8::Handle<v8::Array>::Cast(Array0->Get(0));
*y = Array1->Length();
v8::Handle<v8::Array> Array2 = v8::Handle<v8::Array>::Cast(Array1->Get(0));
*x = Array2->Length();
}
else
*x = *y = *z = 0;
}
示例2: context_scope
extern "C" Handle<Value> create_function(Persistent<Context> context,
char* source_s,
char* name) {
// Create a stack-allocated handle scope.
HandleScope handle_scope;
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::New(source_s);
// Compile the source code.
Handle<Script> script = Script::Compile(source);
// Run the script to get the result.
Handle<Value> result = script->Run();
// magic
Handle<Object> global = context->Global();
Handle<Value> value = global->Get(String::New(name));
Handle<Function> func = v8::Handle<Function>::Cast(value);
func->SetName(String::New(name));
Persistent<Function> persistent_func = Persistent<Function>::New(func);
return persistent_func;
}
示例3: Java_me_sarim_myfirstapp_MainActivity_avroparse
jstring JNICALL Java_me_sarim_myfirstapp_MainActivity_avroparse( JNIEnv* env,jobject thiz,jstring sk1) {
std::string banglatxt;
GetJStringContent(env,sk1,banglatxt);
Context::Scope context_scope(context);
/*
std::string code1 = "OmicronLab.Avro.Phonetic.parse('";
std::string code2 = "');";
std::string finalcode = code1 + banglatxt + code2;
Handle<String> source2 = String::New(finalcode.c_str());
Handle<Script> script2 = Script::Compile(source2);
Handle<Value> result = script2->Run();
*/
Handle<Object> global = context->Global();
Handle<Value> avro_parse = global->Get(String::New("testfunc"));
Handle<Function> avro_parse_func = Handle<Function>::Cast(avro_parse);
Handle<Value> args[1];
Handle<Value> result;
args[0] = v8::String::New(banglatxt.c_str());
result = avro_parse_func->Call(global, 1, args);
// Convert the result to an ASCII string and print it.
String::Utf8Value ascii(result);
//printf("%s\n", *ascii);
//char * bntext = *ascii;
std::string bntext = std::string(*ascii);
return env->NewStringUTF(bntext.c_str());
}
示例4: WrappedContext
Handle<Value> WrappedScript::CreateContext(const Arguments& args)
{
HandleScope scope;
Persistent<Context> context = Context::New(NULL, WrappedContext::global_template);
WrappedContext *wrappedContext = new WrappedContext(context);
Local<Object> global = context->Global();
// Allow current context access to newly created context's objects.
context->SetSecurityToken(Context::GetCurrent()->GetSecurityToken());
// If a sandbox is provided initial the new context's global with it.
if (args.Length() > 0) {
Local<Object> sandbox = args[0]->ToObject();
Local<Array> keys = sandbox->GetPropertyNames();
for (uint32_t i = 0; i < keys->Length(); i++) {
Handle<String> key = keys->Get(Integer::New(i))->ToString();
Handle<Value> value = sandbox->Get(key);
if (value == sandbox) {
value = global;
}
global->Set(key, value);
}
}
return scope.Close(global);
}
示例5: jniScope
/*
* Class: org_appcelerator_kroll_runtime_v8_V8Runtime
* Method: nativeInit
* Signature: (Lorg/appcelerator/kroll/runtime/v8/V8Runtime;)J
*/
JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeInit(JNIEnv *env, jobject self, jboolean useGlobalRefs, jint debuggerPort, jboolean DBG)
{
HandleScope scope;
titanium::JNIScope jniScope(env);
// Log all uncaught V8 exceptions.
V8::AddMessageListener(logV8Exception);
V8::SetCaptureStackTraceForUncaughtExceptions(true);
JavaObject::useGlobalRefs = useGlobalRefs;
V8Runtime::debuggerEnabled = debuggerPort >= 0;
V8Runtime::DBG = DBG;
V8Runtime::javaInstance = env->NewGlobalRef(self);
JNIUtil::initCache();
Persistent<Context> context = Persistent<Context>::New(Context::New());
context->Enter();
V8Runtime::globalContext = context;
V8Runtime::bootstrap(context->Global());
if (V8Runtime::debuggerEnabled) {
jclass v8RuntimeClass = env->FindClass("org/appcelerator/kroll/runtime/v8/V8Runtime");
dispatchDebugMessage = env->GetMethodID(v8RuntimeClass, "dispatchDebugMessages", "()V");
Debug::SetDebugMessageDispatchHandler(dispatchHandler);
Debug::EnableAgent("titanium", debuggerPort, true);
}
LOG_HEAP_STATS(TAG);
}
示例6: Java_com_omicronlab_avrokeyboard_PhoneticIM_avroparse
jstring JNICALL Java_com_omicronlab_avrokeyboard_PhoneticIM_avroparse( JNIEnv* env,jobject thiz,jstring sk1) {
std::string banglatxt;
//convert java String to Cpp String
GetJStringContent(env,sk1,banglatxt);
Context::Scope context_scope(context);
Handle<Object> global = context->Global();
Handle<Value> avro_parse = global->Get(String::New("avroparsefunc"));
Handle<Function> avro_parse_func = Handle<Function>::Cast(avro_parse);
Handle<Value> args[1];
Handle<Value> result;
args[0] = v8::String::New(banglatxt.c_str());
result = avro_parse_func->Call(global, 1, args);
// Convert the result to an ASCII string
String::Utf8Value ascii(result);
std::string bntext = std::string(*ascii);
return env->NewStringUTF(bntext.c_str());
}
示例7: cm_script_GetGeometry
bool cm_script_GetGeometry(cm_script* Script, int x, int y, int z, int* Char, int* Color)
{
// Get geometry size and return on error
int Sizex, Sizey, Sizez;
cm_script_GetGeometrySize(Script, &Sizex, &Sizey, &Sizez);
if(x < 0 || x >= Sizex || y < 0 || y >= Sizey)
return false;
// Thread protection
v8::Locker Locker;
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Get the latest geometry
v8::Local<v8::Function> FunctionName = v8::Local<v8::Function>::Cast(context->Global()->Get(v8::String::New("cm_GetGeometry")));
v8::Handle<v8::Value> args[] = { };
v8::Local<v8::Value> Result = FunctionName->Call(FunctionName, 0, args);
// If we got back an array
if(Result->IsArray())
{
// Turn into array
v8::Handle<v8::Array> Array = v8::Handle<v8::Array>::Cast(Result);
String::AsciiValue Ascii(Array->ToString());
if(Array->IsUndefined())
return false;
v8::Handle<v8::Array> Array0 = v8::Handle<v8::Array>::Cast(Array->Get(z));
String::AsciiValue Ascii0(Array0->ToString());
if(Array0->IsUndefined())
return false;
v8::Handle<v8::Array> Array1 = v8::Handle<v8::Array>::Cast(Array0->Get(y));
String::AsciiValue Ascii1(Array1->ToString());
if(Array1->IsUndefined())
return false;
v8::Handle<v8::Value> Array2 = Array1->Get(x);
String::AsciiValue Ascii2(Array2->ToString());
if(Array2->IsUndefined())
return false;
*Color = CM_BG_RED | CM_FG_WHITE;
*Char = (*Ascii2)[0];
// If empty (space) just return false
if(*Char != ' ')
return true;
}
// Failed
return false;
}
示例8: initJsEngine
// Load up the JS engine
void initJsEngine(){
char path[1024];
uint32_t size = sizeof(path);
if (_NSGetExecutablePath(path, &size) != 0)
printf("buffer too small; need size %u\n", size);
string script_path;
char *pch, *next_pch;
pch = strtok(path, "/");
next_pch = strtok(NULL, "/");
//Rebuild the path, ommitting the last part (the exe name)
while (next_pch != NULL) {
script_path.append( "/" );
script_path.append( pch );
pch = next_pch;
next_pch = strtok(NULL, "/");
}
script_path.append("/script.js");
ifstream infile;
infile.open (script_path.c_str(), ifstream::in);
string file = "";
while (infile.good()){
file += (char) infile.get();
}
//Get rid of the of character
file[file.length() - 1] = ' ';
setJsFile( file.c_str() );
infile.close();
// Lock this v8 instance to this thread?
Locker locker;
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
context->Global()->Set(String::New("System"), getSystemTemplate()->NewInstance() );
context->Global()->Set(String::New("Player"), getPlayerTemplate()->NewInstance() );
context->Global()->Set(String::New("Games"), getGamesTemplate()->NewInstance() );
Handle<String> source = String::New(js_file);
Handle<Script> script = Script::Compile(source);
Handle<Value> result = script->Run();
context.Dispose();
}
示例9:
WrappedContext::WrappedContext(Persistent<Context> context)
: context_(context)
{
HandleScope scope;
Local<Object> globalProxy = context->Global();
Local<Object> global = globalProxy->GetPrototype().As<Object>();
Wrap(global);
}
示例10: 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);
}
}
示例11: cm_script_Interact
/*
void cm_script_Interact(cm_script* Script)
{
// Thread protection
v8::Locker Locker;
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Cast as needed
Persistent<Context> context = *((Persistent<Context>*)Script->__PersistentContext);
// Get the latest geometry
v8::Local<v8::Function> FunctionName = v8::Local<v8::Function>::Cast(context->Global()->Get(v8::String::New("cm_Interact")));
v8::Handle<v8::Value> args[] = { };
FunctionName->Call(FunctionName, 0, args);
}
void cm_script_LookAt(cm_script* Script)
{
// Thread protection
v8::Locker Locker;
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Cast as needed
Persistent<Context> context = *((Persistent<Context>*)Script->__PersistentContext);
// Get the latest geometry
v8::Local<v8::Function> FunctionName = v8::Local<v8::Function>::Cast(context->Global()->Get(v8::String::New("cm_LookAt")));
v8::Handle<v8::Value> args[] = { };
FunctionName->Call(FunctionName, 0, args);
}
*/
void cm_script_Update(cm_script* Script, float dT)
{
// Thread protection
v8::Locker Locker;
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Get the latest geometry
v8::Local<v8::Function> FunctionName = v8::Local<v8::Function>::Cast(context->Global()->Get(v8::String::New("cm_Update")));
v8::Handle<v8::Value> args[] = { v8::Number::New(dT) };
FunctionName->Call(FunctionName, 1, args);
}
示例12: main
int main (int argc, char const *argv[])
{
HandleScope handle_scope;
Handle<ObjectTemplate> global = ObjectTemplate::New();
global->Set(String::New("load"), FunctionTemplate::New(js_load));
Persistent<Context> context = Context::New(NULL, global);
Context::Scope context_scope(context);
Handle<Object> global_obj(context->Global());
IO::initialize(global_obj);
Process::initialize(global_obj);
Handle<Value> result = LoadScript(argv[1]);
context.Dispose();
return 0;
}
示例13: EditorGetCurrentLineRange
Handle<Value> EditorGetCurrentLineRange(const Arguments& args)
{
CComPtr<VirtualPoint> point;
long charOffset;
long lineLen;
long absCharOffset;
g_pSelection->get_ActivePoint(&point);
point->get_AbsoluteCharOffset(&absCharOffset);
point->get_LineCharOffset(&charOffset);
point->get_LineLength(&lineLen);
long lineOffset = absCharOffset - charOffset;
Local<Function> fCreateRange =
Local<Function>::Cast(g_Context->Global()->Get(String::New("createRange")));
Handle<Value> argv[] = { Int32::New(lineOffset), Int32::New(lineOffset + lineLen) };
return fCreateRange->Call(fCreateRange, 2, argv);
}
示例14: render
// Performs a dust.js render inside of V8
int DustJs::render(const string filename, const map<string, string> &model, onRenderFn callback) {
const string tmpl = filename.substr(0, filename.find_last_of("."));
// Create a new scope
HandleScope handle_scope;
Persistent<Context> context = Context::New(NULL);
Context::Scope context_scope(context);
// Load the dust libraries
// Note: The libraries are generated at build time to bundle dust.js
// rather than load it at runtime from an arbitrary location
const char* lib_dust = reinterpret_cast<const char*>(lib_dust_js);
const char* lib_compiler = reinterpret_cast<const char*>(lib_compiler_js);
const char* lib_parser = reinterpret_cast<const char*>(lib_parser_js);
const char* lib_helpers = reinterpret_cast<const char*>(lib_dust_helpers_js);
eval(lib_dust);
eval(lib_compiler);
eval(lib_parser);
eval(lib_helpers);
// Get dust out of the global scope so we can bind it with C++ methods
Handle<Object> global = context->Global();
Handle<Object> dust = global->Get(String::New("dust"))->ToObject();
dust->Set(String::New("onLoad"), FunctionTemplate::New(onLoad)->GetFunction());
// Call dust.render with our arguments
Handle<Value> cbargs[3];
cbargs[0] = String::New(tmpl.c_str());
cbargs[1] = mapToJson(model);
cbargs[2] = FunctionTemplate::New(callback)->GetFunction();
Handle<Function> render = Handle<Function>::Cast(dust->Get(String::New("render")));
render->Call(dust, 3, cbargs);
// Done!
return 0;
}
示例15: ThrowException
Handle<Value> evalInContext(const Arguments& args) {
if (args.Length() < 3) {
return ThrowException(Exception::TypeError(String::New("evalInContext takes 3 arguments.")));
}
if (!args[1]->IsObject()) {
return ThrowException(Exception::TypeError(String::New("evalInContext expects an object as second argument.")));
}
HandleScope scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Local<Object> global = context->Global();
Local<Object> jscontext = args[1]->ToObject()->Clone();
Local<Array> names = jscontext->GetOwnPropertyNames();
for (int i = 0; i < names->Length(); i++) {
global->Set(names->Get(i), jscontext->Get(names->Get(i)));
}
TryCatch tc;
Local<Script> compiled = Script::Compile(args[0]->ToString(), args[2]->ToString());
if (compiled.IsEmpty()) {
return tc.ReThrow();
}
Handle<Value> value = compiled->Run();
if (value.IsEmpty()) {
return tc.ReThrow();
}
return scope.Close(value);
}