| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 809     } | 810     } | 
| 810     printf("+----------------------------------------+-------------+\n"); | 811     printf("+----------------------------------------+-------------+\n"); | 
| 811   } | 812   } | 
| 812   if (counters_file_ != NULL) | 813   if (counters_file_ != NULL) | 
| 813     delete counters_file_; | 814     delete counters_file_; | 
| 814 } | 815 } | 
| 815 #endif  // V8_SHARED | 816 #endif  // V8_SHARED | 
| 816 | 817 | 
| 817 | 818 | 
| 818 static FILE* FOpen(const char* path, const char* mode) { | 819 static FILE* FOpen(const char* path, const char* mode) { | 
| 819 #if (defined(_WIN32) || defined(_WIN64)) | 820 #if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)) | 
| 820   FILE* result; | 821   FILE* result; | 
| 821   if (fopen_s(&result, path, mode) == 0) { | 822   if (fopen_s(&result, path, mode) == 0) { | 
| 822     return result; | 823     return result; | 
| 823   } else { | 824   } else { | 
| 824     return NULL; | 825     return NULL; | 
| 825   } | 826   } | 
| 826 #else | 827 #else | 
| 827   FILE* file = fopen(path, mode); | 828   FILE* file = fopen(path, mode); | 
| 828   if (file == NULL) return NULL; | 829   if (file == NULL) return NULL; | 
| 829   struct stat file_stat; | 830   struct stat file_stat; | 
| (...skipping 63 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1246     } | 1244     } | 
| 1247   } | 1245   } | 
| 1248   for (int i = 1; i < options.num_isolates; ++i) { | 1246   for (int i = 1; i < options.num_isolates; ++i) { | 
| 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(); | 
|  | 1254     if (options.last_run) { | 
|  | 1255       // Keep using the same context in the interactive shell. | 
|  | 1256       evaluation_context_ = context; | 
|  | 1257 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 
|  | 1258       // If the interactive debugger is enabled make sure to activate | 
|  | 1259       // it before running the files passed on the command line. | 
|  | 1260       if (i::FLAG_debugger) { | 
|  | 1261         InstallUtilityScript(); | 
|  | 1262       } | 
|  | 1263 #endif  // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 
|  | 1264     } | 
| 1256     { | 1265     { | 
| 1257       Context::Scope cscope(context); | 1266       Context::Scope cscope(context); | 
| 1258       options.isolate_sources[0].Execute(); | 1267       options.isolate_sources[0].Execute(); | 
| 1259     } | 1268     } | 
| 1260     if (options.last_run) { | 1269     if (!options.last_run) { | 
| 1261       // Keep using the same context in the interactive shell |  | 
| 1262       evaluation_context_ = context; |  | 
| 1263     } else { |  | 
| 1264       context.Dispose(); | 1270       context.Dispose(); | 
| 1265     } | 1271     } | 
| 1266 | 1272 | 
| 1267 #ifndef V8_SHARED | 1273 #ifndef V8_SHARED | 
| 1268     // Start preemption if threads have been created and preemption is enabled. | 1274     // Start preemption if threads have been created and preemption is enabled. | 
| 1269     if (threads.length() > 0 | 1275     if (threads.length() > 0 | 
| 1270         && options.use_preemption) { | 1276         && options.use_preemption) { | 
| 1271       Locker::StartPreemption(options.preemption_interval); | 1277       Locker::StartPreemption(options.preemption_interval); | 
| 1272     } | 1278     } | 
| 1273 #endif  // V8_SHARED | 1279 #endif  // V8_SHARED | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1324     return 0; | 1330     return 0; | 
| 1325   } | 1331   } | 
| 1326 #endif  // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1332 #endif  // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 
| 1327 | 1333 | 
| 1328   // 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 | 
| 1329   // executed, but never on --test | 1335   // executed, but never on --test | 
| 1330 | 1336 | 
| 1331   if (( options.interactive_shell | 1337   if (( options.interactive_shell | 
| 1332       || !options.script_executed ) | 1338       || !options.script_executed ) | 
| 1333       && !options.test_shell ) { | 1339       && !options.test_shell ) { | 
| 1334 #ifndef V8_SHARED | 1340 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 
| 1335     InstallUtilityScript(); | 1341     if (!i::FLAG_debugger) { | 
| 1336 #endif  // V8_SHARED | 1342       InstallUtilityScript(); | 
|  | 1343     } | 
|  | 1344 #endif  // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 
| 1337     RunShell(); | 1345     RunShell(); | 
| 1338   } | 1346   } | 
| 1339 | 1347 | 
| 1340   V8::Dispose(); | 1348   V8::Dispose(); | 
| 1341 | 1349 | 
| 1342 #ifndef V8_SHARED | 1350 #ifndef V8_SHARED | 
| 1343   OnExit(); | 1351   OnExit(); | 
| 1344 #endif  // V8_SHARED | 1352 #endif  // V8_SHARED | 
| 1345 | 1353 | 
| 1346   return result; | 1354   return result; | 
| 1347 } | 1355 } | 
| 1348 | 1356 | 
| 1349 }  // namespace v8 | 1357 }  // namespace v8 | 
| 1350 | 1358 | 
| 1351 | 1359 | 
| 1352 #ifndef GOOGLE3 | 1360 #ifndef GOOGLE3 | 
| 1353 int main(int argc, char* argv[]) { | 1361 int main(int argc, char* argv[]) { | 
| 1354   return v8::Shell::Main(argc, argv); | 1362   return v8::Shell::Main(argc, argv); | 
| 1355 } | 1363 } | 
| 1356 #endif | 1364 #endif | 
| OLD | NEW | 
|---|