Skip to content

Commit

Permalink
Issue #20623: Check the input to WebGLRenderingContext's clear().
Browse files Browse the repository at this point in the history
  • Loading branch information
simartin committed Apr 21, 2018
1 parent 05fe8fa commit f32ffeb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -1866,6 +1866,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
if !self.validate_framebuffer_complete() {
return;
}
if mask & !(constants::DEPTH_BUFFER_BIT | constants::STENCIL_BUFFER_BIT | constants::COLOR_BUFFER_BIT) != 0 {
return self.webgl_error(InvalidValue);
}

self.send_command(WebGLCommand::Clear(mask));
self.mark_as_dirty();
Expand Down
10 changes: 10 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -39229,6 +39229,12 @@
{}
]
],
"mozilla/webgl/clear.html": [
[
"/_mozilla/mozilla/webgl/clear.html",
{}
]
],
"mozilla/webgl/context_creation_error.html": [
[
"/_mozilla/mozilla/webgl/context_creation_error.html",
Expand Down Expand Up @@ -70864,6 +70870,10 @@
"c333c7b99156d63fcd3ad28014c7915a12cf8169",
"testharness"
],
"mozilla/webgl/clear.html": [
"14cc534be5da96b0cc128d5c44f662b2fdfb294c",
"testharness"
],
"mozilla/webgl/clearcolor.html": [
"942ee78ec987d17f63253ed97d6de958dbe8730d",
"reftest"
Expand Down
23 changes: 23 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/webgl/clear.html
@@ -0,0 +1,23 @@
<!doctype html>
<meta charset="utf-8">
<title>WebGLRenderingContext.clear testing (issue #20623)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
var gl = document.createElement("canvas").getContext("webgl");
// Valid values
gl.clear(gl.DEPTH_BUFFER_BIT);
assert_equals(gl.NO_ERROR, gl.getError());
gl.clear(gl.STENCIL_BUFFER_BIT);
assert_equals(gl.NO_ERROR, gl.getError());
gl.clear(gl.COLOR_BUFFER_BIT);
assert_equals(gl.NO_ERROR, gl.getError());
gl.clear(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT | gl.COLOR_BUFFER_BIT);
assert_equals(gl.NO_ERROR, gl.getError());

// Invalid value
gl.clear(42);
assert_equals(gl.INVALID_VALUE, gl.getError());
});
</script>

0 comments on commit f32ffeb

Please sign in to comment.