Repository: google/closure-compiler (language: java)

Issue:
setTransform(matrix) missing for CanvasRenderingContext2D and CanvasPattern
* for CanvasRenderingContext2D the matrix variant is missing
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform
* for CanvasPattern the method is missing
https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform

Source: https://github.com/google/closure-compiler/blob/master/externs/browser/html5.js

upstream of https://github.com/google/elemental2/issues/145


Discussion / hints:
`CanvasRenderingContext2D` extends `BaseRenderingContext2D`

https://github.com/google/closure-compiler/blob/5f0ce35c6ccf72ffcda8bf28b8ab155b7de04b59/externs/browser/html5.js#L838-L843

From which it inherits `setTransform`

https://github.com/google/closure-compiler/blob/5f0ce35c6ccf72ffcda8bf28b8ab155b7de04b59/externs/browser/html5.js#L443-L444

However, we don't seem to have any prototype properties defined for `CanvasPattern` at all.
https://github.com/google/closure-compiler/blob/5f0ce35c6ccf72ffcda8bf28b8ab155b7de04b59/externs/browser/html5.js#L873

@zbynek would you be interested in creating a pull request to add one?
@brad4d thanks for the reply! The problem with `BaseRenderingContext2D.prototype.setTransform`
is that it expects 6 number parameters, even though the standard also allows just one parameter of the DOMMatrixInit type. 

I'm not sure what's the best way to describe both the old and the new syntax in the extern: maybe the first argument needs to be `number|DOMMatrixInit` and all the others marked as optional, but that seems to be sub-optimal for tools that process the  externs. @jDramaix would that generate 12 different syntaxes for Elemental2 (two for each number of arguments)?

If the 5 optional arguments are the best we can do, I can create a PR for that.
Looks like we need to also update the documentation links in `html5.js`

It currently points at
https://www.w3.org/TR/2dcontext/#canvasrenderingcontext2d

But the current standard (found via MDN) seems to be at
https://html.spec.whatwg.org/multipage/canvas.html
Yes, I think 5 optional parameters is really the only way to declare the new single-argument version of `setTransform` in the externs.

Fix patch:
diff --git a/externs/browser/html5.js b/externs/browser/html5.js
index 691e6c4a9a3..156dd699e9e 100644
--- a/externs/browser/html5.js
+++ b/externs/browser/html5.js
@@ -531,16 +531,16 @@ BaseRenderingContext2D.prototype.transform = function(
     m11, m12, m21, m22, dx, dy) {};
 
 /**
- * @param {number} m11
- * @param {number} m12
- * @param {number} m21
- * @param {number} m22
- * @param {number} dx
- * @param {number} dy
+ * @param {(number|DOMMatrixReadOnly)} m11OrMatrix
+ * @param {number=} m12
+ * @param {number=} m21
+ * @param {number=} m22
+ * @param {number=} dx
+ * @param {number=} dy
  * @return {undefined}
  */
 BaseRenderingContext2D.prototype.setTransform = function(
-    m11, m12, m21, m22, dx, dy) {};
+    m11OrMatrix, m12, m21, m22, dx, dy) {};
 
 /**
  * @return {undefined}
@@ -1017,6 +1017,12 @@ CanvasGradient.prototype.addColorStop = function(offset, color) {};
  */
 function CanvasPattern() {}
 
+/**
+ * @param {DOMMatrixReadOnly} matrix
+ * @return {undefined}
+ */
+CanvasPattern.prototype.setTransform = function(matrix) {};
+
 /**
  * @constructor
  * https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics


Test patch: