Skip to content

Commit 7023bee

Browse files
committed
fix deprecated GetContent/ use GetBackingStore instead
1 parent abb1f1e commit 7023bee

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Util.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,34 +82,42 @@ inline v8::Local<v8::Value> makeArrayBuffer(int length) {
8282
return array_buffer.ToLocalChecked();
8383
}
8484

85+
template <typename T,class V> T* getArrayData(V&& value) {
86+
#if (V8_MAJOR_VERSION >= 8)
87+
return (T*)(static_cast<char*>(value->Buffer()->GetBackingStore()->Data()) + value->ByteOffset());
88+
#else
89+
return (T*)(static_cast<char*>(value->Buffer()->GetContents().Data()) + value->ByteOffset());
90+
#endif
91+
}
92+
8593
#define IS_FLOAT32ARRAY(value) (value->IsFloat32Array() && (value.As<v8::Float32Array>()->Length() == 2))
86-
#define GET_FLOAT32ARRAY_DATA(value) (float*)(static_cast<char*>(value.As<v8::Float32Array>()->Buffer()->GetContents().Data()) + value.As<v8::Float32Array>()->ByteOffset())
94+
#define GET_FLOAT32ARRAY_DATA(value) getArrayData<float>(value.As<v8::Float32Array>())
8795
#define IS_FLOAT32ARRAY_ARRAY(value) (value->IsFloat32Array() && ((value.As<v8::Float32Array>()->Length() % 2) == 0))
8896
#define GET_FLOAT32ARRAY_ARRAY_DATA(value) GET_FLOAT32ARRAY_DATA(value)
8997
#define GET_FLOAT32ARRAY_ARRAY_LENGTH(value) (value.As<v8::Float32Array>()->Length())
9098

9199

92100
#define IS_INT32ARRAY(value) (value->IsInt32Array() && (value.As<v8::Int32Array>()->Length() == 2))
93-
#define GET_INT32ARRAY_DATA(value) (int*)(static_cast<char*>(value.As<v8::Int32Array>()->Buffer()->GetContents().Data()) + value.As<v8::Int32Array>()->ByteOffset())
101+
#define GET_INT32ARRAY_DATA(value) getArrayData<int32_t>(value.As<v8::Int32Array>())
94102
#define IS_INT32ARRAY_ARRAY(value) (value->IsInt32Array() && ((value.As<v8::Int32Array>()->Length() % 2) == 0))
95103
#define GET_INT32ARRAY_ARRAY_DATA(value) GET_INT32ARRAY_DATA(value)
96104
#define GET_INT32ARRAY_ARRAY_LENGTH(value) (value.As<v8::Int32Array>()->Length())
97105

98106
#define IS_UINT32ARRAY(value) (value->IsUint32Array() && (value.As<v8::Uint32Array>()->Length() == 2))
99-
#define GET_UINT32ARRAY_DATA(value) (unsigned int*)(static_cast<char*>(value.As<v8::Uint32Array>()->Buffer()->GetContents().Data()) + value.As<v8::Uint32Array>()->ByteOffset())
107+
#define GET_UINT32ARRAY_DATA(value) getArrayData<uint32_t>(value.As<v8::Uint32Array>())
100108
#define IS_UINT32ARRAY_ARRAY(value) (value->IsUint32Array() && ((value.As<v8::Uint32Array>()->Length() % 2) == 0))
101109
#define GET_UINT32ARRAY_ARRAY_DATA(value) GET_UINT32ARRAY_DATA(value)
102110
#define GET_UINT32ARRAY_ARRAY_LENGTH(value) (value.As<v8::Uint32Array>()->Length())
103111

104112

105113
#define IS_UINT16ARRAY(value) (value->IsUint16Array() && (value.As<v8::Uint16Array>()->Length() == 2))
106-
#define GET_UINT16ARRAY_DATA(value) (unsigned short*)(static_cast<char*>(value.As<v8::Uint16Array>()->Buffer()->GetContents().Data()) + value.As<v8::Uint16Array>()->ByteOffset())
114+
#define GET_UINT16ARRAY_DATA(value) getArrayData<uint16_t>(value.As<v8::Uint16Array>())
107115
#define IS_UINT16ARRAY_ARRAY(value) (value->IsUint32Array() && ((value.As<v8::Uint16Array>()->Length() % 2) == 0))
108116
#define GET_UINT16ARRAY_ARRAY_DATA(value) GET_UINT16ARRAY_DATA(value)
109117
#define GET_UINT16ARRAY_ARRAY_LENGTH(value) (value.As<v8::Uint16Array>()->Length())
110118

111119
#define IS_UINT8ARRAY(value) (value->IsUint8Array() && (value.As<v8::Uint8Array>()->Length() == 2))
112-
#define GET_UINT8ARRAY_DATA(value) (unsigned char*)(static_cast<char*>(value.As<v8::Uint8Array>()->Buffer()->GetContents().Data()) + value.As<v8::Uint8Array>()->ByteOffset())
120+
#define GET_UINT8ARRAY_DATA(value) getArrayData<uint8_t>(value.As<v8::Uint8Array>())
113121
#define IS_UINT8ARRAY_ARRAY(value) (value->IsUint8Array() && ((value.As<v8::Uint8Array>()->Length() % 2) == 0))
114122
#define GET_UINT8ARRAY_ARRAY_DATA(value) GET_UINT8ARRAY_DATA(value)
115123
#define GET_UINT8ARRAY_ARRAY_LENGTH(value) (value.As<v8::Uint8Array>()->Length())

0 commit comments

Comments
 (0)