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.
57 * Types that don't have their own TypedArray equivalent, for now.
60 MaxTypedArrayViewType
,
66 static inline size_t byteSize(Type atype
) {
87 case MaxTypedArrayViewType
:
90 MOZ_CRASH("invalid scalar type");
93 static inline bool isSignedIntType(Type atype
) {
111 case MaxTypedArrayViewType
:
114 MOZ_CRASH("invalid scalar type");
117 static inline bool isBigIntType(Type atype
) {
135 case MaxTypedArrayViewType
:
138 MOZ_CRASH("invalid scalar type");
141 static inline bool isFloatingType(Type atype
) {
159 case MaxTypedArrayViewType
:
162 MOZ_CRASH("invalid scalar type");
165 static inline const char* name(Type atype
) {
186 return "Uint8Clamped";
191 case MaxTypedArrayViewType
:
192 return "MaxTypedArrayViewType";
198 MOZ_CRASH("invalid scalar type");
201 static inline const char* byteSizeString(Type atype
) {
222 case MaxTypedArrayViewType
:
225 MOZ_CRASH("invalid scalar type");
228 } // namespace Scalar
234 // This is aliased in NamespaceImports.h, but that is internal-only and
235 // inaccessible to Gecko code, which uses this type fairly heavily. Until such
236 // uses are changed, we need the alias here as well.
237 namespace Scalar
= JS::Scalar
;
241 #endif // js_ScalarType_h