Closed Bug 1297211 Opened 5 years ago Closed 5 years ago

CanvasRenderingContext2D.drawImage can throw 0x80040111 (NS_ERROR_NOT_AVAILABLE)

Categories

(Core :: Canvas: 2D, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: Oriol, Assigned: lsalzman)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

Run this code in the console:

    document.createElement("canvas").getContext("2d")
    .drawImage(new Image(), 0, 0, 0, 0);

Result:

    [Exception... "Component is not available"
     nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"
     location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1"
     data: no]

I think that [checking the usability of the image argument][1] should return "bad" because the intrinsic width and height of the image are 0.

And then [drawImage][2] should abort, but without throwing.

Chrome and Edge don't throw.

[1]: https://html.spec.whatwg.org/multipage/scripting.html#check-the-usability-of-the-image-argument
[2]: https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-drawimage
Can you submit a webplatform test to https://github.com/w3c/web-platform-tests? That will make sure everyone has the same behaviour.
Flags: needinfo?(oriol-bugzilla)
Ok, great. Lee do you think you'd have time to look at this while I'm away next week? It should be pretty easy to fix.
This marks an image element with an empty source as available by letting its size be accessed so that canvas drawImage won't throw an error anymore, as the spec mandates.

This also fixes our results on several web platform tests that check for this behavior.
Assignee: nobody → lsalzman
Status: NEW → ASSIGNED
Attachment #8787715 - Flags: review?(mchang)
Attachment #8787715 - Flags: review?(mchang) → review+
Pushed by lsalzman@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/52eed50488c2
treat an empty src as available in image requests for canvas2d drawImage. r=mchang
https://hg.mozilla.org/mozilla-central/rev/52eed50488c2
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
Duplicate of this bug: 405761
Depends on: 1328005
You need to log in before you can comment on or make changes to this bug.