Skip to content

[OffscreenCanvasRenderingContext2D] the-offscreen-canvas/2d.getcontext.exists.html contains redundant code that will not be reached when OffscreenCanvasRenderingContext2D is undefined #19799

@guest271314

Description

@guest271314

At https://github.com/web-platform-tests/wpt/blob/master/offscreen-canvas/the-offscreen-canvas/2d.getcontext.exists.html the current code is

var t = async_test("The 2D context is implemented");
t.step(function() {
var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');
var offscreenCanvas2 = new OffscreenCanvas(100, 50);
_assertDifferent(offscreenCanvas2.getContext('2d'), null, "offscreenCanvas2.getContext('2d')", "null");
t.done();
});

If OffscreenCanvasRenderingContext2D is undefined an exception will be thrown at Firefox and Nightly

[Exception... "Method not implemented" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line <Line No>" data: no]

before reaching the next line which again attempts to create a OffscreenCanvasRenderingContext2D that is not implemented.

Instead of trying to create the context twice the test can be modified to output true or false

"OffscreenCanvasRenderingContext2D" in globalThis // true or false

or

typeof OffscreenCanvasRenderingContext2D === "function" // true or false (https://stackoverflow.com/a/57304946)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions