Bug 1905259 - Add updated thumbs up and down icons, add CSS animation to active state...
[gecko.git] / js / public / ScalarType.h
blobab410dc7c818913faeb1f5bc005eb4663f7a4a61
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
16 namespace JS {
18 namespace Scalar {
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
28 // * JIT compilation
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.)
35 enum Type {
36 Int8 = 0,
37 Uint8,
38 Int16,
39 Uint16,
40 Int32,
41 Uint32,
42 Float32,
43 Float64,
45 /**
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.
49 Uint8Clamped,
51 BigInt64,
52 BigUint64,
54 Float16,
56 /**
57 * Types that don't have their own TypedArray equivalent, for now.
58 * E.g. DataView
60 MaxTypedArrayViewType,
62 Int64,
63 Simd128,
66 static inline size_t byteSize(Type atype) {
67 switch (atype) {
68 case Int8:
69 case Uint8:
70 case Uint8Clamped:
71 return 1;
72 case Int16:
73 case Uint16:
74 case Float16:
75 return 2;
76 case Int32:
77 case Uint32:
78 case Float32:
79 return 4;
80 case Int64:
81 case Float64:
82 case BigInt64:
83 case BigUint64:
84 return 8;
85 case Simd128:
86 return 16;
87 case MaxTypedArrayViewType:
88 break;
90 MOZ_CRASH("invalid scalar type");
93 static inline bool isSignedIntType(Type atype) {
94 switch (atype) {
95 case Int8:
96 case Int16:
97 case Int32:
98 case Int64:
99 case BigInt64:
100 return true;
101 case Uint8:
102 case Uint8Clamped:
103 case Uint16:
104 case Uint32:
105 case Float16:
106 case Float32:
107 case Float64:
108 case BigUint64:
109 case Simd128:
110 return false;
111 case MaxTypedArrayViewType:
112 break;
114 MOZ_CRASH("invalid scalar type");
117 static inline bool isBigIntType(Type atype) {
118 switch (atype) {
119 case BigInt64:
120 case BigUint64:
121 return true;
122 case Int8:
123 case Int16:
124 case Int32:
125 case Int64:
126 case Uint8:
127 case Uint8Clamped:
128 case Uint16:
129 case Uint32:
130 case Float16:
131 case Float32:
132 case Float64:
133 case Simd128:
134 return false;
135 case MaxTypedArrayViewType:
136 break;
138 MOZ_CRASH("invalid scalar type");
141 static inline bool isFloatingType(Type atype) {
142 switch (atype) {
143 case Int8:
144 case Uint8:
145 case Uint8Clamped:
146 case Int16:
147 case Uint16:
148 case Int32:
149 case Uint32:
150 case Int64:
151 case BigInt64:
152 case BigUint64:
153 return false;
154 case Float16:
155 case Float32:
156 case Float64:
157 case Simd128:
158 return true;
159 case MaxTypedArrayViewType:
160 break;
162 MOZ_CRASH("invalid scalar type");
165 static inline const char* name(Type atype) {
166 switch (atype) {
167 case Int8:
168 return "Int8";
169 case Uint8:
170 return "Uint8";
171 case Int16:
172 return "Int16";
173 case Uint16:
174 return "Uint16";
175 case Int32:
176 return "Int32";
177 case Uint32:
178 return "Uint32";
179 case Float16:
180 return "Float16";
181 case Float32:
182 return "Float32";
183 case Float64:
184 return "Float64";
185 case Uint8Clamped:
186 return "Uint8Clamped";
187 case BigInt64:
188 return "BigInt64";
189 case BigUint64:
190 return "BigUint64";
191 case MaxTypedArrayViewType:
192 return "MaxTypedArrayViewType";
193 case Int64:
194 return "Int64";
195 case Simd128:
196 return "Simd128";
198 MOZ_CRASH("invalid scalar type");
201 static inline const char* byteSizeString(Type atype) {
202 switch (atype) {
203 case Int8:
204 case Uint8:
205 case Uint8Clamped:
206 return "1";
207 case Int16:
208 case Uint16:
209 case Float16:
210 return "2";
211 case Int32:
212 case Uint32:
213 case Float32:
214 return "4";
215 case Int64:
216 case Float64:
217 case BigInt64:
218 case BigUint64:
219 return "8";
220 case Simd128:
221 return "16";
222 case MaxTypedArrayViewType:
223 break;
225 MOZ_CRASH("invalid scalar type");
228 } // namespace Scalar
230 } // namespace JS
232 namespace js {
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;
239 } // namespace js
241 #endif // js_ScalarType_h