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 "src/base/macros.h" 11 #include "src/inspector/protocol/Protocol.h" 12 #include "src/inspector/protocol/Runtime.h" 13 #include "src/inspector/string-16.h" 14 15 #include "include/v8-inspector.h" 16 #include "include/v8.h" 17 18 namespace v8_inspector { 19 20 class ValueMirror; 21 enum class WrapMode; 22 23 struct PrivatePropertyMirror { 24 String16 name; 25 std::unique_ptr<ValueMirror> value; 26 std::unique_ptr<ValueMirror> getter; 27 std::unique_ptr<ValueMirror> setter; 28 }; 29 30 struct InternalPropertyMirror { 31 String16 name; 32 std::unique_ptr<ValueMirror> value; 33 }; 34 35 struct PropertyMirror { 36 String16 name; 37 bool writable; 38 bool configurable; 39 bool enumerable; 40 bool isOwn; 41 bool isIndex; 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 70 class PropertyAccumulator { 71 public: 72 virtual ~PropertyAccumulator() = default; 73 virtual bool Add(PropertyMirror mirror) = 0; 74 }; 75 static bool getProperties(v8::Local<v8::Context> context, 76 v8::Local<v8::Object> object, bool ownProperties, 77 bool accessorPropertiesOnly, 78 PropertyAccumulator* accumulator); 79 static void getInternalProperties( 80 v8::Local<v8::Context> context, v8::Local<v8::Object> object, 81 std::vector<InternalPropertyMirror>* mirrors); 82 static std::vector<PrivatePropertyMirror> getPrivateProperties( 83 v8::Local<v8::Context> context, v8::Local<v8::Object> object); 84 }; 85 } // namespace v8_inspector 86 87 #endif // V8_INSPECTOR_VALUE_MIRROR_H_ 88