| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 6757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6768 ASSERT(obj->IsJSObject()); | 6768 ASSERT(obj->IsJSObject()); |
| 6769 | 6769 |
| 6770 descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); | 6770 descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); |
| 6771 // Check that it really works. | 6771 // Check that it really works. |
| 6772 ASSERT(obj->HasFastProperties()); | 6772 ASSERT(obj->HasFastProperties()); |
| 6773 | 6773 |
| 6774 return obj; | 6774 return obj; |
| 6775 } | 6775 } |
| 6776 | 6776 |
| 6777 | 6777 |
| 6778 // Init line_ends array with code positions of line ends inside script source |
| 6779 void Script::InitLineEnds() { |
| 6780 if (!line_ends()->IsUndefined()) return; |
| 6781 |
| 6782 Handle<String> src(String::cast(source())); |
| 6783 const int src_len = src->length(); |
| 6784 Handle<JSArray> array = Factory::NewJSArray(0); |
| 6785 int array_index = 0; |
| 6786 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); |
| 6787 int position = 0; |
| 6788 while (position < src_len) { |
| 6789 position = Runtime::StringMatch(src, new_line, position); |
| 6790 if (position != -1) { |
| 6791 SetElement(array, array_index++, Handle<Smi>(Smi::FromInt(position++))); |
| 6792 } else { |
| 6793 break; |
| 6794 } |
| 6795 } |
| 6796 |
| 6797 // If the script does not end with a line ending add the final end position |
| 6798 // as just past the last line ending. |
| 6799 if (array_index == 0 || |
| 6800 (Smi::cast(array->GetElement(array_index - 1))->value() != src_len - 1)) { |
| 6801 SetElement(array, array_index++, Handle<Smi>(Smi::FromInt(src_len))); |
| 6802 } |
| 6803 |
| 6804 Handle<FixedArray> fixed_array = Factory::NewFixedArray(0); |
| 6805 set_line_ends(fixed_array->AddKeysFromJSArray(*array)); |
| 6806 ASSERT(line_ends()->IsFixedArray()); |
| 6807 } |
| 6808 |
| 6809 |
| 6810 // Convert code position into line number |
| 6811 int Script::GetLineNumber(int code_pos) { |
| 6812 InitLineEnds(); |
| 6813 FixedArray* line_ends_array = FixedArray::cast(line_ends()); |
| 6814 |
| 6815 int line = -1; |
| 6816 if (code_pos <= (Smi::cast(line_ends_array->get(0)))->value()) { |
| 6817 line = 0; |
| 6818 } else { |
| 6819 const int line_ends_length = line_ends_array->length(); |
| 6820 for (int i = 1; i < line_ends_length; ++i) { |
| 6821 if ((Smi::cast(line_ends_array->get(i - 1)))->value() < code_pos && |
| 6822 code_pos <= (Smi::cast(line_ends_array->get(i)))->value()) { |
| 6823 line = i; |
| 6824 break; |
| 6825 } |
| 6826 } |
| 6827 } |
| 6828 |
| 6829 return line != -1 ? line + line_offset()->value() : line; |
| 6830 } |
| 6831 |
| 6832 |
| 6778 // Check if there is a break point at this code position. | 6833 // Check if there is a break point at this code position. |
| 6779 bool DebugInfo::HasBreakPoint(int code_position) { | 6834 bool DebugInfo::HasBreakPoint(int code_position) { |
| 6780 // Get the break point info object for this code position. | 6835 // Get the break point info object for this code position. |
| 6781 Object* break_point_info = GetBreakPointInfo(code_position); | 6836 Object* break_point_info = GetBreakPointInfo(code_position); |
| 6782 | 6837 |
| 6783 // If there is no break point info object or no break points in the break | 6838 // If there is no break point info object or no break points in the break |
| 6784 // point info object there is no break point at this code position. | 6839 // point info object there is no break point at this code position. |
| 6785 if (break_point_info->IsUndefined()) return false; | 6840 if (break_point_info->IsUndefined()) return false; |
| 6786 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; | 6841 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; |
| 6787 } | 6842 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7014 // No break point. | 7069 // No break point. |
| 7015 if (break_point_objects()->IsUndefined()) return 0; | 7070 if (break_point_objects()->IsUndefined()) return 0; |
| 7016 // Single beak point. | 7071 // Single beak point. |
| 7017 if (!break_point_objects()->IsFixedArray()) return 1; | 7072 if (!break_point_objects()->IsFixedArray()) return 1; |
| 7018 // Multiple break points. | 7073 // Multiple break points. |
| 7019 return FixedArray::cast(break_point_objects())->length(); | 7074 return FixedArray::cast(break_point_objects())->length(); |
| 7020 } | 7075 } |
| 7021 | 7076 |
| 7022 | 7077 |
| 7023 } } // namespace v8::internal | 7078 } } // namespace v8::internal |
| OLD | NEW |