| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 const char* Shell::ToCString(const v8::String::Utf8Value& value) { | 139 const char* Shell::ToCString(const v8::String::Utf8Value& value) { |
| 140 return *value ? *value : "<string conversion failed>"; | 140 return *value ? *value : "<string conversion failed>"; |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 // Executes a string within the current v8 context. | 144 // Executes a string within the current v8 context. |
| 145 bool Shell::ExecuteString(Handle<String> source, | 145 bool Shell::ExecuteString(Handle<String> source, |
| 146 Handle<Value> name, | 146 Handle<Value> name, |
| 147 bool print_result, | 147 bool print_result, |
| 148 bool report_exceptions) { | 148 bool report_exceptions) { |
| 149 #ifndef V8_SHARED | 149 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
| 150 bool FLAG_debugger = i::FLAG_debugger; | 150 bool FLAG_debugger = i::FLAG_debugger; |
| 151 #else | 151 #else |
| 152 bool FLAG_debugger = false; | 152 bool FLAG_debugger = false; |
| 153 #endif // V8_SHARED | 153 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 154 HandleScope handle_scope; | 154 HandleScope handle_scope; |
| 155 TryCatch try_catch; | 155 TryCatch try_catch; |
| 156 options.script_executed = true; | 156 options.script_executed = true; |
| 157 if (FLAG_debugger) { | 157 if (FLAG_debugger) { |
| 158 // When debugging make exceptions appear to be uncaught. | 158 // When debugging make exceptions appear to be uncaught. |
| 159 try_catch.SetVerbose(true); | 159 try_catch.SetVerbose(true); |
| 160 } | 160 } |
| 161 Handle<Script> script = Script::Compile(source, name); | 161 Handle<Script> script = Script::Compile(source, name); |
| 162 if (script.IsEmpty()) { | 162 if (script.IsEmpty()) { |
| 163 // Print errors that happened during compilation. | 163 // Print errors that happened during compilation. |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 void Shell::InstallUtilityScript() { | 587 void Shell::InstallUtilityScript() { |
| 588 Locker lock; | 588 Locker lock; |
| 589 HandleScope scope; | 589 HandleScope scope; |
| 590 // If we use the utility context, we have to set the security tokens so that | 590 // If we use the utility context, we have to set the security tokens so that |
| 591 // utility, evaluation and debug context can all access each other. | 591 // utility, evaluation and debug context can all access each other. |
| 592 utility_context_->SetSecurityToken(Undefined()); | 592 utility_context_->SetSecurityToken(Undefined()); |
| 593 evaluation_context_->SetSecurityToken(Undefined()); | 593 evaluation_context_->SetSecurityToken(Undefined()); |
| 594 Context::Scope utility_scope(utility_context_); | 594 Context::Scope utility_scope(utility_context_); |
| 595 | 595 |
| 596 #ifdef ENABLE_DEBUGGER_SUPPORT | 596 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 597 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); |
| 597 // Install the debugger object in the utility scope | 598 // Install the debugger object in the utility scope |
| 598 i::Debug* debug = i::Isolate::Current()->debug(); | 599 i::Debug* debug = i::Isolate::Current()->debug(); |
| 599 debug->Load(); | 600 debug->Load(); |
| 600 i::Handle<i::JSObject> js_debug | 601 i::Handle<i::JSObject> js_debug |
| 601 = i::Handle<i::JSObject>(debug->debug_context()->global()); | 602 = i::Handle<i::JSObject>(debug->debug_context()->global()); |
| 602 utility_context_->Global()->Set(String::New("$debug"), | 603 utility_context_->Global()->Set(String::New("$debug"), |
| 603 Utils::ToLocal(js_debug)); | 604 Utils::ToLocal(js_debug)); |
| 604 debug->debug_context()->set_security_token(HEAP->undefined_value()); | 605 debug->debug_context()->set_security_token(HEAP->undefined_value()); |
| 605 #endif // ENABLE_DEBUGGER_SUPPORT | 606 #endif // ENABLE_DEBUGGER_SUPPORT |
| 606 | 607 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 | 894 |
| 894 | 895 |
| 895 void Shell::RunShell() { | 896 void Shell::RunShell() { |
| 896 Locker locker; | 897 Locker locker; |
| 897 Context::Scope context_scope(evaluation_context_); | 898 Context::Scope context_scope(evaluation_context_); |
| 898 HandleScope outer_scope; | 899 HandleScope outer_scope; |
| 899 Handle<String> name = String::New("(d8)"); | 900 Handle<String> name = String::New("(d8)"); |
| 900 #ifndef V8_SHARED | 901 #ifndef V8_SHARED |
| 901 console = LineEditor::Get(); | 902 console = LineEditor::Get(); |
| 902 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); | 903 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); |
| 903 if (i::FLAG_debugger) { | |
| 904 printf("JavaScript debugger enabled\n"); | |
| 905 } | |
| 906 console->Open(); | 904 console->Open(); |
| 907 while (true) { | 905 while (true) { |
| 908 i::SmartArrayPointer<char> input = console->Prompt(Shell::kPrompt); | 906 i::SmartArrayPointer<char> input = console->Prompt(Shell::kPrompt); |
| 909 if (input.is_empty()) break; | 907 if (input.is_empty()) break; |
| 910 console->AddHistory(*input); | 908 console->AddHistory(*input); |
| 911 HandleScope inner_scope; | 909 HandleScope inner_scope; |
| 912 ExecuteString(String::New(*input), name, true, true); | 910 ExecuteString(String::New(*input), name, true, true); |
| 913 } | 911 } |
| 914 #else | 912 #else |
| 915 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); | 913 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 options.isolate_sources[i].StartExecuteInThread(); | 1247 options.isolate_sources[i].StartExecuteInThread(); |
| 1250 } | 1248 } |
| 1251 #endif // V8_SHARED | 1249 #endif // V8_SHARED |
| 1252 { // NOLINT | 1250 { // NOLINT |
| 1253 Locker lock; | 1251 Locker lock; |
| 1254 HandleScope scope; | 1252 HandleScope scope; |
| 1255 Persistent<Context> context = CreateEvaluationContext(); | 1253 Persistent<Context> context = CreateEvaluationContext(); |
| 1256 if (options.last_run) { | 1254 if (options.last_run) { |
| 1257 // Keep using the same context in the interactive shell. | 1255 // Keep using the same context in the interactive shell. |
| 1258 evaluation_context_ = context; | 1256 evaluation_context_ = context; |
| 1259 #ifndef V8_SHARED | 1257 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
| 1260 // If the interactive debugger is enabled make sure to activate | 1258 // If the interactive debugger is enabled make sure to activate |
| 1261 // it before running the files passed on the command line. | 1259 // it before running the files passed on the command line. |
| 1262 if (i::FLAG_debugger) { | 1260 if (i::FLAG_debugger) { |
| 1263 InstallUtilityScript(); | 1261 InstallUtilityScript(); |
| 1264 } | 1262 } |
| 1265 #endif // V8_SHARED | 1263 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 1266 } | 1264 } |
| 1267 { | 1265 { |
| 1268 Context::Scope cscope(context); | 1266 Context::Scope cscope(context); |
| 1269 options.isolate_sources[0].Execute(); | 1267 options.isolate_sources[0].Execute(); |
| 1270 } | 1268 } |
| 1271 if (!options.last_run) { | 1269 if (!options.last_run) { |
| 1272 context.Dispose(); | 1270 context.Dispose(); |
| 1273 } | 1271 } |
| 1274 | 1272 |
| 1275 #ifndef V8_SHARED | 1273 #ifndef V8_SHARED |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 return 0; | 1330 return 0; |
| 1333 } | 1331 } |
| 1334 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1332 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 1335 | 1333 |
| 1336 // Run interactive shell if explicitly requested or if no script has been | 1334 // Run interactive shell if explicitly requested or if no script has been |
| 1337 // executed, but never on --test | 1335 // executed, but never on --test |
| 1338 | 1336 |
| 1339 if (( options.interactive_shell | 1337 if (( options.interactive_shell |
| 1340 || !options.script_executed ) | 1338 || !options.script_executed ) |
| 1341 && !options.test_shell ) { | 1339 && !options.test_shell ) { |
| 1342 #ifndef V8_SHARED | 1340 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
| 1343 if (!i::FLAG_debugger) { | 1341 if (!i::FLAG_debugger) { |
| 1344 InstallUtilityScript(); | 1342 InstallUtilityScript(); |
| 1345 } | 1343 } |
| 1346 #endif // V8_SHARED | 1344 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 1347 RunShell(); | 1345 RunShell(); |
| 1348 } | 1346 } |
| 1349 | 1347 |
| 1350 V8::Dispose(); | 1348 V8::Dispose(); |
| 1351 | 1349 |
| 1352 #ifndef V8_SHARED | 1350 #ifndef V8_SHARED |
| 1353 OnExit(); | 1351 OnExit(); |
| 1354 #endif // V8_SHARED | 1352 #endif // V8_SHARED |
| 1355 | 1353 |
| 1356 return result; | 1354 return result; |
| 1357 } | 1355 } |
| 1358 | 1356 |
| 1359 } // namespace v8 | 1357 } // namespace v8 |
| 1360 | 1358 |
| 1361 | 1359 |
| 1362 #ifndef GOOGLE3 | 1360 #ifndef GOOGLE3 |
| 1363 int main(int argc, char* argv[]) { | 1361 int main(int argc, char* argv[]) { |
| 1364 return v8::Shell::Main(argc, argv); | 1362 return v8::Shell::Main(argc, argv); |
| 1365 } | 1363 } |
| 1366 #endif | 1364 #endif |
| OLD | NEW |