diff --git a/include/addon-tools.hpp b/include/addon-tools.hpp index aea1ca3..3780180 100644 --- a/include/addon-tools.hpp +++ b/include/addon-tools.hpp @@ -267,23 +267,20 @@ inline Type* getArrayData(V8_VAR_OBJ obj, int *num = nullptr) { Type *data = nullptr; - if (num) { - *num = 0; - } - - if ( ! obj->IsArrayBufferView() ) { + if (obj->IsArrayBuffer()) { + v8::Local ab = obj.As(); + data = reinterpret_cast(ab->GetContents().Data()); + if (num) { *num = ab->ByteLength() / sizeof(Type); } + } else if (obj->IsTypedArray()) { + v8::Local ta = obj.As(); + data = static_cast(ta->Buffer()->GetContents().Data()) + ta->ByteOffset(); + if (num) { *num = ta->ByteLength() / sizeof(Type); } + } else { + if (num) { *num = 0; } Nan::ThrowError("Argument must be a TypedArray."); - return data; } - - V8_VAR_ABV arr = V8_VAR_ABV::Cast(obj); - if (num) { - *num = arr->ByteLength() / sizeof(Type); - } - data = reinterpret_cast(arr->Buffer()->GetContents().Data()); - + return data; - }