Browse Source

Merge pull request #750 from LinusU/lu-fix-749

Fix segfault in putImageData
v1.x
Linus Unnebäck 9 years ago
parent
commit
95eb35ebd4
  1. 2
      src/CanvasRenderingContext2d.cc
  2. 38
      test/canvas.test.js

2
src/CanvasRenderingContext2d.cc

@ -571,6 +571,8 @@ NAN_METHOD(Context2d::AddPage) {
*/
NAN_METHOD(Context2d::PutImageData) {
if (!info[0]->IsObject())
return Nan::ThrowTypeError("ImageData expected");
Local<Object> obj = info[0]->ToObject();
if (!Nan::New(ImageData::constructor)->HasInstance(obj))
return Nan::ThrowTypeError("ImageData expected");

38
test/canvas.test.js

@ -746,6 +746,44 @@ describe('Canvas', function () {
assert.equal(255, imageData.data[i+3]);
});
it('Context2d#getImageData()', function () {
var canvas = new Canvas(1, 1)
, ctx = canvas.getContext('2d');
assert.throws(function () { ctx.getImageData(0, 0, 0, 0); }, /IndexSizeError/);
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 1, 1);
var pixel = ctx.getImageData(0, 0, 1, 1);
assert.equal(pixel.data[0], 255);
assert.equal(pixel.data[1], 0);
assert.equal(pixel.data[2], 0);
assert.equal(pixel.data[3], 255);
});
it('Context2d#putImageData()', function () {
var canvas = new Canvas(2, 1)
, ctx = canvas.getContext('2d');
assert.throws(function () { ctx.putImageData({}, 0, 0); }, TypeError);
assert.throws(function () { ctx.putImageData(undefined, 0, 0); }, TypeError);
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 1, 1);
// Copy left pixel to the right pixel
ctx.putImageData(ctx.getImageData(0, 0, 1, 1), 1, 0);
var pixel = ctx.getImageData(1, 0, 1, 1);
assert.equal(pixel.data[0], 255);
assert.equal(pixel.data[1], 0);
assert.equal(pixel.data[2], 0);
assert.equal(pixel.data[3], 255);
});
it('Canvas#createSyncPNGStream()', function (done) {
var canvas = new Canvas(20, 20);
var stream = canvas.createSyncPNGStream();

Loading…
Cancel
Save