| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return Shell::ReadFromStdin(isolate_); | 153 return Shell::ReadFromStdin(isolate_); |
| 154 } | 154 } |
| 155 | 155 |
| 156 | 156 |
| 157 #ifndef V8_SHARED | 157 #ifndef V8_SHARED |
| 158 CounterMap* Shell::counter_map_; | 158 CounterMap* Shell::counter_map_; |
| 159 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; | 159 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; |
| 160 CounterCollection Shell::local_counters_; | 160 CounterCollection Shell::local_counters_; |
| 161 CounterCollection* Shell::counters_ = &local_counters_; | 161 CounterCollection* Shell::counters_ = &local_counters_; |
| 162 i::Mutex Shell::context_mutex_; | 162 i::Mutex Shell::context_mutex_; |
| 163 const i::TimeTicks Shell::kInitialTicks = i::TimeTicks::HighResolutionNow(); |
| 163 Persistent<Context> Shell::utility_context_; | 164 Persistent<Context> Shell::utility_context_; |
| 164 #endif // V8_SHARED | 165 #endif // V8_SHARED |
| 165 | 166 |
| 166 Persistent<Context> Shell::evaluation_context_; | 167 Persistent<Context> Shell::evaluation_context_; |
| 167 ShellOptions Shell::options; | 168 ShellOptions Shell::options; |
| 168 const char* Shell::kPrompt = "d8> "; | 169 const char* Shell::kPrompt = "d8> "; |
| 169 | 170 |
| 170 | 171 |
| 171 const int MB = 1024 * 1024; | 172 const int MB = 1024 * 1024; |
| 172 | 173 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 | 284 |
| 284 int PerIsolateData::RealmFind(Handle<Context> context) { | 285 int PerIsolateData::RealmFind(Handle<Context> context) { |
| 285 for (int i = 0; i < realm_count_; ++i) { | 286 for (int i = 0; i < realm_count_; ++i) { |
| 286 if (realms_[i] == context) return i; | 287 if (realms_[i] == context) return i; |
| 287 } | 288 } |
| 288 return -1; | 289 return -1; |
| 289 } | 290 } |
| 290 | 291 |
| 291 | 292 |
| 293 #ifndef V8_SHARED |
| 294 // performance.now() returns a time stamp as double, measured in milliseconds. |
| 295 void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 296 i::TimeDelta delta = i::TimeTicks::HighResolutionNow() - kInitialTicks; |
| 297 args.GetReturnValue().Set(delta.InMillisecondsF()); |
| 298 } |
| 299 #endif // V8_SHARED |
| 300 |
| 301 |
| 292 // Realm.current() returns the index of the currently active realm. | 302 // Realm.current() returns the index of the currently active realm. |
| 293 void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) { | 303 void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 294 Isolate* isolate = args.GetIsolate(); | 304 Isolate* isolate = args.GetIsolate(); |
| 295 PerIsolateData* data = PerIsolateData::Get(isolate); | 305 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 296 int index = data->RealmFind(isolate->GetEnteredContext()); | 306 int index = data->RealmFind(isolate->GetEnteredContext()); |
| 297 if (index == -1) return; | 307 if (index == -1) return; |
| 298 args.GetReturnValue().Set(index); | 308 args.GetReturnValue().Set(index); |
| 299 } | 309 } |
| 300 | 310 |
| 301 | 311 |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 realm_template->Set(String::New("dispose"), | 875 realm_template->Set(String::New("dispose"), |
| 866 FunctionTemplate::New(RealmDispose)); | 876 FunctionTemplate::New(RealmDispose)); |
| 867 realm_template->Set(String::New("switch"), | 877 realm_template->Set(String::New("switch"), |
| 868 FunctionTemplate::New(RealmSwitch)); | 878 FunctionTemplate::New(RealmSwitch)); |
| 869 realm_template->Set(String::New("eval"), | 879 realm_template->Set(String::New("eval"), |
| 870 FunctionTemplate::New(RealmEval)); | 880 FunctionTemplate::New(RealmEval)); |
| 871 realm_template->SetAccessor(String::New("shared"), | 881 realm_template->SetAccessor(String::New("shared"), |
| 872 RealmSharedGet, RealmSharedSet); | 882 RealmSharedGet, RealmSharedSet); |
| 873 global_template->Set(String::New("Realm"), realm_template); | 883 global_template->Set(String::New("Realm"), realm_template); |
| 874 | 884 |
| 885 #ifndef V8_SHARED |
| 886 Handle<ObjectTemplate> performance_template = ObjectTemplate::New(); |
| 887 performance_template->Set(String::New("now"), |
| 888 FunctionTemplate::New(PerformanceNow)); |
| 889 global_template->Set(String::New("performance"), performance_template); |
| 890 #endif // V8_SHARED |
| 891 |
| 875 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) | 892 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) |
| 876 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 893 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); |
| 877 AddOSMethods(os_templ); | 894 AddOSMethods(os_templ); |
| 878 global_template->Set(String::New("os"), os_templ); | 895 global_template->Set(String::New("os"), os_templ); |
| 879 #endif // V8_SHARED | 896 #endif // V8_SHARED |
| 880 | 897 |
| 881 return global_template; | 898 return global_template; |
| 882 } | 899 } |
| 883 | 900 |
| 884 | 901 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 | 1241 |
| 1225 SourceGroup::~SourceGroup() { | 1242 SourceGroup::~SourceGroup() { |
| 1226 #ifndef V8_SHARED | 1243 #ifndef V8_SHARED |
| 1227 delete thread_; | 1244 delete thread_; |
| 1228 thread_ = NULL; | 1245 thread_ = NULL; |
| 1229 #endif // V8_SHARED | 1246 #endif // V8_SHARED |
| 1230 } | 1247 } |
| 1231 | 1248 |
| 1232 | 1249 |
| 1233 void SourceGroup::Execute(Isolate* isolate) { | 1250 void SourceGroup::Execute(Isolate* isolate) { |
| 1251 bool exception_was_thrown = false; |
| 1234 for (int i = begin_offset_; i < end_offset_; ++i) { | 1252 for (int i = begin_offset_; i < end_offset_; ++i) { |
| 1235 const char* arg = argv_[i]; | 1253 const char* arg = argv_[i]; |
| 1236 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { | 1254 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { |
| 1237 // Execute argument given to -e option directly. | 1255 // Execute argument given to -e option directly. |
| 1238 HandleScope handle_scope(isolate); | 1256 HandleScope handle_scope(isolate); |
| 1239 Handle<String> file_name = String::New("unnamed"); | 1257 Handle<String> file_name = String::New("unnamed"); |
| 1240 Handle<String> source = String::New(argv_[i + 1]); | 1258 Handle<String> source = String::New(argv_[i + 1]); |
| 1241 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { | 1259 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { |
| 1242 Shell::Exit(1); | 1260 exception_was_thrown = true; |
| 1261 break; |
| 1243 } | 1262 } |
| 1244 ++i; | 1263 ++i; |
| 1245 } else if (arg[0] == '-') { | 1264 } else if (arg[0] == '-') { |
| 1246 // Ignore other options. They have been parsed already. | 1265 // Ignore other options. They have been parsed already. |
| 1247 } else { | 1266 } else { |
| 1248 // Use all other arguments as names of files to load and run. | 1267 // Use all other arguments as names of files to load and run. |
| 1249 HandleScope handle_scope(isolate); | 1268 HandleScope handle_scope(isolate); |
| 1250 Handle<String> file_name = String::New(arg); | 1269 Handle<String> file_name = String::New(arg); |
| 1251 Handle<String> source = ReadFile(isolate, arg); | 1270 Handle<String> source = ReadFile(isolate, arg); |
| 1252 if (source.IsEmpty()) { | 1271 if (source.IsEmpty()) { |
| 1253 printf("Error reading '%s'\n", arg); | 1272 printf("Error reading '%s'\n", arg); |
| 1254 Shell::Exit(1); | 1273 Shell::Exit(1); |
| 1255 } | 1274 } |
| 1256 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { | 1275 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { |
| 1257 Shell::Exit(1); | 1276 exception_was_thrown = true; |
| 1277 break; |
| 1258 } | 1278 } |
| 1259 } | 1279 } |
| 1260 } | 1280 } |
| 1281 if (exception_was_thrown != Shell::options.expected_to_throw) { |
| 1282 Shell::Exit(1); |
| 1283 } |
| 1261 } | 1284 } |
| 1262 | 1285 |
| 1263 | 1286 |
| 1264 Handle<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) { | 1287 Handle<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) { |
| 1265 int size; | 1288 int size; |
| 1266 char* chars = ReadChars(isolate, name, &size); | 1289 char* chars = ReadChars(isolate, name, &size); |
| 1267 if (chars == NULL) return Handle<String>(); | 1290 if (chars == NULL) return Handle<String>(); |
| 1268 Handle<String> result = String::New(chars, size); | 1291 Handle<String> result = String::New(chars, size); |
| 1269 delete[] chars; | 1292 delete[] chars; |
| 1270 return result; | 1293 return result; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 options.num_parallel_files++; | 1429 options.num_parallel_files++; |
| 1407 #endif // V8_SHARED | 1430 #endif // V8_SHARED |
| 1408 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { | 1431 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { |
| 1409 #ifdef V8_SHARED | 1432 #ifdef V8_SHARED |
| 1410 printf("D8 with shared library does not support constant dumping\n"); | 1433 printf("D8 with shared library does not support constant dumping\n"); |
| 1411 return false; | 1434 return false; |
| 1412 #else | 1435 #else |
| 1413 options.dump_heap_constants = true; | 1436 options.dump_heap_constants = true; |
| 1414 argv[i] = NULL; | 1437 argv[i] = NULL; |
| 1415 #endif | 1438 #endif |
| 1439 } else if (strcmp(argv[i], "--throws") == 0) { |
| 1440 options.expected_to_throw = true; |
| 1441 argv[i] = NULL; |
| 1416 } | 1442 } |
| 1417 #ifdef V8_SHARED | 1443 #ifdef V8_SHARED |
| 1418 else if (strcmp(argv[i], "--dump-counters") == 0) { | 1444 else if (strcmp(argv[i], "--dump-counters") == 0) { |
| 1419 printf("D8 with shared library does not include counters\n"); | 1445 printf("D8 with shared library does not include counters\n"); |
| 1420 return false; | 1446 return false; |
| 1421 } else if (strcmp(argv[i], "--debugger") == 0) { | 1447 } else if (strcmp(argv[i], "--debugger") == 0) { |
| 1422 printf("Javascript debugger not included\n"); | 1448 printf("Javascript debugger not included\n"); |
| 1423 return false; | 1449 return false; |
| 1424 } | 1450 } |
| 1425 #endif // V8_SHARED | 1451 #endif // V8_SHARED |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 } | 1755 } |
| 1730 | 1756 |
| 1731 } // namespace v8 | 1757 } // namespace v8 |
| 1732 | 1758 |
| 1733 | 1759 |
| 1734 #ifndef GOOGLE3 | 1760 #ifndef GOOGLE3 |
| 1735 int main(int argc, char* argv[]) { | 1761 int main(int argc, char* argv[]) { |
| 1736 return v8::Shell::Main(argc, argv); | 1762 return v8::Shell::Main(argc, argv); |
| 1737 } | 1763 } |
| 1738 #endif | 1764 #endif |
| OLD | NEW |