| 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 410 } |
| 411 | 411 |
| 412 | 412 |
| 413 // Init line_ends array with code positions of line ends inside script | 413 // Init line_ends array with code positions of line ends inside script |
| 414 // source. | 414 // source. |
| 415 void InitScriptLineEnds(Handle<Script> script) { | 415 void InitScriptLineEnds(Handle<Script> script) { |
| 416 if (!script->line_ends()->IsUndefined()) return; | 416 if (!script->line_ends()->IsUndefined()) return; |
| 417 | 417 |
| 418 if (!script->source()->IsString()) { | 418 if (!script->source()->IsString()) { |
| 419 ASSERT(script->source()->IsUndefined()); | 419 ASSERT(script->source()->IsUndefined()); |
| 420 script->set_line_ends(*(Factory::NewJSArray(0))); | 420 script->set_line_ends(*(Factory::NewFixedArray(0))); |
| 421 ASSERT(script->line_ends()->IsJSArray()); | 421 ASSERT(script->line_ends()->IsFixedArray()); |
| 422 return; | 422 return; |
| 423 } | 423 } |
| 424 | 424 |
| 425 Handle<String> src(String::cast(script->source())); | 425 Handle<String> src(String::cast(script->source())); |
| 426 const int src_len = src->length(); | 426 const int src_len = src->length(); |
| 427 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); | 427 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); |
| 428 | 428 |
| 429 // Pass 1: Identify line count. | 429 // Pass 1: Identify line count. |
| 430 int line_count = 0; | 430 int line_count = 0; |
| 431 int position = 0; | 431 int position = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 444 position = 0; | 444 position = 0; |
| 445 while (position != -1 && position < src_len) { | 445 while (position != -1 && position < src_len) { |
| 446 position = Runtime::StringMatch(src, new_line, position); | 446 position = Runtime::StringMatch(src, new_line, position); |
| 447 // If the script does not end with a line ending add the final end | 447 // If the script does not end with a line ending add the final end |
| 448 // position as just past the last line ending. | 448 // position as just past the last line ending. |
| 449 array->set(array_index++, | 449 array->set(array_index++, |
| 450 Smi::FromInt(position != -1 ? position++ : src_len)); | 450 Smi::FromInt(position != -1 ? position++ : src_len)); |
| 451 } | 451 } |
| 452 ASSERT(array_index == line_count); | 452 ASSERT(array_index == line_count); |
| 453 | 453 |
| 454 Handle<JSArray> object = Factory::NewJSArrayWithElements(array); | 454 script->set_line_ends(*array); |
| 455 script->set_line_ends(*object); | 455 ASSERT(script->line_ends()->IsFixedArray()); |
| 456 ASSERT(script->line_ends()->IsJSArray()); | |
| 457 } | 456 } |
| 458 | 457 |
| 459 | 458 |
| 460 // Convert code position into line number. | 459 // Convert code position into line number. |
| 461 int GetScriptLineNumber(Handle<Script> script, int code_pos) { | 460 int GetScriptLineNumber(Handle<Script> script, int code_pos) { |
| 462 InitScriptLineEnds(script); | 461 InitScriptLineEnds(script); |
| 463 AssertNoAllocation no_allocation; | 462 AssertNoAllocation no_allocation; |
| 464 JSArray* line_ends_array = JSArray::cast(script->line_ends()); | 463 FixedArray* line_ends = FixedArray::cast(script->line_ends()); |
| 465 const int line_ends_len = (Smi::cast(line_ends_array->length()))->value(); | 464 const int line_ends_len = line_ends->length(); |
| 466 | 465 |
| 467 int line = -1; | 466 int line = -1; |
| 468 if (line_ends_len > 0 && | 467 if (line_ends_len > 0 && |
| 469 code_pos <= (Smi::cast(line_ends_array->GetElement(0)))->value()) { | 468 code_pos <= (Smi::cast(line_ends->get(0)))->value()) { |
| 470 line = 0; | 469 line = 0; |
| 471 } else { | 470 } else { |
| 472 for (int i = 1; i < line_ends_len; ++i) { | 471 for (int i = 1; i < line_ends_len; ++i) { |
| 473 if ((Smi::cast(line_ends_array->GetElement(i - 1)))->value() < code_pos && | 472 if ((Smi::cast(line_ends->get(i - 1)))->value() < code_pos && |
| 474 code_pos <= (Smi::cast(line_ends_array->GetElement(i)))->value()) { | 473 code_pos <= (Smi::cast(line_ends->get(i)))->value()) { |
| 475 line = i; | 474 line = i; |
| 476 break; | 475 break; |
| 477 } | 476 } |
| 478 } | 477 } |
| 479 } | 478 } |
| 480 | 479 |
| 481 return line != -1 ? line + script->line_offset()->value() : line; | 480 return line != -1 ? line + script->line_offset()->value() : line; |
| 482 } | 481 } |
| 483 | 482 |
| 484 | 483 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 Handle<Map> new_map = Factory::CopyMapDropTransitions(old_map); | 758 Handle<Map> new_map = Factory::CopyMapDropTransitions(old_map); |
| 760 obj->set_map(*new_map); | 759 obj->set_map(*new_map); |
| 761 new_map->set_needs_loading(true); | 760 new_map->set_needs_loading(true); |
| 762 // Store the lazy loading info in the constructor field. We'll | 761 // Store the lazy loading info in the constructor field. We'll |
| 763 // reestablish the constructor from the fixed array after loading. | 762 // reestablish the constructor from the fixed array after loading. |
| 764 new_map->set_constructor(*arr); | 763 new_map->set_constructor(*arr); |
| 765 ASSERT(!obj->IsLoaded()); | 764 ASSERT(!obj->IsLoaded()); |
| 766 } | 765 } |
| 767 | 766 |
| 768 } } // namespace v8::internal | 767 } } // namespace v8::internal |
| OLD | NEW |