DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sts=4 et sw=4 tw=99:
 * 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, init, clasp)
 *   name:    The canonical name of the class.
 *   init:    Initialization function. These are |extern "C";|, and clients
 *            should use |extern "C" {}| as appropriate when using this macro.
 *   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[Scalar::TYPE])
#define ERROR_CLASP(TYPE) (&ErrorObject::classes[TYPE])

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

#ifdef ENABLE_BINARYDATA
#define IF_BDATA(real, imaginary) real
#else
#define IF_BDATA(real, imaginary) imaginary
#endif

#ifdef ENABLE_SIMD
#define IF_SIMD(real, imaginary) real
#else
#define IF_SIMD(real, imaginary) imaginary
#endif

#ifdef ENABLE_SHARED_ARRAY_BUFFER
#define IF_SAB(real, imaginary) real
#else
#define IF_SAB(real, imaginary) imaginary
#endif

#define JS_FOR_PROTOTYPES_(REAL, IMAGINARY, REAL_IF_INTL, REAL_IF_BDATA,      \
                           REAL_IF_SAB, REAL_IF_SIMD)                         \
  IMAGINARY(Null, InitNullClass, dummy)                                       \
  REAL(Object, InitViaClassSpec, OCLASP(Plain))                               \
  REAL(Function, InitViaClassSpec, &JSFunction::class_)                       \
  REAL(Array, InitViaClassSpec, OCLASP(Array))                                \
  REAL(Boolean, InitBooleanClass, OCLASP(Boolean))                            \
  REAL(JSON, InitJSONClass, CLASP(JSON))                                      \
  REAL(Date, InitViaClassSpec, OCLASP(Date))                                  \
  REAL(Math, InitMathClass, CLASP(Math))                                      \
  REAL(Number, InitNumberClass, OCLASP(Number))                               \
  REAL(String, InitStringClass, OCLASP(String))                               \
  REAL(RegExp, InitViaClassSpec, OCLASP(RegExp))                              \
  REAL(Error, InitViaClassSpec, ERROR_CLASP(JSEXN_ERR))                       \
  REAL(InternalError, InitViaClassSpec, ERROR_CLASP(JSEXN_INTERNALERR))       \
  REAL(EvalError, InitViaClassSpec, ERROR_CLASP(JSEXN_EVALERR))               \
  REAL(RangeError, InitViaClassSpec, ERROR_CLASP(JSEXN_RANGEERR))             \
  REAL(ReferenceError, InitViaClassSpec, ERROR_CLASP(JSEXN_REFERENCEERR))     \
  REAL(SyntaxError, InitViaClassSpec, ERROR_CLASP(JSEXN_SYNTAXERR))           \
  REAL(TypeError, InitViaClassSpec, ERROR_CLASP(JSEXN_TYPEERR))               \
  REAL(URIError, InitViaClassSpec, ERROR_CLASP(JSEXN_URIERR))                 \
  REAL(DebuggeeWouldRun, InitViaClassSpec,                                    \
       ERROR_CLASP(JSEXN_DEBUGGEEWOULDRUN))                                   \
  REAL(CompileError, InitViaClassSpec, ERROR_CLASP(JSEXN_WASMCOMPILEERROR))   \
  REAL(LinkError, InitViaClassSpec, ERROR_CLASP(JSEXN_WASMLINKERROR))         \
  REAL(RuntimeError, InitViaClassSpec, ERROR_CLASP(JSEXN_WASMRUNTIMEERROR))   \
  IMAGINARY(Iterator, dummy, dummy)                                           \
  REAL(ArrayBuffer, InitViaClassSpec, OCLASP(ArrayBuffer))                    \
  REAL(Int8Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Int8))                  \
  REAL(Uint8Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8))                \
  REAL(Int16Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Int16))                \
  REAL(Uint16Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Uint16))              \
  REAL(Int32Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Int32))                \
  REAL(Uint32Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Uint32))              \
  REAL(Float32Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Float32))            \
  REAL(Float64Array, InitViaClassSpec, TYPED_ARRAY_CLASP(Float64))            \
  REAL(Uint8ClampedArray, InitViaClassSpec, TYPED_ARRAY_CLASP(Uint8Clamped))  \
  REAL(Proxy, InitProxyClass, js::ProxyClassPtr)                              \
  REAL(WeakMap, InitWeakMapClass, OCLASP(WeakMap))                            \
  REAL(Map, InitViaClassSpec, OCLASP(Map))                                    \
  REAL(Set, InitViaClassSpec, OCLASP(Set))                                    \
  REAL(DataView, InitViaClassSpec, OCLASP(DataView))                          \
  REAL(Symbol, InitSymbolClass, OCLASP(Symbol))                               \
  REAL_IF_SAB(SharedArrayBuffer, InitViaClassSpec, OCLASP(SharedArrayBuffer)) \
  REAL_IF_INTL(Intl, InitIntlClass, CLASP(Intl))                              \
  REAL_IF_BDATA(TypedObject, InitTypedObjectModuleObject,                     \
                OCLASP(TypedObjectModule))                                    \
  REAL(Reflect, InitReflect, nullptr)                                         \
  REAL_IF_SIMD(SIMD, InitSimdClass, OCLASP(Simd))                             \
  REAL(WeakSet, InitWeakSetClass, OCLASP(WeakSet))                            \
  REAL(TypedArray, InitViaClassSpec,                                          \
       &js::TypedArrayObject::sharedTypedArrayPrototypeClass)                 \
  REAL_IF_SAB(Atomics, InitAtomicsClass, OCLASP(Atomics))                     \
  REAL(SavedFrame, InitViaClassSpec, &js::SavedFrame::class_)                 \
  REAL(Promise, InitViaClassSpec, OCLASP(Promise))                            \
  REAL(ReadableStream, InitViaClassSpec, &js::ReadableStream::class_)         \
  REAL(ReadableStreamDefaultReader, InitViaClassSpec,                         \
       &js::ReadableStreamDefaultReader::class_)                              \
  REAL(ReadableStreamBYOBReader, InitViaClassSpec,                            \
       &js::ReadableStreamBYOBReader::class_)                                 \
  REAL(ReadableStreamDefaultController, InitViaClassSpec,                     \
       &js::ReadableStreamDefaultController::class_)                          \
  REAL(ReadableByteStreamController, InitViaClassSpec,                        \
       &js::ReadableByteStreamController::class_)                             \
  REAL(ReadableStreamBYOBRequest, InitViaClassSpec,                           \
       &js::ReadableStreamBYOBRequest::class_)                                \
  IMAGINARY(WritableStream, dummy, dummy)                                     \
  IMAGINARY(WritableStreamDefaultWriter, dummy, dummy)                        \
  IMAGINARY(WritableStreamDefaultController, dummy, dummy)                    \
  REAL(ByteLengthQueuingStrategy, InitViaClassSpec,                           \
       &js::ByteLengthQueuingStrategy::class_)                                \
  REAL(CountQueuingStrategy, InitViaClassSpec,                                \
       &js::CountQueuingStrategy::class_)                                     \
  REAL(WebAssembly, InitWebAssemblyClass, CLASP(WebAssembly))                 \
  IMAGINARY(WasmModule, dummy, dummy)                                         \
  IMAGINARY(WasmInstance, dummy, dummy)                                       \
  IMAGINARY(WasmMemory, dummy, dummy)                                         \
  IMAGINARY(WasmTable, dummy, dummy)                                          \
  IMAGINARY(WasmGlobal, dummy, dummy)

#define JS_FOR_PROTOTYPES(REAL, IMAGINARY)                               \
  JS_FOR_PROTOTYPES_(REAL, IMAGINARY, IF_INTL(REAL, IMAGINARY),          \
                     IF_BDATA(REAL, IMAGINARY), IF_SAB(REAL, IMAGINARY), \
                     IF_SIMD(REAL, IMAGINARY))

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

#endif /* js_ProtoKey_h */