value-mirror.h 3.67 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2018 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.

#ifndef V8_INSPECTOR_VALUE_MIRROR_H_
#define V8_INSPECTOR_VALUE_MIRROR_H_

#include <memory>

10
#include "include/v8-inspector.h"
11
#include "include/v8-local-handle.h"
12 13 14 15 16 17 18 19 20 21
#include "src/base/macros.h"
#include "src/inspector/protocol/Protocol.h"
#include "src/inspector/protocol/Runtime.h"
#include "src/inspector/string-16.h"

namespace v8_inspector {

class ValueMirror;
enum class WrapMode;

22 23 24
struct PrivatePropertyMirror {
  String16 name;
  std::unique_ptr<ValueMirror> value;
25 26
  std::unique_ptr<ValueMirror> getter;
  std::unique_ptr<ValueMirror> setter;
27 28
};

29 30 31 32 33 34 35 36 37 38 39 40
struct InternalPropertyMirror {
  String16 name;
  std::unique_ptr<ValueMirror> value;
};

struct PropertyMirror {
  String16 name;
  bool writable;
  bool configurable;
  bool enumerable;
  bool isOwn;
  bool isIndex;
41
  bool isSynthetic;
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  std::unique_ptr<ValueMirror> value;
  std::unique_ptr<ValueMirror> getter;
  std::unique_ptr<ValueMirror> setter;
  std::unique_ptr<ValueMirror> symbol;
  std::unique_ptr<ValueMirror> exception;
};

class ValueMirror {
 public:
  virtual ~ValueMirror();

  static std::unique_ptr<ValueMirror> create(v8::Local<v8::Context> context,
                                             v8::Local<v8::Value> value);
  virtual protocol::Response buildRemoteObject(
      v8::Local<v8::Context> context, WrapMode mode,
57
      std::unique_ptr<protocol::Runtime::RemoteObject>* result) const = 0;
58 59
  virtual void buildPropertyPreview(
      v8::Local<v8::Context> context, const String16& name,
60
      std::unique_ptr<protocol::Runtime::PropertyPreview>*) const {}
61
  virtual void buildObjectPreview(
62
      v8::Local<v8::Context> context, bool generatePreviewForTable,
63
      int* nameLimit, int* indexLimit,
64
      std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {}
65
  virtual void buildEntryPreview(
66
      v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
67 68
      std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {}
  virtual v8::Local<v8::Value> v8Value() const = 0;
69 70 71
  virtual protocol::Response buildWebDriverValue(
      v8::Local<v8::Context> context, int max_depth,
      std::unique_ptr<protocol::Runtime::WebDriverValue>* result) const = 0;
72 73 74 75 76 77 78 79 80

  class PropertyAccumulator {
   public:
    virtual ~PropertyAccumulator() = default;
    virtual bool Add(PropertyMirror mirror) = 0;
  };
  static bool getProperties(v8::Local<v8::Context> context,
                            v8::Local<v8::Object> object, bool ownProperties,
                            bool accessorPropertiesOnly,
81
                            bool nonIndexedPropertiesOnly,
82 83 84 85
                            PropertyAccumulator* accumulator);
  static void getInternalProperties(
      v8::Local<v8::Context> context, v8::Local<v8::Object> object,
      std::vector<InternalPropertyMirror>* mirrors);
86
  static std::vector<PrivatePropertyMirror> getPrivateProperties(
87 88
      v8::Local<v8::Context> context, v8::Local<v8::Object> object,
      bool accessorPropertiesOnly);
89
};
90 91 92 93 94 95 96 97 98 99 100

protocol::Response toProtocolValue(v8::Local<v8::Context> context,
                                   v8::Local<v8::Value> value, int maxDepth,
                                   std::unique_ptr<protocol::Value>* result);
protocol::Response arrayToProtocolValue(
    v8::Local<v8::Context> context, v8::Local<v8::Array> array, int maxDepth,
    std::unique_ptr<protocol::ListValue>* result);
protocol::Response objectToProtocolValue(
    v8::Local<v8::Context> context, v8::Local<v8::Object> object, int maxDepth,
    std::unique_ptr<protocol::DictionaryValue>* result);

101 102 103
}  // namespace v8_inspector

#endif  // V8_INSPECTOR_VALUE_MIRROR_H_