summaryrefslogtreecommitdiffstats
path: root/js/public/ProtoKey.h
blob: 398e1f03f19489eef1a5cf32e31c8220f9655e33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef js_ProtoKey_h
#define js_ProtoKey_h

/* A higher-order macro for enumerating all JSProtoKey values. */
/*
 * Consumers define macros as follows:
 * MACRO(name, clasp)
 *   name:    The canonical name of the class.
 *   clasp:   The JSClass for this object, or "dummy" if it doesn't exist.
 *
 *
 * Consumers wishing to iterate over all the JSProtoKey values, can use
 * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't
 * correspond to real constructors, like Null or constructors that are disabled
 * via preprocessor directives. We still need to include these in the JSProtoKey
 * list in order to maintain binary XDR compatibility, but we need to provide a
 * tool to handle them differently. JS_FOR_PROTOTYPES fills this niche.
 *
 * Consumers pass two macros to JS_FOR_PROTOTYPES - |REAL| and |IMAGINARY|. The
 * former is invoked for entries that have real client-exposed constructors, and
 * the latter is called for the rest. Consumers that don't care about this
 * distinction can simply pass the same macro to both, which is exactly what
 * JS_FOR_EACH_PROTOTYPE does.
 */

#define CLASP(NAME) (&NAME##Class)
#define OCLASP(NAME) (&NAME##Object::class_)
#define TYPED_ARRAY_CLASP(TYPE) (&TypedArrayObject::classes[JS::Scalar::TYPE])
#define ERROR_CLASP(TYPE) (&ErrorObject::classes[TYPE])

#ifdef JS_HAS_INTL_API
#  define IF_INTL(REAL, IMAGINARY) REAL
#else
#  define IF_INTL(REAL, IMAGINARY) IMAGINARY
#endif

#ifdef ENABLE_WASM_TYPE_REFLECTIONS
#  define IF_WASM_TYPE(REAL, IMAGINARY) REAL
#else
#  define IF_WASM_TYPE(REAL, IMAGINARY) IMAGINARY
#endif

#define JS_FOR_PROTOTYPES_(REAL, IMAGINARY, REAL_IF_INTL, REAL_IF_WASM_TYPE) \
  IMAGINARY(Null, dummy)                                                     \
  REAL(Object, OCLASP(Plain))                                                \
  REAL(Function, &FunctionClass)                                             \
  IMAGINARY(BoundFunction, OCLASP(BoundFunction))                            \
  REAL(Array, OCLASP(Array))                                                 \
  REAL(Boolean, OCLASP(Boolean))                                             \
  REAL(JSON, CLASP(JSON))                                                    \
  REAL(Date, OCLASP(Date))                                                   \
  REAL(Math, CLASP(Math))                                                    \
  REAL(Number, OCLASP(Number))                                               \
  REAL(String, OCLASP(String))                                               \
  REAL(RegExp, OCLASP(RegExp))                                               \
  REAL(Error, ERROR_CLASP(JSEXN_ERR))                                        \
  REAL(InternalError, ERROR_CLASP(JSEXN_INTERNALERR))                        \
  REAL(AggregateError, ERROR_CLASP(JSEXN_AGGREGATEERR))                      \
  REAL(EvalError, ERROR_CLASP(JSEXN_EVALERR))                                \
  REAL(RangeError, ERROR_CLASP(JSEXN_RANGEERR))                              \
  REAL(ReferenceError, ERROR_CLASP(JSEXN_REFERENCEERR))                      \
  REAL(SyntaxError, ERROR_CLASP(JSEXN_SYNTAXERR))                            \
  REAL(TypeError, ERROR_CLASP(JSEXN_TYPEERR))                                \
  REAL(URIError, ERROR_CLASP(JSEXN_URIERR))                                  \
  REAL(DebuggeeWouldRun, ERROR_CLASP(JSEXN_DEBUGGEEWOULDRUN))                \
  REAL(CompileError, ERROR_CLASP(JSEXN_WASMCOMPILEERROR))                    \
  REAL(LinkError, ERROR_CLASP(JSEXN_WASMLINKERROR))                          \
  REAL(RuntimeError, ERROR_CLASP(JSEXN_WASMRUNTIMEERROR))                    \
  REAL(ArrayBuffer, OCLASP(ArrayBuffer))                                     \
  REAL(Int8Array, TYPED_ARRAY_CLASP(Int8))                                   \
  REAL(Uint8Array, TYPED_ARRAY_CLASP(Uint8))                                 \
  REAL(Int16Array, TYPED_ARRAY_CLASP(Int16))                                 \
  REAL(Uint16Array, TYPED_ARRAY_CLASP(Uint16))                               \
  REAL(Int32Array, TYPED_ARRAY_CLASP(Int32))                                 \
  REAL(Uint32Array, TYPED_ARRAY_CLASP(Uint32))                               \
  REAL(Float32Array, TYPED_ARRAY_CLASP(Float32))                             \
  REAL(Float64Array, TYPED_ARRAY_CLASP(Float64))                             \
  REAL(Uint8ClampedArray, TYPED_ARRAY_CLASP(Uint8Clamped))                   \
  REAL(BigInt64Array, TYPED_ARRAY_CLASP(BigInt64))                           \
  REAL(BigUint64Array, TYPED_ARRAY_CLASP(BigUint64))                         \
  REAL(BigInt, OCLASP(BigInt))                                               \
  REAL(Proxy, CLASP(Proxy))                                                  \
  REAL(WeakMap, OCLASP(WeakMap))                                             \
  REAL(Map, OCLASP(Map))                                                     \
  REAL(Set, OCLASP(Set))                                                     \
  REAL(DataView, OCLASP(DataView))                                           \
  REAL(Symbol, OCLASP(Symbol))                                               \
  REAL(ShadowRealm, OCLASP(ShadowRealm))                                     \
  REAL(SharedArrayBuffer, OCLASP(SharedArrayBuffer))                         \
  REAL_IF_INTL(Intl, CLASP(Intl))                                            \
  REAL_IF_INTL(Collator, OCLASP(Collator))                                   \
  REAL_IF_INTL(DateTimeFormat, OCLASP(DateTimeFormat))                       \
  REAL_IF_INTL(DisplayNames, OCLASP(DisplayNames))                           \
  REAL_IF_INTL(ListFormat, OCLASP(ListFormat))                               \
  REAL_IF_INTL(Locale, OCLASP(Locale))                                       \
  REAL_IF_INTL(NumberFormat, OCLASP(NumberFormat))                           \
  REAL_IF_INTL(PluralRules, OCLASP(PluralRules))                             \
  REAL_IF_INTL(RelativeTimeFormat, OCLASP(RelativeTimeFormat))               \
  REAL(Reflect, CLASP(Reflect))                                              \
  REAL(WeakSet, OCLASP(WeakSet))                                             \
  REAL(TypedArray, &js::TypedArrayObject::sharedTypedArrayPrototypeClass)    \
  REAL(Atomics, OCLASP(Atomics))                                             \
  REAL(SavedFrame, &js::SavedFrame::class_)                                  \
  REAL(Promise, OCLASP(Promise))                                             \
  REAL(AsyncFunction, CLASP(AsyncFunction))                                  \
  REAL(GeneratorFunction, CLASP(GeneratorFunction))                          \
  REAL(AsyncGeneratorFunction, CLASP(AsyncGeneratorFunction))                \
  REAL(WebAssembly, OCLASP(WasmNamespace))                                   \
  REAL(WasmModule, OCLASP(WasmModule))                                       \
  REAL(WasmInstance, OCLASP(WasmInstance))                                   \
  REAL(WasmMemory, OCLASP(WasmMemory))                                       \
  REAL(WasmTable, OCLASP(WasmTable))                                         \
  REAL(WasmGlobal, OCLASP(WasmGlobal))                                       \
  REAL(WasmTag, OCLASP(WasmTag))                                             \
  REAL_IF_WASM_TYPE(WasmFunction, CLASP(WasmFunction))                       \
  REAL(WasmException, OCLASP(WasmException))                                 \
  REAL(FinalizationRegistry, OCLASP(FinalizationRegistry))                   \
  REAL(WeakRef, OCLASP(WeakRef))                                             \
  REAL(Iterator, OCLASP(Iterator))                                           \
  REAL(AsyncIterator, OCLASP(AsyncIterator))                                 \
  IF_RECORD_TUPLE(REAL(Record, (&RecordType::class_)))                       \
  IF_RECORD_TUPLE(REAL(Tuple, (&TupleType::class_)))

#define JS_FOR_PROTOTYPES(REAL, IMAGINARY)                      \
  JS_FOR_PROTOTYPES_(REAL, IMAGINARY, IF_INTL(REAL, IMAGINARY), \
                     IF_WASM_TYPE(REAL, IMAGINARY))

#define JS_FOR_EACH_PROTOTYPE(MACRO) JS_FOR_PROTOTYPES(MACRO, MACRO)

#endif /* js_ProtoKey_h */