| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 Handle<Script> script = Script::Compile(source, name); | 121 Handle<Script> script = Script::Compile(source, name); |
| 122 if (script.IsEmpty()) { | 122 if (script.IsEmpty()) { |
| 123 // Print errors that happened during compilation. | 123 // Print errors that happened during compilation. |
| 124 if (report_exceptions && !i::FLAG_debugger) | 124 if (report_exceptions && !i::FLAG_debugger) |
| 125 ReportException(&try_catch); | 125 ReportException(&try_catch); |
| 126 return false; | 126 return false; |
| 127 } else { | 127 } else { |
| 128 Handle<Value> result = script->Run(); | 128 Handle<Value> result = script->Run(); |
| 129 if (result.IsEmpty()) { | 129 if (result.IsEmpty()) { |
| 130 ASSERT(try_catch.HasCaught()); |
| 130 // Print errors that happened during execution. | 131 // Print errors that happened during execution. |
| 131 if (report_exceptions && !i::FLAG_debugger) | 132 if (report_exceptions && !i::FLAG_debugger) |
| 132 ReportException(&try_catch); | 133 ReportException(&try_catch); |
| 133 return false; | 134 return false; |
| 134 } else { | 135 } else { |
| 136 ASSERT(!try_catch.HasCaught()); |
| 135 if (print_result && !result->IsUndefined()) { | 137 if (print_result && !result->IsUndefined()) { |
| 136 // If all went well and the result wasn't undefined then print | 138 // If all went well and the result wasn't undefined then print |
| 137 // the returned value. | 139 // the returned value. |
| 138 v8::String::Utf8Value str(result); | 140 v8::String::Utf8Value str(result); |
| 139 const char* cstr = ToCString(str); | 141 const char* cstr = ToCString(str); |
| 140 printf("%s\n", cstr); | 142 printf("%s\n", cstr); |
| 141 } | 143 } |
| 142 return true; | 144 return true; |
| 143 } | 145 } |
| 144 } | 146 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 398 |
| 397 void Shell::AddHistogramSample(void* histogram, int sample) { | 399 void Shell::AddHistogramSample(void* histogram, int sample) { |
| 398 Counter* counter = reinterpret_cast<Counter*>(histogram); | 400 Counter* counter = reinterpret_cast<Counter*>(histogram); |
| 399 counter->AddSample(sample); | 401 counter->AddSample(sample); |
| 400 } | 402 } |
| 401 | 403 |
| 402 | 404 |
| 403 void Shell::Initialize() { | 405 void Shell::Initialize() { |
| 404 Shell::counter_map_ = new CounterMap(); | 406 Shell::counter_map_ = new CounterMap(); |
| 405 // Set up counters | 407 // Set up counters |
| 406 if (i::FLAG_map_counters != NULL) | 408 if (i::StrLength(i::FLAG_map_counters) != 0) |
| 407 MapCounters(i::FLAG_map_counters); | 409 MapCounters(i::FLAG_map_counters); |
| 408 if (i::FLAG_dump_counters) { | 410 if (i::FLAG_dump_counters) { |
| 409 V8::SetCounterFunction(LookupCounter); | 411 V8::SetCounterFunction(LookupCounter); |
| 410 V8::SetCreateHistogramFunction(CreateHistogram); | 412 V8::SetCreateHistogramFunction(CreateHistogram); |
| 411 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 413 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| 412 } | 414 } |
| 413 | 415 |
| 414 // Initialize the global objects | 416 // Initialize the global objects |
| 415 HandleScope scope; | 417 HandleScope scope; |
| 416 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 418 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); |
| 417 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 419 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); |
| 418 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); | 420 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); |
| 419 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); | 421 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); |
| 420 global_template->Set(String::New("readline"), | 422 global_template->Set(String::New("readline"), |
| 421 FunctionTemplate::New(ReadLine)); | 423 FunctionTemplate::New(ReadLine)); |
| 422 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 424 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); |
| 423 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 425 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
| 424 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 426 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
| 425 | 427 |
| 428 #ifdef LIVE_OBJECT_LIST |
| 429 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); |
| 430 #else |
| 431 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); |
| 432 #endif |
| 433 |
| 426 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 434 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); |
| 427 AddOSMethods(os_templ); | 435 AddOSMethods(os_templ); |
| 428 global_template->Set(String::New("os"), os_templ); | 436 global_template->Set(String::New("os"), os_templ); |
| 429 | 437 |
| 430 utility_context_ = Context::New(NULL, global_template); | 438 utility_context_ = Context::New(NULL, global_template); |
| 431 utility_context_->SetSecurityToken(Undefined()); | 439 utility_context_->SetSecurityToken(Undefined()); |
| 432 Context::Scope utility_scope(utility_context_); | 440 Context::Scope utility_scope(utility_context_); |
| 433 | 441 |
| 434 i::JSArguments js_args = i::FLAG_js_arguments; | 442 i::JSArguments js_args = i::FLAG_js_arguments; |
| 435 i::Handle<i::FixedArray> arguments_array = | 443 i::Handle<i::FixedArray> arguments_array = |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 return 0; | 785 return 0; |
| 778 } | 786 } |
| 779 | 787 |
| 780 | 788 |
| 781 } // namespace v8 | 789 } // namespace v8 |
| 782 | 790 |
| 783 | 791 |
| 784 int main(int argc, char* argv[]) { | 792 int main(int argc, char* argv[]) { |
| 785 return v8::Shell::Main(argc, argv); | 793 return v8::Shell::Main(argc, argv); |
| 786 } | 794 } |
| OLD | NEW |