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/. */
7 /* An enumeration of all possible element types in typed data. */
9 #ifndef js_ScalarType_h
10 #define js_ScalarType_h
12 #include "mozilla/Assertions.h" // MOZ_CRASH
14 #include <stddef.h> // size_t
20 // Scalar types that can appear in typed arrays.
21 // The enum values must be kept in sync with:
23 // * the TYPEDARRAY_KIND constants
24 // * the SCTAG_TYPED_ARRAY constants
25 // * JS_FOR_EACH_TYPED_ARRAY
26 // * JS_FOR_PROTOTYPES_
27 // * JS_FOR_EACH_UNIQUE_SCALAR_TYPE_REPR_CTYPE
30 // and the existing entries here must not be renumbered, since they are
31 // necessary for backwards compatibility with structured clones from previous
32 // versions. (It is fine to add new entries and increment
33 // MaxTypedArrayViewType, or change anything at or after
34 // MaxTypedArrayViewType.)
46 * Special type that is a uint8_t, but assignments are clamped to [0, 256).
47 * Treat the raw data type as a uint8_t.
55 * Types that don't have their own TypedArray equivalent, for now.
58 MaxTypedArrayViewType
,
64 static inline size_t byteSize(Type atype
) {
84 case MaxTypedArrayViewType
:
87 MOZ_CRASH("invalid scalar type");
90 static inline bool isSignedIntType(Type atype
) {
107 case MaxTypedArrayViewType
:
110 MOZ_CRASH("invalid scalar type");
113 static inline bool isBigIntType(Type atype
) {
130 case MaxTypedArrayViewType
:
133 MOZ_CRASH("invalid scalar type");
136 static inline bool isFloatingType(Type atype
) {
153 case MaxTypedArrayViewType
:
156 MOZ_CRASH("invalid scalar type");
159 static inline const char* name(Type atype
) {
178 return "Uint8Clamped";
183 case MaxTypedArrayViewType
:
184 return "MaxTypedArrayViewType";
190 MOZ_CRASH("invalid scalar type");
193 static inline const char* byteSizeString(Type atype
) {
213 case MaxTypedArrayViewType
:
216 MOZ_CRASH("invalid scalar type");
219 } // namespace Scalar
225 // This is aliased in NamespaceImports.h, but that is internal-only and
226 // inaccessible to Gecko code, which uses this type fairly heavily. Until such
227 // uses are changed, we need the alias here as well.
228 namespace Scalar
= JS::Scalar
;
232 #endif // js_ScalarType_h