Skip to content

Commit a8afb2d

Browse files
KevinEadymhdawson
authored andcommitted
src: remove TypedArray::unknown_array_type
PR-URL: #1209 Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 257a52f commit a8afb2d

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

napi-inl.h

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,19 +2003,13 @@ inline void DataView::WriteData(size_t byteOffset, T value) const {
20032003
////////////////////////////////////////////////////////////////////////////////
20042004

20052005
inline TypedArray::TypedArray()
2006-
: Object(), _type(TypedArray::unknown_array_type), _length(0) {}
2006+
: Object(), _type(napi_typedarray_type::napi_int8_array), _length(0) {}
20072007

20082008
inline TypedArray::TypedArray(napi_env env, napi_value value)
2009-
: Object(env, value), _type(TypedArray::unknown_array_type), _length(0) {}
2010-
2011-
inline TypedArray::TypedArray(napi_env env,
2012-
napi_value value,
2013-
napi_typedarray_type type,
2014-
size_t length)
2015-
: Object(env, value), _type(type), _length(length) {}
2016-
2017-
inline napi_typedarray_type TypedArray::TypedArrayType() const {
2018-
if (_type == TypedArray::unknown_array_type) {
2009+
: Object(env, value),
2010+
_type(napi_typedarray_type::napi_int8_array),
2011+
_length(0) {
2012+
if (value != nullptr) {
20192013
napi_status status =
20202014
napi_get_typedarray_info(_env,
20212015
_value,
@@ -2024,14 +2018,22 @@ inline napi_typedarray_type TypedArray::TypedArrayType() const {
20242018
nullptr,
20252019
nullptr,
20262020
nullptr);
2027-
NAPI_THROW_IF_FAILED(_env, status, napi_int8_array);
2021+
NAPI_THROW_IF_FAILED_VOID(_env, status);
20282022
}
2023+
}
2024+
2025+
inline TypedArray::TypedArray(napi_env env,
2026+
napi_value value,
2027+
napi_typedarray_type type,
2028+
size_t length)
2029+
: Object(env, value), _type(type), _length(length) {}
20292030

2031+
inline napi_typedarray_type TypedArray::TypedArrayType() const {
20302032
return _type;
20312033
}
20322034

20332035
inline uint8_t TypedArray::ElementSize() const {
2034-
switch (TypedArrayType()) {
2036+
switch (_type) {
20352037
case napi_int8_array:
20362038
case napi_uint8_array:
20372039
case napi_uint8_clamped_array:
@@ -2055,18 +2057,6 @@ inline uint8_t TypedArray::ElementSize() const {
20552057
}
20562058

20572059
inline size_t TypedArray::ElementLength() const {
2058-
if (_type == TypedArray::unknown_array_type) {
2059-
napi_status status =
2060-
napi_get_typedarray_info(_env,
2061-
_value,
2062-
&const_cast<TypedArray*>(this)->_type,
2063-
&const_cast<TypedArray*>(this)->_length,
2064-
nullptr,
2065-
nullptr,
2066-
nullptr);
2067-
NAPI_THROW_IF_FAILED(_env, status, 0);
2068-
}
2069-
20702060
return _length;
20712061
}
20722062

napi.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,6 @@ class TypedArray : public Object {
11691169
napi_typedarray_type type,
11701170
size_t length);
11711171

1172-
static const napi_typedarray_type unknown_array_type =
1173-
static_cast<napi_typedarray_type>(-1);
1174-
11751172
template <typename T>
11761173
static
11771174
#if defined(NAPI_HAS_CONSTEXPR)
@@ -1191,7 +1188,7 @@ class TypedArray : public Object {
11911188
: std::is_same<T, int64_t>::value ? napi_bigint64_array
11921189
: std::is_same<T, uint64_t>::value ? napi_biguint64_array
11931190
#endif // NAPI_VERSION > 5
1194-
: unknown_array_type;
1191+
: napi_int8_array;
11951192
}
11961193
/// !endcond
11971194
};

0 commit comments

Comments
 (0)