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

Unified Diff: src/objects/breakpoints-info.cc

Issue 2900713004: [objects] Extract DebugInfo and BreakPointInfo to own file (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: src/objects/breakpoints-info.cc
diff --git a/src/objects/breakpoints-info.cc b/src/objects/breakpoints-info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2b9dcd9cf0b68ce482af1cb5e5a59b9718f1936
--- /dev/null
+++ b/src/objects/breakpoints-info.cc
@@ -0,0 +1,113 @@
+// Copyright 2017 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/objects/breakpoints-info.h"
+
+#include "src/objects-inl.h"
+
+namespace v8 {
+namespace internal {
+
+// Remove the specified break point object.
+void BreakPointInfo::ClearBreakPoint(Handle<BreakPointInfo> break_point_info,
+ Handle<Object> break_point_object) {
+ Isolate* isolate = break_point_info->GetIsolate();
+ // If there are no break points just ignore.
+ if (break_point_info->break_point_objects()->IsUndefined(isolate)) return;
+ // If there is a single break point clear it if it is the same.
+ if (!break_point_info->break_point_objects()->IsFixedArray()) {
+ if (break_point_info->break_point_objects() == *break_point_object) {
+ break_point_info->set_break_point_objects(
+ isolate->heap()->undefined_value());
+ }
+ return;
+ }
+ // If there are multiple break points shrink the array
+ DCHECK(break_point_info->break_point_objects()->IsFixedArray());
+ Handle<FixedArray> old_array = Handle<FixedArray>(
+ FixedArray::cast(break_point_info->break_point_objects()));
+ Handle<FixedArray> new_array =
+ isolate->factory()->NewFixedArray(old_array->length() - 1);
+ int found_count = 0;
+ for (int i = 0; i < old_array->length(); i++) {
+ if (old_array->get(i) == *break_point_object) {
+ DCHECK(found_count == 0);
+ found_count++;
+ } else {
+ new_array->set(i - found_count, old_array->get(i));
+ }
+ }
+ // If the break point was found in the list change it.
+ if (found_count > 0) break_point_info->set_break_point_objects(*new_array);
+}
+
+// Add the specified break point object.
+void BreakPointInfo::SetBreakPoint(Handle<BreakPointInfo> break_point_info,
+ Handle<Object> break_point_object) {
+ Isolate* isolate = break_point_info->GetIsolate();
+
+ // If there was no break point objects before just set it.
+ if (break_point_info->break_point_objects()->IsUndefined(isolate)) {
+ break_point_info->set_break_point_objects(*break_point_object);
+ return;
+ }
+ // If the break point object is the same as before just ignore.
+ if (break_point_info->break_point_objects() == *break_point_object) return;
+ // If there was one break point object before replace with array.
+ if (!break_point_info->break_point_objects()->IsFixedArray()) {
+ Handle<FixedArray> array = isolate->factory()->NewFixedArray(2);
+ array->set(0, break_point_info->break_point_objects());
+ array->set(1, *break_point_object);
+ break_point_info->set_break_point_objects(*array);
+ return;
+ }
+ // If there was more than one break point before extend array.
+ Handle<FixedArray> old_array = Handle<FixedArray>(
+ FixedArray::cast(break_point_info->break_point_objects()));
+ Handle<FixedArray> new_array =
+ isolate->factory()->NewFixedArray(old_array->length() + 1);
+ for (int i = 0; i < old_array->length(); i++) {
+ // If the break point was there before just ignore.
+ if (old_array->get(i) == *break_point_object) return;
+ new_array->set(i, old_array->get(i));
+ }
+ // Add the new break point.
+ new_array->set(old_array->length(), *break_point_object);
+ break_point_info->set_break_point_objects(*new_array);
+}
+
+bool BreakPointInfo::HasBreakPointObject(
+ Handle<BreakPointInfo> break_point_info,
+ Handle<Object> break_point_object) {
+ // No break point.
+ Isolate* isolate = break_point_info->GetIsolate();
+ if (break_point_info->break_point_objects()->IsUndefined(isolate)) {
+ return false;
+ }
+ // Single break point.
+ if (!break_point_info->break_point_objects()->IsFixedArray()) {
+ return break_point_info->break_point_objects() == *break_point_object;
+ }
+ // Multiple break points.
+ FixedArray* array = FixedArray::cast(break_point_info->break_point_objects());
+ for (int i = 0; i < array->length(); i++) {
+ if (array->get(i) == *break_point_object) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// Get the number of break points.
+int BreakPointInfo::GetBreakPointCount() {
+ // No break point.
+ if (break_point_objects()->IsUndefined(GetIsolate())) return 0;
+ // Single break point.
+ if (!break_point_objects()->IsFixedArray()) return 1;
+ // Multiple break points.
+ return FixedArray::cast(break_point_objects())->length();
+}
+
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698