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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 | 1224 |
1225 SourceGroup::~SourceGroup() { | 1225 SourceGroup::~SourceGroup() { |
1226 #ifndef V8_SHARED | 1226 #ifndef V8_SHARED |
1227 delete thread_; | 1227 delete thread_; |
1228 thread_ = NULL; | 1228 thread_ = NULL; |
1229 #endif // V8_SHARED | 1229 #endif // V8_SHARED |
1230 } | 1230 } |
1231 | 1231 |
1232 | 1232 |
1233 void SourceGroup::Execute(Isolate* isolate) { | 1233 void SourceGroup::Execute(Isolate* isolate) { |
| 1234 bool exception_was_thrown = false; |
1234 for (int i = begin_offset_; i < end_offset_; ++i) { | 1235 for (int i = begin_offset_; i < end_offset_; ++i) { |
1235 const char* arg = argv_[i]; | 1236 const char* arg = argv_[i]; |
1236 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { | 1237 if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { |
1237 // Execute argument given to -e option directly. | 1238 // Execute argument given to -e option directly. |
1238 HandleScope handle_scope(isolate); | 1239 HandleScope handle_scope(isolate); |
1239 Handle<String> file_name = String::New("unnamed"); | 1240 Handle<String> file_name = String::New("unnamed"); |
1240 Handle<String> source = String::New(argv_[i + 1]); | 1241 Handle<String> source = String::New(argv_[i + 1]); |
1241 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { | 1242 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { |
1242 Shell::Exit(1); | 1243 exception_was_thrown = true; |
| 1244 break; |
1243 } | 1245 } |
1244 ++i; | 1246 ++i; |
1245 } else if (arg[0] == '-') { | 1247 } else if (arg[0] == '-') { |
1246 // Ignore other options. They have been parsed already. | 1248 // Ignore other options. They have been parsed already. |
1247 } else { | 1249 } else { |
1248 // Use all other arguments as names of files to load and run. | 1250 // Use all other arguments as names of files to load and run. |
1249 HandleScope handle_scope(isolate); | 1251 HandleScope handle_scope(isolate); |
1250 Handle<String> file_name = String::New(arg); | 1252 Handle<String> file_name = String::New(arg); |
1251 Handle<String> source = ReadFile(isolate, arg); | 1253 Handle<String> source = ReadFile(isolate, arg); |
1252 if (source.IsEmpty()) { | 1254 if (source.IsEmpty()) { |
1253 printf("Error reading '%s'\n", arg); | 1255 printf("Error reading '%s'\n", arg); |
1254 Shell::Exit(1); | 1256 Shell::Exit(1); |
1255 } | 1257 } |
1256 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { | 1258 if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { |
1257 Shell::Exit(1); | 1259 exception_was_thrown = true; |
| 1260 break; |
1258 } | 1261 } |
1259 } | 1262 } |
1260 } | 1263 } |
| 1264 if (exception_was_thrown != Shell::options.expected_to_throw) { |
| 1265 Shell::Exit(1); |
| 1266 } |
1261 } | 1267 } |
1262 | 1268 |
1263 | 1269 |
1264 Handle<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) { | 1270 Handle<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) { |
1265 int size; | 1271 int size; |
1266 char* chars = ReadChars(isolate, name, &size); | 1272 char* chars = ReadChars(isolate, name, &size); |
1267 if (chars == NULL) return Handle<String>(); | 1273 if (chars == NULL) return Handle<String>(); |
1268 Handle<String> result = String::New(chars, size); | 1274 Handle<String> result = String::New(chars, size); |
1269 delete[] chars; | 1275 delete[] chars; |
1270 return result; | 1276 return result; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 options.num_parallel_files++; | 1412 options.num_parallel_files++; |
1407 #endif // V8_SHARED | 1413 #endif // V8_SHARED |
1408 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { | 1414 } else if (strcmp(argv[i], "--dump-heap-constants") == 0) { |
1409 #ifdef V8_SHARED | 1415 #ifdef V8_SHARED |
1410 printf("D8 with shared library does not support constant dumping\n"); | 1416 printf("D8 with shared library does not support constant dumping\n"); |
1411 return false; | 1417 return false; |
1412 #else | 1418 #else |
1413 options.dump_heap_constants = true; | 1419 options.dump_heap_constants = true; |
1414 argv[i] = NULL; | 1420 argv[i] = NULL; |
1415 #endif | 1421 #endif |
| 1422 } else if (strcmp(argv[i], "--throws") == 0) { |
| 1423 options.expected_to_throw = true; |
| 1424 argv[i] = NULL; |
1416 } | 1425 } |
1417 #ifdef V8_SHARED | 1426 #ifdef V8_SHARED |
1418 else if (strcmp(argv[i], "--dump-counters") == 0) { | 1427 else if (strcmp(argv[i], "--dump-counters") == 0) { |
1419 printf("D8 with shared library does not include counters\n"); | 1428 printf("D8 with shared library does not include counters\n"); |
1420 return false; | 1429 return false; |
1421 } else if (strcmp(argv[i], "--debugger") == 0) { | 1430 } else if (strcmp(argv[i], "--debugger") == 0) { |
1422 printf("Javascript debugger not included\n"); | 1431 printf("Javascript debugger not included\n"); |
1423 return false; | 1432 return false; |
1424 } | 1433 } |
1425 #endif // V8_SHARED | 1434 #endif // V8_SHARED |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 } | 1738 } |
1730 | 1739 |
1731 } // namespace v8 | 1740 } // namespace v8 |
1732 | 1741 |
1733 | 1742 |
1734 #ifndef GOOGLE3 | 1743 #ifndef GOOGLE3 |
1735 int main(int argc, char* argv[]) { | 1744 int main(int argc, char* argv[]) { |
1736 return v8::Shell::Main(argc, argv); | 1745 return v8::Shell::Main(argc, argv); |
1737 } | 1746 } |
1738 #endif | 1747 #endif |
OLD | NEW |