本文整理汇总了C++中Handle::Exit方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::Exit方法的具体用法?C++ Handle::Exit怎么用?C++ Handle::Exit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handle
的用法示例。
在下文中一共展示了Handle::Exit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jsEval
//.........这里部分代码省略.........
TclVariableBindingsMap* varbindings = new TclVariableBindingsMap;
isolate->SetData(0, varbindings);
v8log("jsEval: created new bindings map at %lp\n", (void*)varbindings );
// validate input params
if ( (objc != 3) ) {
std::string msg("usage: jsEval [list of tcl vars to add to v8 context] { javascript }");
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg.c_str(), msg.length()));
return TCL_ERROR;
}
// get the argument list
Tcl_Obj* arglist = objv[1];
if ( (arglist->typePtr == NULL) || strcmp(arglist->typePtr->name, "list") ) {
std::string msg("jsEval: 1st arg not a list");
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg.c_str(), msg.length()));
return TCL_ERROR;
}
// get the JS snippet
char* javascript = Tcl_GetString(objv[2]);
if ( strlen(javascript) == 0 ) {
std::string msg("jsEval: 2nd arg not a string");
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg.c_str(), msg.length()));
return TCL_ERROR;
}
// Create stack-allocated isolate and handle scopes.
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);
// new v8 global template
Handle<ObjectTemplate> global_templ = ObjectTemplate::New(isolate);
// scrum our F18 Interceptors
global_templ->SetNamedPropertyHandler(
&TclVariableBinding::GenericNamedPropertyReader,
&TclVariableBinding::GenericNamedPropertyWriter
);
// Create and Enter a new context for compiling and running the script.
Handle<Context> context = Context::New(isolate, NULL, global_templ);
context->Enter();
int arglistLength;
Tcl_ListObjLength(interp, arglist, &arglistLength);
v8log("arg list length == %d\n", arglistLength);
for ( int i = 0; i < arglistLength; i++ ) {
// get the variable NAME
Tcl_Obj* varName;
Tcl_ListObjIndex(interp, arglist, i, &varName);
char* vn = Tcl_GetString(varName);
v8log("binding %s (idx: %d) to V8\n", vn, i);
// then create a binding and store it
(*varbindings)[vn] = new TclVariableBinding(interp, varName);
}
// Compile
v8log("compiling jsEval'ed script\n");
v8::MaybeLocal<v8::Script> jsSource = v8::Script::Compile(context, Nan::New<String>(javascript).ToLocalChecked());
if (jsSource.IsEmpty()) {
v8log("*** jsSource.IsEmpty()\n");
} else {
// Run
v8log("running jsEval'ed script\n");
Nan::TryCatch tc;
Nan::MaybeLocal<v8::Value> retv = jsSource.ToLocalChecked()->Run();
v8log("done running jsEval'ed script\n");
if ( tc.HasCaught() ) {
// oops, exception raised from V8 while in JS land
Local<Message> msg = tc.Message();
std::string msgtext(*String::Utf8Value(msg->Get()));
v8log("*** caught JS exception: %s\n", msgtext.c_str());
}
TclVariableBindingsMap::const_iterator it;
for (it = varbindings->begin(); it != varbindings->end(); it++) {
TclVariableBinding* vb = it->second;
v8log("reverse mapping of %s (v8: %p) to Tcl...\n", it->first.c_str(), vb->m_v8val);
Tcl_SetVar2Ex(vb->m_interp, it->first.c_str(), NULL, vb->m_tclvar, 0);
delete vb;
}
varbindings->clear();
// handle return value, if there is one
if (!retv.IsEmpty()) {
Local<Value> rv = retv.ToLocalChecked();
std::string res(*String::Utf8Value(rv));
std::string restype(V8ValueType(rv));
v8log("Tcl_SetObjResult(interp == %lp, result == %s (%s)\n", (void*) interp, res.c_str(), restype.c_str());
Tcl_Obj* tclres = V8ToTcl(interp, rv);
Tcl_SetObjResult(interp, tclres);
}
delete varbindings;
}
context->Exit();
// TODO: error handling!
return TCL_OK;
}
示例2: worker_routine
//.........这里部分代码省略.........
zmq_msg_close (&req);
zmq_msg_close (&reply);
continue;
#endif
//std::cout << "thread: " << pthread_self() << " Received script: " << (char*) zmq_msg_data(&req) << std::endl;
//leveldb::Status s;
#if 1
Context::Scope contextScope(context);
// Compile a function which will keep using the stack until v8 cuts it off
//Local<Script> script = Local<Script>::New(Script::Compile(String::New( (char*) zmq_msg_data(&req) )));
TryCatch try_catch;
Local<String> source = String::New((char*) zmq_msg_data(&req));
Local<Script> script = Script::Compile(source);
if(script.IsEmpty())
{
ReportException(&try_catch);
String::Utf8Value error(try_catch.Exception());
v8::Handle<v8::Message> message = try_catch.Message();
int line_num = 0;
int col_num = 0;
if (message.IsEmpty()) {
}else {
line_num = message->GetLineNumber();
col_num = message->GetStartColumn();
}
int mess_size = error.length()+100;
rc = zmq_msg_init_size (&reply, mess_size);
assert (rc == 0);
//cerr << "compile error line: " << " message: " << *error << endl;
snprintf ((char*) zmq_msg_data (&reply), mess_size, "2; {res: 'COMPILE ERROR', line: %d, col: %d, message: '%s'}", line_num, col_num, *error);
}
else {
// Run the function once and catch the error to generate machine code
Local<Value> result = script->Run();
if (try_catch.HasCaught()) {
//TODO: escape string
String::Utf8Value message(try_catch.Exception());
int mess_size = message.length()+100;
rc = zmq_msg_init_size (&reply, mess_size);
assert (rc == 0);
std::cout <<"exception->" <<*message <<"\n";
snprintf ((char*) zmq_msg_data (&reply), mess_size, "1; {res: 'ERROR', message: '%s'}", *message);
}
else {
//TODO: escape string
String::Utf8Value message(result->ToString());
int mess_size = message.length()+2;
rc = zmq_msg_init_size (&reply, mess_size);
assert (rc == 0);
snprintf ((char*) zmq_msg_data (&reply), mess_size, " %s", *message);
}
}
#endif
/* Send the message to the socket */
rc = zmq_send (receiver, &reply, 0);
assert (rc == 0);
//s_sleep(1);
zmq_msg_close (&req);
zmq_msg_close (&reply);
free_objects();
}
context->Exit();
//printf("Iter: %d , Result: %ld ; from thread: %ld \n", i, res, tid);
//context.Dispose();
//script.Dispose();
Unlocker unlock(isolate);
//isolate->Exit();
//isolate->Dispose();
zmq_close (receiver);
return NULL;
}
示例3: c_contextExit
void c_contextExit(Handle<Context> context) {
context->Exit();
}