| 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)) { |
| 275 while (argc > arg_index && IsFlag(argv[arg_index])) arg_index++; | 274 arg_index++; |
| 275 } |
| 276 if (argc > arg_index) { | 276 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; | 277 expects.throws = true; |
| 283 do { | 278 arg_index++; |
| 279 if (argc > arg_index && !IsFlag(argv[arg_index])) { |
| 280 expects.type = argv[arg_index]; |
| 284 arg_index++; | 281 arg_index++; |
| 285 } while (argc > arg_index && IsFlag(argv[arg_index])); | 282 if (argc > arg_index && !IsFlag(argv[arg_index])) { |
| 286 if (argc > arg_index) { | 283 expects.beg_pos = atoi(argv[arg_index]); // NOLINT |
| 287 // Next argument is the exception type identifier. | |
| 288 expects.type = argv[arg_index]; | |
| 289 do { | |
| 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) { | |
| 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 | 286 expects.end_pos = atoi(argv[arg_index]); // NOLINT |
| 299 } | 287 } |
| 300 } | 288 } |
| 301 } | 289 } |
| 302 } | 290 } |
| 303 return expects; | 291 return expects; |
| 304 } | 292 } |
| 305 | 293 |
| 306 | 294 |
| 307 int main(int argc, const char* argv[]) { | 295 int main(int argc, const char* argv[]) { |
| 308 // Parse command line. | 296 // Parse command line. |
| 309 // Format: preparser (<scriptfile> | -e "<source>") | 297 // Format: preparser (<scriptfile> | -e "<source>") |
| 310 // ["throws" [<exn-type> [<start> [<end>]]]] | 298 // ["throws" [<exn-type> [<start> [<end>]]]] |
| 311 // Any flags (except an initial -s) are ignored. | 299 // Any flags (except an initial -e) are ignored. |
| 300 // Flags must not separate "throws" and its arguments. |
| 312 | 301 |
| 313 // Check for mandatory filename argument. | 302 // Check for mandatory filename argument. |
| 314 int arg_index = 1; | 303 int arg_index = 1; |
| 315 if (argc <= arg_index) { | 304 if (argc <= arg_index) { |
| 316 fail(NULL, "ERROR: No filename on command line.\n"); | 305 fail(NULL, "ERROR: No filename on command line.\n"); |
| 317 } | 306 } |
| 318 const uint8_t* source = NULL; | 307 const uint8_t* source = NULL; |
| 319 const char* filename = argv[arg_index]; | 308 const char* filename = argv[arg_index]; |
| 320 if (!strcmp(filename, "-e")) { | 309 if (!strcmp(filename, "-e")) { |
| 321 arg_index++; | 310 arg_index++; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 if (data.stack_overflow()) { | 359 if (data.stack_overflow()) { |
| 371 fail(&data, "ERROR: Stack overflow\n"); | 360 fail(&data, "ERROR: Stack overflow\n"); |
| 372 } | 361 } |
| 373 | 362 |
| 374 // Check that the expected exception is thrown, if an exception is | 363 // Check that the expected exception is thrown, if an exception is |
| 375 // expected. | 364 // expected. |
| 376 CheckException(&data, &expects); | 365 CheckException(&data, &expects); |
| 377 | 366 |
| 378 return EXIT_SUCCESS; | 367 return EXIT_SUCCESS; |
| 379 } | 368 } |
| OLD | NEW |