tor-browser

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

Object.h (10549B)


      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_Object_h
      8 #define debugger_Object_h
      9 
     10 #include "mozilla/Assertions.h"  // for AssertionConditionType, MOZ_ASSERT
     11 #include "mozilla/Maybe.h"       // for Maybe
     12 #include "mozilla/Range.h"       // for Range
     13 #include "mozilla/Result.h"      // for Result
     14 
     15 #include "jstypes.h"           // for JS_PUBLIC_API
     16 #include "NamespaceImports.h"  // for Value, MutableHandleValue, HandleId
     17 
     18 #include "js/Promise.h"       // for PromiseState
     19 #include "js/Proxy.h"         // for PropertyDescriptor
     20 #include "vm/JSObject.h"      // for JSObject (ptr only)
     21 #include "vm/NativeObject.h"  // for NativeObject
     22 
     23 class JS_PUBLIC_API JSAtom;
     24 struct JS_PUBLIC_API JSContext;
     25 
     26 namespace js {
     27 
     28 class Completion;
     29 class Debugger;
     30 class EvalOptions;
     31 class GlobalObject;
     32 class PromiseObject;
     33 
     34 class DebuggerObject : public NativeObject {
     35 public:
     36  static const JSClass class_;
     37 
     38  static NativeObject* initClass(JSContext* cx, Handle<GlobalObject*> global,
     39                                 HandleObject debugCtor);
     40  static DebuggerObject* create(JSContext* cx, HandleObject proto,
     41                                HandleObject referent,
     42                                Handle<NativeObject*> debugger);
     43 
     44  void trace(JSTracer* trc);
     45 
     46  // Properties
     47  [[nodiscard]] static bool getClassName(JSContext* cx,
     48                                         Handle<DebuggerObject*> object,
     49                                         MutableHandleString result);
     50  [[nodiscard]] static bool getBoundTargetFunction(
     51      JSContext* cx, Handle<DebuggerObject*> object,
     52      MutableHandle<DebuggerObject*> result);
     53  [[nodiscard]] static bool getBoundThis(JSContext* cx,
     54                                         Handle<DebuggerObject*> object,
     55                                         MutableHandleValue result);
     56  [[nodiscard]] static bool getBoundArguments(
     57      JSContext* cx, Handle<DebuggerObject*> object,
     58      MutableHandle<ValueVector> result);
     59  [[nodiscard]] static bool getAllocationSite(JSContext* cx,
     60                                              Handle<DebuggerObject*> object,
     61                                              MutableHandleObject result);
     62  [[nodiscard]] static bool getErrorMessageName(JSContext* cx,
     63                                                Handle<DebuggerObject*> object,
     64                                                MutableHandleString result);
     65  [[nodiscard]] static bool getErrorNotes(JSContext* cx,
     66                                          Handle<DebuggerObject*> object,
     67                                          MutableHandleValue result);
     68  [[nodiscard]] static bool getErrorLineNumber(JSContext* cx,
     69                                               Handle<DebuggerObject*> object,
     70                                               MutableHandleValue result);
     71  [[nodiscard]] static bool getErrorColumnNumber(JSContext* cx,
     72                                                 Handle<DebuggerObject*> object,
     73                                                 MutableHandleValue result);
     74  [[nodiscard]] static bool getScriptedProxyTarget(
     75      JSContext* cx, Handle<DebuggerObject*> object,
     76      MutableHandle<DebuggerObject*> result);
     77  [[nodiscard]] static bool getScriptedProxyHandler(
     78      JSContext* cx, Handle<DebuggerObject*> object,
     79      MutableHandle<DebuggerObject*> result);
     80  [[nodiscard]] static bool getPromiseValue(JSContext* cx,
     81                                            Handle<DebuggerObject*> object,
     82                                            MutableHandleValue result);
     83  [[nodiscard]] static bool getPromiseReason(JSContext* cx,
     84                                             Handle<DebuggerObject*> object,
     85                                             MutableHandleValue result);
     86 
     87  // Methods
     88  [[nodiscard]] static bool isExtensible(JSContext* cx,
     89                                         Handle<DebuggerObject*> object,
     90                                         bool& result);
     91  [[nodiscard]] static bool isSealed(JSContext* cx,
     92                                     Handle<DebuggerObject*> object,
     93                                     bool& result);
     94  [[nodiscard]] static bool isFrozen(JSContext* cx,
     95                                     Handle<DebuggerObject*> object,
     96                                     bool& result);
     97  [[nodiscard]] static JS::Result<Completion> getProperty(
     98      JSContext* cx, Handle<DebuggerObject*> object, HandleId id,
     99      HandleValue receiver);
    100  [[nodiscard]] static JS::Result<Completion> setProperty(
    101      JSContext* cx, Handle<DebuggerObject*> object, HandleId id,
    102      HandleValue value, HandleValue receiver);
    103  [[nodiscard]] static bool getPrototypeOf(
    104      JSContext* cx, Handle<DebuggerObject*> object,
    105      MutableHandle<DebuggerObject*> result);
    106  [[nodiscard]] static bool getOwnPropertyNames(JSContext* cx,
    107                                                Handle<DebuggerObject*> object,
    108                                                MutableHandleIdVector result);
    109  [[nodiscard]] static bool getOwnPropertyNamesLength(
    110      JSContext* cx, Handle<DebuggerObject*> object, size_t* result);
    111  [[nodiscard]] static bool getOwnPropertySymbols(
    112      JSContext* cx, Handle<DebuggerObject*> object,
    113      MutableHandleIdVector result);
    114  [[nodiscard]] static bool getOwnPrivateProperties(
    115      JSContext* cx, Handle<DebuggerObject*> object,
    116      MutableHandleIdVector result);
    117  [[nodiscard]] static bool getOwnPropertyDescriptor(
    118      JSContext* cx, Handle<DebuggerObject*> object, HandleId id,
    119      MutableHandle<mozilla::Maybe<PropertyDescriptor>> desc);
    120  [[nodiscard]] static bool preventExtensions(JSContext* cx,
    121                                              Handle<DebuggerObject*> object);
    122  [[nodiscard]] static bool seal(JSContext* cx, Handle<DebuggerObject*> object);
    123  [[nodiscard]] static bool freeze(JSContext* cx,
    124                                   Handle<DebuggerObject*> object);
    125  [[nodiscard]] static bool defineProperty(JSContext* cx,
    126                                           Handle<DebuggerObject*> object,
    127                                           HandleId id,
    128                                           Handle<PropertyDescriptor> desc);
    129  [[nodiscard]] static bool defineProperties(
    130      JSContext* cx, Handle<DebuggerObject*> object, Handle<IdVector> ids,
    131      Handle<PropertyDescriptorVector> descs);
    132  [[nodiscard]] static bool deleteProperty(JSContext* cx,
    133                                           Handle<DebuggerObject*> object,
    134                                           HandleId id, ObjectOpResult& result);
    135  [[nodiscard]] static mozilla::Maybe<Completion> call(
    136      JSContext* cx, Handle<DebuggerObject*> object, HandleValue thisv,
    137      Handle<ValueVector> args);
    138  [[nodiscard]] static bool forceLexicalInitializationByName(
    139      JSContext* cx, Handle<DebuggerObject*> object, HandleId id, bool& result);
    140  [[nodiscard]] static JS::Result<Completion> executeInGlobal(
    141      JSContext* cx, Handle<DebuggerObject*> object,
    142      mozilla::Range<const char16_t> chars, HandleObject bindings,
    143      const EvalOptions& options);
    144  [[nodiscard]] static bool makeDebuggeeValue(JSContext* cx,
    145                                              Handle<DebuggerObject*> object,
    146                                              HandleValue value,
    147                                              MutableHandleValue result);
    148  enum class CheckJitInfo { No, Yes };
    149  [[nodiscard]] static bool isSameNative(JSContext* cx,
    150                                         Handle<DebuggerObject*> object,
    151                                         HandleValue value,
    152                                         CheckJitInfo checkJitInfo,
    153                                         MutableHandleValue result);
    154  [[nodiscard]] static bool isNativeGetterWithJitInfo(
    155      JSContext* cx, Handle<DebuggerObject*> object, MutableHandleValue result);
    156  [[nodiscard]] static bool unsafeDereference(JSContext* cx,
    157                                              Handle<DebuggerObject*> object,
    158                                              MutableHandleObject result);
    159  [[nodiscard]] static bool unwrap(JSContext* cx,
    160                                   Handle<DebuggerObject*> object,
    161                                   MutableHandle<DebuggerObject*> result);
    162 
    163  // Infallible properties
    164  bool isCallable() const;
    165  bool isFunction() const;
    166  bool isDebuggeeFunction() const;
    167  bool isBoundFunction() const;
    168  bool isDebuggeeBoundFunction() const;
    169  bool isArrowFunction() const;
    170  bool isAsyncFunction() const;
    171  bool isGeneratorFunction() const;
    172  bool isClassConstructor() const;
    173  bool isGlobal() const;
    174  bool isScriptedProxy() const;
    175  bool isPromise() const;
    176  bool isError() const;
    177  bool isMutedError(JSContext* cx) const;
    178 
    179  bool name(JSContext* cx, JS::MutableHandle<JSAtom*> result) const;
    180  bool displayName(JSContext* cx, JS::MutableHandle<JSAtom*> result) const;
    181 
    182  JS::PromiseState promiseState() const;
    183  double promiseLifetime() const;
    184  double promiseTimeToResolution() const;
    185 
    186  Debugger* owner() const;
    187 
    188  JSObject* maybeReferent() const {
    189    return maybePtrFromReservedSlot<JSObject>(OBJECT_SLOT);
    190  }
    191  JSObject* referent() const {
    192    JSObject* obj = maybeReferent();
    193    MOZ_ASSERT(obj);
    194    return obj;
    195  }
    196 
    197  void clearReferent() { clearReservedSlotGCThingAsPrivate(OBJECT_SLOT); }
    198 
    199 private:
    200  enum { OBJECT_SLOT, OWNER_SLOT, RESERVED_SLOTS };
    201 
    202  static const JSClassOps classOps_;
    203 
    204  static const JSPropertySpec properties_[];
    205  static const JSPropertySpec promiseProperties_[];
    206  static const JSFunctionSpec methods_[];
    207 
    208  PromiseObject* promise() const;
    209 
    210  [[nodiscard]] static bool requireGlobal(JSContext* cx,
    211                                          Handle<DebuggerObject*> object);
    212  [[nodiscard]] static bool requirePromise(JSContext* cx,
    213                                           Handle<DebuggerObject*> object);
    214  [[nodiscard]] static bool construct(JSContext* cx, unsigned argc, Value* vp);
    215 
    216  struct CallData;
    217  struct PromiseReactionRecordBuilder;
    218 
    219  [[nodiscard]] static bool getErrorReport(JSContext* cx,
    220                                           HandleObject maybeError,
    221                                           JSErrorReport*& report);
    222 };
    223 
    224 } /* namespace js */
    225 
    226 #endif /* debugger_Object_h */