Bug 1237191 - Add check for getQueryParameter to return correct error. r=jgilbert
authorEthan Lin <ethlin@mozilla.com>
Thu, 07 Jan 2016 20:05:00 +0100
changeset 320218 adfe8792f603842f79ea9394a7b7001e024130be
parent 320217 d538bcfa4e69980a85c62f4dd2199a8ffa258994
child 320219 e0603b355f0c98b14c7dc8ca4784c26aca550937
push id9164
push useratolfsen@mozilla.com
push dateSat, 09 Jan 2016 21:37:35 +0000
reviewersjgilbert
bugs1237191
milestone46.0a1
Bug 1237191 - Add check for getQueryParameter to return correct error. r=jgilbert
dom/canvas/WebGL2ContextQueries.cpp
--- a/dom/canvas/WebGL2ContextQueries.cpp
+++ b/dom/canvas/WebGL2ContextQueries.cpp
@@ -282,25 +282,42 @@ WebGL2Context::GetQuery(GLenum target, G
     if (tmp && tmp->mType != target) {
         // Query in slot doesn't match target
         return nullptr;
     }
 
     return tmp.forget();
 }
 
+static bool
+ValidateQueryEnum(WebGLContext* webgl, GLenum pname, const char* info)
+{
+    switch (pname) {
+    case LOCAL_GL_QUERY_RESULT_AVAILABLE:
+    case LOCAL_GL_QUERY_RESULT:
+        return true;
+
+    default:
+        webgl->ErrorInvalidEnum("%s: invalid pname: %s", info, webgl->EnumName(pname));
+        return false;
+    }
+}
+
 void
 WebGL2Context::GetQueryParameter(JSContext*, WebGLQuery* query, GLenum pname,
                                  JS::MutableHandleValue retval)
 {
     retval.set(JS::NullValue());
 
     if (IsContextLost())
         return;
 
+    if (!ValidateQueryEnum(this, pname, "getQueryParameter"))
+        return;
+
     if (!query) {
         /* OpenGL ES 3.0 spec 6.1.7 (spec getQueryObject 1):
          *    If id is not the name of a query object, or if the query object
          *    named by id is currently active, then an INVALID_OPERATION error
          *    is generated. pname must be QUERY_RESULT or
          *    QUERY_RESULT_AVAILABLE.
          */
         ErrorInvalidOperation("getQueryObject: `query` should not be null.");
@@ -325,16 +342,19 @@ WebGL2Context::GetQueryParameter(JSConte
          *     mean that query->mGLName is not a query object yet.
          */
         ErrorInvalidOperation("getQueryObject: `query` has never been active.");
         return;
     }
 
     // We must wait for an event loop before the query can be available
     if (!query->mCanBeAvailable && !gfxPrefs::WebGLImmediateQueries()) {
+        if (pname == LOCAL_GL_QUERY_RESULT_AVAILABLE) {
+            retval.set(JS::BooleanValue(false));
+        }
         return;
     }
 
     MakeContextCurrent();
     GLuint returned = 0;
     switch (pname) {
     case LOCAL_GL_QUERY_RESULT_AVAILABLE:
         gl->fGetQueryObjectuiv(query->mGLName, LOCAL_GL_QUERY_RESULT_AVAILABLE, &returned);