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 js_ProtoKey_h
8 #define js_ProtoKey_h
9 
10 /* A higher-order macro for enumerating all JSProtoKey values. */
11 /*
12  * Consumers define macros as follows:
13  * MACRO(name, clasp)
14  *   name:    The canonical name of the class.
15  *   clasp:   The JSClass for this object, or "dummy" if it doesn't exist.
16  *
17  *
18  * Consumers wishing to iterate over all the JSProtoKey values, can use
19  * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't
20  * correspond to real constructors, like Null or constructors that are disabled
21  * via preprocessor directives. We still need to include these in the JSProtoKey
22  * list in order to maintain binary XDR compatibility, but we need to provide a
23  * tool to handle them differently. JS_FOR_PROTOTYPES fills this niche.
24  *
25  * Consumers pass two macros to JS_FOR_PROTOTYPES - |REAL| and |IMAGINARY|. The
26  * former is invoked for entries that have real client-exposed constructors, and
27  * the latter is called for the rest. Consumers that don't care about this
28  * distinction can simply pass the same macro to both, which is exactly what
29  * JS_FOR_EACH_PROTOTYPE does.
30  */
31 
32 #define CLASP(NAME) (&NAME##Class)
33 #define OCLASP(NAME) (&NAME##Object::class_)
34 #define TYPED_ARRAY_CLASP(TYPE) (&TypedArrayObject::classes[Scalar::TYPE])
35 #define ERROR_CLASP(TYPE) (&ErrorObject::classes[TYPE])
36 
37 #ifdef JS_HAS_INTL_API
38 #  define IF_INTL(REAL, IMAGINARY) REAL
39 #else
40 #  define IF_INTL(REAL, IMAGINARY) IMAGINARY
41 #endif
42 
43 #ifdef JS_HAS_TYPED_OBJECTS
44 #  define IF_TYPEDOBJ(REAL, IMAGINARY) REAL
45 #else
46 #  define IF_TYPEDOBJ(REAL, IMAGINARY) IMAGINARY
47 #endif
48 
49 #define JS_FOR_PROTOTYPES_(REAL, IMAGINARY, REAL_IF_INTL, REAL_IF_BDATA)      \
50   IMAGINARY(Null, dummy)                                                      \
51   REAL(Object, OCLASP(Plain))                                                 \
52   REAL(Function, &JSFunction::class_)                                         \
53   REAL(Array, OCLASP(Array))                                                  \
54   REAL(Boolean, OCLASP(Boolean))                                              \
55   REAL(JSON, CLASP(JSON))                                                     \
56   REAL(Date, OCLASP(Date))                                                    \
57   REAL(Math, CLASP(Math))                                                     \
58   REAL(Number, OCLASP(Number))                                                \
59   REAL(String, OCLASP(String))                                                \
60   REAL(RegExp, OCLASP(RegExp))                                                \
61   REAL(Error, ERROR_CLASP(JSEXN_ERR))                                         \
62   REAL(InternalError, ERROR_CLASP(JSEXN_INTERNALERR))                         \
63   REAL(AggregateError, ERROR_CLASP(JSEXN_AGGREGATEERR))                       \
64   REAL(EvalError, ERROR_CLASP(JSEXN_EVALERR))                                 \
65   REAL(RangeError, ERROR_CLASP(JSEXN_RANGEERR))                               \
66   REAL(ReferenceError, ERROR_CLASP(JSEXN_REFERENCEERR))                       \
67   REAL(SyntaxError, ERROR_CLASP(JSEXN_SYNTAXERR))                             \
68   REAL(TypeError, ERROR_CLASP(JSEXN_TYPEERR))                                 \
69   REAL(URIError, ERROR_CLASP(JSEXN_URIERR))                                   \
70   REAL(DebuggeeWouldRun, ERROR_CLASP(JSEXN_DEBUGGEEWOULDRUN))                 \
71   REAL(CompileError, ERROR_CLASP(JSEXN_WASMCOMPILEERROR))                     \
72   REAL(LinkError, ERROR_CLASP(JSEXN_WASMLINKERROR))                           \
73   REAL(RuntimeError, ERROR_CLASP(JSEXN_WASMRUNTIMEERROR))                     \
74   REAL(ArrayBuffer, OCLASP(ArrayBuffer))                                      \
75   REAL(Int8Array, TYPED_ARRAY_CLASP(Int8))                                    \
76   REAL(Uint8Array, TYPED_ARRAY_CLASP(Uint8))                                  \
77   REAL(Int16Array, TYPED_ARRAY_CLASP(Int16))                                  \
78   REAL(Uint16Array, TYPED_ARRAY_CLASP(Uint16))                                \
79   REAL(Int32Array, TYPED_ARRAY_CLASP(Int32))                                  \
80   REAL(Uint32Array, TYPED_ARRAY_CLASP(Uint32))                                \
81   REAL(Float32Array, TYPED_ARRAY_CLASP(Float32))                              \
82   REAL(Float64Array, TYPED_ARRAY_CLASP(Float64))                              \
83   REAL(Uint8ClampedArray, TYPED_ARRAY_CLASP(Uint8Clamped))                    \
84   REAL(BigInt64Array, TYPED_ARRAY_CLASP(BigInt64))                            \
85   REAL(BigUint64Array, TYPED_ARRAY_CLASP(BigUint64))                          \
86   REAL(BigInt, OCLASP(BigInt))                                                \
87   REAL(Proxy, CLASP(Proxy))                                                   \
88   REAL(WeakMap, OCLASP(WeakMap))                                              \
89   REAL(Map, OCLASP(Map))                                                      \
90   REAL(Set, OCLASP(Set))                                                      \
91   REAL(DataView, OCLASP(DataView))                                            \
92   REAL(Symbol, OCLASP(Symbol))                                                \
93   REAL(SharedArrayBuffer, OCLASP(SharedArrayBuffer))                          \
94   REAL_IF_INTL(Intl, CLASP(Intl))                                             \
95   REAL_IF_INTL(Collator, OCLASP(Collator))                                    \
96   REAL_IF_INTL(DateTimeFormat, OCLASP(DateTimeFormat))                        \
97   REAL_IF_INTL(DisplayNames, OCLASP(DisplayNames))                            \
98   REAL_IF_INTL(ListFormat, OCLASP(ListFormat))                                \
99   REAL_IF_INTL(Locale, OCLASP(Locale))                                        \
100   REAL_IF_INTL(NumberFormat, OCLASP(NumberFormat))                            \
101   REAL_IF_INTL(PluralRules, OCLASP(PluralRules))                              \
102   REAL_IF_INTL(RelativeTimeFormat, OCLASP(RelativeTimeFormat))                \
103   REAL_IF_BDATA(TypedObject, OCLASP(TypedObjectModule))                       \
104   REAL(Reflect, CLASP(Reflect))                                               \
105   REAL(WeakSet, OCLASP(WeakSet))                                              \
106   REAL(TypedArray, &js::TypedArrayObject::sharedTypedArrayPrototypeClass)     \
107   REAL(Atomics, OCLASP(Atomics))                                              \
108   REAL(SavedFrame, &js::SavedFrame::class_)                                   \
109   REAL(Promise, OCLASP(Promise))                                              \
110   REAL(AsyncFunction, CLASP(AsyncFunction))                                   \
111   REAL(GeneratorFunction, CLASP(GeneratorFunction))                           \
112   REAL(AsyncGeneratorFunction, CLASP(AsyncGeneratorFunction))                 \
113   REAL(ReadableStream, &js::ReadableStream::class_)                           \
114   REAL(ReadableStreamDefaultReader, &js::ReadableStreamDefaultReader::class_) \
115   REAL(ReadableStreamDefaultController,                                       \
116        &js::ReadableStreamDefaultController::class_)                          \
117   REAL(ReadableByteStreamController,                                          \
118        &js::ReadableByteStreamController::class_)                             \
119   REAL(WritableStream, &js::WritableStream::class_)                           \
120   REAL(WritableStreamDefaultController,                                       \
121        &js::WritableStreamDefaultController::class_)                          \
122   REAL(WritableStreamDefaultWriter, &js::WritableStreamDefaultWriter::class_) \
123   REAL(ByteLengthQueuingStrategy, &js::ByteLengthQueuingStrategy::class_)     \
124   REAL(CountQueuingStrategy, &js::CountQueuingStrategy::class_)               \
125   REAL(WebAssembly, CLASP(WebAssembly))                                       \
126   REAL(WasmModule, OCLASP(WasmModule))                                        \
127   REAL(WasmInstance, OCLASP(WasmInstance))                                    \
128   REAL(WasmMemory, OCLASP(WasmMemory))                                        \
129   REAL(WasmTable, OCLASP(WasmTable))                                          \
130   REAL(WasmGlobal, OCLASP(WasmGlobal))                                        \
131   REAL(FinalizationRegistry, OCLASP(FinalizationRegistry))                    \
132   REAL(WeakRef, OCLASP(WeakRef))
133 
134 #define JS_FOR_PROTOTYPES(REAL, IMAGINARY)                      \
135   JS_FOR_PROTOTYPES_(REAL, IMAGINARY, IF_INTL(REAL, IMAGINARY), \
136                      IF_TYPEDOBJ(REAL, IMAGINARY))
137 
138 #define JS_FOR_EACH_PROTOTYPE(MACRO) JS_FOR_PROTOTYPES(MACRO, MACRO)
139 
140 #endif /* js_ProtoKey_h */
141