js/src/jsprototypes.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jsprototypes.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef jsprototypes_h
    1.11 +#define jsprototypes_h
    1.12 +
    1.13 +/* A higher-order macro for enumerating all JSProtoKey values. */
    1.14 +/*
    1.15 + * Consumers define macros as follows:
    1.16 + * macro(name, code, init, clasp)
    1.17 + *   name:    The canonical name of the class.
    1.18 + *   code:    The enumerator code. There are part of the XDR API, and must not change.
    1.19 + *   init:    Initialization function. These are |extern "C";|, and clients should use
    1.20 + *            |extern "C" {}| as appropriate when using this macro.
    1.21 + *   clasp:   The JSClass for this object, or "dummy" if it doesn't exist.
    1.22 + *
    1.23 + *
    1.24 + * Consumers wishing to iterate over all the JSProtoKey values, can use
    1.25 + * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't correspond
    1.26 + * to real constructors, like Null or constructors that are disabled via
    1.27 + * preprocessor directives. We still need to include these in the JSProtoKey list
    1.28 + * in order to maintain binary XDR compatibility, but we need to provide a tool
    1.29 + * to handle them differently. JS_FOR_PROTOTYPES fills this niche.
    1.30 + *
    1.31 + * Consumers pass two macros to JS_FOR_PROTOTYPES - |real| and |imaginary|. The
    1.32 + * former is invoked for entries that have real client-exposed constructors, and
    1.33 + * the latter is called for the rest. Consumers that don't care about this
    1.34 + * distinction can simply pass the same macro to both, which is exactly what
    1.35 + * JS_FOR_EACH_PROTOTYPE does.
    1.36 + */
    1.37 +
    1.38 +#define CLASP(name)                 (&name##Class)
    1.39 +#define OCLASP(name)                (&name##Object::class_)
    1.40 +#define TYPED_ARRAY_CLASP(type)     (&TypedArrayObject::classes[ScalarTypeDescr::type])
    1.41 +
    1.42 +#ifdef ENABLE_PARALLEL_JS
    1.43 +#define IF_PJS(real,imaginary) real
    1.44 +#else
    1.45 +#define IF_PJS(real,imaginary) imaginary
    1.46 +#endif
    1.47 +
    1.48 +#ifdef EXPOSE_INTL_API
    1.49 +#define IF_INTL(real,imaginary) real
    1.50 +#else
    1.51 +#define IF_INTL(real,imaginary) imaginary
    1.52 +#endif
    1.53 +
    1.54 +#ifdef ENABLE_BINARYDATA
    1.55 +#define IF_BDATA(real,imaginary) real
    1.56 +#else
    1.57 +#define IF_BDATA(real,imaginary) imaginary
    1.58 +#endif
    1.59 +
    1.60 +#ifdef ENABLE_SHARED_ARRAY_BUFFER
    1.61 +#define IF_SAB(real,imaginary) real
    1.62 +#else
    1.63 +#define IF_SAB(real,imaginary) imaginary
    1.64 +#endif
    1.65 +
    1.66 +#define JS_FOR_PROTOTYPES(real,imaginary) \
    1.67 +    imaginary(Null,              0,     js_InitNullClass,          dummy) \
    1.68 +    real(Object,                 1,     js_InitObjectClass,        &JSObject::class_) \
    1.69 +    real(Function,               2,     js_InitFunctionClass,      &JSFunction::class_) \
    1.70 +    real(Array,                  3,     js_InitArrayClass,         OCLASP(Array)) \
    1.71 +    real(Boolean,                4,     js_InitBooleanClass,       OCLASP(Boolean)) \
    1.72 +    real(JSON,                   5,     js_InitJSONClass,          CLASP(JSON)) \
    1.73 +    real(Date,                   6,     js_InitViaClassSpec,       OCLASP(Date)) \
    1.74 +    real(Math,                   7,     js_InitMathClass,          CLASP(Math)) \
    1.75 +    real(Number,                 8,     js_InitNumberClass,        OCLASP(Number)) \
    1.76 +    real(String,                 9,     js_InitStringClass,        OCLASP(String)) \
    1.77 +    real(RegExp,                10,     js_InitRegExpClass,        OCLASP(RegExp)) \
    1.78 +    real(Error,                 11,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.79 +    real(InternalError,         12,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.80 +    real(EvalError,             13,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.81 +    real(RangeError,            14,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.82 +    real(ReferenceError,        15,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.83 +    real(SyntaxError,           16,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.84 +    real(TypeError,             17,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.85 +    real(URIError,              18,     js_InitExceptionClasses,   OCLASP(Error)) \
    1.86 +    real(Iterator,              19,     js_InitIteratorClasses,    OCLASP(PropertyIterator)) \
    1.87 +    real(StopIteration,         20,     js_InitIteratorClasses,    OCLASP(StopIteration)) \
    1.88 +    real(ArrayBuffer,           21,     js_InitTypedArrayClasses,  &js::ArrayBufferObject::protoClass) \
    1.89 +    real(Int8Array,             22,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_INT8)) \
    1.90 +    real(Uint8Array,            23,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_UINT8)) \
    1.91 +    real(Int16Array,            24,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_INT16)) \
    1.92 +    real(Uint16Array,           25,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_UINT16)) \
    1.93 +    real(Int32Array,            26,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_INT32)) \
    1.94 +    real(Uint32Array,           27,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_UINT32)) \
    1.95 +    real(Float32Array,          28,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_FLOAT32)) \
    1.96 +    real(Float64Array,          29,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_FLOAT64)) \
    1.97 +    real(Uint8ClampedArray,     30,     js_InitTypedArrayClasses,  TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)) \
    1.98 +    real(Proxy,                 31,     js_InitProxyClass,         &ProxyObject::uncallableClass_) \
    1.99 +    real(WeakMap,               32,     js_InitWeakMapClass,       OCLASP(WeakMap)) \
   1.100 +    real(Map,                   33,     js_InitMapClass,           OCLASP(Map)) \
   1.101 +    real(Set,                   34,     js_InitSetClass,           OCLASP(Set)) \
   1.102 +    real(DataView,              35,     js_InitTypedArrayClasses,  OCLASP(DataView)) \
   1.103 +IF_SAB(real,imaginary)(SharedArrayBuffer,       36,     js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \
   1.104 +IF_INTL(real,imaginary) (Intl,                  37,     js_InitIntlClass,          CLASP(Intl)) \
   1.105 +IF_BDATA(real,imaginary)(TypedObject,           38,     js_InitTypedObjectModuleObject,   OCLASP(TypedObjectModule)) \
   1.106 +    imaginary(GeneratorFunction,     39,     js_InitIteratorClasses, dummy) \
   1.107 +IF_BDATA(real,imaginary)(SIMD,                  40,     js_InitSIMDClass, OCLASP(SIMD)) \
   1.108 +
   1.109 +#define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro)
   1.110 +
   1.111 +#endif /* jsprototypes_h */

mercurial