diff --git a/examples/addon/package.json b/examples/addon/package.json index 14f835c..7d90332 100644 --- a/examples/addon/package.json +++ b/examples/addon/package.json @@ -4,6 +4,6 @@ "private": true, "main": "index.js", "dependencies": { - "addon-tools-raub": "1.0.0" + "addon-tools-raub": "4.2.0" } } diff --git a/examples/deps/package.json b/examples/deps/package.json index 14f835c..7d90332 100644 --- a/examples/deps/package.json +++ b/examples/deps/package.json @@ -4,6 +4,6 @@ "private": true, "main": "index.js", "dependencies": { - "addon-tools-raub": "1.0.0" + "addon-tools-raub": "4.2.0" } } diff --git a/include/addon-tools.hpp b/include/addon-tools.hpp index 3780180..3e29d21 100644 --- a/include/addon-tools.hpp +++ b/include/addon-tools.hpp @@ -177,15 +177,6 @@ typedef Nan::Persistent V8_STORE_VAL; V8_VAR_ARR VAR = V8_VAR_ARR::Cast(_obj_##VAR) -#define REQ_TYPED_ARRAY_ARG(I, VAR, ARR) \ - REQ_OBJ_ARG(I, _obj_##VAR); \ - if ( ! _obj_##VAR->IsArrayBufferView() ) { \ - return Nan::ThrowTypeError("Argument " #I " must be an array buffer"); \ - } \ - v8::Local obj = Nan::To(_obj_##VAR).ToLocalChecked();\ - v8::Local VAR = obj.As(); - - #define SET_PROP(OBJ, KEY, VAL) OBJ->Set(JS_STR(KEY), VAL); #define SET_I(ARR, I, VAL) ARR->Set(I, VAL); @@ -270,13 +261,20 @@ inline Type* getArrayData(V8_VAR_OBJ obj, int *num = nullptr) { if (obj->IsArrayBuffer()) { v8::Local ab = obj.As(); data = reinterpret_cast(ab->GetContents().Data()); - if (num) { *num = ab->ByteLength() / sizeof(Type); } + 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); } + auto slice = static_cast(ta->Buffer()->GetContents().Data()); + data = reinterpret_cast(slice + ta->ByteOffset()); + if (num) { + *num = ta->ByteLength() / sizeof(Type); + } } else { - if (num) { *num = 0; } + if (num) { + *num = 0; + } Nan::ThrowError("Argument must be a TypedArray."); } diff --git a/test/package.json b/test/package.json index 0f2580a..6556a5c 100644 --- a/test/package.json +++ b/test/package.json @@ -8,7 +8,7 @@ "start": "mocha" }, "dependencies": { - "addon-tools-raub": "1.0.0", + "addon-tools-raub": "file:../", "chai": "^4.2.0", "mocha": "^5.2.0", "sinon": "^7.1.1"