Skip to content

Commit

Permalink
Relax createImageBitmap parameter check
Browse files Browse the repository at this point in the history
Allow null or undefined in place of the "options" parameter.

Change-Id: I69048e7366781fc7842976c53f717c3d5f5b2bf8
  • Loading branch information
tbuschto committed Jul 29, 2020
1 parent 78b55dc commit 6e442b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tabris/ImageBitmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/tabris/ImageBitmap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);

Expand Down

0 comments on commit 6e442b9

Please sign in to comment.