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 6941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6952 ASSERT(obj->IsJSObject()); | 6952 ASSERT(obj->IsJSObject()); |
6953 | 6953 |
6954 descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); | 6954 descriptors->SetNextEnumerationIndex(NextEnumerationIndex()); |
6955 // Check that it really works. | 6955 // Check that it really works. |
6956 ASSERT(obj->HasFastProperties()); | 6956 ASSERT(obj->HasFastProperties()); |
6957 | 6957 |
6958 return obj; | 6958 return obj; |
6959 } | 6959 } |
6960 | 6960 |
6961 | 6961 |
6962 // Init line_ends array with code positions of line ends inside script source | |
6963 void Script::InitLineEnds() { | |
6964 if (!line_ends()->IsUndefined()) return; | |
6965 | |
6966 if (!source()->IsString()) { | |
6967 ASSERT(source()->IsUndefined()); | |
6968 set_line_ends(*(Factory::NewJSArray(0))); | |
6969 ASSERT(line_ends()->IsJSArray()); | |
6970 return; | |
6971 } | |
6972 | |
6973 Handle<String> src(String::cast(source())); | |
6974 const int src_len = src->length(); | |
6975 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); | |
6976 | |
6977 // Pass 1: Identify line count | |
6978 int line_count = 0; | |
6979 int position = 0; | |
6980 while (position != -1 && position < src_len) { | |
6981 position = Runtime::StringMatch(src, new_line, position); | |
6982 if (position != -1) { | |
6983 position++; | |
6984 } | |
6985 // Even if the last line misses a line end, it is counted | |
6986 line_count++; | |
6987 } | |
6988 | |
6989 // Pass 2: Fill in line ends positions | |
6990 Handle<FixedArray> array = Factory::NewFixedArray(line_count); | |
6991 int array_index = 0; | |
6992 position = 0; | |
6993 while (position != -1 && position < src_len) { | |
6994 position = Runtime::StringMatch(src, new_line, position); | |
6995 // If the script does not end with a line ending add the final end position | |
6996 // as just past the last line ending. | |
6997 array->set(array_index++, | |
6998 Smi::FromInt(position != -1 ? position++ : src_len)); | |
6999 } | |
7000 ASSERT(array_index == line_count); | |
7001 | |
7002 Handle<JSArray> object = Factory::NewJSArrayWithElements(array); | |
7003 set_line_ends(*object); | |
7004 ASSERT(line_ends()->IsJSArray()); | |
7005 } | |
7006 | |
7007 | |
7008 // Convert code position into line number | |
7009 int Script::GetLineNumber(int code_pos) { | |
7010 InitLineEnds(); | |
7011 JSArray* line_ends_array = JSArray::cast(line_ends()); | |
7012 const int line_ends_len = (Smi::cast(line_ends_array->length()))->value(); | |
7013 | |
7014 int line = -1; | |
7015 if (line_ends_len > 0 && | |
7016 code_pos <= (Smi::cast(line_ends_array->GetElement(0)))->value()) { | |
7017 line = 0; | |
7018 } else { | |
7019 for (int i = 1; i < line_ends_len; ++i) { | |
7020 if ((Smi::cast(line_ends_array->GetElement(i - 1)))->value() < code_pos && | |
7021 code_pos <= (Smi::cast(line_ends_array->GetElement(i)))->value()) { | |
7022 line = i; | |
7023 break; | |
7024 } | |
7025 } | |
7026 } | |
7027 | |
7028 return line != -1 ? line + line_offset()->value() : line; | |
7029 } | |
7030 | |
7031 | |
7032 // Check if there is a break point at this code position. | 6962 // Check if there is a break point at this code position. |
7033 bool DebugInfo::HasBreakPoint(int code_position) { | 6963 bool DebugInfo::HasBreakPoint(int code_position) { |
7034 // Get the break point info object for this code position. | 6964 // Get the break point info object for this code position. |
7035 Object* break_point_info = GetBreakPointInfo(code_position); | 6965 Object* break_point_info = GetBreakPointInfo(code_position); |
7036 | 6966 |
7037 // If there is no break point info object or no break points in the break | 6967 // If there is no break point info object or no break points in the break |
7038 // point info object there is no break point at this code position. | 6968 // point info object there is no break point at this code position. |
7039 if (break_point_info->IsUndefined()) return false; | 6969 if (break_point_info->IsUndefined()) return false; |
7040 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; | 6970 return BreakPointInfo::cast(break_point_info)->GetBreakPointCount() > 0; |
7041 } | 6971 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7268 // No break point. | 7198 // No break point. |
7269 if (break_point_objects()->IsUndefined()) return 0; | 7199 if (break_point_objects()->IsUndefined()) return 0; |
7270 // Single beak point. | 7200 // Single beak point. |
7271 if (!break_point_objects()->IsFixedArray()) return 1; | 7201 if (!break_point_objects()->IsFixedArray()) return 1; |
7272 // Multiple break points. | 7202 // Multiple break points. |
7273 return FixedArray::cast(break_point_objects())->length(); | 7203 return FixedArray::cast(break_point_objects())->length(); |
7274 } | 7204 } |
7275 | 7205 |
7276 | 7206 |
7277 } } // namespace v8::internal | 7207 } } // namespace v8::internal |
OLD | NEW |