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_DEBUG_DEBUG_PROPERTY_ITERATOR_H_
6 #define V8_DEBUG_DEBUG_PROPERTY_ITERATOR_H_
7 
8 #include "include/v8-local-handle.h"
9 #include "include/v8-maybe.h"
10 #include "include/v8-object.h"
11 #include "src/debug/debug-interface.h"
12 #include "src/execution/isolate.h"
13 #include "src/handles/handles.h"
14 #include "src/objects/prototype.h"
15 
16 namespace v8 {
17 
18 class Name;
19 
20 namespace internal {
21 
22 class JSReceiver;
23 
24 class DebugPropertyIterator final : public debug::PropertyIterator {
25  public:
26   V8_WARN_UNUSED_RESULT static std::unique_ptr<DebugPropertyIterator> Create(
27       Isolate* isolate, Handle<JSReceiver> receiver, bool skip_indices);
28   ~DebugPropertyIterator() override = default;
29   DebugPropertyIterator(const DebugPropertyIterator&) = delete;
30   DebugPropertyIterator& operator=(const DebugPropertyIterator&) = delete;
31 
32   bool Done() const override;
33   V8_WARN_UNUSED_RESULT Maybe<bool> Advance() override;
34 
35   v8::Local<v8::Name> name() const override;
36   bool is_native_accessor() override;
37   bool has_native_getter() override;
38   bool has_native_setter() override;
39   v8::Maybe<v8::PropertyAttribute> attributes() override;
40   v8::Maybe<v8::debug::PropertyDescriptor> descriptor() override;
41 
42   bool is_own() override;
43   bool is_array_index() override;
44 
45  private:
46   DebugPropertyIterator(Isolate* isolate, Handle<JSReceiver> receiver,
47                         bool skip_indices);
48 
49   V8_WARN_UNUSED_RESULT bool FillKeysForCurrentPrototypeAndStage();
50   bool should_move_to_next_stage() const;
51   void CalculateNativeAccessorFlags();
52   Handle<Name> raw_name() const;
53   void AdvanceToPrototype();
54   V8_WARN_UNUSED_RESULT bool AdvanceInternal();
55 
56   Isolate* isolate_;
57   PrototypeIterator prototype_iterator_;
58   enum {
59     kExoticIndices = 0,
60     kEnumerableStrings = 1,
61     kAllProperties = 2
62   } stage_ = kExoticIndices;
63   bool skip_indices_;
64 
65   size_t current_key_index_;
66   Handle<FixedArray> current_keys_;
67   size_t current_keys_length_;
68 
69   bool calculated_native_accessor_flags_ = false;
70   int native_accessor_flags_ = 0;
71   bool is_own_ = true;
72   bool is_done_ = false;
73 };
74 }  // namespace internal
75 }  // namespace v8
76 
77 #endif  // V8_DEBUG_DEBUG_PROPERTY_ITERATOR_H_
78