@@ -2003,19 +2003,13 @@ inline void DataView::WriteData(size_t byteOffset, T value) const {
2003
2003
// //////////////////////////////////////////////////////////////////////////////
2004
2004
2005
2005
inline TypedArray::TypedArray ()
2006
- : Object(), _type(TypedArray::unknown_array_type ), _length(0 ) {}
2006
+ : Object(), _type(napi_typedarray_type::napi_int8_array ), _length(0 ) {}
2007
2007
2008
2008
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 ) {
2019
2013
napi_status status =
2020
2014
napi_get_typedarray_info (_env,
2021
2015
_value,
@@ -2024,14 +2018,22 @@ inline napi_typedarray_type TypedArray::TypedArrayType() const {
2024
2018
nullptr ,
2025
2019
nullptr ,
2026
2020
nullptr );
2027
- NAPI_THROW_IF_FAILED (_env, status, napi_int8_array );
2021
+ NAPI_THROW_IF_FAILED_VOID (_env, status);
2028
2022
}
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) {}
2029
2030
2031
+ inline napi_typedarray_type TypedArray::TypedArrayType () const {
2030
2032
return _type;
2031
2033
}
2032
2034
2033
2035
inline uint8_t TypedArray::ElementSize () const {
2034
- switch (TypedArrayType () ) {
2036
+ switch (_type ) {
2035
2037
case napi_int8_array:
2036
2038
case napi_uint8_array:
2037
2039
case napi_uint8_clamped_array:
@@ -2055,18 +2057,6 @@ inline uint8_t TypedArray::ElementSize() const {
2055
2057
}
2056
2058
2057
2059
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
-
2070
2060
return _length;
2071
2061
}
2072
2062
0 commit comments