js/src/jsprototypes.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef jsprototypes_h
michael@0 8 #define jsprototypes_h
michael@0 9
michael@0 10 /* A higher-order macro for enumerating all JSProtoKey values. */
michael@0 11 /*
michael@0 12 * Consumers define macros as follows:
michael@0 13 * macro(name, code, init, clasp)
michael@0 14 * name: The canonical name of the class.
michael@0 15 * code: The enumerator code. There are part of the XDR API, and must not change.
michael@0 16 * init: Initialization function. These are |extern "C";|, and clients should use
michael@0 17 * |extern "C" {}| as appropriate when using this macro.
michael@0 18 * clasp: The JSClass for this object, or "dummy" if it doesn't exist.
michael@0 19 *
michael@0 20 *
michael@0 21 * Consumers wishing to iterate over all the JSProtoKey values, can use
michael@0 22 * JS_FOR_EACH_PROTOTYPE. However, there are certain values that don't correspond
michael@0 23 * to real constructors, like Null or constructors that are disabled via
michael@0 24 * preprocessor directives. We still need to include these in the JSProtoKey list
michael@0 25 * in order to maintain binary XDR compatibility, but we need to provide a tool
michael@0 26 * to handle them differently. JS_FOR_PROTOTYPES fills this niche.
michael@0 27 *
michael@0 28 * Consumers pass two macros to JS_FOR_PROTOTYPES - |real| and |imaginary|. The
michael@0 29 * former is invoked for entries that have real client-exposed constructors, and
michael@0 30 * the latter is called for the rest. Consumers that don't care about this
michael@0 31 * distinction can simply pass the same macro to both, which is exactly what
michael@0 32 * JS_FOR_EACH_PROTOTYPE does.
michael@0 33 */
michael@0 34
michael@0 35 #define CLASP(name) (&name##Class)
michael@0 36 #define OCLASP(name) (&name##Object::class_)
michael@0 37 #define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[ScalarTypeDescr::type])
michael@0 38
michael@0 39 #ifdef ENABLE_PARALLEL_JS
michael@0 40 #define IF_PJS(real,imaginary) real
michael@0 41 #else
michael@0 42 #define IF_PJS(real,imaginary) imaginary
michael@0 43 #endif
michael@0 44
michael@0 45 #ifdef EXPOSE_INTL_API
michael@0 46 #define IF_INTL(real,imaginary) real
michael@0 47 #else
michael@0 48 #define IF_INTL(real,imaginary) imaginary
michael@0 49 #endif
michael@0 50
michael@0 51 #ifdef ENABLE_BINARYDATA
michael@0 52 #define IF_BDATA(real,imaginary) real
michael@0 53 #else
michael@0 54 #define IF_BDATA(real,imaginary) imaginary
michael@0 55 #endif
michael@0 56
michael@0 57 #ifdef ENABLE_SHARED_ARRAY_BUFFER
michael@0 58 #define IF_SAB(real,imaginary) real
michael@0 59 #else
michael@0 60 #define IF_SAB(real,imaginary) imaginary
michael@0 61 #endif
michael@0 62
michael@0 63 #define JS_FOR_PROTOTYPES(real,imaginary) \
michael@0 64 imaginary(Null, 0, js_InitNullClass, dummy) \
michael@0 65 real(Object, 1, js_InitObjectClass, &JSObject::class_) \
michael@0 66 real(Function, 2, js_InitFunctionClass, &JSFunction::class_) \
michael@0 67 real(Array, 3, js_InitArrayClass, OCLASP(Array)) \
michael@0 68 real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \
michael@0 69 real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \
michael@0 70 real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \
michael@0 71 real(Math, 7, js_InitMathClass, CLASP(Math)) \
michael@0 72 real(Number, 8, js_InitNumberClass, OCLASP(Number)) \
michael@0 73 real(String, 9, js_InitStringClass, OCLASP(String)) \
michael@0 74 real(RegExp, 10, js_InitRegExpClass, OCLASP(RegExp)) \
michael@0 75 real(Error, 11, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 76 real(InternalError, 12, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 77 real(EvalError, 13, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 78 real(RangeError, 14, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 79 real(ReferenceError, 15, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 80 real(SyntaxError, 16, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 81 real(TypeError, 17, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 82 real(URIError, 18, js_InitExceptionClasses, OCLASP(Error)) \
michael@0 83 real(Iterator, 19, js_InitIteratorClasses, OCLASP(PropertyIterator)) \
michael@0 84 real(StopIteration, 20, js_InitIteratorClasses, OCLASP(StopIteration)) \
michael@0 85 real(ArrayBuffer, 21, js_InitTypedArrayClasses, &js::ArrayBufferObject::protoClass) \
michael@0 86 real(Int8Array, 22, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT8)) \
michael@0 87 real(Uint8Array, 23, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8)) \
michael@0 88 real(Int16Array, 24, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT16)) \
michael@0 89 real(Uint16Array, 25, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT16)) \
michael@0 90 real(Int32Array, 26, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_INT32)) \
michael@0 91 real(Uint32Array, 27, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT32)) \
michael@0 92 real(Float32Array, 28, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT32)) \
michael@0 93 real(Float64Array, 29, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_FLOAT64)) \
michael@0 94 real(Uint8ClampedArray, 30, js_InitTypedArrayClasses, TYPED_ARRAY_CLASP(TYPE_UINT8_CLAMPED)) \
michael@0 95 real(Proxy, 31, js_InitProxyClass, &ProxyObject::uncallableClass_) \
michael@0 96 real(WeakMap, 32, js_InitWeakMapClass, OCLASP(WeakMap)) \
michael@0 97 real(Map, 33, js_InitMapClass, OCLASP(Map)) \
michael@0 98 real(Set, 34, js_InitSetClass, OCLASP(Set)) \
michael@0 99 real(DataView, 35, js_InitTypedArrayClasses, OCLASP(DataView)) \
michael@0 100 IF_SAB(real,imaginary)(SharedArrayBuffer, 36, js_InitSharedArrayBufferClass, &js::SharedArrayBufferObject::protoClass) \
michael@0 101 IF_INTL(real,imaginary) (Intl, 37, js_InitIntlClass, CLASP(Intl)) \
michael@0 102 IF_BDATA(real,imaginary)(TypedObject, 38, js_InitTypedObjectModuleObject, OCLASP(TypedObjectModule)) \
michael@0 103 imaginary(GeneratorFunction, 39, js_InitIteratorClasses, dummy) \
michael@0 104 IF_BDATA(real,imaginary)(SIMD, 40, js_InitSIMDClass, OCLASP(SIMD)) \
michael@0 105
michael@0 106 #define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro)
michael@0 107
michael@0 108 #endif /* jsprototypes_h */

mercurial