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

Side by Side Diff: preparser/preparser-process.cc

Issue 7061008: Create template system for strict-mode tests. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
32 32
33 #include "../include/v8stdint.h" 33 #include "../include/v8stdint.h"
34 #include "../include/v8-preparser.h" 34 #include "../include/v8-preparser.h"
35 35
36 #include "../src/preparse-data-format.h" 36 #include "../src/preparse-data-format.h"
37 37
38 namespace i = v8::internal; 38 namespace i = v8::internal;
39 39
40 // This file is only used for testing the stand-alone preparser 40 // This file is only used for testing the stand-alone preparser
41 // library. 41 // library.
42 // The first argument must be the path of a JavaScript source file. 42 // The first argument must be the path of a JavaScript source file, or
43 // the flags "-e" and the next argument is then the source of a JavaScript
44 // program.
43 // Optionally this can be followed by the word "throws" (case sensitive), 45 // Optionally this can be followed by the word "throws" (case sensitive),
44 // which signals that the parsing is expected to throw - the default is 46 // which signals that the parsing is expected to throw - the default is
45 // to expect the parsing to not throw. 47 // to expect the parsing to not throw.
46 // The command line can further be followed by a message text (the 48 // The command line can further be followed by a message text (the
47 // *type* of the exception to throw), and even more optionally, the 49 // *type* of the exception to throw), and even more optionally, the
48 // start and end position reported with the exception. 50 // start and end position reported with the exception.
49 // 51 //
50 // This source file is preparsed and tested against the expectations, and if 52 // This source file is preparsed and tested against the expectations, and if
51 // successful, the resulting preparser data is written to stdout. 53 // successful, the resulting preparser data is written to stdout.
52 // Diagnostic output is output on stderr. 54 // Diagnostic output is output on stderr.
53 // The source file must contain only ASCII characters (UTF-8 isn't supported). 55 // The source file must contain only ASCII characters (UTF-8 isn't supported).
54 // The file is read into memory, so it should have a reasonable size. 56 // The file is read into memory, so it should have a reasonable size.
55 57
56 58
57 // Adapts an ASCII string to the UnicodeInputStream interface. 59 // Adapts an ASCII string to the UnicodeInputStream interface.
58 class AsciiInputStream : public v8::UnicodeInputStream { 60 class AsciiInputStream : public v8::UnicodeInputStream {
59 public: 61 public:
60 AsciiInputStream(uint8_t* buffer, size_t length) 62 AsciiInputStream(const uint8_t* buffer, size_t length)
61 : buffer_(buffer), 63 : buffer_(buffer),
62 end_offset_(static_cast<int>(length)), 64 end_offset_(static_cast<int>(length)),
63 offset_(0) { } 65 offset_(0) { }
64 66
65 virtual ~AsciiInputStream() { } 67 virtual ~AsciiInputStream() { }
66 68
67 virtual void PushBack(int32_t ch) { 69 virtual void PushBack(int32_t ch) {
68 offset_--; 70 offset_--;
69 #ifdef DEBUG 71 #ifdef DEBUG
70 if (offset_ < 0 || 72 if (offset_ < 0 ||
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 171
170 const uint8_t* const data_; 172 const uint8_t* const data_;
171 const int length_; 173 const int length_;
172 const char* message_; 174 const char* message_;
173 }; 175 };
174 176
175 177
176 template <typename T> 178 template <typename T>
177 class ScopedPointer { 179 class ScopedPointer {
178 public: 180 public:
181 explicit ScopedPointer() : pointer_(NULL) {}
179 explicit ScopedPointer(T* pointer) : pointer_(pointer) {} 182 explicit ScopedPointer(T* pointer) : pointer_(pointer) {}
180 ~ScopedPointer() { delete[] pointer_; } 183 ~ScopedPointer() { if (pointer_ != NULL) delete[] pointer_; }
181 T& operator[](int index) { return pointer_[index]; } 184 T& operator[](int index) { return pointer_[index]; }
182 T* operator*() { return pointer_ ;} 185 T* operator*() { return pointer_ ;}
186 T*& operator=(T* new_value) {
187 if (pointer_ != NULL) delete[] pointer_;
188 pointer_ = new_value;
189 }
183 private: 190 private:
184 T* pointer_; 191 T* pointer_;
185 }; 192 };
186 193
187 194
188 195
189 void fail(v8::PreParserData* data, const char* message, ...) { 196 void fail(v8::PreParserData* data, const char* message, ...) {
190 va_list args; 197 va_list args;
191 va_start(args, message); 198 va_start(args, message);
192 vfprintf(stderr, message, args); 199 vfprintf(stderr, message, args);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 298 }
292 } 299 }
293 } 300 }
294 } 301 }
295 return expects; 302 return expects;
296 } 303 }
297 304
298 305
299 int main(int argc, const char* argv[]) { 306 int main(int argc, const char* argv[]) {
300 // Parse command line. 307 // Parse command line.
301 // Format: preparser <scriptfile> ["throws" [<exn-type> [<start> [<end>]]]] 308 // Format: preparser (<scriptfile> | -e "<source>")
302 // Any flags on the line are ignored. 309 // ["throws" [<exn-type> [<start> [<end>]]]]
310 // Any flags (except an initial -s) are ignored.
303 311
304 // Check for mandatory filename argument. 312 // Check for mandatory filename argument.
305 int arg_index = 1; 313 int arg_index = 1;
306 while (argc > arg_index && IsFlag(argv[arg_index])) arg_index++;
307 if (argc <= arg_index) { 314 if (argc <= arg_index) {
308 fail(NULL, "ERROR: No filename on command line.\n"); 315 fail(NULL, "ERROR: No filename on command line.\n");
309 } 316 }
317 const uint8_t* source = NULL;
310 const char* filename = argv[arg_index]; 318 const char* filename = argv[arg_index];
319 if (!strcmp(filename, "-e")) {
320 arg_index++;
321 if (argc <= arg_index) {
322 fail(NULL, "ERROR: No source after -e on command line.\n");
323 }
324 source = reinterpret_cast<const uint8_t*>(argv[arg_index]);
325 printf("SOURCE:\n%s\n---\n", source);
Mads Ager (chromium) 2011/05/23 10:31:13 Remove debug printing?
Lasse Reichstein 2011/05/23 10:35:20 Let's :)
326 }
311 // Check remainder of command line for exception expectations. 327 // Check remainder of command line for exception expectations.
312 arg_index++; 328 arg_index++;
313 ExceptionExpectation expects = 329 ExceptionExpectation expects =
314 ParseExpectation(argc - arg_index, argv + arg_index); 330 ParseExpectation(argc - arg_index, argv + arg_index);
315 331
316 // Open JS file. 332 ScopedPointer<uint8_t> buffer;
317 FILE* input = fopen(filename, "rb"); 333 size_t length;
318 if (input == NULL) { 334
319 perror("ERROR: Error opening file"); 335 if (source == NULL) {
320 fflush(stderr); 336 // Open JS file.
321 return EXIT_FAILURE; 337 FILE* input = fopen(filename, "rb");
338 if (input == NULL) {
339 perror("ERROR: Error opening file");
340 fflush(stderr);
341 return EXIT_FAILURE;
342 }
343 // Find length of JS file.
344 if (fseek(input, 0, SEEK_END) != 0) {
345 perror("ERROR: Error during seek");
346 fflush(stderr);
347 return EXIT_FAILURE;
348 }
349 length = static_cast<size_t>(ftell(input));
350 rewind(input);
351 // Read JS file into memory buffer.
352 buffer = new uint8_t[length];
353 if (!ReadBuffer(input, *buffer, length)) {
354 perror("ERROR: Reading file");
355 fflush(stderr);
356 return EXIT_FAILURE;
357 }
358 fclose(input);
359 source = *buffer;
360 } else {
361 length = strlen(reinterpret_cast<const char*>(source));
322 } 362 }
323 363
324 // Find length of JS file.
325 if (fseek(input, 0, SEEK_END) != 0) {
326 perror("ERROR: Error during seek");
327 fflush(stderr);
328 return EXIT_FAILURE;
329 }
330 size_t length = static_cast<size_t>(ftell(input));
331 rewind(input);
332
333 // Read JS file into memory buffer.
334 ScopedPointer<uint8_t> buffer(new uint8_t[length]);
335 if (!ReadBuffer(input, *buffer, length)) {
336 perror("ERROR: Reading file");
337 fflush(stderr);
338 return EXIT_FAILURE;
339 }
340 fclose(input);
341
342 // Preparse input file. 364 // Preparse input file.
343 AsciiInputStream input_buffer(*buffer, length); 365 AsciiInputStream input_buffer(source, length);
344 size_t kMaxStackSize = 64 * 1024 * sizeof(void*); // NOLINT 366 size_t kMaxStackSize = 64 * 1024 * sizeof(void*); // NOLINT
345 v8::PreParserData data = v8::Preparse(&input_buffer, kMaxStackSize); 367 v8::PreParserData data = v8::Preparse(&input_buffer, kMaxStackSize);
346 368
347 // Fail if stack overflow. 369 // Fail if stack overflow.
348 if (data.stack_overflow()) { 370 if (data.stack_overflow()) {
349 fail(&data, "ERROR: Stack overflow\n"); 371 fail(&data, "ERROR: Stack overflow\n");
350 } 372 }
351 373
352 // Check that the expected exception is thrown, if an exception is 374 // Check that the expected exception is thrown, if an exception is
353 // expected. 375 // expected.
354 CheckException(&data, &expects); 376 CheckException(&data, &expects);
355 377
356 return EXIT_SUCCESS; 378 return EXIT_SUCCESS;
357 } 379 }
OLDNEW
« 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