Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Unified Diff: preparser/preparser-process.cc

Issue 7061008: Create template system for strict-mode tests. (Closed)
Patch Set: Remove debug print. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: preparser/preparser-process.cc
diff --git a/preparser/preparser-process.cc b/preparser/preparser-process.cc
index 9c8d7b44821fdf1dd61883e43dba7e841b6ed293..66b53a1b376b0674218d19af22667319de0b8cfc 100644
--- a/preparser/preparser-process.cc
+++ b/preparser/preparser-process.cc
@@ -39,7 +39,9 @@ namespace i = v8::internal;
// This file is only used for testing the stand-alone preparser
// library.
-// The first argument must be the path of a JavaScript source file.
+// The first argument must be the path of a JavaScript source file, or
+// the flags "-e" and the next argument is then the source of a JavaScript
+// program.
// Optionally this can be followed by the word "throws" (case sensitive),
// which signals that the parsing is expected to throw - the default is
// to expect the parsing to not throw.
@@ -57,7 +59,7 @@ namespace i = v8::internal;
// Adapts an ASCII string to the UnicodeInputStream interface.
class AsciiInputStream : public v8::UnicodeInputStream {
public:
- AsciiInputStream(uint8_t* buffer, size_t length)
+ AsciiInputStream(const uint8_t* buffer, size_t length)
: buffer_(buffer),
end_offset_(static_cast<int>(length)),
offset_(0) { }
@@ -176,10 +178,15 @@ class PreparseDataInterpreter {
template <typename T>
class ScopedPointer {
public:
+ explicit ScopedPointer() : pointer_(NULL) {}
explicit ScopedPointer(T* pointer) : pointer_(pointer) {}
- ~ScopedPointer() { delete[] pointer_; }
+ ~ScopedPointer() { if (pointer_ != NULL) delete[] pointer_; }
T& operator[](int index) { return pointer_[index]; }
T* operator*() { return pointer_ ;}
+ T*& operator=(T* new_value) {
+ if (pointer_ != NULL) delete[] pointer_;
+ pointer_ = new_value;
+ }
private:
T* pointer_;
};
@@ -298,49 +305,63 @@ ExceptionExpectation ParseExpectation(int argc, const char* argv[]) {
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.
+ // Format: preparser (<scriptfile> | -e "<source>")
+ // ["throws" [<exn-type> [<start> [<end>]]]]
+ // Any flags (except an initial -s) 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 uint8_t* source = NULL;
const char* filename = argv[arg_index];
+ if (!strcmp(filename, "-e")) {
+ arg_index++;
+ if (argc <= arg_index) {
+ fail(NULL, "ERROR: No source after -e on command line.\n");
+ }
+ source = reinterpret_cast<const uint8_t*>(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.
- FILE* input = fopen(filename, "rb");
- if (input == NULL) {
- perror("ERROR: Error opening file");
- fflush(stderr);
- return EXIT_FAILURE;
- }
+ ScopedPointer<uint8_t> buffer;
+ size_t length;
- // Find length of JS file.
- if (fseek(input, 0, SEEK_END) != 0) {
- perror("ERROR: Error during seek");
- fflush(stderr);
- return EXIT_FAILURE;
- }
- size_t length = static_cast<size_t>(ftell(input));
- rewind(input);
-
- // Read JS file into memory buffer.
- ScopedPointer<uint8_t> buffer(new uint8_t[length]);
- if (!ReadBuffer(input, *buffer, length)) {
- perror("ERROR: Reading file");
- fflush(stderr);
- return EXIT_FAILURE;
+ if (source == NULL) {
+ // Open JS file.
+ FILE* input = fopen(filename, "rb");
+ if (input == NULL) {
+ perror("ERROR: Error opening file");
+ fflush(stderr);
+ return EXIT_FAILURE;
+ }
+ // Find length of JS file.
+ if (fseek(input, 0, SEEK_END) != 0) {
+ perror("ERROR: Error during seek");
+ fflush(stderr);
+ return EXIT_FAILURE;
+ }
+ length = static_cast<size_t>(ftell(input));
+ rewind(input);
+ // Read JS file into memory buffer.
+ buffer = new uint8_t[length];
+ if (!ReadBuffer(input, *buffer, length)) {
+ perror("ERROR: Reading file");
+ fflush(stderr);
+ return EXIT_FAILURE;
+ }
+ fclose(input);
+ source = *buffer;
+ } else {
+ length = strlen(reinterpret_cast<const char*>(source));
}
- fclose(input);
// Preparse input file.
- AsciiInputStream input_buffer(*buffer, length);
+ AsciiInputStream input_buffer(source, length);
size_t kMaxStackSize = 64 * 1024 * sizeof(void*); // NOLINT
v8::PreParserData data = v8::Preparse(&input_buffer, kMaxStackSize);
« no previous file with comments | « no previous file | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698