| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 309 |
| 310 bool MemoryMappedExternalResource::EnsureIsAscii(bool abort_if_failed) const { | 310 bool MemoryMappedExternalResource::EnsureIsAscii(bool abort_if_failed) const { |
| 311 bool is_ascii = true; | 311 bool is_ascii = true; |
| 312 | 312 |
| 313 int line_no = 1; | 313 int line_no = 1; |
| 314 const char* start_of_line = data_; | 314 const char* start_of_line = data_; |
| 315 const char* end = data_ + length_; | 315 const char* end = data_ + length_; |
| 316 for (const char* p = data_; p < end; p++) { | 316 for (const char* p = data_; p < end; p++) { |
| 317 char c = *p; | 317 char c = *p; |
| 318 if ((c & 0x80) != 0) { | 318 if ((c & 0x80) != 0) { |
| 319 // Non-ascii detected: | 319 // Non-ASCII detected: |
| 320 is_ascii = false; | 320 is_ascii = false; |
| 321 | 321 |
| 322 // Report the error and abort if appropriate: | 322 // Report the error and abort if appropriate: |
| 323 if (abort_if_failed) { | 323 if (abort_if_failed) { |
| 324 int char_no = static_cast<int>(p - start_of_line) - 1; | 324 int char_no = static_cast<int>(p - start_of_line) - 1; |
| 325 | 325 |
| 326 ASSERT(filename_ != NULL); | 326 ASSERT(filename_ != NULL); |
| 327 PrintF("\n\n\n" | 327 PrintF("\n\n\n" |
| 328 "Abort: Non-Ascii character 0x%.2x in file %s line %d char %d", | 328 "Abort: Non-Ascii character 0x%.2x in file %s line %d char %d", |
| 329 c, filename_, line_no, char_no); | 329 c, filename_, line_no, char_no); |
| 330 | 330 |
| 331 // Allow for some context up to kNumberOfLeadingContextChars chars | 331 // Allow for some context up to kNumberOfLeadingContextChars chars |
| 332 // before the offending non-ascii char to help the user see where | 332 // before the offending non-ASCII char to help the user see where |
| 333 // the offending char is. | 333 // the offending char is. |
| 334 const int kNumberOfLeadingContextChars = 10; | 334 const int kNumberOfLeadingContextChars = 10; |
| 335 const char* err_context = p - kNumberOfLeadingContextChars; | 335 const char* err_context = p - kNumberOfLeadingContextChars; |
| 336 if (err_context < data_) { | 336 if (err_context < data_) { |
| 337 err_context = data_; | 337 err_context = data_; |
| 338 } | 338 } |
| 339 // Compute the length of the error context and print it. | 339 // Compute the length of the error context and print it. |
| 340 int err_context_length = static_cast<int>(p - err_context); | 340 int err_context_length = static_cast<int>(p - err_context); |
| 341 if (err_context_length != 0) { | 341 if (err_context_length != 0) { |
| 342 PrintF(" after \"%.*s\"", err_context_length, err_context); | 342 PrintF(" after \"%.*s\"", err_context_length, err_context); |
| 343 } | 343 } |
| 344 PrintF(".\n\n\n"); | 344 PrintF(".\n\n\n"); |
| 345 OS::Abort(); | 345 OS::Abort(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 break; // Non-ascii detected. No need to continue scanning. | 348 break; // Non-ASCII detected. No need to continue scanning. |
| 349 } | 349 } |
| 350 if (c == '\n') { | 350 if (c == '\n') { |
| 351 start_of_line = p; | 351 start_of_line = p; |
| 352 line_no++; | 352 line_no++; |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 return is_ascii; | 356 return is_ascii; |
| 357 } | 357 } |
| 358 | 358 |
| 359 | 359 |
| 360 } } // namespace v8::internal | 360 } } // namespace v8::internal |
| OLD | NEW |