11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_V8_INSPECTOR_H_
61cb0ef41Sopenharmony_ci#define V8_V8_INSPECTOR_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <stdint.h>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include <cctype>
111cb0ef41Sopenharmony_ci#include <memory>
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#include "v8-isolate.h"       // NOLINT(build/include_directory)
141cb0ef41Sopenharmony_ci#include "v8-local-handle.h"  // NOLINT(build/include_directory)
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cinamespace v8 {
171cb0ef41Sopenharmony_ciclass Context;
181cb0ef41Sopenharmony_ciclass Name;
191cb0ef41Sopenharmony_ciclass Object;
201cb0ef41Sopenharmony_ciclass StackTrace;
211cb0ef41Sopenharmony_ciclass Value;
221cb0ef41Sopenharmony_ci}  // namespace v8
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cinamespace v8_inspector {
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cinamespace internal {
271cb0ef41Sopenharmony_ciclass V8DebuggerId;
281cb0ef41Sopenharmony_ci}  // namespace internal
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cinamespace protocol {
311cb0ef41Sopenharmony_cinamespace Debugger {
321cb0ef41Sopenharmony_cinamespace API {
331cb0ef41Sopenharmony_ciclass SearchMatch;
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci}  // namespace Debugger
361cb0ef41Sopenharmony_cinamespace Runtime {
371cb0ef41Sopenharmony_cinamespace API {
381cb0ef41Sopenharmony_ciclass RemoteObject;
391cb0ef41Sopenharmony_ciclass StackTrace;
401cb0ef41Sopenharmony_ciclass StackTraceId;
411cb0ef41Sopenharmony_ci}  // namespace API
421cb0ef41Sopenharmony_ci}  // namespace Runtime
431cb0ef41Sopenharmony_cinamespace Schema {
441cb0ef41Sopenharmony_cinamespace API {
451cb0ef41Sopenharmony_ciclass Domain;
461cb0ef41Sopenharmony_ci}
471cb0ef41Sopenharmony_ci}  // namespace Schema
481cb0ef41Sopenharmony_ci}  // namespace protocol
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ciclass V8_EXPORT StringView {
511cb0ef41Sopenharmony_ci public:
521cb0ef41Sopenharmony_ci  StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {}
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci  StringView(const uint8_t* characters, size_t length)
551cb0ef41Sopenharmony_ci      : m_is8Bit(true), m_length(length), m_characters8(characters) {}
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  StringView(const uint16_t* characters, size_t length)
581cb0ef41Sopenharmony_ci      : m_is8Bit(false), m_length(length), m_characters16(characters) {}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci  bool is8Bit() const { return m_is8Bit; }
611cb0ef41Sopenharmony_ci  size_t length() const { return m_length; }
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci  // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used
641cb0ef41Sopenharmony_ci  // here.
651cb0ef41Sopenharmony_ci  const uint8_t* characters8() const { return m_characters8; }
661cb0ef41Sopenharmony_ci  const uint16_t* characters16() const { return m_characters16; }
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci private:
691cb0ef41Sopenharmony_ci  bool m_is8Bit;
701cb0ef41Sopenharmony_ci  size_t m_length;
711cb0ef41Sopenharmony_ci  union {
721cb0ef41Sopenharmony_ci    const uint8_t* m_characters8;
731cb0ef41Sopenharmony_ci    const uint16_t* m_characters16;
741cb0ef41Sopenharmony_ci  };
751cb0ef41Sopenharmony_ci};
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ciclass V8_EXPORT StringBuffer {
781cb0ef41Sopenharmony_ci public:
791cb0ef41Sopenharmony_ci  virtual ~StringBuffer() = default;
801cb0ef41Sopenharmony_ci  virtual StringView string() const = 0;
811cb0ef41Sopenharmony_ci  // This method copies contents.
821cb0ef41Sopenharmony_ci  static std::unique_ptr<StringBuffer> create(StringView);
831cb0ef41Sopenharmony_ci};
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ciclass V8_EXPORT V8ContextInfo {
861cb0ef41Sopenharmony_ci public:
871cb0ef41Sopenharmony_ci  V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId,
881cb0ef41Sopenharmony_ci                StringView humanReadableName)
891cb0ef41Sopenharmony_ci      : context(context),
901cb0ef41Sopenharmony_ci        contextGroupId(contextGroupId),
911cb0ef41Sopenharmony_ci        humanReadableName(humanReadableName),
921cb0ef41Sopenharmony_ci        hasMemoryOnConsole(false) {}
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci  v8::Local<v8::Context> context;
951cb0ef41Sopenharmony_ci  // Each v8::Context is a part of a group. The group id must be non-zero.
961cb0ef41Sopenharmony_ci  int contextGroupId;
971cb0ef41Sopenharmony_ci  StringView humanReadableName;
981cb0ef41Sopenharmony_ci  StringView origin;
991cb0ef41Sopenharmony_ci  StringView auxData;
1001cb0ef41Sopenharmony_ci  bool hasMemoryOnConsole;
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ci  static int executionContextId(v8::Local<v8::Context> context);
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci  // Disallow copying and allocating this one.
1051cb0ef41Sopenharmony_ci  enum NotNullTagEnum { NotNullLiteral };
1061cb0ef41Sopenharmony_ci  void* operator new(size_t) = delete;
1071cb0ef41Sopenharmony_ci  void* operator new(size_t, NotNullTagEnum, void*) = delete;
1081cb0ef41Sopenharmony_ci  void* operator new(size_t, void*) = delete;
1091cb0ef41Sopenharmony_ci  V8ContextInfo(const V8ContextInfo&) = delete;
1101cb0ef41Sopenharmony_ci  V8ContextInfo& operator=(const V8ContextInfo&) = delete;
1111cb0ef41Sopenharmony_ci};
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ci// This debugger id tries to be unique by generating two random
1141cb0ef41Sopenharmony_ci// numbers, which should most likely avoid collisions.
1151cb0ef41Sopenharmony_ci// Debugger id has a 1:1 mapping to context group. It is used to
1161cb0ef41Sopenharmony_ci// attribute stack traces to a particular debugging, when doing any
1171cb0ef41Sopenharmony_ci// cross-debugger operations (e.g. async step in).
1181cb0ef41Sopenharmony_ci// See also Runtime.UniqueDebuggerId in the protocol.
1191cb0ef41Sopenharmony_ciclass V8_EXPORT V8DebuggerId {
1201cb0ef41Sopenharmony_ci public:
1211cb0ef41Sopenharmony_ci  V8DebuggerId() = default;
1221cb0ef41Sopenharmony_ci  V8DebuggerId(const V8DebuggerId&) = default;
1231cb0ef41Sopenharmony_ci  V8DebuggerId& operator=(const V8DebuggerId&) = default;
1241cb0ef41Sopenharmony_ci
1251cb0ef41Sopenharmony_ci  std::unique_ptr<StringBuffer> toString() const;
1261cb0ef41Sopenharmony_ci  bool isValid() const;
1271cb0ef41Sopenharmony_ci  std::pair<int64_t, int64_t> pair() const;
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci private:
1301cb0ef41Sopenharmony_ci  friend class internal::V8DebuggerId;
1311cb0ef41Sopenharmony_ci  explicit V8DebuggerId(std::pair<int64_t, int64_t>);
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci  int64_t m_first = 0;
1341cb0ef41Sopenharmony_ci  int64_t m_second = 0;
1351cb0ef41Sopenharmony_ci};
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_cistruct V8_EXPORT V8StackFrame {
1381cb0ef41Sopenharmony_ci  StringView sourceURL;
1391cb0ef41Sopenharmony_ci  StringView functionName;
1401cb0ef41Sopenharmony_ci  int lineNumber;
1411cb0ef41Sopenharmony_ci  int columnNumber;
1421cb0ef41Sopenharmony_ci};
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ciclass V8_EXPORT V8StackTrace {
1451cb0ef41Sopenharmony_ci public:
1461cb0ef41Sopenharmony_ci  virtual StringView firstNonEmptySourceURL() const = 0;
1471cb0ef41Sopenharmony_ci  virtual bool isEmpty() const = 0;
1481cb0ef41Sopenharmony_ci  virtual StringView topSourceURL() const = 0;
1491cb0ef41Sopenharmony_ci  virtual int topLineNumber() const = 0;
1501cb0ef41Sopenharmony_ci  virtual int topColumnNumber() const = 0;
1511cb0ef41Sopenharmony_ci  virtual int topScriptId() const = 0;
1521cb0ef41Sopenharmony_ci  virtual StringView topFunctionName() const = 0;
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci  virtual ~V8StackTrace() = default;
1551cb0ef41Sopenharmony_ci  virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
1561cb0ef41Sopenharmony_ci  buildInspectorObject(int maxAsyncDepth) const = 0;
1571cb0ef41Sopenharmony_ci  virtual std::unique_ptr<StringBuffer> toString() const = 0;
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ci  // Safe to pass between threads, drops async chain.
1601cb0ef41Sopenharmony_ci  virtual std::unique_ptr<V8StackTrace> clone() = 0;
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci  virtual std::vector<V8StackFrame> frames() const = 0;
1631cb0ef41Sopenharmony_ci};
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ciclass V8_EXPORT V8InspectorSession {
1661cb0ef41Sopenharmony_ci public:
1671cb0ef41Sopenharmony_ci  virtual ~V8InspectorSession() = default;
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci  // Cross-context inspectable values (DOM nodes in different worlds, etc.).
1701cb0ef41Sopenharmony_ci  class V8_EXPORT Inspectable {
1711cb0ef41Sopenharmony_ci   public:
1721cb0ef41Sopenharmony_ci    virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0;
1731cb0ef41Sopenharmony_ci    virtual ~Inspectable() = default;
1741cb0ef41Sopenharmony_ci  };
1751cb0ef41Sopenharmony_ci  class V8_EXPORT CommandLineAPIScope {
1761cb0ef41Sopenharmony_ci   public:
1771cb0ef41Sopenharmony_ci    virtual ~CommandLineAPIScope() = default;
1781cb0ef41Sopenharmony_ci  };
1791cb0ef41Sopenharmony_ci  virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ci  // Dispatching protocol messages.
1821cb0ef41Sopenharmony_ci  static bool canDispatchMethod(StringView method);
1831cb0ef41Sopenharmony_ci  virtual void dispatchProtocolMessage(StringView message) = 0;
1841cb0ef41Sopenharmony_ci  virtual std::vector<uint8_t> state() = 0;
1851cb0ef41Sopenharmony_ci  virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
1861cb0ef41Sopenharmony_ci  supportedDomains() = 0;
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci  virtual std::unique_ptr<V8InspectorSession::CommandLineAPIScope>
1891cb0ef41Sopenharmony_ci  initializeCommandLineAPIScope(int executionContextId) = 0;
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ci  // Debugger actions.
1921cb0ef41Sopenharmony_ci  virtual void schedulePauseOnNextStatement(StringView breakReason,
1931cb0ef41Sopenharmony_ci                                            StringView breakDetails) = 0;
1941cb0ef41Sopenharmony_ci  virtual void cancelPauseOnNextStatement() = 0;
1951cb0ef41Sopenharmony_ci  virtual void breakProgram(StringView breakReason,
1961cb0ef41Sopenharmony_ci                            StringView breakDetails) = 0;
1971cb0ef41Sopenharmony_ci  virtual void setSkipAllPauses(bool) = 0;
1981cb0ef41Sopenharmony_ci  virtual void resume(bool setTerminateOnResume = false) = 0;
1991cb0ef41Sopenharmony_ci  virtual void stepOver() = 0;
2001cb0ef41Sopenharmony_ci  virtual std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
2011cb0ef41Sopenharmony_ci  searchInTextByLines(StringView text, StringView query, bool caseSensitive,
2021cb0ef41Sopenharmony_ci                      bool isRegex) = 0;
2031cb0ef41Sopenharmony_ci
2041cb0ef41Sopenharmony_ci  // Remote objects.
2051cb0ef41Sopenharmony_ci  virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
2061cb0ef41Sopenharmony_ci      v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName,
2071cb0ef41Sopenharmony_ci      bool generatePreview) = 0;
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci  virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error,
2101cb0ef41Sopenharmony_ci                            StringView objectId, v8::Local<v8::Value>*,
2111cb0ef41Sopenharmony_ci                            v8::Local<v8::Context>*,
2121cb0ef41Sopenharmony_ci                            std::unique_ptr<StringBuffer>* objectGroup) = 0;
2131cb0ef41Sopenharmony_ci  virtual void releaseObjectGroup(StringView) = 0;
2141cb0ef41Sopenharmony_ci  virtual void triggerPreciseCoverageDeltaUpdate(StringView occasion) = 0;
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci  // Prepare for shutdown (disables debugger pausing, etc.).
2171cb0ef41Sopenharmony_ci  virtual void stop() = 0;
2181cb0ef41Sopenharmony_ci};
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ciclass V8_EXPORT WebDriverValue {
2211cb0ef41Sopenharmony_ci public:
2221cb0ef41Sopenharmony_ci  explicit WebDriverValue(std::unique_ptr<StringBuffer> type,
2231cb0ef41Sopenharmony_ci                          v8::MaybeLocal<v8::Value> value = {})
2241cb0ef41Sopenharmony_ci      : type(std::move(type)), value(value) {}
2251cb0ef41Sopenharmony_ci  std::unique_ptr<StringBuffer> type;
2261cb0ef41Sopenharmony_ci  v8::MaybeLocal<v8::Value> value;
2271cb0ef41Sopenharmony_ci};
2281cb0ef41Sopenharmony_ci
2291cb0ef41Sopenharmony_ciclass V8_EXPORT V8InspectorClient {
2301cb0ef41Sopenharmony_ci public:
2311cb0ef41Sopenharmony_ci  virtual ~V8InspectorClient() = default;
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_ci  virtual void runMessageLoopOnPause(int contextGroupId) {}
2341cb0ef41Sopenharmony_ci  virtual void runMessageLoopOnInstrumentationPause(int contextGroupId) {
2351cb0ef41Sopenharmony_ci    runMessageLoopOnPause(contextGroupId);
2361cb0ef41Sopenharmony_ci  }
2371cb0ef41Sopenharmony_ci  virtual void quitMessageLoopOnPause() {}
2381cb0ef41Sopenharmony_ci  virtual void runIfWaitingForDebugger(int contextGroupId) {}
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ci  virtual void muteMetrics(int contextGroupId) {}
2411cb0ef41Sopenharmony_ci  virtual void unmuteMetrics(int contextGroupId) {}
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_ci  virtual void beginUserGesture() {}
2441cb0ef41Sopenharmony_ci  virtual void endUserGesture() {}
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ci  virtual std::unique_ptr<WebDriverValue> serializeToWebDriverValue(
2471cb0ef41Sopenharmony_ci      v8::Local<v8::Value> v8_value, int max_depth) {
2481cb0ef41Sopenharmony_ci    return nullptr;
2491cb0ef41Sopenharmony_ci  }
2501cb0ef41Sopenharmony_ci  virtual std::unique_ptr<StringBuffer> valueSubtype(v8::Local<v8::Value>) {
2511cb0ef41Sopenharmony_ci    return nullptr;
2521cb0ef41Sopenharmony_ci  }
2531cb0ef41Sopenharmony_ci  virtual std::unique_ptr<StringBuffer> descriptionForValueSubtype(
2541cb0ef41Sopenharmony_ci      v8::Local<v8::Context>, v8::Local<v8::Value>) {
2551cb0ef41Sopenharmony_ci    return nullptr;
2561cb0ef41Sopenharmony_ci  }
2571cb0ef41Sopenharmony_ci  virtual bool isInspectableHeapObject(v8::Local<v8::Object>) { return true; }
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  virtual v8::Local<v8::Context> ensureDefaultContextInGroup(
2601cb0ef41Sopenharmony_ci      int contextGroupId) {
2611cb0ef41Sopenharmony_ci    return v8::Local<v8::Context>();
2621cb0ef41Sopenharmony_ci  }
2631cb0ef41Sopenharmony_ci  virtual void beginEnsureAllContextsInGroup(int contextGroupId) {}
2641cb0ef41Sopenharmony_ci  virtual void endEnsureAllContextsInGroup(int contextGroupId) {}
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci  virtual void installAdditionalCommandLineAPI(v8::Local<v8::Context>,
2671cb0ef41Sopenharmony_ci                                               v8::Local<v8::Object>) {}
2681cb0ef41Sopenharmony_ci  virtual void consoleAPIMessage(int contextGroupId,
2691cb0ef41Sopenharmony_ci                                 v8::Isolate::MessageErrorLevel level,
2701cb0ef41Sopenharmony_ci                                 const StringView& message,
2711cb0ef41Sopenharmony_ci                                 const StringView& url, unsigned lineNumber,
2721cb0ef41Sopenharmony_ci                                 unsigned columnNumber, V8StackTrace*) {}
2731cb0ef41Sopenharmony_ci  virtual v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate*,
2741cb0ef41Sopenharmony_ci                                               v8::Local<v8::Context>) {
2751cb0ef41Sopenharmony_ci    return v8::MaybeLocal<v8::Value>();
2761cb0ef41Sopenharmony_ci  }
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_ci  virtual void consoleTime(const StringView& title) {}
2791cb0ef41Sopenharmony_ci  virtual void consoleTimeEnd(const StringView& title) {}
2801cb0ef41Sopenharmony_ci  virtual void consoleTimeStamp(const StringView& title) {}
2811cb0ef41Sopenharmony_ci  virtual void consoleClear(int contextGroupId) {}
2821cb0ef41Sopenharmony_ci  virtual double currentTimeMS() { return 0; }
2831cb0ef41Sopenharmony_ci  typedef void (*TimerCallback)(void*);
2841cb0ef41Sopenharmony_ci  virtual void startRepeatingTimer(double, TimerCallback, void* data) {}
2851cb0ef41Sopenharmony_ci  virtual void cancelTimer(void* data) {}
2861cb0ef41Sopenharmony_ci
2871cb0ef41Sopenharmony_ci  // TODO(dgozman): this was added to support service worker shadow page. We
2881cb0ef41Sopenharmony_ci  // should not connect at all.
2891cb0ef41Sopenharmony_ci  virtual bool canExecuteScripts(int contextGroupId) { return true; }
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_ci  virtual void maxAsyncCallStackDepthChanged(int depth) {}
2921cb0ef41Sopenharmony_ci
2931cb0ef41Sopenharmony_ci  virtual std::unique_ptr<StringBuffer> resourceNameToUrl(
2941cb0ef41Sopenharmony_ci      const StringView& resourceName) {
2951cb0ef41Sopenharmony_ci    return nullptr;
2961cb0ef41Sopenharmony_ci  }
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci  // The caller would defer to generating a random 64 bit integer if
2991cb0ef41Sopenharmony_ci  // this method returns 0.
3001cb0ef41Sopenharmony_ci  virtual int64_t generateUniqueId() { return 0; }
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci  virtual void dispatchError(v8::Local<v8::Context>, v8::Local<v8::Message>,
3031cb0ef41Sopenharmony_ci                             v8::Local<v8::Value>) {}
3041cb0ef41Sopenharmony_ci};
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci// These stack trace ids are intended to be passed between debuggers and be
3071cb0ef41Sopenharmony_ci// resolved later. This allows to track cross-debugger calls and step between
3081cb0ef41Sopenharmony_ci// them if a single client connects to multiple debuggers.
3091cb0ef41Sopenharmony_cistruct V8_EXPORT V8StackTraceId {
3101cb0ef41Sopenharmony_ci  uintptr_t id;
3111cb0ef41Sopenharmony_ci  std::pair<int64_t, int64_t> debugger_id;
3121cb0ef41Sopenharmony_ci  bool should_pause = false;
3131cb0ef41Sopenharmony_ci
3141cb0ef41Sopenharmony_ci  V8StackTraceId();
3151cb0ef41Sopenharmony_ci  V8StackTraceId(const V8StackTraceId&) = default;
3161cb0ef41Sopenharmony_ci  V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id);
3171cb0ef41Sopenharmony_ci  V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id,
3181cb0ef41Sopenharmony_ci                 bool should_pause);
3191cb0ef41Sopenharmony_ci  explicit V8StackTraceId(StringView);
3201cb0ef41Sopenharmony_ci  V8StackTraceId& operator=(const V8StackTraceId&) = default;
3211cb0ef41Sopenharmony_ci  V8StackTraceId& operator=(V8StackTraceId&&) noexcept = default;
3221cb0ef41Sopenharmony_ci  ~V8StackTraceId() = default;
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ci  bool IsInvalid() const;
3251cb0ef41Sopenharmony_ci  std::unique_ptr<StringBuffer> ToString();
3261cb0ef41Sopenharmony_ci};
3271cb0ef41Sopenharmony_ci
3281cb0ef41Sopenharmony_ciclass V8_EXPORT V8Inspector {
3291cb0ef41Sopenharmony_ci public:
3301cb0ef41Sopenharmony_ci  static std::unique_ptr<V8Inspector> create(v8::Isolate*, V8InspectorClient*);
3311cb0ef41Sopenharmony_ci  virtual ~V8Inspector() = default;
3321cb0ef41Sopenharmony_ci
3331cb0ef41Sopenharmony_ci  // Contexts instrumentation.
3341cb0ef41Sopenharmony_ci  virtual void contextCreated(const V8ContextInfo&) = 0;
3351cb0ef41Sopenharmony_ci  virtual void contextDestroyed(v8::Local<v8::Context>) = 0;
3361cb0ef41Sopenharmony_ci  virtual void resetContextGroup(int contextGroupId) = 0;
3371cb0ef41Sopenharmony_ci  virtual v8::MaybeLocal<v8::Context> contextById(int contextId) = 0;
3381cb0ef41Sopenharmony_ci  virtual V8DebuggerId uniqueDebuggerId(int contextId) = 0;
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci  // Various instrumentation.
3411cb0ef41Sopenharmony_ci  virtual void idleStarted() = 0;
3421cb0ef41Sopenharmony_ci  virtual void idleFinished() = 0;
3431cb0ef41Sopenharmony_ci
3441cb0ef41Sopenharmony_ci  // Async stack traces instrumentation.
3451cb0ef41Sopenharmony_ci  virtual void asyncTaskScheduled(StringView taskName, void* task,
3461cb0ef41Sopenharmony_ci                                  bool recurring) = 0;
3471cb0ef41Sopenharmony_ci  virtual void asyncTaskCanceled(void* task) = 0;
3481cb0ef41Sopenharmony_ci  virtual void asyncTaskStarted(void* task) = 0;
3491cb0ef41Sopenharmony_ci  virtual void asyncTaskFinished(void* task) = 0;
3501cb0ef41Sopenharmony_ci  virtual void allAsyncTasksCanceled() = 0;
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ci  virtual V8StackTraceId storeCurrentStackTrace(StringView description) = 0;
3531cb0ef41Sopenharmony_ci  virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0;
3541cb0ef41Sopenharmony_ci  virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0;
3551cb0ef41Sopenharmony_ci
3561cb0ef41Sopenharmony_ci  // Exceptions instrumentation.
3571cb0ef41Sopenharmony_ci  virtual unsigned exceptionThrown(v8::Local<v8::Context>, StringView message,
3581cb0ef41Sopenharmony_ci                                   v8::Local<v8::Value> exception,
3591cb0ef41Sopenharmony_ci                                   StringView detailedMessage, StringView url,
3601cb0ef41Sopenharmony_ci                                   unsigned lineNumber, unsigned columnNumber,
3611cb0ef41Sopenharmony_ci                                   std::unique_ptr<V8StackTrace>,
3621cb0ef41Sopenharmony_ci                                   int scriptId) = 0;
3631cb0ef41Sopenharmony_ci  virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
3641cb0ef41Sopenharmony_ci                                StringView message) = 0;
3651cb0ef41Sopenharmony_ci  virtual bool associateExceptionData(v8::Local<v8::Context>,
3661cb0ef41Sopenharmony_ci                                      v8::Local<v8::Value> exception,
3671cb0ef41Sopenharmony_ci                                      v8::Local<v8::Name> key,
3681cb0ef41Sopenharmony_ci                                      v8::Local<v8::Value> value) = 0;
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_ci  // Connection.
3711cb0ef41Sopenharmony_ci  class V8_EXPORT Channel {
3721cb0ef41Sopenharmony_ci   public:
3731cb0ef41Sopenharmony_ci    virtual ~Channel() = default;
3741cb0ef41Sopenharmony_ci    virtual void sendResponse(int callId,
3751cb0ef41Sopenharmony_ci                              std::unique_ptr<StringBuffer> message) = 0;
3761cb0ef41Sopenharmony_ci    virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0;
3771cb0ef41Sopenharmony_ci    virtual void flushProtocolNotifications() = 0;
3781cb0ef41Sopenharmony_ci  };
3791cb0ef41Sopenharmony_ci  enum ClientTrustLevel { kUntrusted, kFullyTrusted };
3801cb0ef41Sopenharmony_ci  enum SessionPauseState { kWaitingForDebugger, kNotWaitingForDebugger };
3811cb0ef41Sopenharmony_ci  // TODO(chromium:1352175): remove default value once downstream change lands.
3821cb0ef41Sopenharmony_ci  virtual std::unique_ptr<V8InspectorSession> connect(
3831cb0ef41Sopenharmony_ci      int contextGroupId, Channel*, StringView state,
3841cb0ef41Sopenharmony_ci      ClientTrustLevel client_trust_level,
3851cb0ef41Sopenharmony_ci      SessionPauseState = kNotWaitingForDebugger) {
3861cb0ef41Sopenharmony_ci    return nullptr;
3871cb0ef41Sopenharmony_ci  }
3881cb0ef41Sopenharmony_ci
3891cb0ef41Sopenharmony_ci  // API methods.
3901cb0ef41Sopenharmony_ci  virtual std::unique_ptr<V8StackTrace> createStackTrace(
3911cb0ef41Sopenharmony_ci      v8::Local<v8::StackTrace>) = 0;
3921cb0ef41Sopenharmony_ci  virtual std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) = 0;
3931cb0ef41Sopenharmony_ci};
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_ci}  // namespace v8_inspector
3961cb0ef41Sopenharmony_ci
3971cb0ef41Sopenharmony_ci#endif  // V8_V8_INSPECTOR_H_
398