Fix getArrayData

This commit is contained in:
Luis Blanco 2019-08-09 14:12:07 +03:00
parent 670cef5102
commit f72cc86fc5
1 changed files with 16 additions and 12 deletions

View File

@ -305,21 +305,25 @@ inline Type* getArrayData(Napi::Env env, Napi::Object obj, int *num = nullptr) {
Type *data = nullptr; Type *data = nullptr;
if (num) { if (data.IsTypedArray()) {
*num = 0; Napi::ArrayBuffer arr = obj.As<Napi::TypedArray>().ArrayBuffer();
} if (num) {
*num = arr.ByteLength() / sizeof(Type);
if ( ! obj.IsArrayBuffer() ) { }
data = static_cast<Type *>(arr.Data());
} else if (data.IsArrayBuffer()) {
Napi::ArrayBuffer arr = obj.As<Napi::ArrayBuffer>();
if (num) {
*num = arr.ByteLength() / sizeof(Type);
}
data = static_cast<Type *>(arr.Data());
} else {
if (num) {
*num = 0;
}
JS_THROW("Argument must be of type `TypedArray`."); JS_THROW("Argument must be of type `TypedArray`.");
return data;
} }
Napi::ArrayBuffer arr = obj.As<Napi::ArrayBuffer>();
if (num) {
*num = arr.ByteLength() / sizeof(Type);
}
data = static_cast<Type *>(arr.Data());
return data; return data;
} }