Bug 1863873 - Block ability to perform audio decoding outside of Utility on release...
[gecko.git] / dom / bindings / WebIDLGlobalNameHash.h
blobbbe047d4d38702a04d2ab341574c6417fb8c29ae
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/. */
7 #ifndef mozilla_dom_WebIDLGlobalNameHash_h__
8 #define mozilla_dom_WebIDLGlobalNameHash_h__
10 #include "js/RootingAPI.h"
11 #include "nsTArray.h"
12 #include "mozilla/dom/BindingDeclarations.h"
14 class JSLinearString;
16 namespace mozilla::dom {
18 enum class BindingNamesOffset : uint16_t;
20 namespace constructors::id {
21 enum ID : uint16_t;
22 } // namespace constructors::id
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);
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;
38 class WebIDLGlobalNameHash {
39 public:
40 using ConstructorEnabled = WebIDLNameTableEntry::ConstructorEnabled;
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);
49 static bool MayResolve(jsid aId);
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
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);
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);
70 static bool NewEnumerateSystemGlobal(
71 JSContext* aCx, JS::Handle<JSObject*> aObj,
72 JS::MutableHandleVector<jsid> aProperties, bool aEnumerableOnly);
74 private:
75 friend struct WebIDLNameTableEntry;
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);
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;
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[];
90 } // namespace mozilla::dom
92 #endif // mozilla_dom_WebIDLGlobalNameHash_h__