• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #ifndef V8_INSPECTOR_VALUE_MIRROR_H_
6 #define V8_INSPECTOR_VALUE_MIRROR_H_
7 
8 #include <memory>
9 
10 #include "include/v8-inspector.h"
11 #include "include/v8-local-handle.h"
12 #include "src/base/macros.h"
13 #include "src/inspector/protocol/Protocol.h"
14 #include "src/inspector/protocol/Runtime.h"
15 #include "src/inspector/string-16.h"
16 
17 namespace v8_inspector {
18 
19 class ValueMirror;
20 enum class WrapMode;
21 
22 struct PrivatePropertyMirror {
23   String16 name;
24   std::unique_ptr<ValueMirror> value;
25   std::unique_ptr<ValueMirror> getter;
26   std::unique_ptr<ValueMirror> setter;
27 };
28 
29 struct InternalPropertyMirror {
30   String16 name;
31   std::unique_ptr<ValueMirror> value;
32 };
33 
34 struct PropertyMirror {
35   String16 name;
36   bool writable;
37   bool configurable;
38   bool enumerable;
39   bool isOwn;
40   bool isIndex;
41   bool isSynthetic;
42   std::unique_ptr<ValueMirror> value;
43   std::unique_ptr<ValueMirror> getter;
44   std::unique_ptr<ValueMirror> setter;
45   std::unique_ptr<ValueMirror> symbol;
46   std::unique_ptr<ValueMirror> exception;
47 };
48 
49 class ValueMirror {
50  public:
51   virtual ~ValueMirror();
52 
53   static std::unique_ptr<ValueMirror> create(v8::Local<v8::Context> context,
54                                              v8::Local<v8::Value> value);
55   virtual protocol::Response buildRemoteObject(
56       v8::Local<v8::Context> context, WrapMode mode,
57       std::unique_ptr<protocol::Runtime::RemoteObject>* result) const = 0;
buildPropertyPreview(v8::Local<v8::Context> context,const String16 & name,std::unique_ptr<protocol::Runtime::PropertyPreview> *)58   virtual void buildPropertyPreview(
59       v8::Local<v8::Context> context, const String16& name,
60       std::unique_ptr<protocol::Runtime::PropertyPreview>*) const {}
buildObjectPreview(v8::Local<v8::Context> context,bool generatePreviewForTable,int * nameLimit,int * indexLimit,std::unique_ptr<protocol::Runtime::ObjectPreview> *)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 {}
buildEntryPreview(v8::Local<v8::Context> context,int * nameLimit,int * indexLimit,std::unique_ptr<protocol::Runtime::ObjectPreview> *)65   virtual void buildEntryPreview(
66       v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
67       std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {}
68   virtual v8::Local<v8::Value> v8Value() const = 0;
69   virtual protocol::Response buildWebDriverValue(
70       v8::Local<v8::Context> context, int max_depth,
71       std::unique_ptr<protocol::Runtime::WebDriverValue>* result) const = 0;
72 
73   class PropertyAccumulator {
74    public:
75     virtual ~PropertyAccumulator() = default;
76     virtual bool Add(PropertyMirror mirror) = 0;
77   };
78   static bool getProperties(v8::Local<v8::Context> context,
79                             v8::Local<v8::Object> object, bool ownProperties,
80                             bool accessorPropertiesOnly,
81                             bool nonIndexedPropertiesOnly,
82                             PropertyAccumulator* accumulator);
83   static void getInternalProperties(
84       v8::Local<v8::Context> context, v8::Local<v8::Object> object,
85       std::vector<InternalPropertyMirror>* mirrors);
86   static std::vector<PrivatePropertyMirror> getPrivateProperties(
87       v8::Local<v8::Context> context, v8::Local<v8::Object> object,
88       bool accessorPropertiesOnly);
89 };
90 
91 protocol::Response toProtocolValue(v8::Local<v8::Context> context,
92                                    v8::Local<v8::Value> value, int maxDepth,
93                                    std::unique_ptr<protocol::Value>* result);
94 protocol::Response arrayToProtocolValue(
95     v8::Local<v8::Context> context, v8::Local<v8::Array> array, int maxDepth,
96     std::unique_ptr<protocol::ListValue>* result);
97 protocol::Response objectToProtocolValue(
98     v8::Local<v8::Context> context, v8::Local<v8::Object> object, int maxDepth,
99     std::unique_ptr<protocol::DictionaryValue>* result);
100 
101 }  // namespace v8_inspector
102 
103 #endif  // V8_INSPECTOR_VALUE_MIRROR_H_
104