[whatwg] Canvas.getContext error handling

Glenn Maynard glenn at zewt.org
Sat Apr 9 19:55:24 PDT 2011


getContext doesn't specify error handling.  WebGL solves this oddly: if an
error occurs, it dispatches an event with error details at the canvas.  It's
odd for a synchronous API to report error information with an event; it
would make a lot more sense to raise an exception.  However, getContext
doesn't specify error handling for the "Return a new object for contextId"
algorithms.

The "primary context" should only be set by getContext after "Return a new
object for contextId" completes successfully; it shouldn't be set on error.
The cached return value used in step 5 should also only happen after
success; don't cache a null response.  This way, you can retry getContext on
failure, and getContext is a straightforward no-op after an error.

(I don't know if the WebGL folks could be convinced to change to throwing an
exception or if they want to continue returning null and firing an event.)

Related thread:
https://www.khronos.org/webgl/public-mailing-list/archives/1104/msg00027.html

-- 
Glenn Maynard


More information about the whatwg mailing list