Commit dcfa021f authored by lrn@chromium.org's avatar lrn@chromium.org

Make preparser-process.cc ignore flags on the command line.

Avoids breaking when passed, e.g., the --nosse2 flag by certain builders.

Review URL: http://codereview.chromium.org/6964008

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7821 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 7cd41c87
// Copyright 2010 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -203,74 +203,114 @@ void fail(v8::PreParserData* data, const char* message, ...) { ...@@ -203,74 +203,114 @@ void fail(v8::PreParserData* data, const char* message, ...) {
}; };
bool IsFlag(const char* arg) {
// Anything starting with '-' is considered a flag.
// It's summarily ignored for now.
return arg[0] == '-';
}
struct ExceptionExpectation {
ExceptionExpectation()
: throws(false), type(NULL), beg_pos(-1), end_pos(-1) { }
bool throws;
const char* type;
int beg_pos;
int end_pos;
};
void CheckException(v8::PreParserData* data, void CheckException(v8::PreParserData* data,
bool throws, ExceptionExpectation* expects) {
const char* message,
int beg_pos,
int end_pos) {
PreparseDataInterpreter reader(data->data(), data->size()); PreparseDataInterpreter reader(data->data(), data->size());
if (throws) { if (expects->throws) {
if (!reader.throws()) { if (!reader.throws()) {
if (message == NULL) { if (expects->type == NULL) {
fail(data, "Didn't throw as expected\n"); fail(data, "Didn't throw as expected\n");
} else { } else {
fail(data, "Didn't throw \"%s\" as expected\n", message); fail(data, "Didn't throw \"%s\" as expected\n", expects->type);
} }
} }
if (message != NULL) { if (expects->type != NULL) {
const char* actual_message = reader.message(); const char* actual_message = reader.message();
if (strcmp(message, actual_message)) { if (strcmp(expects->type, actual_message)) {
fail(data, "Wrong error message. Expected <%s>, found <%s>\n", fail(data, "Wrong error message. Expected <%s>, found <%s>\n",
message, actual_message); expects->type, actual_message);
} }
} }
if (beg_pos >= 0) { if (expects->beg_pos >= 0) {
if (beg_pos != reader.beg_pos()) { if (expects->beg_pos != reader.beg_pos()) {
fail(data, "Wrong error start position: Expected %i, found %i\n", fail(data, "Wrong error start position: Expected %i, found %i\n",
beg_pos, reader.beg_pos()); expects->beg_pos, reader.beg_pos());
} }
} }
if (end_pos >= 0) { if (expects->end_pos >= 0) {
if (end_pos != reader.end_pos()) { if (expects->end_pos != reader.end_pos()) {
fail(data, "Wrong error end position: Expected %i, found %i\n", fail(data, "Wrong error end position: Expected %i, found %i\n",
end_pos, reader.end_pos()); expects->end_pos, reader.end_pos());
} }
} }
} else if (reader.throws()) { } else if (reader.throws()) {
const char* message = reader.message(); const char* message = reader.message();
fail(data, "Throws unexpectedly with message: %s\n", fail(data, "Throws unexpectedly with message: %s\n", message);
message);
} }
} }
int main(int argc, char* argv[]) {
// Check for filename argument. ExceptionExpectation ParseExpectation(int argc, const char* argv[]) {
if (argc < 2) { ExceptionExpectation expects;
fail(NULL, "ERROR: No filename on command line.\n");
} // Parse exception expectations from (the remainder of) the command line.
const char* filename = argv[1]; int arg_index = 0;
// Skip any flags.
// Parse expectations. while (argc > arg_index && IsFlag(argv[arg_index])) arg_index++;
bool throws = false; if (argc > arg_index) {
const char* throws_message = NULL; if (strncmp("throws", argv[arg_index], 7)) {
int throws_beg_pos = -1; // First argument after filename, if present, must be the verbatim
int throws_end_pos = -1; // "throws", marking that the preparsing should fail with an exception.
// Check for throws argument.
if (argc > 2) {
if (strncmp("throws", argv[2], 6)) {
fail(NULL, "ERROR: Extra arguments not prefixed by \"throws\".\n"); fail(NULL, "ERROR: Extra arguments not prefixed by \"throws\".\n");
} }
throws = true; expects.throws = true;
if (argc > 3) { do {
throws_message = argv[3]; arg_index++;
} } while (argc > arg_index && IsFlag(argv[arg_index]));
if (argc > 4) { if (argc > arg_index) {
throws_beg_pos = atoi(argv[4]); // Next argument is the exception type identifier.
} expects.type = argv[arg_index];
if (argc > 5) { do {
throws_end_pos = atoi(argv[5]); arg_index++;
} while (argc > arg_index && IsFlag(argv[arg_index]));
if (argc > arg_index) {
expects.beg_pos = atoi(argv[arg_index]);
do {
arg_index++;
} while (argc > arg_index && IsFlag(argv[arg_index]));
if (argc > arg_index) {
expects.end_pos = atoi(argv[arg_index]);
}
}
} }
} }
return expects;
}
int main(int argc, const char* argv[]) {
// Parse command line.
// Format: preparser <scriptfile> ["throws" [<exn-type> [<start> [<end>]]]]
// Any flags on the line are ignored.
// Check for mandatory filename argument.
int arg_index = 1;
while (argc > arg_index && IsFlag(argv[arg_index])) arg_index++;
if (argc <= arg_index) {
fail(NULL, "ERROR: No filename on command line.\n");
}
const char* filename = argv[arg_index];
// Check remainder of command line for exception expectations.
arg_index++;
ExceptionExpectation expects =
ParseExpectation(argc - arg_index, argv + arg_index);
// Open JS file. // Open JS file.
FILE* input = fopen(filename, "rb"); FILE* input = fopen(filename, "rb");
...@@ -310,8 +350,7 @@ int main(int argc, char* argv[]) { ...@@ -310,8 +350,7 @@ int main(int argc, char* argv[]) {
// Check that the expected exception is thrown, if an exception is // Check that the expected exception is thrown, if an exception is
// expected. // expected.
CheckException(&data, throws, throws_message, CheckException(&data, &expects);
throws_beg_pos, throws_end_pos);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment