• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_INTERFACE_H_
6 #define V8_DEBUG_DEBUG_INTERFACE_H_
7 
8 #include <memory>
9 
10 #include "include/v8-callbacks.h"
11 #include "include/v8-date.h"
12 #include "include/v8-debug.h"
13 #include "include/v8-embedder-heap.h"
14 #include "include/v8-local-handle.h"
15 #include "include/v8-memory-span.h"
16 #include "include/v8-promise.h"
17 #include "include/v8-script.h"
18 #include "include/v8-util.h"
19 #include "src/base/enum-set.h"
20 #include "src/base/vector.h"
21 #include "src/common/globals.h"
22 #include "src/debug/interface-types.h"
23 
24 namespace v8_inspector {
25 class V8Inspector;
26 }  // namespace v8_inspector
27 
28 namespace v8 {
29 
30 class Platform;
31 
32 namespace internal {
33 struct CoverageBlock;
34 struct CoverageFunction;
35 struct CoverageScript;
36 struct TypeProfileEntry;
37 struct TypeProfileScript;
38 class Coverage;
39 class DisableBreak;
40 class PostponeInterruptsScope;
41 class Script;
42 class TypeProfile;
43 }  // namespace internal
44 
45 namespace debug {
46 
47 void SetContextId(Local<Context> context, int id);
48 int GetContextId(Local<Context> context);
49 
50 void SetInspector(Isolate* isolate, v8_inspector::V8Inspector*);
51 v8_inspector::V8Inspector* GetInspector(Isolate* isolate);
52 
53 // Returns a debug string representation of the bigint.
54 Local<String> GetBigIntDescription(Isolate* isolate, Local<BigInt> bigint);
55 
56 // Returns a debug string representation of the date.
57 Local<String> GetDateDescription(Local<Date> date);
58 
59 // Returns a debug string representation of the function.
60 Local<String> GetFunctionDescription(Local<Function> function);
61 
62 // Schedule a debugger break to happen when function is called inside given
63 // isolate.
64 V8_EXPORT_PRIVATE void SetBreakOnNextFunctionCall(Isolate* isolate);
65 
66 // Remove scheduled debugger break in given isolate if it has not
67 // happened yet.
68 V8_EXPORT_PRIVATE void ClearBreakOnNextFunctionCall(Isolate* isolate);
69 
70 /**
71  * Returns array of internal properties specific to the value type. Result has
72  * the following format: [<name>, <value>,...,<name>, <value>]. Result array
73  * will be allocated in the current context.
74  */
75 MaybeLocal<Array> GetInternalProperties(Isolate* isolate, Local<Value> value);
76 
77 /**
78  * Returns through the out parameters names_out a vector of names
79  * in v8::String for private members, including fields, methods,
80  * accessors specific to the value type.
81  * The values are returned through the out parameter values_out in the
82  * corresponding indices. Private fields and methods are returned directly
83  * while accessors are returned as v8::debug::AccessorPair. Missing components
84  * in the accessor pairs are null.
85  * If an exception occurs, false is returned. Otherwise true is returned.
86  * Results will be allocated in the current context and handle scope.
87  */
88 V8_EXPORT_PRIVATE bool GetPrivateMembers(Local<Context> context,
89                                          Local<Object> value,
90                                          std::vector<Local<Value>>* names_out,
91                                          std::vector<Local<Value>>* values_out);
92 
93 /**
94  * Forwards to v8::Object::CreationContext, but with special handling for
95  * JSGlobalProxy objects.
96  */
97 MaybeLocal<Context> GetCreationContext(Local<Object> value);
98 
99 enum ExceptionBreakState {
100   NoBreakOnException = 0,
101   BreakOnUncaughtException = 1,
102   BreakOnAnyException = 2
103 };
104 
105 /**
106  * Defines if VM will pause on exceptions or not.
107  * If BreakOnAnyExceptions is set then VM will pause on caught and uncaught
108  * exception, if BreakOnUncaughtException is set then VM will pause only on
109  * uncaught exception, otherwise VM won't stop on any exception.
110  */
111 void ChangeBreakOnException(Isolate* isolate, ExceptionBreakState state);
112 
113 void RemoveBreakpoint(Isolate* isolate, BreakpointId id);
114 void SetBreakPointsActive(Isolate* isolate, bool is_active);
115 
116 enum StepAction {
117   StepOut = 0,   // Step out of the current function.
118   StepOver = 1,  // Step to the next statement in the current function.
119   StepInto = 2   // Step into new functions invoked or the next statement
120                  // in the current function.
121 };
122 
123 // Record the reason for why the debugger breaks.
124 enum class BreakReason : uint8_t {
125   kAlreadyPaused,
126   kStep,
127   kAsyncStep,
128   kException,
129   kAssert,
130   kDebuggerStatement,
131   kOOM,
132   kScheduled,
133   kAgent
134 };
135 typedef base::EnumSet<BreakReason> BreakReasons;
136 
137 void PrepareStep(Isolate* isolate, StepAction action);
138 void ClearStepping(Isolate* isolate);
139 V8_EXPORT_PRIVATE void BreakRightNow(
140     Isolate* isolate, base::EnumSet<BreakReason> break_reason = {});
141 
142 // Use `SetTerminateOnResume` to indicate that an TerminateExecution interrupt
143 // should be set shortly before resuming, i.e. shortly before returning into
144 // the JavaScript stack frames on the stack. In contrast to setting the
145 // interrupt with `RequestTerminateExecution` directly, this flag allows
146 // the isolate to be entered for further JavaScript execution.
147 V8_EXPORT_PRIVATE void SetTerminateOnResume(Isolate* isolate);
148 
149 bool CanBreakProgram(Isolate* isolate);
150 
151 class Script;
152 
153 struct LiveEditResult {
154   enum Status {
155     OK,
156     COMPILE_ERROR,
157     BLOCKED_BY_RUNNING_GENERATOR,
158     BLOCKED_BY_ACTIVE_FUNCTION
159   };
160   Status status = OK;
161   bool stack_changed = false;
162   // Available only for OK.
163   v8::Local<v8::debug::Script> script;
164   // Fields below are available only for COMPILE_ERROR.
165   v8::Local<v8::String> message;
166   int line_number = -1;
167   int column_number = -1;
168 };
169 
170 /**
171  * An internal representation of the source for a given
172  * `v8::debug::Script`, which can be a `v8::String`, in
173  * which case it represents JavaScript source, or it can
174  * be a managed pointer to a native Wasm module, or it
175  * can be undefined to indicate that source is unavailable.
176  */
177 class V8_EXPORT_PRIVATE ScriptSource {
178  public:
179   // The number of characters in case of JavaScript or
180   // the size of the memory in case of WebAssembly.
181   size_t Length() const;
182 
183   // The actual size of the source in bytes.
184   size_t Size() const;
185 
186   MaybeLocal<String> JavaScriptCode() const;
187 #if V8_ENABLE_WEBASSEMBLY
188   Maybe<MemorySpan<const uint8_t>> WasmBytecode() const;
189 #endif  // V8_ENABLE_WEBASSEMBLY
190 };
191 
192 /**
193  * Native wrapper around v8::internal::Script object.
194  */
195 class V8_EXPORT_PRIVATE Script {
196  public:
197   v8::Isolate* GetIsolate() const;
198 
199   ScriptOriginOptions OriginOptions() const;
200   bool WasCompiled() const;
201   bool IsEmbedded() const;
202   int Id() const;
203   int StartLine() const;
204   int StartColumn() const;
205   int EndLine() const;
206   int EndColumn() const;
207   MaybeLocal<String> Name() const;
208   MaybeLocal<String> SourceURL() const;
209   MaybeLocal<String> SourceMappingURL() const;
210   Maybe<int> ContextId() const;
211   Local<ScriptSource> Source() const;
212   bool IsModule() const;
213   bool GetPossibleBreakpoints(
214       const debug::Location& start, const debug::Location& end,
215       bool restrict_to_function,
216       std::vector<debug::BreakLocation>* locations) const;
217   int GetSourceOffset(const debug::Location& location) const;
218   v8::debug::Location GetSourceLocation(int offset) const;
219   bool SetScriptSource(v8::Local<v8::String> newSource, bool preview,
220                        LiveEditResult* result) const;
221   bool SetBreakpoint(v8::Local<v8::String> condition, debug::Location* location,
222                      BreakpointId* id) const;
223 #if V8_ENABLE_WEBASSEMBLY
224   bool IsWasm() const;
225   void RemoveWasmBreakpoint(BreakpointId id);
226 #endif  // V8_ENABLE_WEBASSEMBLY
227   bool SetInstrumentationBreakpoint(BreakpointId* id) const;
228 };
229 
230 #if V8_ENABLE_WEBASSEMBLY
231 // Specialization for wasm Scripts.
232 class WasmScript : public Script {
233  public:
234   static WasmScript* Cast(Script* script);
235 
236   enum class DebugSymbolsType { None, SourceMap, EmbeddedDWARF, ExternalDWARF };
237   DebugSymbolsType GetDebugSymbolType() const;
238   MemorySpan<const char> ExternalSymbolsURL() const;
239   int NumFunctions() const;
240   int NumImportedFunctions() const;
241 
242   std::pair<int, int> GetFunctionRange(int function_index) const;
243   int GetContainingFunction(int byte_offset) const;
244 
245   uint32_t GetFunctionHash(int function_index);
246 
247   int CodeOffset() const;
248   int CodeLength() const;
249 };
250 #endif  // V8_ENABLE_WEBASSEMBLY
251 
252 V8_EXPORT_PRIVATE void GetLoadedScripts(Isolate* isolate,
253                                         PersistentValueVector<Script>& scripts);
254 
255 MaybeLocal<UnboundScript> CompileInspectorScript(Isolate* isolate,
256                                                  Local<String> source);
257 
258 enum ExceptionType { kException, kPromiseRejection };
259 
260 class DebugDelegate {
261  public:
262   virtual ~DebugDelegate() = default;
ScriptCompiled(v8::Local<Script> script,bool is_live_edited,bool has_compile_error)263   virtual void ScriptCompiled(v8::Local<Script> script, bool is_live_edited,
264                               bool has_compile_error) {}
265   // |inspector_break_points_hit| contains id of breakpoints installed with
266   // debug::Script::SetBreakpoint API.
267   virtual void BreakProgramRequested(
268       v8::Local<v8::Context> paused_context,
269       const std::vector<debug::BreakpointId>& inspector_break_points_hit,
270       base::EnumSet<BreakReason> break_reasons = {}) {}
BreakOnInstrumentation(v8::Local<v8::Context> paused_context,const debug::BreakpointId instrumentationId)271   virtual void BreakOnInstrumentation(
272       v8::Local<v8::Context> paused_context,
273       const debug::BreakpointId instrumentationId) {}
ExceptionThrown(v8::Local<v8::Context> paused_context,v8::Local<v8::Value> exception,v8::Local<v8::Value> promise,bool is_uncaught,ExceptionType exception_type)274   virtual void ExceptionThrown(v8::Local<v8::Context> paused_context,
275                                v8::Local<v8::Value> exception,
276                                v8::Local<v8::Value> promise, bool is_uncaught,
277                                ExceptionType exception_type) {}
IsFunctionBlackboxed(v8::Local<debug::Script> script,const debug::Location & start,const debug::Location & end)278   virtual bool IsFunctionBlackboxed(v8::Local<debug::Script> script,
279                                     const debug::Location& start,
280                                     const debug::Location& end) {
281     return false;
282   }
ShouldBeSkipped(v8::Local<v8::debug::Script> script,int line,int column)283   virtual bool ShouldBeSkipped(v8::Local<v8::debug::Script> script, int line,
284                                int column) {
285     return false;
286   }
287 };
288 
289 V8_EXPORT_PRIVATE void SetDebugDelegate(Isolate* isolate,
290                                         DebugDelegate* listener);
291 
292 #if V8_ENABLE_WEBASSEMBLY
293 V8_EXPORT_PRIVATE void TierDownAllModulesPerIsolate(Isolate* isolate);
294 V8_EXPORT_PRIVATE void TierUpAllModulesPerIsolate(Isolate* isolate);
295 #endif  // V8_ENABLE_WEBASSEMBLY
296 
297 class AsyncEventDelegate {
298  public:
299   virtual ~AsyncEventDelegate() = default;
300   virtual void AsyncEventOccurred(debug::DebugAsyncActionType type, int id,
301                                   bool is_blackboxed) = 0;
302 };
303 
304 V8_EXPORT_PRIVATE void SetAsyncEventDelegate(Isolate* isolate,
305                                              AsyncEventDelegate* delegate);
306 
307 void ResetBlackboxedStateCache(Isolate* isolate,
308                                v8::Local<debug::Script> script);
309 
310 int EstimatedValueSize(Isolate* isolate, v8::Local<v8::Value> value);
311 
312 enum Builtin { kStringToLowerCase };
313 
314 Local<Function> GetBuiltin(Isolate* isolate, Builtin builtin);
315 
316 V8_EXPORT_PRIVATE void SetConsoleDelegate(Isolate* isolate,
317                                           ConsoleDelegate* delegate);
318 
319 V8_EXPORT_PRIVATE v8::Local<v8::Message> CreateMessageFromException(
320     Isolate* isolate, v8::Local<v8::Value> error);
321 
322 /**
323  * Native wrapper around v8::internal::JSGeneratorObject object.
324  */
325 class GeneratorObject {
326  public:
327   v8::MaybeLocal<debug::Script> Script();
328   v8::Local<v8::Function> Function();
329   debug::Location SuspendedLocation();
330   bool IsSuspended();
331 
332   static v8::Local<debug::GeneratorObject> Cast(v8::Local<v8::Value> value);
333 };
334 
335 /*
336  * Provide API layer between inspector and code coverage.
337  */
338 class V8_EXPORT_PRIVATE Coverage {
339  public:
340   MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(Coverage);
341 
342   // Forward declarations.
343   class ScriptData;
344   class FunctionData;
345 
346   class V8_EXPORT_PRIVATE BlockData {
347    public:
348     MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(BlockData);
349 
350     int StartOffset() const;
351     int EndOffset() const;
352     uint32_t Count() const;
353 
354    private:
BlockData(i::CoverageBlock * block,std::shared_ptr<i::Coverage> coverage)355     explicit BlockData(i::CoverageBlock* block,
356                        std::shared_ptr<i::Coverage> coverage)
357         : block_(block), coverage_(std::move(coverage)) {}
358 
359     i::CoverageBlock* block_;
360     std::shared_ptr<i::Coverage> coverage_;
361 
362     friend class v8::debug::Coverage::FunctionData;
363   };
364 
365   class V8_EXPORT_PRIVATE FunctionData {
366    public:
367     MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(FunctionData);
368 
369     int StartOffset() const;
370     int EndOffset() const;
371     uint32_t Count() const;
372     MaybeLocal<String> Name() const;
373     size_t BlockCount() const;
374     bool HasBlockCoverage() const;
375     BlockData GetBlockData(size_t i) const;
376 
377    private:
FunctionData(i::CoverageFunction * function,std::shared_ptr<i::Coverage> coverage)378     explicit FunctionData(i::CoverageFunction* function,
379                           std::shared_ptr<i::Coverage> coverage)
380         : function_(function), coverage_(std::move(coverage)) {}
381 
382     i::CoverageFunction* function_;
383     std::shared_ptr<i::Coverage> coverage_;
384 
385     friend class v8::debug::Coverage::ScriptData;
386   };
387 
388   class V8_EXPORT_PRIVATE ScriptData {
389    public:
390     MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(ScriptData);
391 
392     Local<debug::Script> GetScript() const;
393     size_t FunctionCount() const;
394     FunctionData GetFunctionData(size_t i) const;
395 
396    private:
397     explicit ScriptData(size_t index, std::shared_ptr<i::Coverage> c);
398 
399     i::CoverageScript* script_;
400     std::shared_ptr<i::Coverage> coverage_;
401 
402     friend class v8::debug::Coverage;
403   };
404 
405   static Coverage CollectPrecise(Isolate* isolate);
406   static Coverage CollectBestEffort(Isolate* isolate);
407 
408   static void SelectMode(Isolate* isolate, CoverageMode mode);
409 
410   size_t ScriptCount() const;
411   ScriptData GetScriptData(size_t i) const;
IsEmpty()412   bool IsEmpty() const { return coverage_ == nullptr; }
413 
414  private:
Coverage(std::shared_ptr<i::Coverage> coverage)415   explicit Coverage(std::shared_ptr<i::Coverage> coverage)
416       : coverage_(std::move(coverage)) {}
417   std::shared_ptr<i::Coverage> coverage_;
418 };
419 
420 /*
421  * Provide API layer between inspector and type profile.
422  */
423 class V8_EXPORT_PRIVATE TypeProfile {
424  public:
425   MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(TypeProfile);
426 
427   class ScriptData;  // Forward declaration.
428 
429   class V8_EXPORT_PRIVATE Entry {
430    public:
431     MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(Entry);
432 
433     int SourcePosition() const;
434     std::vector<MaybeLocal<String>> Types() const;
435 
436    private:
Entry(const i::TypeProfileEntry * entry,std::shared_ptr<i::TypeProfile> type_profile)437     explicit Entry(const i::TypeProfileEntry* entry,
438                    std::shared_ptr<i::TypeProfile> type_profile)
439         : entry_(entry), type_profile_(std::move(type_profile)) {}
440 
441     const i::TypeProfileEntry* entry_;
442     std::shared_ptr<i::TypeProfile> type_profile_;
443 
444     friend class v8::debug::TypeProfile::ScriptData;
445   };
446 
447   class V8_EXPORT_PRIVATE ScriptData {
448    public:
449     MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(ScriptData);
450 
451     Local<debug::Script> GetScript() const;
452     std::vector<Entry> Entries() const;
453 
454    private:
455     explicit ScriptData(size_t index,
456                         std::shared_ptr<i::TypeProfile> type_profile);
457 
458     i::TypeProfileScript* script_;
459     std::shared_ptr<i::TypeProfile> type_profile_;
460 
461     friend class v8::debug::TypeProfile;
462   };
463 
464   static TypeProfile Collect(Isolate* isolate);
465 
466   static void SelectMode(Isolate* isolate, TypeProfileMode mode);
467 
468   size_t ScriptCount() const;
469   ScriptData GetScriptData(size_t i) const;
470 
471  private:
TypeProfile(std::shared_ptr<i::TypeProfile> type_profile)472   explicit TypeProfile(std::shared_ptr<i::TypeProfile> type_profile)
473       : type_profile_(std::move(type_profile)) {}
474 
475   std::shared_ptr<i::TypeProfile> type_profile_;
476 };
477 
478 class V8_EXPORT_PRIVATE ScopeIterator {
479  public:
480   static std::unique_ptr<ScopeIterator> CreateForFunction(
481       v8::Isolate* isolate, v8::Local<v8::Function> func);
482   static std::unique_ptr<ScopeIterator> CreateForGeneratorObject(
483       v8::Isolate* isolate, v8::Local<v8::Object> generator);
484 
485   ScopeIterator() = default;
486   virtual ~ScopeIterator() = default;
487   ScopeIterator(const ScopeIterator&) = delete;
488   ScopeIterator& operator=(const ScopeIterator&) = delete;
489 
490   enum ScopeType {
491     ScopeTypeGlobal = 0,
492     ScopeTypeLocal,
493     ScopeTypeWith,
494     ScopeTypeClosure,
495     ScopeTypeCatch,
496     ScopeTypeBlock,
497     ScopeTypeScript,
498     ScopeTypeEval,
499     ScopeTypeModule,
500     ScopeTypeWasmExpressionStack
501   };
502 
503   virtual bool Done() = 0;
504   virtual void Advance() = 0;
505   virtual ScopeType GetType() = 0;
506   virtual v8::Local<v8::Object> GetObject() = 0;
507   virtual v8::Local<v8::Value> GetFunctionDebugName() = 0;
508   virtual int GetScriptId() = 0;
509   virtual bool HasLocationInfo() = 0;
510   virtual debug::Location GetStartLocation() = 0;
511   virtual debug::Location GetEndLocation() = 0;
512 
513   virtual bool SetVariableValue(v8::Local<v8::String> name,
514                                 v8::Local<v8::Value> value) = 0;
515 };
516 
517 class V8_EXPORT_PRIVATE StackTraceIterator {
518  public:
519   static std::unique_ptr<StackTraceIterator> Create(Isolate* isolate,
520                                                     int index = 0);
521   StackTraceIterator() = default;
522   virtual ~StackTraceIterator() = default;
523   StackTraceIterator(const StackTraceIterator&) = delete;
524   StackTraceIterator& operator=(const StackTraceIterator&) = delete;
525 
526   virtual bool Done() const = 0;
527   virtual void Advance() = 0;
528 
529   virtual int GetContextId() const = 0;
530   virtual v8::MaybeLocal<v8::Value> GetReceiver() const = 0;
531   virtual v8::Local<v8::Value> GetReturnValue() const = 0;
532   virtual v8::Local<v8::String> GetFunctionDebugName() const = 0;
533   virtual v8::Local<v8::debug::Script> GetScript() const = 0;
534   virtual debug::Location GetSourceLocation() const = 0;
535   virtual v8::Local<v8::Function> GetFunction() const = 0;
536   virtual std::unique_ptr<ScopeIterator> GetScopeIterator() const = 0;
537 
538   virtual v8::MaybeLocal<v8::Value> Evaluate(v8::Local<v8::String> source,
539                                              bool throw_on_side_effect) = 0;
540 };
541 
542 class QueryObjectPredicate {
543  public:
544   virtual ~QueryObjectPredicate() = default;
545   virtual bool Filter(v8::Local<v8::Object> object) = 0;
546 };
547 
548 void QueryObjects(v8::Local<v8::Context> context,
549                   QueryObjectPredicate* predicate,
550                   v8::PersistentValueVector<v8::Object>* objects);
551 
552 void GlobalLexicalScopeNames(v8::Local<v8::Context> context,
553                              v8::PersistentValueVector<v8::String>* names);
554 
555 void SetReturnValue(v8::Isolate* isolate, v8::Local<v8::Value> value);
556 
557 enum class NativeAccessorType {
558   None = 0,
559   HasGetter = 1 << 0,
560   HasSetter = 1 << 1
561 };
562 
563 int64_t GetNextRandomInt64(v8::Isolate* isolate);
564 
565 MaybeLocal<Value> CallFunctionOn(Local<Context> context,
566                                  Local<Function> function, Local<Value> recv,
567                                  int argc, Local<Value> argv[],
568                                  bool throw_on_side_effect);
569 
570 enum class EvaluateGlobalMode {
571   kDefault,
572   kDisableBreaks,
573   kDisableBreaksAndThrowOnSideEffect
574 };
575 
576 V8_EXPORT_PRIVATE v8::MaybeLocal<v8::Value> EvaluateGlobal(
577     v8::Isolate* isolate, v8::Local<v8::String> source, EvaluateGlobalMode mode,
578     bool repl_mode = false);
579 
580 V8_EXPORT_PRIVATE v8::MaybeLocal<v8::Value> EvaluateGlobalForTesting(
581     v8::Isolate* isolate, v8::Local<v8::Script> function,
582     v8::debug::EvaluateGlobalMode mode, bool repl);
583 
584 int GetDebuggingId(v8::Local<v8::Function> function);
585 
586 bool SetFunctionBreakpoint(v8::Local<v8::Function> function,
587                            v8::Local<v8::String> condition, BreakpointId* id);
588 
589 v8::Platform* GetCurrentPlatform();
590 
591 void ForceGarbageCollection(
592     v8::Isolate* isolate,
593     v8::EmbedderHeapTracer::EmbedderStackState embedder_stack_state);
594 
595 class V8_NODISCARD PostponeInterruptsScope {
596  public:
597   explicit PostponeInterruptsScope(v8::Isolate* isolate);
598   ~PostponeInterruptsScope();
599 
600  private:
601   std::unique_ptr<i::PostponeInterruptsScope> scope_;
602 };
603 
604 class V8_NODISCARD DisableBreakScope {
605  public:
606   explicit DisableBreakScope(v8::Isolate* isolate);
607   ~DisableBreakScope();
608 
609  private:
610   std::unique_ptr<i::DisableBreak> scope_;
611 };
612 
613 class EphemeronTable : public v8::Object {
614  public:
615   EphemeronTable() = delete;
616   V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT v8::MaybeLocal<v8::Value> Get(
617       v8::Isolate* isolate, v8::Local<v8::Value> key);
618   V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT v8::Local<EphemeronTable> Set(
619       v8::Isolate* isolate, v8::Local<v8::Value> key,
620       v8::Local<v8::Value> value);
621 
622   V8_EXPORT_PRIVATE static Local<EphemeronTable> New(v8::Isolate* isolate);
623   V8_INLINE static EphemeronTable* Cast(Value* obj);
624 };
625 
626 /**
627  * Pairs of accessors.
628  *
629  * In the case of private accessors, getters and setters are either null or
630  * Functions.
631  */
632 class V8_EXPORT_PRIVATE AccessorPair : public v8::Value {
633  public:
634   AccessorPair() = delete;
635   v8::Local<v8::Value> getter();
636   v8::Local<v8::Value> setter();
637 
638   static bool IsAccessorPair(v8::Local<v8::Value> obj);
639   V8_INLINE static AccessorPair* Cast(v8::Value* obj);
640 
641  private:
642   static void CheckCast(v8::Value* obj);
643 };
644 
645 struct PropertyDescriptor {
646   bool enumerable : 1;
647   bool has_enumerable : 1;
648   bool configurable : 1;
649   bool has_configurable : 1;
650   bool writable : 1;
651   bool has_writable : 1;
652   v8::Local<v8::Value> value;
653   v8::Local<v8::Value> get;
654   v8::Local<v8::Value> set;
655 };
656 
657 class V8_EXPORT_PRIVATE PropertyIterator {
658  public:
659   // Creating a PropertyIterator can potentially throw an exception.
660   // The returned std::unique_ptr is empty iff that happens.
661   V8_WARN_UNUSED_RESULT static std::unique_ptr<PropertyIterator> Create(
662       v8::Local<v8::Context> context, v8::Local<v8::Object> object,
663       bool skip_indices = false);
664 
665   virtual ~PropertyIterator() = default;
666 
667   virtual bool Done() const = 0;
668   // Returns |Nothing| should |Advance| throw an exception,
669   // |true| otherwise.
670   V8_WARN_UNUSED_RESULT virtual Maybe<bool> Advance() = 0;
671 
672   virtual v8::Local<v8::Name> name() const = 0;
673 
674   virtual bool is_native_accessor() = 0;
675   virtual bool has_native_getter() = 0;
676   virtual bool has_native_setter() = 0;
677   virtual Maybe<PropertyAttribute> attributes() = 0;
678   virtual Maybe<PropertyDescriptor> descriptor() = 0;
679 
680   virtual bool is_own() = 0;
681   virtual bool is_array_index() = 0;
682 };
683 
684 #if V8_ENABLE_WEBASSEMBLY
685 class V8_EXPORT_PRIVATE WasmValueObject : public v8::Object {
686  public:
687   WasmValueObject() = delete;
688   static bool IsWasmValueObject(v8::Local<v8::Value> obj);
Cast(v8::Value * value)689   static WasmValueObject* Cast(v8::Value* value) {
690 #ifdef V8_ENABLE_CHECKS
691     CheckCast(value);
692 #endif
693     return static_cast<WasmValueObject*>(value);
694   }
695 
696   v8::Local<v8::String> type() const;
697 
698  private:
699   static void CheckCast(v8::Value* obj);
700 };
701 #endif  // V8_ENABLE_WEBASSEMBLY
702 
Cast(v8::Value * value)703 AccessorPair* AccessorPair::Cast(v8::Value* value) {
704 #ifdef V8_ENABLE_CHECKS
705   CheckCast(value);
706 #endif
707   return static_cast<AccessorPair*>(value);
708 }
709 
710 MaybeLocal<Message> GetMessageFromPromise(Local<Promise> promise);
711 
712 bool isExperimentalAsyncStackTaggingApiEnabled();
713 
714 }  // namespace debug
715 }  // namespace v8
716 
717 #endif  // V8_DEBUG_DEBUG_INTERFACE_H_
718