OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
29 #include <stdlib.h> | 29 #include <stdlib.h> |
30 | 30 |
31 #include "d8.h" | 31 #include "d8.h" |
| 32 #include "d8-debug.h" |
32 #include "debug.h" | 33 #include "debug.h" |
33 #include "api.h" | 34 #include "api.h" |
34 #include "natives.h" | 35 #include "natives.h" |
35 | 36 |
36 | 37 |
37 namespace v8 { | 38 namespace v8 { |
38 | 39 |
39 | 40 |
40 const char* Shell::kHistoryFileName = ".d8_history"; | 41 const char* Shell::kHistoryFileName = ".d8_history"; |
41 const char* Shell::kPrompt = "d8> "; | 42 const char* Shell::kPrompt = "d8> "; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 Persistent<Context> Shell::evaluation_context_; | 92 Persistent<Context> Shell::evaluation_context_; |
92 | 93 |
93 | 94 |
94 // Executes a string within the current v8 context. | 95 // Executes a string within the current v8 context. |
95 bool Shell::ExecuteString(Handle<String> source, | 96 bool Shell::ExecuteString(Handle<String> source, |
96 Handle<Value> name, | 97 Handle<Value> name, |
97 bool print_result, | 98 bool print_result, |
98 bool report_exceptions) { | 99 bool report_exceptions) { |
99 HandleScope handle_scope; | 100 HandleScope handle_scope; |
100 TryCatch try_catch; | 101 TryCatch try_catch; |
| 102 if (i::FLAG_debugger) { |
| 103 // When debugging make exceptions appear to be uncaught. |
| 104 try_catch.SetVerbose(true); |
| 105 } |
101 Handle<Script> script = Script::Compile(source, name); | 106 Handle<Script> script = Script::Compile(source, name); |
102 if (script.IsEmpty()) { | 107 if (script.IsEmpty()) { |
103 // Print errors that happened during compilation. | 108 // Print errors that happened during compilation. |
104 if (report_exceptions) | 109 if (report_exceptions) |
105 ReportException(&try_catch); | 110 ReportException(&try_catch); |
106 return false; | 111 return false; |
107 } else { | 112 } else { |
108 Handle<Value> result = script->Run(); | 113 Handle<Value> result = script->Run(); |
109 if (result.IsEmpty()) { | 114 if (result.IsEmpty()) { |
110 // Print errors that happened during execution. | 115 // Print errors that happened during execution. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 Context::Scope context_scope(utility_context_); | 210 Context::Scope context_scope(utility_context_); |
206 Handle<Object> global = utility_context_->Global(); | 211 Handle<Object> global = utility_context_->Global(); |
207 Handle<Value> fun = global->Get(String::New("GetCompletions")); | 212 Handle<Value> fun = global->Get(String::New("GetCompletions")); |
208 static const int kArgc = 3; | 213 static const int kArgc = 3; |
209 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; | 214 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; |
210 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 215 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
211 return handle_scope.Close(Handle<Array>::Cast(val)); | 216 return handle_scope.Close(Handle<Array>::Cast(val)); |
212 } | 217 } |
213 | 218 |
214 | 219 |
| 220 Handle<String> Shell::DebugEventToText(Handle<Object> event) { |
| 221 HandleScope handle_scope; |
| 222 Context::Scope context_scope(utility_context_); |
| 223 Handle<Object> global = utility_context_->Global(); |
| 224 Handle<Value> fun = global->Get(String::New("DebugEventToText")); |
| 225 TryCatch try_catch; |
| 226 try_catch.SetVerbose(true); |
| 227 static const int kArgc = 1; |
| 228 Handle<Value> argv[kArgc] = { event }; |
| 229 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 230 if (try_catch.HasCaught()) { |
| 231 return handle_scope.Close(try_catch.Exception()->ToString()); |
| 232 } else { |
| 233 return handle_scope.Close(Handle<String>::Cast(val)); |
| 234 } |
| 235 } |
| 236 |
| 237 |
| 238 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { |
| 239 Context::Scope context_scope(utility_context_); |
| 240 Handle<Object> global = utility_context_->Global(); |
| 241 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); |
| 242 static const int kArgc = 1; |
| 243 Handle<Value> argv[kArgc] = { command }; |
| 244 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 245 return val; |
| 246 } |
| 247 |
| 248 |
| 249 Handle<Object> Shell::DebugResponseDetails(Handle<String> response) { |
| 250 Context::Scope context_scope(utility_context_); |
| 251 Handle<Object> global = utility_context_->Global(); |
| 252 Handle<Value> fun = global->Get(String::New("DebugResponseDetails")); |
| 253 static const int kArgc = 1; |
| 254 Handle<Value> argv[kArgc] = { response }; |
| 255 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 256 return Handle<Object>::Cast(val); |
| 257 } |
| 258 |
| 259 |
215 int32_t* Counter::Bind(const char* name) { | 260 int32_t* Counter::Bind(const char* name) { |
216 int i; | 261 int i; |
217 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) | 262 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) |
218 name_[i] = static_cast<char>(name[i]); | 263 name_[i] = static_cast<char>(name[i]); |
219 name_[i] = '\0'; | 264 name_[i] = '\0'; |
220 return &counter_; | 265 return &counter_; |
221 } | 266 } |
222 | 267 |
223 | 268 |
224 CounterCollection::CounterCollection() { | 269 CounterCollection::CounterCollection() { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 Handle<String> file_name = v8::String::New(str); | 453 Handle<String> file_name = v8::String::New(str); |
409 Handle<String> source = ReadFile(str); | 454 Handle<String> source = ReadFile(str); |
410 if (source.IsEmpty()) { | 455 if (source.IsEmpty()) { |
411 printf("Error reading '%s'\n", str); | 456 printf("Error reading '%s'\n", str); |
412 return 1; | 457 return 1; |
413 } | 458 } |
414 if (!ExecuteString(source, file_name, false, true)) | 459 if (!ExecuteString(source, file_name, false, true)) |
415 return 1; | 460 return 1; |
416 } | 461 } |
417 } | 462 } |
| 463 if (i::FLAG_debugger) |
| 464 v8::Debug::AddDebugEventListener(HandleDebugEvent); |
418 if (run_shell) | 465 if (run_shell) |
419 RunShell(); | 466 RunShell(); |
420 OnExit(); | 467 OnExit(); |
421 return 0; | 468 return 0; |
422 } | 469 } |
423 | 470 |
424 | 471 |
425 } // namespace v8 | 472 } // namespace v8 |
426 | 473 |
427 | 474 |
428 int main(int argc, char* argv[]) { | 475 int main(int argc, char* argv[]) { |
429 return v8::Shell::Main(argc, argv); | 476 return v8::Shell::Main(argc, argv); |
430 } | 477 } |
OLD | NEW |