tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Environment.h (3438B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef debugger_Environment_h
      8 #define debugger_Environment_h
      9 
     10 #include "mozilla/Assertions.h"  // for AssertionConditionType, MOZ_ASSERT
     11 #include "mozilla/Maybe.h"       // for Maybe
     12 
     13 #include "jstypes.h"            // for JS_PUBLIC_API
     14 #include "NamespaceImports.h"   // for Value, HandleId, HandleObject
     15 #include "debugger/Debugger.h"  // for Env
     16 #include "js/PropertySpec.h"    // for JSFunctionSpec, JSPropertySpec
     17 #include "js/RootingAPI.h"      // for Handle, MutableHandle
     18 #include "vm/NativeObject.h"    // for NativeObject
     19 #include "vm/Scope.h"           // for ScopeKind
     20 
     21 class JS_PUBLIC_API JSObject;
     22 struct JS_PUBLIC_API JSContext;
     23 class JSTracer;
     24 
     25 namespace js {
     26 
     27 class GlobalObject;
     28 
     29 enum class DebuggerEnvironmentType { Declarative, With, Object };
     30 
     31 class DebuggerEnvironment : public NativeObject {
     32 public:
     33  enum { ENV_SLOT, OWNER_SLOT, RESERVED_SLOTS };
     34 
     35  static const JSClass class_;
     36 
     37  static NativeObject* initClass(JSContext* cx, Handle<GlobalObject*> global,
     38                                 HandleObject dbgCtor);
     39  static DebuggerEnvironment* create(JSContext* cx, HandleObject proto,
     40                                     HandleObject referent,
     41                                     Handle<NativeObject*> debugger);
     42 
     43  void trace(JSTracer* trc);
     44 
     45  DebuggerEnvironmentType type() const;
     46  mozilla::Maybe<ScopeKind> scopeKind() const;
     47  [[nodiscard]] bool getParent(
     48      JSContext* cx, MutableHandle<DebuggerEnvironment*> result) const;
     49  [[nodiscard]] bool getObject(JSContext* cx,
     50                               MutableHandle<DebuggerObject*> result) const;
     51  [[nodiscard]] bool getCalleeScript(
     52      JSContext* cx, MutableHandle<DebuggerScript*> result) const;
     53  bool isDebuggee() const;
     54  bool isOptimized() const;
     55 
     56  [[nodiscard]] static bool getNames(JSContext* cx,
     57                                     Handle<DebuggerEnvironment*> environment,
     58                                     MutableHandleIdVector result);
     59  [[nodiscard]] static bool find(JSContext* cx,
     60                                 Handle<DebuggerEnvironment*> environment,
     61                                 HandleId id,
     62                                 MutableHandle<DebuggerEnvironment*> result);
     63  [[nodiscard]] static bool getVariable(
     64      JSContext* cx, Handle<DebuggerEnvironment*> environment, HandleId id,
     65      MutableHandleValue result);
     66  [[nodiscard]] static bool setVariable(
     67      JSContext* cx, Handle<DebuggerEnvironment*> environment, HandleId id,
     68      HandleValue value);
     69 
     70  Debugger* owner() const;
     71 
     72  Env* maybeReferent() const { return maybePtrFromReservedSlot<Env>(ENV_SLOT); }
     73 
     74  Env* referent() const {
     75    Env* env = maybeReferent();
     76    MOZ_ASSERT(env);
     77    return env;
     78  }
     79 
     80  void clearReferent() { clearReservedSlotGCThingAsPrivate(ENV_SLOT); }
     81 
     82 private:
     83  static const JSClassOps classOps_;
     84 
     85  static const JSPropertySpec properties_[];
     86  static const JSFunctionSpec methods_[];
     87 
     88  bool requireDebuggee(JSContext* cx) const;
     89 
     90  [[nodiscard]] static bool construct(JSContext* cx, unsigned argc, Value* vp);
     91 
     92  struct CallData;
     93 };
     94 
     95 } /* namespace js */
     96 
     97 #endif /* debugger_Environment_h */