From 6e442b994a53ec2ac1f469b0cd86de41caeb849e Mon Sep 17 00:00:00 2001 From: Tim Buschtoens Date: Wed, 29 Jul 2020 11:25:40 +0200 Subject: [PATCH] Relax createImageBitmap parameter check Allow null or undefined in place of the "options" parameter. Change-Id: I69048e7366781fc7842976c53f717c3d5f5b2bf8 --- src/tabris/ImageBitmap.js | 4 ++-- test/tabris/ImageBitmap.test.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/tabris/ImageBitmap.js b/src/tabris/ImageBitmap.js index bce188cc0..2172d69b1 100644 --- a/src/tabris/ImageBitmap.js +++ b/src/tabris/ImageBitmap.js @@ -118,14 +118,14 @@ function getOptions(args) { throw new TypeError(`${args.length} is not a valid argument count for any overload of createImageBitmap.`); } const options = {}; - if (args.length === 2) { + if (args.length === 2 && args[1] != null) { if (!(args[1] instanceof Object)) { throw new TypeError('Argument 2 of createImageBitmap is not an object.'); } Object.assign(options, args[1]); } else if (args.length >= 5) { if (args.length === 6) { - if (!(args[5] instanceof Object)) { + if (args[5] != null && !(args[5] instanceof Object)) { throw new TypeError('Argument 6 of createImageBitmap is not an object.'); } } diff --git a/test/tabris/ImageBitmap.test.js b/test/tabris/ImageBitmap.test.js index 93c6efdeb..1234e561a 100644 --- a/test/tabris/ImageBitmap.test.js +++ b/test/tabris/ImageBitmap.test.js @@ -398,6 +398,13 @@ describe('ImageBitmap', function() { }); }); + it('ignores null', function() { + createImageBitmap(new Blob(), null); + + const call = client.calls({type: 'tabris.ImageBitmap', op: 'create'})[0]; + expect(call.properties).to.deep.equal({}); + }); + }); describe('with source rectangle', function() { @@ -412,6 +419,15 @@ describe('ImageBitmap', function() { expect(call.properties).to.deep.equal(Object.assign({}, options, {rect})); }); + it('ignores null for options', function() { + const rect = {sx: 0, sy: 1, sw: 2, sh: 3}; + + createImageBitmap(new Blob(), rect.sx, rect.sy, rect.sw, rect.sh, null); + + const call = client.calls({type: 'tabris.ImageBitmap', op: 'create'})[0]; + expect(call.properties).to.deep.equal(Object.assign({}, {rect})); + }); + it('normalizes rect', function() { createImageBitmap(new Blob(), 0.1, 1, '2', 3);