Passing undefined as the maxWidth argument of CRC2D.fillText does not behave correctly |
||||
Issue description
ctx.fillText("Hello World!", 10, 10, undefined);
behaves the same as:
ctx.fillText("Hello World!", 10, 10);
This should only be the case when using the [TreatUndefinedAs=Missing] exended attribute, which is not the case for this argument.
The correct behavior is convert to a number, which yields NaN. The IDL for fillText says the argument is an optional unrestricted double, so the NaN should get passed down to the implementation of fillText.
The tesxt preparation algorithm, which consume maxWidth, doe not state how to handle NaN: https://html.spec.whatwg.org/multipage/scripting.html#text-preparation-algorithm
It currently says: "If maxWidth was provided but is less than or equal to zero, return an empty array." It should probably be modified to say: "If maxWidth was provided but is less than or equal to zero or equal to NaN, return an empty array."
We should check what other implementations are doing to be sure.
,
Jun 21 2016
The behavior of passing null, undefined, and NaN is inconsistent through different browsers. Chrome: passing null and NaN is the same as passing 0, not showing anything. But fillText(text, x, y, undefined) == fillText(test, x, y) Edge: passing null, undefined, NaN are always treated the same as passing 0, which means not showing anything. Firefox: fillText(text, x, y, null) == fillText(text, x, y, undefined) == fillText(text, x, y). While passing NaN is the same as passing 0, not showing anything.
,
Jun 21 2016
,
Jun 21 2016
Could you start a thread on the whatwg issue tracker about this? FWIW, I think edge is the browser that is doing the right thing here. The spec needs to be clarified that NaN means draw nothing. Then everything else is well defined: ES6 spec says undefined converts to NaN, and null converts to 0.
,
Jun 21 2016
Filed here: https://github.com/whatwg/html/issues/1452
,
Jun 21 2016
The fact that NaN and undefined have different behaviors in Chrome suggests that there might be a bug in the bindings.
,
Jun 23 2016
Please refer to discussion here: https://codereview.chromium.org/2085973005/ The behavior is following the specs, and there is no bug. |
||||
►
Sign in to add a comment |
||||
Comment 1 by junov@chromium.org
, Jun 21 2016