tor-browser

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

WebIDLGlobalNameHash.h (3370B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_WebIDLGlobalNameHash_h__
      8 #define mozilla_dom_WebIDLGlobalNameHash_h__
      9 
     10 #include "js/RootingAPI.h"
     11 #include "mozilla/dom/BindingDeclarations.h"
     12 #include "nsTArray.h"
     13 
     14 class JSLinearString;
     15 
     16 namespace mozilla::dom {
     17 
     18 enum class BindingNamesOffset : uint16_t;
     19 
     20 namespace constructors::id {
     21 enum ID : uint16_t;
     22 }  // namespace constructors::id
     23 
     24 struct WebIDLNameTableEntry {
     25  // Check whether a constructor should be enabled for the given object.
     26  // Note that the object should NOT be an Xray, since Xrays will end up
     27  // defining constructors on the underlying object.
     28  using ConstructorEnabled = bool (*)(JSContext* cx, JS::Handle<JSObject*> obj);
     29 
     30  BindingNamesOffset mNameOffset;
     31  uint16_t mNameLength;
     32  constructors::id::ID mConstructorId;
     33  CreateInterfaceObjectsMethod mCreate;
     34  // May be null if enabled unconditionally
     35  ConstructorEnabled mEnabled;
     36 };
     37 
     38 class WebIDLGlobalNameHash {
     39 public:
     40  using ConstructorEnabled = WebIDLNameTableEntry::ConstructorEnabled;
     41 
     42  // Returns false if something failed. aFound is set to true if the name is in
     43  // the hash, whether it's enabled or not.
     44  static bool DefineIfEnabled(
     45      JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId,
     46      JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> aDesc,
     47      bool* aFound);
     48 
     49  static bool MayResolve(jsid aId);
     50 
     51  // The type of names we're asking for.
     52  enum NameType {
     53    // All WebIDL names enabled for aObj.
     54    AllNames,
     55    // Only the names that are enabled for aObj and have not been resolved for
     56    // aObj in the past (and therefore can't have been deleted).
     57    UnresolvedNamesOnly
     58  };
     59  // Returns false if an exception has been thrown on aCx.
     60  static bool GetNames(JSContext* aCx, JS::Handle<JSObject*> aObj,
     61                       NameType aNameType,
     62                       JS::MutableHandleVector<jsid> aNames);
     63 
     64  // Helpers for resolving & enumerating names on the system global.
     65  // NOTE: These are distinct as it currently lacks a ProtoAndIfaceCache, and is
     66  // an XPCOM global.
     67  static bool ResolveForSystemGlobal(JSContext* aCx, JS::Handle<JSObject*> aObj,
     68                                     JS::Handle<jsid> aId, bool* aResolvedp);
     69 
     70  static bool NewEnumerateSystemGlobal(
     71      JSContext* aCx, JS::Handle<JSObject*> aObj,
     72      JS::MutableHandleVector<jsid> aProperties, bool aEnumerableOnly);
     73 
     74 private:
     75  friend struct WebIDLNameTableEntry;
     76 
     77  // Look up an entry by key name. `nullptr` if the entry was not found.
     78  // The impl of GetEntry is generated by Codegen.py in RegisterBindings.cpp
     79  static const WebIDLNameTableEntry* GetEntry(JSLinearString* aKey);
     80 
     81  // The total number of names in the hash.
     82  // The value of sCount is generated by Codegen.py in RegisterBindings.cpp.
     83  static const uint32_t sCount;
     84 
     85  // The name table entries in the hash.
     86  // The value of sEntries is generated by Codegen.py in RegisterBindings.cpp.
     87  static const WebIDLNameTableEntry sEntries[];
     88 };
     89 
     90 }  // namespace mozilla::dom
     91 
     92 #endif  // mozilla_dom_WebIDLGlobalNameHash_h__