OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/allocation-site-scopes.h" | 10 #include "src/allocation-site-scopes.h" |
(...skipping 9914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9925 DisallowHeapAllocation no_allocation; | 9925 DisallowHeapAllocation no_allocation; |
9926 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); | 9926 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); |
9927 line_number = line_number - script->line_offset()->value(); | 9927 line_number = line_number - script->line_offset()->value(); |
9928 if (line_number == 0) return code_pos + script->column_offset()->value(); | 9928 if (line_number == 0) return code_pos + script->column_offset()->value(); |
9929 int prev_line_end_pos = | 9929 int prev_line_end_pos = |
9930 Smi::cast(line_ends_array->get(line_number - 1))->value(); | 9930 Smi::cast(line_ends_array->get(line_number - 1))->value(); |
9931 return code_pos - (prev_line_end_pos + 1); | 9931 return code_pos - (prev_line_end_pos + 1); |
9932 } | 9932 } |
9933 | 9933 |
9934 | 9934 |
9935 int Script::GetLineNumberWithArray(int code_pos) { | 9935 int Script::GetLineNumberWithArray(int position) { |
9936 DisallowHeapAllocation no_allocation; | 9936 DisallowHeapAllocation no_allocation; |
9937 DCHECK(line_ends()->IsFixedArray()); | 9937 FixedArray* line_ends = FixedArray::cast(this->line_ends()); |
9938 FixedArray* line_ends_array = FixedArray::cast(line_ends()); | 9938 int upper = line_ends->length() - 1; |
9939 int line_ends_len = line_ends_array->length(); | 9939 if (upper < 0) return -1; |
9940 if (line_ends_len == 0) return -1; | 9940 int offset = line_offset()->value(); |
9941 | 9941 |
9942 if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) { | 9942 if (position > Smi::cast(line_ends->get(upper))->value()) { |
9943 return line_offset()->value(); | 9943 return upper + 1 + offset; |
9944 } | 9944 } |
| 9945 if (position <= Smi::cast(line_ends->get(0))->value()) return offset; |
9945 | 9946 |
9946 int left = 0; | 9947 int lower = 1; |
9947 int right = line_ends_len; | 9948 // Binary search. |
9948 while (int half = (right - left) / 2) { | 9949 while (true) { |
9949 if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) { | 9950 int mid = (lower + upper) / 2; |
9950 right -= half; | 9951 if (position <= Smi::cast(line_ends->get(mid - 1))->value()) { |
| 9952 upper = mid - 1; |
| 9953 } else if (position > Smi::cast(line_ends->get(mid))->value()) { |
| 9954 lower = mid + 1; |
9951 } else { | 9955 } else { |
9952 left += half; | 9956 return mid + offset; |
9953 } | 9957 } |
9954 } | 9958 } |
9955 return right + line_offset()->value(); | 9959 return -1; |
9956 } | 9960 } |
9957 | 9961 |
9958 | 9962 |
9959 int Script::GetLineNumber(Handle<Script> script, int code_pos) { | 9963 int Script::GetLineNumber(Handle<Script> script, int code_pos) { |
9960 InitLineEnds(script); | 9964 InitLineEnds(script); |
9961 return script->GetLineNumberWithArray(code_pos); | 9965 return script->GetLineNumberWithArray(code_pos); |
9962 } | 9966 } |
9963 | 9967 |
9964 | 9968 |
9965 int Script::GetLineNumber(int code_pos) { | 9969 int Script::GetLineNumber(int code_pos) { |
(...skipping 6806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16772 Handle<DependentCode> codes = | 16776 Handle<DependentCode> codes = |
16773 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), | 16777 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), |
16774 DependentCode::kPropertyCellChangedGroup, | 16778 DependentCode::kPropertyCellChangedGroup, |
16775 info->object_wrapper()); | 16779 info->object_wrapper()); |
16776 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); | 16780 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); |
16777 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( | 16781 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( |
16778 cell, info->zone()); | 16782 cell, info->zone()); |
16779 } | 16783 } |
16780 | 16784 |
16781 } } // namespace v8::internal | 16785 } } // namespace v8::internal |
OLD | NEW |