Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: src/objects/break-points-info.cc

Issue 2900713004: [objects] Extract DebugInfo and BreakPointInfo to own file (Closed)
Patch Set: Rename Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/objects/break-points-info.h"
6
7 #include "src/objects-inl.h"
8
9 namespace v8 {
10 namespace internal {
11
12 // Remove the specified break point object.
13 void BreakPointInfo::ClearBreakPoint(Handle<BreakPointInfo> break_point_info,
14 Handle<Object> break_point_object) {
15 Isolate* isolate = break_point_info->GetIsolate();
16 // If there are no break points just ignore.
17 if (break_point_info->break_point_objects()->IsUndefined(isolate)) return;
18 // If there is a single break point clear it if it is the same.
19 if (!break_point_info->break_point_objects()->IsFixedArray()) {
20 if (break_point_info->break_point_objects() == *break_point_object) {
21 break_point_info->set_break_point_objects(
22 isolate->heap()->undefined_value());
23 }
24 return;
25 }
26 // If there are multiple break points shrink the array
27 DCHECK(break_point_info->break_point_objects()->IsFixedArray());
28 Handle<FixedArray> old_array = Handle<FixedArray>(
29 FixedArray::cast(break_point_info->break_point_objects()));
30 Handle<FixedArray> new_array =
31 isolate->factory()->NewFixedArray(old_array->length() - 1);
32 int found_count = 0;
33 for (int i = 0; i < old_array->length(); i++) {
34 if (old_array->get(i) == *break_point_object) {
35 DCHECK(found_count == 0);
36 found_count++;
37 } else {
38 new_array->set(i - found_count, old_array->get(i));
39 }
40 }
41 // If the break point was found in the list change it.
42 if (found_count > 0) break_point_info->set_break_point_objects(*new_array);
43 }
44
45 // Add the specified break point object.
46 void BreakPointInfo::SetBreakPoint(Handle<BreakPointInfo> break_point_info,
47 Handle<Object> break_point_object) {
48 Isolate* isolate = break_point_info->GetIsolate();
49
50 // If there was no break point objects before just set it.
51 if (break_point_info->break_point_objects()->IsUndefined(isolate)) {
52 break_point_info->set_break_point_objects(*break_point_object);
53 return;
54 }
55 // If the break point object is the same as before just ignore.
56 if (break_point_info->break_point_objects() == *break_point_object) return;
57 // If there was one break point object before replace with array.
58 if (!break_point_info->break_point_objects()->IsFixedArray()) {
59 Handle<FixedArray> array = isolate->factory()->NewFixedArray(2);
60 array->set(0, break_point_info->break_point_objects());
61 array->set(1, *break_point_object);
62 break_point_info->set_break_point_objects(*array);
63 return;
64 }
65 // If there was more than one break point before extend array.
66 Handle<FixedArray> old_array = Handle<FixedArray>(
67 FixedArray::cast(break_point_info->break_point_objects()));
68 Handle<FixedArray> new_array =
69 isolate->factory()->NewFixedArray(old_array->length() + 1);
70 for (int i = 0; i < old_array->length(); i++) {
71 // If the break point was there before just ignore.
72 if (old_array->get(i) == *break_point_object) return;
73 new_array->set(i, old_array->get(i));
74 }
75 // Add the new break point.
76 new_array->set(old_array->length(), *break_point_object);
77 break_point_info->set_break_point_objects(*new_array);
78 }
79
80 bool BreakPointInfo::HasBreakPointObject(
81 Handle<BreakPointInfo> break_point_info,
82 Handle<Object> break_point_object) {
83 // No break point.
84 Isolate* isolate = break_point_info->GetIsolate();
85 if (break_point_info->break_point_objects()->IsUndefined(isolate)) {
86 return false;
87 }
88 // Single break point.
89 if (!break_point_info->break_point_objects()->IsFixedArray()) {
90 return break_point_info->break_point_objects() == *break_point_object;
91 }
92 // Multiple break points.
93 FixedArray* array = FixedArray::cast(break_point_info->break_point_objects());
94 for (int i = 0; i < array->length(); i++) {
95 if (array->get(i) == *break_point_object) {
96 return true;
97 }
98 }
99 return false;
100 }
101
102 // Get the number of break points.
103 int BreakPointInfo::GetBreakPointCount() {
104 // No break point.
105 if (break_point_objects()->IsUndefined(GetIsolate())) return 0;
106 // Single break point.
107 if (!break_point_objects()->IsFixedArray()) return 1;
108 // Multiple break points.
109 return FixedArray::cast(break_point_objects())->length();
110 }
111
112 } // namespace internal
113 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698