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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 } | 260 } |
261 } else if (reader.throws()) { | 261 } else if (reader.throws()) { |
262 const char* message = reader.message(); | 262 const char* message = reader.message(); |
263 fail(data, "Throws unexpectedly with message: %s at location %d-%d\n", | 263 fail(data, "Throws unexpectedly with message: %s at location %d-%d\n", |
264 message, reader.beg_pos(), reader.end_pos()); | 264 message, reader.beg_pos(), reader.end_pos()); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 | 268 |
269 ExceptionExpectation ParseExpectation(int argc, const char* argv[]) { | 269 ExceptionExpectation ParseExpectation(int argc, const char* argv[]) { |
270 // Parse ["throws" [<exn-type> [<start> [<end>]]]]. | |
270 ExceptionExpectation expects; | 271 ExceptionExpectation expects; |
271 | |
272 // Parse exception expectations from (the remainder of) the command line. | |
273 int arg_index = 0; | 272 int arg_index = 0; |
274 // Skip any flags. | 273 while (argc > arg_index && strncmp("throws", argv[arg_index], 7)) |
Lasse Reichstein
2011/10/13 13:08:14
Braces around then-branch.
ulan
2011/10/13 13:43:18
Done.
| |
275 while (argc > arg_index && IsFlag(argv[arg_index])) arg_index++; | 274 ++arg_index; |
Lasse Reichstein
2011/10/13 13:08:14
For consistency with the remaining code, just use
ulan
2011/10/13 13:43:18
Done.
| |
276 if (argc > arg_index) { | 275 if (argc > arg_index) { |
277 if (strncmp("throws", argv[arg_index], 7)) { | |
278 // First argument after filename, if present, must be the verbatim | |
279 // "throws", marking that the preparsing should fail with an exception. | |
280 fail(NULL, "ERROR: Extra arguments not prefixed by \"throws\".\n"); | |
281 } | |
282 expects.throws = true; | 276 expects.throws = true; |
283 do { | 277 ++arg_index; |
284 arg_index++; | 278 if (argc == arg_index || IsFlag(argv[arg_index])) |
Lasse Reichstein
2011/10/13 13:08:14
Always curly braces around then-branch on multi-li
ulan
2011/10/13 13:43:18
Done.
| |
285 } while (argc > arg_index && IsFlag(argv[arg_index])); | 279 fail(NULL, "ERROR: exception type must follow 'throws'.\n"); |
Lasse Reichstein
2011/10/13 13:08:14
This changes the command line to require the excep
ulan
2011/10/13 13:43:18
Yep, didn't notice that it is optional.
I prefer t
| |
286 if (argc > arg_index) { | 280 expects.type = argv[arg_index]; |
287 // Next argument is the exception type identifier. | 281 ++arg_index; |
288 expects.type = argv[arg_index]; | 282 if (argc > arg_index && !IsFlag(argv[arg_index])) { |
289 do { | 283 expects.beg_pos = atoi(argv[arg_index]); // NOLINT |
290 arg_index++; | 284 ++arg_index; |
291 } while (argc > arg_index && IsFlag(argv[arg_index])); | 285 if (argc > arg_index && !IsFlag(argv[arg_index])) { |
292 if (argc > arg_index) { | 286 expects.end_pos = atoi(argv[arg_index]); // NOLINT |
293 expects.beg_pos = atoi(argv[arg_index]); // NOLINT | |
294 do { | |
295 arg_index++; | |
296 } while (argc > arg_index && IsFlag(argv[arg_index])); | |
297 if (argc > arg_index) { | |
298 expects.end_pos = atoi(argv[arg_index]); // NOLINT | |
299 } | |
300 } | 287 } |
301 } | 288 } |
302 } | 289 } |
303 return expects; | 290 return expects; |
304 } | 291 } |
305 | 292 |
306 | 293 |
307 int main(int argc, const char* argv[]) { | 294 int main(int argc, const char* argv[]) { |
308 // Parse command line. | 295 // Parse command line. |
309 // Format: preparser (<scriptfile> | -e "<source>") | 296 // Format: preparser (<scriptfile> | -e "<source>") |
310 // ["throws" [<exn-type> [<start> [<end>]]]] | 297 // ["throws" [<exn-type> [<start> [<end>]]]] |
311 // Any flags (except an initial -s) are ignored. | 298 // Any flags (except an initial -s) are ignored. |
Lasse Reichstein
2011/10/13 13:08:14
"-s" should probably be "-e". Mea culpa :)
ulan
2011/10/13 13:43:18
Done.
| |
299 // Flags must not separate "throws" and its arguments. | |
Lasse Reichstein
2011/10/13 13:08:14
Yes, that's perfectly fine. No good reason to allo
| |
312 | 300 |
313 // Check for mandatory filename argument. | 301 // Check for mandatory filename argument. |
314 int arg_index = 1; | 302 int arg_index = 1; |
315 if (argc <= arg_index) { | 303 if (argc <= arg_index) { |
316 fail(NULL, "ERROR: No filename on command line.\n"); | 304 fail(NULL, "ERROR: No filename on command line.\n"); |
317 } | 305 } |
318 const uint8_t* source = NULL; | 306 const uint8_t* source = NULL; |
319 const char* filename = argv[arg_index]; | 307 const char* filename = argv[arg_index]; |
320 if (!strcmp(filename, "-e")) { | 308 if (!strcmp(filename, "-e")) { |
321 arg_index++; | 309 arg_index++; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 if (data.stack_overflow()) { | 358 if (data.stack_overflow()) { |
371 fail(&data, "ERROR: Stack overflow\n"); | 359 fail(&data, "ERROR: Stack overflow\n"); |
372 } | 360 } |
373 | 361 |
374 // Check that the expected exception is thrown, if an exception is | 362 // Check that the expected exception is thrown, if an exception is |
375 // expected. | 363 // expected. |
376 CheckException(&data, &expects); | 364 CheckException(&data, &expects); |
377 | 365 |
378 return EXIT_SUCCESS; | 366 return EXIT_SUCCESS; |
379 } | 367 } |
OLD | NEW |