Skip to content

Commit 83d9da9

Browse files
committed
Merge pull request #671 from zbjornson/master
Use Nan::TypedArrayContents, fix a signed/unsigned comp warning
2 parents f12c54f + 83a8b27 commit 83d9da9

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test-server": "node test/server.js"
3030
},
3131
"dependencies": {
32-
"nan": "^2.0.9"
32+
"nan": "^2.1.0"
3333
},
3434
"devDependencies": {
3535
"body-parser": "^1.13.3",

src/CanvasRenderingContext2d.cc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -736,22 +736,15 @@ NAN_METHOD(Context2d::GetImageData) {
736736
Local<Object> global = Context::GetCurrent()->Global();
737737

738738
Local<Int32> sizeHandle = Nan::New(size);
739-
Local<Value> bufargv[] = { sizeHandle };
740-
Local<Object> buffer = global->Get(Nan::New("ArrayBuffer").ToLocalChecked()).As<Function>()->NewInstance(1, bufargv);
741-
742-
Local<Int32> zeroHandle = Nan::New(0);
743-
Local<Value> caargv[] = { buffer, zeroHandle, sizeHandle };
739+
Local<Value> caargv[] = { sizeHandle };
744740
Local<Object> clampedArray = global->Get(Nan::New("Uint8ClampedArray").ToLocalChecked()).As<Function>()->NewInstance(3, caargv);
745-
uint8_t *dst = (uint8_t *) clampedArray->GetIndexedPropertiesExternalArrayData();
746741
#else
747742
Local<ArrayBuffer> buffer = ArrayBuffer::New(Isolate::GetCurrent(), size);
748743
Local<Uint8ClampedArray> clampedArray = Uint8ClampedArray::New(buffer, 0, size);
749-
#if NODE_MAJOR_VERSION < 3
750-
uint8_t *dst = (uint8_t *)clampedArray->GetIndexedPropertiesExternalArrayData();
751-
#else
752-
uint8_t *dst = (uint8_t *)buffer->GetContents().Data();
753-
#endif
754744
#endif
745+
746+
Nan::TypedArrayContents<uint8_t> typedArrayContents(clampedArray);
747+
uint8_t* dst = *typedArrayContents;
755748

756749
// Normalize data (argb -> rgba)
757750
for (int y = 0; y < sh; ++y) {

src/ImageData.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ NAN_METHOD(ImageData::New) {
4242
Local<Uint8ClampedArray> clampedArray;
4343
#endif
4444

45-
int width;
46-
int height;
45+
uint32_t width;
46+
uint32_t height;
4747
int length;
4848

4949
if (info[0]->IsUint32() && info[1]->IsUint32()) {
@@ -104,13 +104,9 @@ NAN_METHOD(ImageData::New) {
104104
return;
105105
}
106106

107-
#if NODE_MAJOR_VERSION < 3
108-
void *dataPtr = clampedArray->GetIndexedPropertiesExternalArrayData();
109-
#else
110-
void *dataPtr = clampedArray->Buffer()->GetContents().Data();
111-
#endif
107+
Nan::TypedArrayContents<uint8_t> dataPtr(clampedArray);
112108

113-
ImageData *imageData = new ImageData(reinterpret_cast<uint8_t*>(dataPtr), width, height);
109+
ImageData *imageData = new ImageData(reinterpret_cast<uint8_t*>(*dataPtr), width, height);
114110
imageData->Wrap(info.This());
115111
info.This()->Set(Nan::New("data").ToLocalChecked(), clampedArray);
116112
info.GetReturnValue().Set(info.This());

0 commit comments

Comments
 (0)