Closed Bug 1006656 Opened 10 years ago Closed 10 years ago

SetLineDash with negative values doesn't react as per the spec

Categories

(Core :: Graphics: Canvas2D, defect)

30 Branch
x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla32

People

(Reporter: david+bugzilla, Assigned: david+bugzilla)

Details

Attachments

(2 files, 4 obsolete files)

Attached file firefox-canvas-linedash.html (obsolete) —
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140428174145

Steps to reproduce:

I recently added lineDash support to a canvas implementation for node.js (https://github.com/LearnBoost/node-canvas/pull/373) and while testing I noticed that Firefox and Chrome differed in how they handle bad line values passed to setLineDash().

After reading the w3 specs, I think that Chrome is handling things correctly and Firefox is not.

I've attached a test case that illustrates the issue.


Actual results:

In the test case I see 3 solid red lines.

This means that Firefox reset the line dash setting to the default when bad values were passed to setLineDash().


Expected results:

The red lines should retain the same line dash settings as the green line above them.

The spec says (http://www.w3.org/TR/2dcontext/#line-styles):

  When the setLineDash() method is invoked, it must run the following steps:

    1. Let a be a copy of the array provided as the argument.

    2. If any value in the array is not finite (e.g. an Infinity or a NaN
       value), or if any value is negative (less than zero), then abort
       these steps (without throwing an exception; user agents could show a
       message on a developer console, though, as that would be helpful for
       debugging).

    3. If the number of elements in a is odd, then let a be the
       concatentation of two copies of a.

    4. Let the object's dash list be a.

From my reading, step 2 means that it should abort without proceeding to step 4, and so the line dash should not be changed when bad values are encountered.
Attached patch Proposed Patch (obsolete) — Splinter Review
I went ahead and had a go at making a patch for this. The patch is simple--it creates a new array, bailing out if it finds an invalid input. If it makes it to the end, it assigns over top of the old dash array, just like the SetMozDash() setter does it.

In fact, I even stole the float checking expression from JSValToDashArray() in CanvasUtil.h (which is what SetMozDash() uses).

After applying this patch, the test case gives me the dashed red lines that I expect.
Attached patch setlinedash.patch (obsolete) — Splinter Review
I've amended my patch to include a testcase.
Attachment #8418552 - Attachment is obsolete: true
Attachment #8427298 - Flags: review?(roc)
The patch looks great. However, it seems to me that this is actually a WebIDL bug; setLineDash takes a sequence<double>, so non-finite values shouldn't even reach our C++ code here. We would however have to annotate setLineDash with LenientFloat to get the correct behavior.

bz, am I right?
Flags: needinfo?(bzbarsky)
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #3)
> The patch looks great. However, it seems to me that this is actually a
> WebIDL bug; setLineDash takes a sequence<double>, so non-finite values
> shouldn't even reach our C++ code here.

Ah, I see: my original testcase tested for negative values, which make it through the WebIDL bindings (since they are finite). The subsequent tests failed, but only because the first one had failed (a poor test on my part).

So: the patch doesn't need to test for NaN or Infinity, just negative. I'll update that momentarily.
Attached a more correct visual test showing that only negatives behave incorrectly.
Attachment #8418176 - Attachment is obsolete: true
Attached patch set-linedash-r2.patch (obsolete) — Splinter Review
This new patch stops checking for finite in the C++ code, but still checks for negative.

I also updated the test to reset the line dash before each test so test failures don't cascade.
Attachment #8427298 - Attachment is obsolete: true
Attachment #8427298 - Flags: review?(roc)
Attachment #8427407 - Flags: review?(roc)
Ah, brilliant. I should have known our WebIDL code was flawless :-)
Flags: needinfo?(bzbarsky)
This is the same as the last patch, but has the required check-in comment and author name, ready for committing.
Attachment #8427407 - Attachment is obsolete: true
Attachment #8427420 - Flags: checkin?
Summary: SetLineDash with invalid values doesn't react as per the spec → SetLineDash with negative values doesn't react as per the spec
Oops, I already checked in with my own checkin comment (but your name of course):

https://hg.mozilla.org/integration/mozilla-inbound/rev/d18ebc644b89

Thanks!!!
No worries. Thanks!
Attachment #8427420 - Flags: checkin? → checkin+
clearing the checkin flag since roc did the checkin :) Also David thanks for contributing to Mozilla!
Assignee: nobody → david+bugzilla
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
https://hg.mozilla.org/mozilla-central/rev/d18ebc644b89
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla32
QA Whiteboard: [good first verify]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: