tor-browser

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

ProtoKey.h (11025B)


      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) \
     35  (&TypedArrayObject::fixedLengthClasses[JS::Scalar::TYPE])
     36 #define ERROR_CLASP(TYPE) (&ErrorObject::classes[TYPE])
     37 
     38 #ifdef JS_HAS_INTL_API
     39 #  define IF_INTL(REAL, IMAGINARY) REAL
     40 #else
     41 #  define IF_INTL(REAL, IMAGINARY) IMAGINARY
     42 #endif
     43 
     44 #ifdef ENABLE_WASM_TYPE_REFLECTIONS
     45 #  define IF_WASM_TYPE(REAL, IMAGINARY) REAL
     46 #else
     47 #  define IF_WASM_TYPE(REAL, IMAGINARY) IMAGINARY
     48 #endif
     49 
     50 #ifdef ENABLE_WASM_JSPI
     51 #  define IF_WASM_JSPI(REAL, IMAGINARY) REAL
     52 #else
     53 #  define IF_WASM_JSPI(REAL, IMAGINARY) IMAGINARY
     54 #endif
     55 
     56 #ifdef NIGHTLY_BUILD
     57 #  define IF_NIGHTLY(REAL, IMAGINARY) REAL
     58 #else
     59 #  define IF_NIGHTLY(REAL, IMAGINARY) IMAGINARY
     60 #endif
     61 
     62 #define JS_FOR_PROTOTYPES_(REAL, IMAGINARY, REAL_IF_INTL, REAL_IF_WASM_TYPE, \
     63                           REAL_IF_WASM_JSPI, REAL_IF_NIGHTLY)               \
     64  IMAGINARY(Null, dummy)                                                     \
     65  REAL(Object, OCLASP(Plain))                                                \
     66  REAL(Function, &FunctionClass)                                             \
     67  IMAGINARY(BoundFunction, OCLASP(BoundFunction))                            \
     68  REAL(Array, OCLASP(Array))                                                 \
     69  REAL(Boolean, OCLASP(Boolean))                                             \
     70  REAL(JSON, CLASP(JSON))                                                    \
     71  REAL(Date, OCLASP(Date))                                                   \
     72  REAL(Math, CLASP(Math))                                                    \
     73  REAL(Number, OCLASP(Number))                                               \
     74  REAL(String, OCLASP(String))                                               \
     75  REAL(RegExp, OCLASP(RegExp))                                               \
     76  REAL(Error, ERROR_CLASP(JSEXN_ERR))                                        \
     77  REAL(InternalError, ERROR_CLASP(JSEXN_INTERNALERR))                        \
     78  REAL(AggregateError, ERROR_CLASP(JSEXN_AGGREGATEERR))                      \
     79  REAL(EvalError, ERROR_CLASP(JSEXN_EVALERR))                                \
     80  REAL(RangeError, ERROR_CLASP(JSEXN_RANGEERR))                              \
     81  REAL(ReferenceError, ERROR_CLASP(JSEXN_REFERENCEERR))                      \
     82  IF_EXPLICIT_RESOURCE_MANAGEMENT(                                           \
     83      REAL(SuppressedError, ERROR_CLASP(JSEXN_SUPPRESSEDERR)))               \
     84  REAL(SyntaxError, ERROR_CLASP(JSEXN_SYNTAXERR))                            \
     85  REAL(TypeError, ERROR_CLASP(JSEXN_TYPEERR))                                \
     86  REAL(URIError, ERROR_CLASP(JSEXN_URIERR))                                  \
     87  REAL(DebuggeeWouldRun, ERROR_CLASP(JSEXN_DEBUGGEEWOULDRUN))                \
     88  REAL(CompileError, ERROR_CLASP(JSEXN_WASMCOMPILEERROR))                    \
     89  REAL(LinkError, ERROR_CLASP(JSEXN_WASMLINKERROR))                          \
     90  REAL(RuntimeError, ERROR_CLASP(JSEXN_WASMRUNTIMEERROR))                    \
     91  REAL_IF_WASM_JSPI(SuspendError, ERROR_CLASP(JSEXN_WASMSUSPENDERROR))       \
     92  REAL(ArrayBuffer, OCLASP(FixedLengthArrayBuffer))                          \
     93  REAL(Int8Array, TYPED_ARRAY_CLASP(Int8))                                   \
     94  REAL(Uint8Array, TYPED_ARRAY_CLASP(Uint8))                                 \
     95  REAL(Int16Array, TYPED_ARRAY_CLASP(Int16))                                 \
     96  REAL(Uint16Array, TYPED_ARRAY_CLASP(Uint16))                               \
     97  REAL(Int32Array, TYPED_ARRAY_CLASP(Int32))                                 \
     98  REAL(Uint32Array, TYPED_ARRAY_CLASP(Uint32))                               \
     99  REAL(Float32Array, TYPED_ARRAY_CLASP(Float32))                             \
    100  REAL(Float64Array, TYPED_ARRAY_CLASP(Float64))                             \
    101  REAL(Uint8ClampedArray, TYPED_ARRAY_CLASP(Uint8Clamped))                   \
    102  REAL(BigInt64Array, TYPED_ARRAY_CLASP(BigInt64))                           \
    103  REAL(BigUint64Array, TYPED_ARRAY_CLASP(BigUint64))                         \
    104  REAL(Float16Array, TYPED_ARRAY_CLASP(Float16))                             \
    105  REAL(BigInt, OCLASP(BigInt))                                               \
    106  REAL(Proxy, CLASP(Proxy))                                                  \
    107  REAL(WeakMap, OCLASP(WeakMap))                                             \
    108  REAL(Map, OCLASP(Map))                                                     \
    109  REAL(Set, OCLASP(Set))                                                     \
    110  REAL(DataView, OCLASP(FixedLengthDataView))                                \
    111  REAL(Symbol, OCLASP(Symbol))                                               \
    112  REAL(ShadowRealm, OCLASP(ShadowRealm))                                     \
    113  REAL(SharedArrayBuffer, OCLASP(FixedLengthSharedArrayBuffer))              \
    114  REAL_IF_INTL(Intl, CLASP(Intl))                                            \
    115  REAL_IF_INTL(Collator, OCLASP(Collator))                                   \
    116  REAL_IF_INTL(DateTimeFormat, OCLASP(DateTimeFormat))                       \
    117  REAL_IF_INTL(DisplayNames, OCLASP(DisplayNames))                           \
    118  REAL_IF_INTL(DurationFormat, OCLASP(DurationFormat))                       \
    119  REAL_IF_INTL(ListFormat, OCLASP(ListFormat))                               \
    120  REAL_IF_INTL(Locale, OCLASP(Locale))                                       \
    121  REAL_IF_INTL(NumberFormat, OCLASP(NumberFormat))                           \
    122  REAL_IF_INTL(PluralRules, OCLASP(PluralRules))                             \
    123  REAL_IF_INTL(RelativeTimeFormat, OCLASP(RelativeTimeFormat))               \
    124  REAL_IF_INTL(Segmenter, OCLASP(Segmenter))                                 \
    125  REAL(Reflect, CLASP(Reflect))                                              \
    126  REAL(WeakSet, OCLASP(WeakSet))                                             \
    127  REAL(TypedArray, &js::TypedArrayObject::sharedTypedArrayPrototypeClass)    \
    128  REAL(Atomics, OCLASP(Atomics))                                             \
    129  REAL(SavedFrame, &js::SavedFrame::class_)                                  \
    130  REAL(Promise, OCLASP(Promise))                                             \
    131  REAL(AsyncFunction, CLASP(AsyncFunction))                                  \
    132  REAL(GeneratorFunction, CLASP(GeneratorFunction))                          \
    133  REAL(AsyncGeneratorFunction, CLASP(AsyncGeneratorFunction))                \
    134  REAL(WebAssembly, OCLASP(WasmNamespace))                                   \
    135  REAL(WasmModule, OCLASP(WasmModule))                                       \
    136  REAL(WasmInstance, OCLASP(WasmInstance))                                   \
    137  REAL(WasmMemory, OCLASP(WasmMemory))                                       \
    138  REAL(WasmTable, OCLASP(WasmTable))                                         \
    139  REAL(WasmGlobal, OCLASP(WasmGlobal))                                       \
    140  REAL(WasmTag, OCLASP(WasmTag))                                             \
    141  REAL_IF_WASM_TYPE(WasmFunction, CLASP(WasmFunction))                       \
    142  REAL_IF_WASM_JSPI(WasmSuspending, OCLASP(WasmSuspending))                  \
    143  REAL(WasmException, OCLASP(WasmException))                                 \
    144  REAL(FinalizationRegistry, OCLASP(FinalizationRegistry))                   \
    145  REAL(WeakRef, OCLASP(WeakRef))                                             \
    146  REAL(Iterator, OCLASP(Iterator))                                           \
    147  REAL(AsyncIterator, OCLASP(AsyncIterator))                                 \
    148  IF_EXPLICIT_RESOURCE_MANAGEMENT(                                           \
    149      REAL(DisposableStack, OCLASP(DisposableStack)))                        \
    150  IF_EXPLICIT_RESOURCE_MANAGEMENT(                                           \
    151      REAL(AsyncDisposableStack, OCLASP(AsyncDisposableStack)))              \
    152  REAL_IF_INTL(Temporal, OCLASP(temporal::Temporal))                         \
    153  REAL_IF_INTL(Duration, OCLASP(temporal::Duration))                         \
    154  REAL_IF_INTL(Instant, OCLASP(temporal::Instant))                           \
    155  REAL_IF_INTL(PlainDate, OCLASP(temporal::PlainDate))                       \
    156  REAL_IF_INTL(PlainDateTime, OCLASP(temporal::PlainDateTime))               \
    157  REAL_IF_INTL(PlainMonthDay, OCLASP(temporal::PlainMonthDay))               \
    158  REAL_IF_INTL(PlainYearMonth, OCLASP(temporal::PlainYearMonth))             \
    159  REAL_IF_INTL(PlainTime, OCLASP(temporal::PlainTime))                       \
    160  REAL_IF_INTL(TemporalNow, OCLASP(temporal::TemporalNow))                   \
    161  REAL_IF_INTL(ZonedDateTime, OCLASP(temporal::ZonedDateTime))
    162 // DO NOT ADD CONDITIONAL ENTRIES TO THIS LIST! (As in, do not add entries
    163 // guarded by #ifdef.) It will break binary compatibility. Instead, create an
    164 // IF_<feature> macro and add it to the parameter list below and add a
    165 // corresponding parameter to JS_FOR_PROTOTYPES_ above.
    166 //
    167 // Note that entries may be freely added to or removed from this list, even in
    168 // the middle. The only invariant that must be upheld is that the offsets in the
    169 // list do not change depending on configuration settings of the same version of
    170 // the source.
    171 
    172 #define JS_FOR_PROTOTYPES(REAL, IMAGINARY)                      \
    173  JS_FOR_PROTOTYPES_(REAL, IMAGINARY, IF_INTL(REAL, IMAGINARY), \
    174                     IF_WASM_TYPE(REAL, IMAGINARY),             \
    175                     IF_WASM_JSPI(REAL, IMAGINARY),             \
    176                     IF_NIGHTLY(REAL, IMAGINARY))
    177 
    178 #define JS_FOR_EACH_PROTOTYPE(MACRO) JS_FOR_PROTOTYPES(MACRO, MACRO)
    179 
    180 #endif /* js_ProtoKey_h */