Changeset 14055 for trunk/FACT++/src/InterpreterV8.cc
- Timestamp:
- 06/03/12 21:39:43 (12 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.