File tree 2 files changed +12
-5
lines changed
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -2834,20 +2834,27 @@ inline void ArrayBuffer::Detach() {
2834
2834
}
2835
2835
2836
2836
template <typename T>
2837
- inline Buffer<T>::Buffer () : Uint8Array () {}
2837
+ inline Buffer<T>::Buffer () : Object () {}
2838
2838
2839
2839
template <typename T>
2840
2840
inline Buffer<T>::Buffer (napi_env env, napi_value value)
2841
- : Uint8Array (env, value) {}
2841
+ : Object (env, value) {}
2842
2842
2843
2843
template <typename T>
2844
2844
inline size_t Buffer<T>::Length () const {
2845
- return ByteLength () / sizeof (T);
2845
+ void *data = nullptr ;
2846
+ size_t length = 0 ;
2847
+ napi_status status = napi_get_buffer_info (_env, _value, &data, &length);
2848
+ NAPI_THROW_IF_FAILED (_env, status, Buffer<T>());
2849
+ return length;
2846
2850
}
2847
2851
2848
2852
template <typename T>
2849
2853
inline T* Buffer<T>::Data () const {
2850
- return reinterpret_cast <T*>(const_cast <uint8_t *>(Uint8Array::Data ()));
2854
+ void *data = nullptr ;
2855
+ size_t length = 0 ;
2856
+ napi_get_buffer_info (_env, _value, &data, &length);
2857
+ return reinterpret_cast <T*>(data);
2851
2858
}
2852
2859
2853
2860
// //////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change @@ -1516,7 +1516,7 @@ class Date : public Value {
1516
1516
};
1517
1517
1518
1518
template <typename T>
1519
- class Buffer : public Uint8Array {
1519
+ class Buffer : public Object {
1520
1520
public:
1521
1521
static Buffer<T> New (napi_env env, size_t length);
1522
1522
#ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
You can’t perform that action at this time.
0 commit comments