v8-debugger-id.cc 1.88 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2020 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/inspector/v8-debugger-id.h"

#include "src/debug/debug-interface.h"
8
#include "src/inspector/string-util.h"
9 10 11 12 13 14 15
#include "src/inspector/v8-inspector-impl.h"

namespace v8_inspector {

V8DebuggerId::V8DebuggerId(std::pair<int64_t, int64_t> pair)
    : m_first(pair.first), m_second(pair.second) {}

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
std::unique_ptr<StringBuffer> V8DebuggerId::toString() const {
  return StringBufferFrom(String16::fromInteger64(m_first) + "." +
                          String16::fromInteger64(m_second));
}

bool V8DebuggerId::isValid() const { return m_first || m_second; }

std::pair<int64_t, int64_t> V8DebuggerId::pair() const {
  return std::make_pair(m_first, m_second);
}

namespace internal {

V8DebuggerId::V8DebuggerId(std::pair<int64_t, int64_t> pair)
    : m_debugger_id(pair) {}

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
// static
V8DebuggerId V8DebuggerId::generate(V8InspectorImpl* inspector) {
  return V8DebuggerId(std::make_pair(inspector->generateUniqueId(),
                                     inspector->generateUniqueId()));
}

V8DebuggerId::V8DebuggerId(const String16& debuggerId) {
  const UChar dot = '.';
  size_t pos = debuggerId.find(dot);
  if (pos == String16::kNotFound) return;
  bool ok = false;
  int64_t first = debuggerId.substring(0, pos).toInteger64(&ok);
  if (!ok) return;
  int64_t second = debuggerId.substring(pos + 1).toInteger64(&ok);
  if (!ok) return;
47
  m_debugger_id = v8_inspector::V8DebuggerId(std::make_pair(first, second));
48 49 50
}

String16 V8DebuggerId::toString() const {
51
  return toString16(m_debugger_id.toString()->string());
52 53
}

54
bool V8DebuggerId::isValid() const { return m_debugger_id.isValid(); }
55 56

std::pair<int64_t, int64_t> V8DebuggerId::pair() const {
57
  return m_debugger_id.pair();
58 59
}

60
}  // namespace internal
61
}  // namespace v8_inspector