Changeset 14055 for trunk/FACT++
- Timestamp:
- 06/03/12 21:39:43 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14051 r14055 13 13 using namespace v8; 14 14 15 voidInterpreterV8::ReportException(TryCatch* try_catch)15 bool InterpreterV8::ReportException(TryCatch* try_catch) 16 16 { 17 17 const HandleScope handle_scope; 18 18 19 19 const String::Utf8Value exception(try_catch->Exception()); 20 21 if (*exception && string(*exception)=="exit") 22 return true; 20 23 21 24 const Handle<Message> message = try_catch->Message(); … … 29 32 out << *filename; 30 33 if (!message.IsEmpty()) 31 out << ": l. 34 out << ": l." << message->GetLineNumber(); 32 35 if (*exception) 33 36 out << ": " << *exception; … … 36 39 37 40 if (message.IsEmpty()) 38 return ;41 return false; 39 42 40 43 // Print line of source code. … … 48 51 49 52 out.str(""); 50 out << setfill(' ') << setw(start) << ' '; 51 out << setfill('^') << setw(end-start) << '^'; 53 if (start>0) 54 out << setfill(' ') << setw(start) << ' '; 55 out << setfill('^') << setw(end-start) << '^'; 52 56 53 57 JsException(out.str()); … … 55 59 String::Utf8Value stack_trace(try_catch->StackTrace()); 56 60 if (stack_trace.length()<=0) 57 return; 58 59 if (*stack_trace) 60 JsException(string("\n")+*stack_trace); 61 return false; 62 63 //if (*stack_trace) 64 // JsException(string("\n")+*stack_trace); 65 66 return false; 61 67 } 62 68 … … 95 101 96 102 if (exception.HasCaught()) 97 { 98 ReportException(&exception); 99 return false; 100 } 103 return ReportException(&exception); 104 101 105 return rc; 102 106 } … … 191 195 JsSleep(args[0]->Int32Value()); 192 196 197 return Undefined(); 198 } 199 200 Handle<Value> InterpreterV8::FuncExit(const Arguments &) 201 { 202 v8::V8::TerminateExecution(fThreadId); 203 return ThrowException(String::New("exit")); 204 /* 205 if (args.Length()!=1) 206 return ThrowException(String::New("Number of arguments must be exactly 1.")); 207 208 if (!args[0]->IsUint32()) 209 return ThrowException(String::New("Argument 1 must be an uint32.")); 210 211 const HandleScope handle_scope; 212 213 JsSleep(args[0]->Int32Value()); 214 */ 193 215 return Undefined(); 194 216 } … … 234 256 } 235 257 236 bool InterpreterV8::JsRun(const string &filename) 258 #include <iostream> 259 260 bool InterpreterV8::JsRun(const string &filename, const map<string, string> &map) 237 261 { 238 262 v8::Locker locker; … … 253 277 global->Set(String::New("include"), FunctionTemplate::New(WrapInclude), ReadOnly); 254 278 global->Set(String::New("sleep"), FunctionTemplate::New(WrapSleep), ReadOnly); 279 global->Set(String::New("exit"), FunctionTemplate::New(WrapExit), ReadOnly); 255 280 global->Set(String::New("version"), FunctionTemplate::New(InterpreterV8::FuncVersion), ReadOnly); 256 281 … … 263 288 } 264 289 290 v8::Context::Scope scope(context); 291 292 Local<Array> args = Array::New(map.size()); 293 for (auto it=map.begin(); it!=map.end(); it++) 294 args->Set(String::New(it->first.c_str()), String::New(it->second.c_str())); 295 context->Global()->Set(String::New("arg"), args); 296 265 297 JsStart(filename); 266 298 267 v8::Context::Scope scope(context);268 299 //context->Enter(); 269 270 300 v8::Locker::StartPreemption(10); 271 301 const bool rc = ExecuteFile(filename); 272 302 v8::Locker::StopPreemption(); 273 274 303 //context->Exit(); 275 304 -
trunk/FACT++/src/InterpreterV8.h
r14051 r14055 2 2 #define FACT_InterpreterV8 3 3 4 #include <map> 4 5 #include <string> 5 6 … … 15 16 16 17 #ifdef HAVE_V8 17 voidReportException(v8::TryCatch* try_catch);18 bool ReportException(v8::TryCatch* try_catch); 18 19 bool ExecuteStringNT(const v8::Handle<v8::String> &code, const v8::Handle<v8::Value> &file); 19 20 bool ExecuteCode(const v8::Handle<v8::String> &code, const v8::Handle<v8::Value> &file); … … 26 27 v8::Handle<v8::Value> FuncPrint(const v8::Arguments& args); 27 28 v8::Handle<v8::Value> FuncInclude(const v8::Arguments& args); 29 v8::Handle<v8::Value> FuncExit(const v8::Arguments& args); 28 30 29 31 static v8::Handle<v8::Value> FuncVersion(const v8::Arguments&); … … 33 35 static v8::Handle<v8::Value> WrapSend(const v8::Arguments &args) { if (This) return This->FuncSend(args); else return v8::Undefined(); } 34 36 static v8::Handle<v8::Value> WrapSleep(const v8::Arguments &args) { if (This) return This->FuncSleep(args); else return v8::Undefined(); } 37 static v8::Handle<v8::Value> WrapExit(const v8::Arguments &args) { if (This) return This->FuncExit(args); else return v8::Undefined(); } 35 38 #endif 36 39 … … 56 59 virtual int JsWait(const std::string &, int32_t, uint32_t) { return -1; }; 57 60 58 bool JsRun(const std::string & filename);61 bool JsRun(const std::string &, const std::map<std::string,std::string> & = std::map<std::string,std::string>()); 59 62 static void JsStop(); 60 63 }; 61 64 62 65 #ifndef HAVE_V8 63 inline bool InterpreterV8::JsRun(const std::string & ) { return false; }66 inline bool InterpreterV8::JsRun(const std::string &, const std::map<std::string,std::string> & = std::map<std::string,std::string>()) { return false; } 64 67 inline void InterpreterV8::JsStop() { } 65 68 #endif -
trunk/FACT++/src/RemoteControl.h
r14050 r14055 249 249 if (str.substr(0, 4)==".js ") 250 250 { 251 JsRun(Tools::Trim(str.substr(3))); 251 string opt(str.substr(4)); 252 253 map<string,string> data = Tools::Split(opt, true); 254 if (opt.size()==0) 255 { 256 if (data.size()==0) 257 lout << kRed << "JavaScript filename missing." << endl; 258 else 259 lout << kRed << "Equal sign missing in argument '" << data.begin()->first << "'" << endl; 260 261 return true; 262 } 263 264 JsRun(opt, data); 252 265 return true; 253 266 }
Note:
See TracChangeset
for help on using the changeset viewer.