1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sts=4 et sw=4 tw=99:
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 jsprototypes_h
8 #define jsprototypes_h
9 
10 /* A higher-order macro for enumerating all JSProtoKey values. */
11 /*
12  * Consumers define macros as follows:
13  * macro(name, code, init, clasp)
14  *   name:    The canonical name of the class.
15  *   code:    The enumerator code. There are part of the XDR API, and must not change.
16  *   init:    Initialization function. These are |extern "C";|, and clients should use
17  *            |extern "C" {}| as appropriate when using this macro.
18  *   clasp:   The JSClass for this object, or "dummy" if it doesn't exist.
19  *
20  *
21  * Consumers wishing to iterate over all the JSProtoKey values, can use
22  * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't correspond
23  * to real constructors, like Null or constructors that are disabled via
24  * preprocessor directives. We still need to include these in the JSProtoKey list
25  * in order to maintain binary XDR compatibility, but we need to provide a tool
26  * to handle them differently. JS_FOR_PROTOTYPES fills this niche.
27  *
28  * Consumers pass two macros to JS_FOR_PROTOTYPES - |real| and |imaginary|. The
29  * former is invoked for entries that have real client-exposed constructors, and
30  * the latter is called for the rest. Consumers that don't care about this
31  * distinction can simply pass the same macro to both, which is exactly what
32  * JS_FOR_EACH_PROTOTYPE does.
33  */
34 
35 #define CLASP(name)                 (&name##Class)
36 #define OCLASP(name)                (&name##Object::class_)
37 #define TYPED_ARRAY_CLASP(type)     (&TypedArrayObject::classes[Scalar::type])
38 #define ERROR_CLASP(type)           (&ErrorObject::classes[type])
39 
40 #ifdef EXPOSE_INTL_API
41 #define IF_INTL(real,imaginary) real
42 #else
43 #define IF_INTL(real,imaginary) imaginary
44 #endif
45 
46 #ifdef ENABLE_BINARYDATA
47 #define IF_BDATA(real,imaginary) real
48 #else
49 #define IF_BDATA(real,imaginary) imaginary
50 #endif
51 
52 #ifdef ENABLE_SHARED_ARRAY_BUFFER
53 #define IF_SAB(real,imaginary) real
54 #else
55 #define IF_SAB(real,imaginary) imaginary
56 #endif
57 
58 #define JS_FOR_PROTOTYPES(real,imaginary) \
59     imaginary(Null,              0,     InitNullClass,          dummy) \
60     real(Object,                 1,     InitViaClassSpec,       OCLASP(Plain)) \
61     real(Function,               2,     InitViaClassSpec,       &JSFunction::class_) \
62     real(Array,                  3,     InitViaClassSpec,       OCLASP(Array)) \
63     real(Boolean,                4,     InitBooleanClass,       OCLASP(Boolean)) \
64     real(JSON,                   5,     InitJSONClass,          CLASP(JSON)) \
65     real(Date,                   6,     InitViaClassSpec,       OCLASP(Date)) \
66     real(Math,                   7,     InitMathClass,          CLASP(Math)) \
67     real(Number,                 8,     InitNumberClass,        OCLASP(Number)) \
68     real(String,                 9,     InitStringClass,        OCLASP(String)) \
69     real(RegExp,                10,     InitViaClassSpec,       OCLASP(RegExp)) \
70     real(Error,                 11,     InitViaClassSpec,       ERROR_CLASP(JSEXN_ERR)) \
71     real(InternalError,         12,     InitViaClassSpec,       ERROR_CLASP(JSEXN_INTERNALERR)) \
72     real(EvalError,             13,     InitViaClassSpec,       ERROR_CLASP(JSEXN_EVALERR)) \
73     real(RangeError,            14,     InitViaClassSpec,       ERROR_CLASP(JSEXN_RANGEERR)) \
74     real(ReferenceError,        15,     InitViaClassSpec,       ERROR_CLASP(JSEXN_REFERENCEERR)) \
75     real(SyntaxError,           16,     InitViaClassSpec,       ERROR_CLASP(JSEXN_SYNTAXERR)) \
76     real(TypeError,             17,     InitViaClassSpec,       ERROR_CLASP(JSEXN_TYPEERR)) \
77     real(URIError,              18,     InitViaClassSpec,       ERROR_CLASP(JSEXN_URIERR)) \
78     real(Iterator,              19,     InitLegacyIteratorClass,OCLASP(PropertyIterator)) \
79     real(StopIteration,         20,     InitStopIterationClass, OCLASP(StopIteration)) \
80     real(ArrayBuffer,           21,     InitArrayBufferClass,   &js::ArrayBufferObject::protoClass) \
81     real(Int8Array,             22,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Int8)) \
82     real(Uint8Array,            23,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Uint8)) \
83     real(Int16Array,            24,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Int16)) \
84     real(Uint16Array,           25,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Uint16)) \
85     real(Int32Array,            26,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Int32)) \
86     real(Uint32Array,           27,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Uint32)) \
87     real(Float32Array,          28,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Float32)) \
88     real(Float64Array,          29,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Float64)) \
89     real(Uint8ClampedArray,     30,     InitViaClassSpec,       TYPED_ARRAY_CLASP(Uint8Clamped)) \
90     real(Proxy,                 31,     InitProxyClass,         js::ProxyClassPtr) \
91     real(WeakMap,               32,     InitWeakMapClass,       OCLASP(WeakMap)) \
92     real(Map,                   33,     InitMapClass,           OCLASP(Map)) \
93     real(Set,                   34,     InitSetClass,           OCLASP(Set)) \
94     real(DataView,              35,     InitDataViewClass,      OCLASP(DataView)) \
95     real(Symbol,                36,     InitSymbolClass,        OCLASP(Symbol)) \
96 IF_SAB(real,imaginary)(SharedArrayBuffer,       37,     InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \
97 IF_INTL(real,imaginary) (Intl,                  38,     InitIntlClass,          CLASP(Intl)) \
98 IF_BDATA(real,imaginary)(TypedObject,           39,     InitTypedObjectModuleObject,   OCLASP(TypedObjectModule)) \
99     real(Reflect,               40,     InitReflect,            nullptr) \
100 IF_BDATA(real,imaginary)(SIMD,                  41,     InitSIMDClass, OCLASP(SIMD)) \
101     real(WeakSet,               42,     InitWeakSetClass,       OCLASP(WeakSet)) \
102     real(TypedArray,            43,      InitViaClassSpec,      &js::TypedArrayObject::sharedTypedArrayPrototypeClass) \
103 IF_SAB(real,imaginary)(Atomics,                 44,     InitAtomicsClass, OCLASP(Atomics)) \
104     real(SavedFrame,            45,      InitViaClassSpec,      &js::SavedFrame::class_) \
105 
106 #define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro)
107 
108 #endif /* jsprototypes_h */
109