OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 if (!script->line_ends()->IsUndefined()) return; | 450 if (!script->line_ends()->IsUndefined()) return; |
451 | 451 |
452 if (!script->source()->IsString()) { | 452 if (!script->source()->IsString()) { |
453 ASSERT(script->source()->IsUndefined()); | 453 ASSERT(script->source()->IsUndefined()); |
454 script->set_line_ends(*(Factory::NewFixedArray(0))); | 454 script->set_line_ends(*(Factory::NewFixedArray(0))); |
455 ASSERT(script->line_ends()->IsFixedArray()); | 455 ASSERT(script->line_ends()->IsFixedArray()); |
456 return; | 456 return; |
457 } | 457 } |
458 | 458 |
459 Handle<String> src(String::cast(script->source())); | 459 Handle<String> src(String::cast(script->source())); |
| 460 |
| 461 Handle<FixedArray> array = CalculateLineEnds(src, true); |
| 462 |
| 463 script->set_line_ends(*array); |
| 464 ASSERT(script->line_ends()->IsFixedArray()); |
| 465 } |
| 466 |
| 467 |
| 468 Handle<FixedArray> CalculateLineEnds(Handle<String> src, |
| 469 bool with_imaginary_last_new_line) { |
460 const int src_len = src->length(); | 470 const int src_len = src->length(); |
461 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); | 471 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); |
462 | 472 |
463 // Pass 1: Identify line count. | 473 // Pass 1: Identify line count. |
464 int line_count = 0; | 474 int line_count = 0; |
465 int position = 0; | 475 int position = 0; |
466 while (position != -1 && position < src_len) { | 476 while (position != -1 && position < src_len) { |
467 position = Runtime::StringMatch(src, new_line, position); | 477 position = Runtime::StringMatch(src, new_line, position); |
468 if (position != -1) { | 478 if (position != -1) { |
469 position++; | 479 position++; |
470 } | 480 } |
471 // Even if the last line misses a line end, it is counted. | 481 if (position != -1) { |
472 line_count++; | 482 line_count++; |
| 483 } else if (with_imaginary_last_new_line) { |
| 484 // Even if the last line misses a line end, it is counted. |
| 485 line_count++; |
| 486 } |
473 } | 487 } |
474 | 488 |
475 // Pass 2: Fill in line ends positions | 489 // Pass 2: Fill in line ends positions |
476 Handle<FixedArray> array = Factory::NewFixedArray(line_count); | 490 Handle<FixedArray> array = Factory::NewFixedArray(line_count); |
477 int array_index = 0; | 491 int array_index = 0; |
478 position = 0; | 492 position = 0; |
479 while (position != -1 && position < src_len) { | 493 while (position != -1 && position < src_len) { |
480 position = Runtime::StringMatch(src, new_line, position); | 494 position = Runtime::StringMatch(src, new_line, position); |
481 // If the script does not end with a line ending add the final end | 495 if (position != -1) { |
482 // position as just past the last line ending. | 496 array->set(array_index++, Smi::FromInt(position++)); |
483 array->set(array_index++, | 497 } else if (with_imaginary_last_new_line) { |
484 Smi::FromInt(position != -1 ? position++ : src_len)); | 498 // If the script does not end with a line ending add the final end |
| 499 // position as just past the last line ending. |
| 500 array->set(array_index++, Smi::FromInt(src_len)); |
| 501 } |
485 } | 502 } |
486 ASSERT(array_index == line_count); | 503 ASSERT(array_index == line_count); |
487 | 504 |
488 script->set_line_ends(*array); | 505 return array; |
489 ASSERT(script->line_ends()->IsFixedArray()); | |
490 } | 506 } |
491 | 507 |
492 | 508 |
493 // Convert code position into line number. | 509 // Convert code position into line number. |
494 int GetScriptLineNumber(Handle<Script> script, int code_pos) { | 510 int GetScriptLineNumber(Handle<Script> script, int code_pos) { |
495 InitScriptLineEnds(script); | 511 InitScriptLineEnds(script); |
496 AssertNoAllocation no_allocation; | 512 AssertNoAllocation no_allocation; |
497 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); | 513 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); |
498 const int line_ends_len = line_ends_array->length(); | 514 const int line_ends_len = line_ends_array->length(); |
499 | 515 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 | 796 |
781 OptimizedObjectForAddingMultipleProperties:: | 797 OptimizedObjectForAddingMultipleProperties:: |
782 ~OptimizedObjectForAddingMultipleProperties() { | 798 ~OptimizedObjectForAddingMultipleProperties() { |
783 // Reoptimize the object to allow fast property access. | 799 // Reoptimize the object to allow fast property access. |
784 if (has_been_transformed_) { | 800 if (has_been_transformed_) { |
785 TransformToFastProperties(object_, unused_property_fields_); | 801 TransformToFastProperties(object_, unused_property_fields_); |
786 } | 802 } |
787 } | 803 } |
788 | 804 |
789 } } // namespace v8::internal | 805 } } // namespace v8::internal |
OLD | NEW |