| Index: src/handles.cc
|
| diff --git a/src/handles.cc b/src/handles.cc
|
| index 05cb3f2b383ab32c279e8fe058a572733647c56e..84ee20bba1a7a48f51068814518b459e05e4259b 100644
|
| --- a/src/handles.cc
|
| +++ b/src/handles.cc
|
| @@ -457,6 +457,16 @@ void InitScriptLineEnds(Handle<Script> script) {
|
| }
|
|
|
| Handle<String> src(String::cast(script->source()));
|
| +
|
| + Handle<FixedArray> array = CalculateLineEnds(src, true);
|
| +
|
| + script->set_line_ends(*array);
|
| + ASSERT(script->line_ends()->IsFixedArray());
|
| +}
|
| +
|
| +
|
| +Handle<FixedArray> CalculateLineEnds(Handle<String> src,
|
| + bool with_imaginary_last_new_line) {
|
| const int src_len = src->length();
|
| Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n"));
|
|
|
| @@ -468,8 +478,12 @@ void InitScriptLineEnds(Handle<Script> script) {
|
| if (position != -1) {
|
| position++;
|
| }
|
| - // Even if the last line misses a line end, it is counted.
|
| - line_count++;
|
| + if (position != -1) {
|
| + line_count++;
|
| + } else if (with_imaginary_last_new_line) {
|
| + // Even if the last line misses a line end, it is counted.
|
| + line_count++;
|
| + }
|
| }
|
|
|
| // Pass 2: Fill in line ends positions
|
| @@ -478,15 +492,17 @@ void InitScriptLineEnds(Handle<Script> script) {
|
| position = 0;
|
| while (position != -1 && position < src_len) {
|
| position = Runtime::StringMatch(src, new_line, position);
|
| - // If the script does not end with a line ending add the final end
|
| - // position as just past the last line ending.
|
| - array->set(array_index++,
|
| - Smi::FromInt(position != -1 ? position++ : src_len));
|
| + if (position != -1) {
|
| + array->set(array_index++, Smi::FromInt(position++));
|
| + } else if (with_imaginary_last_new_line) {
|
| + // If the script does not end with a line ending add the final end
|
| + // position as just past the last line ending.
|
| + array->set(array_index++, Smi::FromInt(src_len));
|
| + }
|
| }
|
| ASSERT(array_index == line_count);
|
|
|
| - script->set_line_ends(*array);
|
| - ASSERT(script->line_ends()->IsFixedArray());
|
| + return array;
|
| }
|
|
|
|
|
|
|