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 <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 10349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10360 DisallowHeapAllocation no_allocation; | 10360 DisallowHeapAllocation no_allocation; |
10361 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); | 10361 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); |
10362 line_number = line_number - script->line_offset()->value(); | 10362 line_number = line_number - script->line_offset()->value(); |
10363 if (line_number == 0) return code_pos + script->column_offset()->value(); | 10363 if (line_number == 0) return code_pos + script->column_offset()->value(); |
10364 int prev_line_end_pos = | 10364 int prev_line_end_pos = |
10365 Smi::cast(line_ends_array->get(line_number - 1))->value(); | 10365 Smi::cast(line_ends_array->get(line_number - 1))->value(); |
10366 return code_pos - (prev_line_end_pos + 1); | 10366 return code_pos - (prev_line_end_pos + 1); |
10367 } | 10367 } |
10368 | 10368 |
10369 | 10369 |
10370 int Script::GetLineNumberWithArray(int position) { | 10370 int Script::GetLineNumberWithArray(int code_pos) { |
10371 DisallowHeapAllocation no_allocation; | 10371 DisallowHeapAllocation no_allocation; |
10372 FixedArray* line_ends = FixedArray::cast(this->line_ends()); | 10372 DCHECK(line_ends()->IsFixedArray()); |
10373 int upper = line_ends->length() - 1; | 10373 FixedArray* line_ends_array = FixedArray::cast(line_ends()); |
10374 if (upper < 0) return -1; | 10374 int line_ends_len = line_ends_array->length(); |
10375 int offset = line_offset()->value(); | 10375 if (line_ends_len == 0) return -1; |
10376 | 10376 |
10377 if (position > Smi::cast(line_ends->get(upper))->value()) { | 10377 if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) { |
10378 return upper + 1 + offset; | 10378 return line_offset()->value(); |
10379 } | 10379 } |
10380 if (position <= Smi::cast(line_ends->get(0))->value()) return offset; | |
10381 | 10380 |
10382 int lower = 1; | 10381 int left = 0; |
10383 // Binary search. | 10382 int right = line_ends_len; |
10384 while (true) { | 10383 while (int half = (right - left) / 2) { |
10385 int mid = (lower + upper) / 2; | 10384 if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) { |
10386 if (position <= Smi::cast(line_ends->get(mid - 1))->value()) { | 10385 right -= half; |
10387 upper = mid - 1; | |
10388 } else if (position > Smi::cast(line_ends->get(mid))->value()) { | |
10389 lower = mid + 1; | |
10390 } else { | 10386 } else { |
10391 return mid + offset; | 10387 left += half; |
10392 } | 10388 } |
10393 } | 10389 } |
10394 return -1; | 10390 return right + line_offset()->value(); |
10395 } | 10391 } |
10396 | 10392 |
10397 | 10393 |
10398 int Script::GetLineNumber(Handle<Script> script, int code_pos) { | 10394 int Script::GetLineNumber(Handle<Script> script, int code_pos) { |
10399 InitLineEnds(script); | 10395 InitLineEnds(script); |
10400 return script->GetLineNumberWithArray(code_pos); | 10396 return script->GetLineNumberWithArray(code_pos); |
10401 } | 10397 } |
10402 | 10398 |
10403 | 10399 |
10404 int Script::GetLineNumber(int code_pos) { | 10400 int Script::GetLineNumber(int code_pos) { |
(...skipping 6780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17185 CompilationInfo* info) { | 17181 CompilationInfo* info) { |
17186 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo( | 17182 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo( |
17187 handle(cell->dependent_code(), info->isolate()), | 17183 handle(cell->dependent_code(), info->isolate()), |
17188 DependentCode::kPropertyCellChangedGroup, info->object_wrapper()); | 17184 DependentCode::kPropertyCellChangedGroup, info->object_wrapper()); |
17189 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); | 17185 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); |
17190 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( | 17186 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( |
17191 cell, info->zone()); | 17187 cell, info->zone()); |
17192 } | 17188 } |
17193 | 17189 |
17194 } } // namespace v8::internal | 17190 } } // namespace v8::internal |
OLD | NEW |