Closed Bug 308928 Opened 19 years ago Closed 18 years ago

Invalid input for the canvas fillStyle/strokeStyle throws an exception but should be ignored

Categories

(Core :: Graphics: Canvas2D, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: kamiel, Assigned: asqueella)

References

()

Details

(Keywords: testcase)

Attachments

(2 files, 3 obsolete files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4

When the fillStyle property gets an invalid colour/pattern/gradient assigned,
this results in a NS_ERROR_INVALID_ARG exception being thrown while according to
the specification these should be ignored:

'If the value is a string but is not a valid colour, or is neither a string, a
CanvasGradient, nor a CanvasPattern, then it must be ignored, and the attribute
must retain its previous value.'

Reproducible: Always

Steps to Reproduce:
1. Assign invalid string value to fillStyle (rgb(100%,0,0))

Actual Results:  
The scripts halts because of the exeception while the original value for
fillStyle/strokeStyle should be retained

Expected Results:  
Script should continue execution
Attached file Testcase (obsolete) —
This should draw a black rectangle on the canvas but doesn't.
Version: Trunk → 1.8 Branch
Hrm.  This may be a spec issue; I think that it should throw an exception -- silent failure sucks in so many ways, that I can't think of a good reason to specify it.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: lamespec
CSS parsing normally specifies swallowing errors, mainly as a forward-compatibility mechanism.  That said, it doesn't necessarily make sense to apply that to the DOM as well.

That said, either way, the spec could be clearer, but I think it says that it shouldn't throw, and I expect that's what Ian intended.  If nobody else (Safari, Opera) throws, we should match.

This bug is mentioned in http://annevankesteren.nl/2006/09/moving-square .
http://whatwg.org/specs/web-apps/current-work/#fillstyle
"On setting, strings should be parsed as CSS <color> values. [CSS3COLOR] If the value is a string but is not a valid colour, or is neither a string, a CanvasGradient, nor a CanvasPattern, then it must be ignored, and the attribute must retain its previous value."

I think it's pretty clear. Opera doesn't throw.
Keywords: testcase
Whiteboard: lamespec
Version: 1.8 Branch → Trunk
Attached patch patch (obsolete) — Splinter Review
Assignee: nobody → asqueella
Status: NEW → ASSIGNED
Attachment #241629 - Flags: superreview?(vladimir)
Attachment #241629 - Flags: review?(vladimir)
Or perhaps we want to report the error to the Error console?
We shouldn't have an NS_WARNING because content is broken -- they're for problems in the code.
Summary: Invalid input for the canvas fillStyle/strokStyle throws an exception but should be ignored → Invalid input for the canvas fillStyle/strokeStyle throws an exception but should be ignored
Attached patch patch (obsolete) — Splinter Review
OK, what about this? (Ignore the nsCanvasRenderingContext2D::StyleColorToString part, it's for another bug.)

I don't like that reported warnings are too unspecific in this and other cases, but I wouldn't like to fix it now in this bug.
Attachment #241629 - Attachment is obsolete: true
Attachment #241651 - Flags: superreview?(vladimir)
Attachment #241651 - Flags: review?(vladimir)
Attachment #241629 - Flags: superreview?(vladimir)
Attachment #241629 - Flags: review?(vladimir)
Comment on attachment 241651 [details] [diff] [review]
patch

I'm not excited about the changing of the returned format for colors, but I guess it /is/ in the spec, in excruciating detail. :)
Attachment #241651 - Flags: superreview?(vladimir)
Attachment #241651 - Flags: superreview+
Attachment #241651 - Flags: review?(vladimir)
Attachment #241651 - Flags: review+
Actually, please don't land the color getter parts as part of this patch -- they should be dealt with in bug 329593.  The error handling stuff is fine, though.
Removed the irrelevant part of the patch and fixed a dump typo.
Attachment #241651 - Attachment is obsolete: true
OS: Windows XP → All
Hardware: PC → All
Whiteboard: [checkin needed]
Target Milestone: --- → mozilla1.9alpha
Attached file another testcase
Clearer green/red testcase, which also includes more tests.
Attachment #196408 - Attachment is obsolete: true
Checked in on trunk:

Checking in content/canvas/src/nsCanvasRenderingContext2D.cpp;
/cvsroot/mozilla/content/canvas/src/nsCanvasRenderingContext2D.cpp,v  <--  nsCanvasRenderingContext2D.cpp
new revision: 1.73; previous revision: 1.72
done
Checking in dom/locales/en-US/chrome/dom/dom.properties;
/cvsroot/mozilla/dom/locales/en-US/chrome/dom/dom.properties,v  <--  dom.properties
new revision: 1.6; previous revision: 1.5
done
Checking in layout/style/nsCSSParser.cpp;
/cvsroot/mozilla/layout/style/nsCSSParser.cpp,v  <--  nsCSSParser.cpp
new revision: 3.329; previous revision: 3.328
done
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: