browser: fix jsdom exception drawing in canvas

jsdom requires that the tile is a HTMLCanvasElement element type

Receiver.dataMessage (private/mmeeks/deltas/browser/node_modules/ws/lib/receiver.js:51
7:14) TypeError: The first argument must be an object
    at CanvasRenderingContext2D.ctx.<computed> [as drawImage] (private/mmeeks/deltas/browser/
node_modules/jsdom/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js:124:17)
    at TilesSection.paintSimple (private/mmeeks/deltas/browser/dist/bundle.js:1:136355
4)
    at TilesSection.paint (private/mmeeks/deltas/browser/dist/bundle.js:1:1364132)
    at TilesSection.<anonymous> (private/mmeeks/deltas/browser/dist/bundle.js:1:136981
2)

Change-Id: I55b77e3a9ae80afd519f1a6c6c5388070c85193e
Signed-off-by: Henry Castro <hcastro@collabora.com>
This commit is contained in:
Henry Castro 2022-04-28 08:56:19 -04:00 committed by Michael Meeks
parent e382d52102
commit 28d940eb93

View file

@ -29,6 +29,7 @@ class TilesSection {
map: any;
offscreenCanvases: Array<any> = new Array(0);
oscCtxs: Array<any> = new Array(0);
isJSDOM: boolean = false; // testing
isCalcRTL: () => boolean;
@ -52,6 +53,7 @@ class TilesSection {
this.sectionProperties.pageBackgroundFillColorWriter = 'white';
this.sectionProperties.pageBackgroundTextColor = 'grey';
this.sectionProperties.pageBackgroundFont = String(40 * app.roundedDpiScale) + 'px Arial';
this.isJSDOM = typeof window === 'object' && window.name === 'nodejs';
}
public onInitialize () {
@ -427,7 +429,13 @@ class TilesSection {
// Ensure tile is loaded and is within document bounds.
if (tile && tile.loaded && docLayer._isValidTile(coords)) {
this.paint(tile, ctx, false /* async? */);
if (this.isJSDOM) // perf-test code
{
if (tile.el && (tile.el instanceof HTMLCanvasElement))
this.paint(tile, ctx, false /* async? */);
}
else
this.paint(tile, ctx, false /* async? */);
}
doneTiles.add(coords.key());
return true; // continue with remaining tiles.