Bug 1099427 - Reformat WebGL. - r=kamidphish
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 13 Nov 2014 20:03:50 -0800
changeset 217811 10a7d6c3fa977bcc39c82ee01b94b5f7ce2fe46f
parent 217810 0cea8df6968107dc42d6dc2c0b7edc1b7a3d5f13
child 217812 df5c7392ecbf148b287bf0090be292fa52102ea2
push idunknown
push userunknown
push dateunknown
reviewerskamidphish
bugs1099427
milestone36.0a1
Bug 1099427 - Reformat WebGL. - r=kamidphish
dom/canvas/WebGL1Context.cpp
dom/canvas/WebGL2Context.cpp
dom/canvas/WebGL2Context.h
dom/canvas/WebGL2ContextQueries.cpp
dom/canvas/WebGL2ContextTextures.cpp
dom/canvas/WebGLActiveInfo.cpp
dom/canvas/WebGLActiveInfo.h
dom/canvas/WebGLBuffer.cpp
dom/canvas/WebGLBuffer.h
dom/canvas/WebGLContext.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextBuffers.cpp
dom/canvas/WebGLContextDraw.cpp
dom/canvas/WebGLContextExtensions.cpp
dom/canvas/WebGLContextGL.cpp
dom/canvas/WebGLContextLossHandler.cpp
dom/canvas/WebGLContextLossHandler.h
dom/canvas/WebGLContextNotSupported.cpp
dom/canvas/WebGLContextReporter.cpp
dom/canvas/WebGLContextUtils.cpp
dom/canvas/WebGLContextUtils.h
dom/canvas/WebGLContextValidate.cpp
dom/canvas/WebGLContextVertexArray.cpp
dom/canvas/WebGLContextVertices.cpp
dom/canvas/WebGLElementArrayCache.cpp
dom/canvas/WebGLElementArrayCache.h
dom/canvas/WebGLExtensionBlendMinMax.cpp
dom/canvas/WebGLExtensionColorBufferFloat.cpp
dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp
dom/canvas/WebGLExtensionCompressedTextureATC.cpp
dom/canvas/WebGLExtensionCompressedTextureETC1.cpp
dom/canvas/WebGLExtensionCompressedTexturePVRTC.cpp
dom/canvas/WebGLExtensionCompressedTextureS3TC.cpp
dom/canvas/WebGLExtensionDebugRendererInfo.cpp
dom/canvas/WebGLExtensionDebugShaders.cpp
dom/canvas/WebGLExtensionDepthTexture.cpp
dom/canvas/WebGLExtensionDrawBuffers.cpp
dom/canvas/WebGLExtensionElementIndexUint.cpp
dom/canvas/WebGLExtensionFragDepth.cpp
dom/canvas/WebGLExtensionInstancedArrays.cpp
dom/canvas/WebGLExtensionLoseContext.cpp
dom/canvas/WebGLExtensionSRGB.cpp
dom/canvas/WebGLExtensionShaderTextureLod.cpp
dom/canvas/WebGLExtensionStandardDerivatives.cpp
dom/canvas/WebGLExtensionTextureFilterAnisotropic.cpp
dom/canvas/WebGLExtensionTextureFloat.cpp
dom/canvas/WebGLExtensionTextureFloatLinear.cpp
dom/canvas/WebGLExtensionTextureHalfFloat.cpp
dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp
dom/canvas/WebGLExtensionVertexArray.cpp
dom/canvas/WebGLExtensions.h
dom/canvas/WebGLFramebuffer.cpp
dom/canvas/WebGLFramebuffer.h
dom/canvas/WebGLMemoryTracker.h
dom/canvas/WebGLObjectModel.cpp
dom/canvas/WebGLObjectModel.h
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLProgram.h
dom/canvas/WebGLQuery.cpp
dom/canvas/WebGLQuery.h
dom/canvas/WebGLRenderbuffer.cpp
dom/canvas/WebGLRenderbuffer.h
dom/canvas/WebGLSampler.cpp
dom/canvas/WebGLSampler.h
dom/canvas/WebGLShader.cpp
dom/canvas/WebGLShader.h
dom/canvas/WebGLShaderPrecisionFormat.cpp
dom/canvas/WebGLShaderPrecisionFormat.h
dom/canvas/WebGLStrongTypes.h
dom/canvas/WebGLSync.cpp
dom/canvas/WebGLSync.h
dom/canvas/WebGLTexelConversions.cpp
dom/canvas/WebGLTexture.cpp
dom/canvas/WebGLTexture.h
dom/canvas/WebGLTransformFeedback.cpp
dom/canvas/WebGLTransformFeedback.h
dom/canvas/WebGLUniformLocation.cpp
dom/canvas/WebGLUniformLocation.h
dom/canvas/WebGLValidateStrings.h
dom/canvas/WebGLVertexArray.cpp
dom/canvas/WebGLVertexArray.h
dom/canvas/WebGLVertexArrayFake.cpp
dom/canvas/WebGLVertexArrayFake.h
dom/canvas/WebGLVertexArrayGL.cpp
dom/canvas/WebGLVertexArrayGL.h
dom/canvas/WebGLVertexAttribData.h
dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp
dom/canvas/compiledtest/moz.build
dom/canvas/moz.build
--- a/dom/canvas/WebGL1Context.cpp
+++ b/dom/canvas/WebGL1Context.cpp
@@ -20,30 +20,24 @@ WebGL1Context::WebGL1Context()
     : WebGLContext()
 {
 }
 
 WebGL1Context::~WebGL1Context()
 {
 }
 
-////////////////////////////////////////
-// nsWrapperCache
-
 JSObject*
 WebGL1Context::WrapObject(JSContext* cx)
 {
     return dom::WebGLRenderingContextBinding::Wrap(cx, this);
 }
 
 } // namespace mozilla
 
-////////////////////////////////////////
-// nsIDOMWebGLRenderingContext
-
 nsresult
 NS_NewCanvasRenderingContextWebGL(nsIDOMWebGLRenderingContext** out_result)
 {
     mozilla::Telemetry::Accumulate(mozilla::Telemetry::CANVAS_WEBGL_USED, 1);
 
     nsIDOMWebGLRenderingContext* ctx = mozilla::WebGL1Context::Create();
 
     NS_ADDREF(*out_result = ctx);
--- a/dom/canvas/WebGL2Context.cpp
+++ b/dom/canvas/WebGL2Context.cpp
@@ -1,65 +1,53 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGL2Context.h"
+
 #include "GLContext.h"
 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 
-using namespace mozilla;
-using namespace mozilla::gl;
-
-// -----------------------------------------------------------------------------
-// CONSTRUCTOR & DESTRUCTOR
+namespace mozilla {
 
 WebGL2Context::WebGL2Context()
     : WebGLContext()
 {
     MOZ_ASSERT(IsSupported(), "not supposed to create a WebGL2Context"
                               "context when not supported");
 }
 
 WebGL2Context::~WebGL2Context()
 {
 
 }
 
-
-// -----------------------------------------------------------------------------
-// STATIC FUNCTIONS
-
-bool
+/*static*/ bool
 WebGL2Context::IsSupported()
 {
     return Preferences::GetBool("webgl.enable-prototype-webgl2", false);
 }
 
-WebGL2Context*
+/*static*/ WebGL2Context*
 WebGL2Context::Create()
 {
     return new WebGL2Context();
 }
 
-
-// -----------------------------------------------------------------------------
-// IMPLEMENT nsWrapperCache
-
 JSObject*
-WebGL2Context::WrapObject(JSContext *cx)
+WebGL2Context::WrapObject(JSContext* cx)
 {
     return dom::WebGL2RenderingContextBinding::Wrap(cx, this);
 }
 
-
-// -----------------------------------------------------------------------------
+////////////////////////////////////////////////////////////////////////////////
 // WebGL 2 initialisation
 
 bool
 WebGLContext::InitWebGL2()
 {
     MOZ_ASSERT(IsWebGL2(), "WebGLContext is not a WebGL 2 context!");
 
     const WebGLExtensionID sExtensionNativelySupportedArr[] = {
@@ -71,63 +59,65 @@ WebGLContext::InitWebGL2()
         WebGLExtensionID::OES_texture_float,
         WebGLExtensionID::OES_texture_float_linear,
         WebGLExtensionID::OES_texture_half_float,
         WebGLExtensionID::OES_texture_half_float_linear,
         WebGLExtensionID::OES_vertex_array_object,
         WebGLExtensionID::WEBGL_depth_texture,
         WebGLExtensionID::WEBGL_draw_buffers
     };
-    const GLFeature sFeatureRequiredArr[] = {
-        GLFeature::instanced_non_arrays,
-        GLFeature::transform_feedback2,
-        GLFeature::invalidate_framebuffer
+    const gl::GLFeature sFeatureRequiredArr[] = {
+        gl::GLFeature::instanced_non_arrays,
+        gl::GLFeature::transform_feedback2,
+        gl::GLFeature::invalidate_framebuffer
     };
 
     // check WebGL extensions that are supposed to be natively supported
-    for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++)
-    {
+    size_t len = MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr);
+    for (size_t i = 0; i < len; i++) {
         WebGLExtensionID extension = sExtensionNativelySupportedArr[i];
 
         if (!IsExtensionSupported(extension)) {
             GenerateWarning("WebGL 2 requires %s!", GetExtensionString(extension));
             return false;
         }
     }
 
     // check required OpenGL extensions
-    if (!gl->IsExtensionSupported(GLContext::EXT_gpu_shader4)) {
+    if (!gl->IsExtensionSupported(gl::GLContext::EXT_gpu_shader4)) {
         GenerateWarning("WebGL 2 requires GL_EXT_gpu_shader4!");
         return false;
     }
 
     // check OpenGL features
-    if (!gl->IsSupported(GLFeature::occlusion_query) &&
-        !gl->IsSupported(GLFeature::occlusion_query_boolean))
+    if (!gl->IsSupported(gl::GLFeature::occlusion_query) &&
+        !gl->IsSupported(gl::GLFeature::occlusion_query_boolean))
     {
-        /*
-         * on desktop, we fake occlusion_query_boolean with occlusion_query if
-         * necessary. See WebGLContextAsyncQueries.cpp.
-         */
+        // On desktop, we fake occlusion_query_boolean with occlusion_query if
+        //necessary. (See WebGLContextAsyncQueries.cpp)
         GenerateWarning("WebGL 2 requires occlusion queries!");
         return false;
     }
 
-    for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sFeatureRequiredArr)); i++)
-    {
+    for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sFeatureRequiredArr)); i++) {
         if (!gl->IsSupported(sFeatureRequiredArr[i])) {
-            GenerateWarning("WebGL 2 requires GLFeature::%s!", GLContext::GetFeatureName(sFeatureRequiredArr[i]));
+            GenerateWarning("WebGL 2 requires GLFeature::%s!",
+                            gl::GLContext::GetFeatureName(sFeatureRequiredArr[i]));
             return false;
         }
     }
 
     // ok WebGL 2 is compatible, we can enable natively supported extensions.
-    for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++) {
+    len = MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr);
+    for (size_t i = 0; i < len; i++) {
         EnableExtension(sExtensionNativelySupportedArr[i]);
 
         MOZ_ASSERT(IsExtensionEnabled(sExtensionNativelySupportedArr[i]));
     }
 
     // we initialise WebGL 2 related stuff.
-    gl->GetUIntegerv(LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &mGLMaxTransformFeedbackSeparateAttribs);
+    gl->GetUIntegerv(LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
+                     &mGLMaxTransformFeedbackSeparateAttribs);
 
     return true;
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2Context.h
+++ b/dom/canvas/WebGL2Context.h
@@ -28,17 +28,17 @@ public:
     virtual bool IsWebGL2() const MOZ_OVERRIDE
     {
         return true;
     }
 
     // -------------------------------------------------------------------------
     // IMPLEMENT nsWrapperCache
 
-    virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
+    virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
 
 
     // -------------------------------------------------------------------------
     // Buffer objects - WebGL2ContextBuffers.cpp
 
     void CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
                            GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
     void GetBufferSubData(GLenum target, GLintptr offset, const dom::ArrayBuffer& returnedData);
--- a/dom/canvas/WebGL2ContextQueries.cpp
+++ b/dom/canvas/WebGL2ContextQueries.cpp
@@ -9,21 +9,21 @@
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 /*
  * We fake ANY_SAMPLES_PASSED and ANY_SAMPLES_PASSED_CONSERVATIVE with
  * SAMPLES_PASSED on desktop.
  *
- * OpenGL ES 3.0 spec 4.1.6
- *  If the target of the query is ANY_SAMPLES_PASSED_CONSERVATIVE, an
- *  implementation may choose to use a less precise version of the test which
- *  can additionally set the samples-boolean state to TRUE in some other
- *  implementation-dependent cases.
+ * OpenGL ES 3.0 spec 4.1.6:
+ *     If the target of the query is ANY_SAMPLES_PASSED_CONSERVATIVE, an
+ *     implementation may choose to use a less precise version of the test which
+ *     can additionally set the samples-boolean state to TRUE in some other
+ *     implementation-dependent cases.
  */
 
 static const char*
 GetQueryTargetEnumString(GLenum target)
 {
     switch (target)
     {
         case LOCAL_GL_ANY_SAMPLES_PASSED:
@@ -83,19 +83,19 @@ WebGL2Context::CreateQuery()
 
     if (mActiveOcclusionQuery && !gl->IsGLES()) {
         /* http://www.opengl.org/registry/specs/ARB/occlusion_query.txt
          *
          * Calling either GenQueriesARB or DeleteQueriesARB while any query of
          * any target is active causes an INVALID_OPERATION error to be
          * generated.
          */
-        GenerateWarning("createQuery: the WebGL 2 prototype might generate "
-                        "INVALID_OPERATION when creating a query object while "
-                        "one other is active.");
+        GenerateWarning("createQuery: The WebGL 2 prototype might generate"
+                        " INVALID_OPERATION when creating a query object while"
+                        " one other is active.");
         /*
          * We *need* to lock webgl2 to GL>=3.0 on desktop, but we don't have a
          * good mechanism to do this yet. See bug 898404.
          */
     }
 
     nsRefPtr<WebGLQuery> globj = new WebGLQuery(this);
 
@@ -119,19 +119,19 @@ WebGL2Context::DeleteQuery(WebGLQuery* q
 
     if (mActiveOcclusionQuery && !gl->IsGLES()) {
         /* http://www.opengl.org/registry/specs/ARB/occlusion_query.txt
          *
          * Calling either GenQueriesARB or DeleteQueriesARB while any query of
          * any target is active causes an INVALID_OPERATION error to be
          * generated.
          */
-        GenerateWarning("deleteQuery: the WebGL 2 prototype might generate "
-                        "INVALID_OPERATION when deleting a query object while "
-                        "one other is active.");
+        GenerateWarning("deleteQuery: The WebGL 2 prototype might generate"
+                        " INVALID_OPERATION when deleting a query object while"
+                        " one other is active.");
     }
 
     query->RequestDelete();
 }
 
 bool
 WebGL2Context::IsQuery(WebGLQuery* query)
 {
@@ -154,69 +154,66 @@ WebGL2Context::BeginQuery(GLenum target,
 
     WebGLRefPtr<WebGLQuery>* targetSlot = GetQueryTargetSlot(target);
     if (!targetSlot) {
         ErrorInvalidEnum("beginQuery: unknown query target");
         return;
     }
 
     if (!query) {
-        /* SPECS BeginQuery.1
-         * http://www.khronos.org/registry/gles/extensions/EXT/EXT_occlusion_query_boolean.txt
-         * BeginQueryEXT sets the active query object name for the query type given
-         * by <target> to <id>. If BeginQueryEXT is called with an <id> of zero, if
-         * the active query object name for <target> is non-zero (for the targets
-         * ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if the
-         * active query for either target is non-zero), if <id> is the name of an
-         * existing query object whose type does not match <target>, or if <id> is the
-         * active query object name for any query type, the error INVALID_OPERATION is
-         * generated.
+        /* From GLES's EXT_occlusion_query_boolean:
+         *     BeginQueryEXT sets the active query object name for the query
+         *     type given by <target> to <id>. If BeginQueryEXT is called with
+         *     an <id> of zero, if the active query object name for <target> is
+         *     non-zero (for the targets ANY_SAMPLES_PASSED_EXT and
+         *     ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if the active query for
+         *     either target is non-zero), if <id> is the name of an existing
+         *     query object whose type does not match <target>, or if <id> is
+         *     the active query object name for any query type, the error
+         *     INVALID_OPERATION is generated.
          */
-        ErrorInvalidOperation("beginQuery: query should not be null");
+        ErrorInvalidOperation("beginQuery: Query should not be null.");
         return;
     }
 
     if (query->IsDeleted()) {
-        /* http://www.khronos.org/registry/gles/extensions/EXT/EXT_occlusion_query_boolean.txt
-         * BeginQueryEXT fails and an INVALID_OPERATION error is generated if <id>
-         * is not a name returned from a previous call to GenQueriesEXT, or if such
-         * a name has since been deleted with DeleteQueriesEXT.
+        /* From GLES's EXT_occlusion_query_boolean:
+         *     BeginQueryEXT fails and an INVALID_OPERATION error is generated
+         *     if <id> is not a name returned from a previous call to
+         *     GenQueriesEXT, or if such a name has since been deleted with
+         *     DeleteQueriesEXT.
          */
-        ErrorInvalidOperation("beginQuery: query has been deleted");
+        ErrorInvalidOperation("beginQuery: Query has been deleted.");
         return;
     }
 
     if (query->HasEverBeenActive() &&
         query->mType != target)
     {
-        /*
-         * See SPECS BeginQuery.1
-         */
-        ErrorInvalidOperation("beginQuery: target doesn't match with the query type");
+        ErrorInvalidOperation("beginQuery: Target doesn't match with the query"
+                              " type.");
         return;
     }
 
     if (*targetSlot) {
-        /*
-         * See SPECS BeginQuery.1
-         */
-        ErrorInvalidOperation("beginQuery: an other query already active");
+        ErrorInvalidOperation("beginQuery: An other query already active.");
         return;
     }
 
-    if (!query->HasEverBeenActive()) {
+    if (!query->HasEverBeenActive())
         query->mType = target;
-    }
 
     MakeContextCurrent();
 
     if (target == LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN) {
-        gl->fBeginQuery(LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query->mGLName);
+        gl->fBeginQuery(LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
+                        query->mGLName);
     } else {
-        gl->fBeginQuery(SimulateOcclusionQueryTarget(gl, target), query->mGLName);
+        gl->fBeginQuery(SimulateOcclusionQueryTarget(gl, target),
+                        query->mGLName);
     }
 
     *targetSlot = query;
 }
 
 void
 WebGL2Context::EndQuery(GLenum target)
 {
@@ -224,28 +221,31 @@ WebGL2Context::EndQuery(GLenum target)
         return;
 
     WebGLRefPtr<WebGLQuery>* targetSlot = GetQueryTargetSlot(target);
     if (!targetSlot) {
         ErrorInvalidEnum("endQuery: unknown query target");
         return;
     }
 
-    if (!*targetSlot || target != (*targetSlot)->mType) {
-        /* http://www.khronos.org/registry/gles/extensions/EXT/EXT_occlusion_query_boolean.txt
-         * marks the end of the sequence of commands to be tracked for the query type
-         * given by <target>. The active query object for <target> is updated to
-         * indicate that query results are not available, and the active query object
-         * name for <target> is reset to zero. When the commands issued prior to
-         * EndQueryEXT have completed and a final query result is available, the
-         * query object active when EndQueryEXT is called is updated by the GL. The
-         * query object is updated to indicate that the query results are available
-         * and to contain the query result. If the active query object name for
-         * <target> is zero when EndQueryEXT is called, the error INVALID_OPERATION
-         * is generated.
+    if (!*targetSlot ||
+        target != (*targetSlot)->mType)
+    {
+        /* From GLES's EXT_occlusion_query_boolean:
+         *     marks the end of the sequence of commands to be tracked for the
+         *     query type given by <target>. The active query object for
+         *     <target> is updated to indicate that query results are not
+         *     available, and the active query object name for <target> is reset
+         *     to zero. When the commands issued prior to EndQueryEXT have
+         *     completed and a final query result is available, the query object
+         *     active when EndQueryEXT is called is updated by the GL. The query
+         *     object is updated to indicate that the query results are
+         *     available and to contain the query result. If the active query
+         *     object name for <target> is zero when EndQueryEXT is called, the
+         *     error INVALID_OPERATION is generated.
          */
         ErrorInvalidOperation("endQuery: There is no active query of type %s.",
                               GetQueryTargetEnumString(target));
         return;
     }
 
     MakeContextCurrent();
 
@@ -266,63 +266,65 @@ WebGL2Context::GetQuery(GLenum target, G
 
     WebGLRefPtr<WebGLQuery>* targetSlot = GetQueryTargetSlot(target);
     if (!targetSlot) {
         ErrorInvalidEnum("getQuery: unknown query target");
         return nullptr;
     }
 
     if (pname != LOCAL_GL_CURRENT_QUERY) {
-        /* OpenGL ES 3.0 spec 6.1.7
-         *  pname must be CURRENT_QUERY.
+        /* OpenGL ES 3.0 spec 6.1.7:
+         *     pname must be CURRENT_QUERY.
          */
-        ErrorInvalidEnum("getQuery: pname must be CURRENT_QUERY");
+        ErrorInvalidEnum("getQuery: `pname` must be CURRENT_QUERY.");
         return nullptr;
     }
 
     nsRefPtr<WebGLQuery> tmp = targetSlot->get();
     return tmp.forget();
 }
 
 void
-WebGL2Context::GetQueryParameter(JSContext*, WebGLQuery* query, GLenum pname, JS::MutableHandleValue retval)
+WebGL2Context::GetQueryParameter(JSContext*, WebGLQuery* query, GLenum pname,
+                                 JS::MutableHandleValue retval)
 {
     retval.set(JS::NullValue());
 
     if (IsContextLost())
         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.
+        /* 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");
+        ErrorInvalidOperation("getQueryObject: `query` should not be null.");
         return;
     }
 
     if (query->IsDeleted()) {
         // See (spec getQueryObject 1)
-        ErrorInvalidOperation("getQueryObject: query has been deleted");
+        ErrorInvalidOperation("getQueryObject: `query` has been deleted.");
         return;
     }
 
     if (query->IsActive()) {
         // See (spec getQueryObject 1)
-        ErrorInvalidOperation("getQueryObject: query is active");
+        ErrorInvalidOperation("getQueryObject: `query` is active.");
         return;
     }
 
     if (!query->HasEverBeenActive()) {
         /* See (spec getQueryObject 1)
-         *  If this instance of WebGLQuery has never been active before, that mean that
-         *  query->mGLName is not a query object yet.
+         *     If this instance of WebGLQuery has never been active before, that
+         *     mean that query->mGLName is not a query object yet.
          */
-        ErrorInvalidOperation("getQueryObject: query has never been active");
+        ErrorInvalidOperation("getQueryObject: `query` has never been active.");
         return;
     }
 
     MakeContextCurrent();
     GLuint returned = 0;
     switch (pname) {
     case LOCAL_GL_QUERY_RESULT_AVAILABLE:
         gl->fGetQueryObjectuiv(query->mGLName, LOCAL_GL_QUERY_RESULT_AVAILABLE, &returned);
@@ -344,10 +346,10 @@ WebGL2Context::GetQueryParameter(JSConte
          */
         retval.set(JS::BooleanValue(returned != 0));
         return;
 
     default:
         break;
     }
 
-    ErrorInvalidEnum("getQueryObject: pname must be QUERY_RESULT{_AVAILABLE}");
+    ErrorInvalidEnum("getQueryObject: `pname` must be QUERY_RESULT{_AVAILABLE}.");
 }
--- a/dom/canvas/WebGL2ContextTextures.cpp
+++ b/dom/canvas/WebGL2ContextTextures.cpp
@@ -85,17 +85,17 @@ WebGL2Context::ValidateSizedInternalForm
 
 /** Validates parameters to texStorage{2D,3D} */
 bool
 WebGL2Context::ValidateTexStorage(GLenum target, GLsizei levels, GLenum internalformat,
                                       GLsizei width, GLsizei height, GLsizei depth,
                                       const char* info)
 {
     // GL_INVALID_OPERATION is generated if the default texture object is curently bound to target.
-    WebGLTexture* tex = activeBoundTextureForTarget(target);
+    WebGLTexture* tex = ActiveBoundTextureForTarget(target);
     if (!tex) {
         ErrorInvalidOperation("%s: no texture is bound to target %s", info, EnumName(target));
         return false;
     }
 
     // GL_INVALID_OPERATION is generated if the texture object currently bound to target already has
     // GL_TEXTURE_IMMUTABLE_FORMAT set to GL_TRUE.
     if (tex->IsImmutable()) {
@@ -140,17 +140,17 @@ WebGL2Context::TexStorage2D(GLenum targe
 
     GetAndFlushUnderlyingGLErrors();
     gl->fTexStorage2D(target, levels, internalformat, width, height);
     GLenum error = GetAndFlushUnderlyingGLErrors();
     if (error) {
         return GenerateWarning("texStorage2D generated error %s", ErrorName(error));
     }
 
-    WebGLTexture* tex = activeBoundTextureForTarget(target);
+    WebGLTexture* tex = ActiveBoundTextureForTarget(target);
     tex->SetImmutable();
 
     const size_t facesCount = (target == LOCAL_GL_TEXTURE_2D) ? 1 : 6;
     GLsizei w = width;
     GLsizei h = height;
     for (size_t l = 0; l < size_t(levels); l++) {
         for (size_t f = 0; f < facesCount; f++) {
             tex->SetImageInfo(TexImageTargetForTargetAndFace(target, f),
@@ -179,17 +179,17 @@ WebGL2Context::TexStorage3D(GLenum targe
 
     GetAndFlushUnderlyingGLErrors();
     gl->fTexStorage3D(target, levels, internalformat, width, height, depth);
     GLenum error = GetAndFlushUnderlyingGLErrors();
     if (error) {
         return GenerateWarning("texStorage3D generated error %s", ErrorName(error));
     }
 
-    WebGLTexture* tex = activeBoundTextureForTarget(target);
+    WebGLTexture* tex = ActiveBoundTextureForTarget(target);
     tex->SetImmutable();
 
     GLsizei w = width;
     GLsizei h = height;
     GLsizei d = depth;
     for (size_t l = 0; l < size_t(levels); l++) {
         tex->SetImageInfo(TexImageTargetForTargetAndFace(target, 0),
                           l, w, h, d,
@@ -270,17 +270,17 @@ WebGL2Context::TexImage3D(GLenum target,
         return ErrorInvalidOperation("texSubImage2D: integer overflow computing the needed buffer size");
 
     uint32_t bytesNeeded = checked_neededByteLength.value();
 
     if (dataLength && dataLength < bytesNeeded)
         return ErrorInvalidOperation("texImage3D: not enough data for operation (need %d, have %d)",
                                  bytesNeeded, dataLength);
 
-    WebGLTexture* tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
 
     if (!tex)
         return ErrorInvalidOperation("texImage3D: no texture is bound to this target");
 
     if (tex->IsImmutable()) {
         return ErrorInvalidOperation(
             "texImage3D: disallowed because the texture "
             "bound to this target has already been made immutable by texStorage3D");
@@ -333,17 +333,17 @@ WebGL2Context::TexSubImage3D(GLenum rawT
     const WebGLTexImageFunc func = WebGLTexImageFunc::TexSubImage;
     const WebGLTexDimensions dims = WebGLTexDimensions::Tex3D;
 
     if (!ValidateTexImageTarget(rawTarget, func, dims))
         return;
 
     TexImageTarget texImageTarget(rawTarget);
 
-    WebGLTexture* tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
     if (!tex) {
         return ErrorInvalidOperation("texSubImage3D: no texture bound on active texture unit");
     }
 
     if (!tex->HasImageInfoAt(texImageTarget, level)) {
         return ErrorInvalidOperation("texSubImage3D: no previously defined texture image");
     }
 
--- a/dom/canvas/WebGLActiveInfo.cpp
+++ b/dom/canvas/WebGLActiveInfo.cpp
@@ -1,15 +1,20 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "WebGLActiveInfo.h"
+
+#include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
 #include "WebGLTexture.h"
-#include "mozilla/dom/WebGLRenderingContextBinding.h"
 
-using namespace mozilla;
+namespace mozilla {
 
 JSObject*
-WebGLActiveInfo::WrapObject(JSContext *cx) {
+WebGLActiveInfo::WrapObject(JSContext* cx)
+{
     return dom::WebGLActiveInfoBinding::Wrap(cx, this);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLActiveInfo.h
+++ b/dom/canvas/WebGLActiveInfo.h
@@ -1,55 +1,55 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef WEBGLACTIVEINFO_H_
-#define WEBGLACTIVEINFO_H_
+#ifndef WEBGL_ACTIVE_INFO_H_
+#define WEBGL_ACTIVE_INFO_H_
 
-#include "WebGLObjectModel.h"
+#include "js/TypeDecls.h"
 #include "nsString.h"
-#include "js/TypeDecls.h"
+#include "WebGLObjectModel.h"
 
 namespace mozilla {
 
 class WebGLActiveInfo MOZ_FINAL
 {
 public:
-    WebGLActiveInfo(GLint size, GLenum type, const nsACString& name) :
-        mSize(size),
-        mType(type),
-        mName(NS_ConvertASCIItoUTF16(name))
+    WebGLActiveInfo(GLint size, GLenum type, const nsACString& name)
+        : mSize(size)
+        , mType(type)
+        , mName(NS_ConvertASCIItoUTF16(name))
     {}
 
     // WebIDL attributes
 
     GLint Size() const {
         return mSize;
     }
 
     GLenum Type() const {
         return mType;
     }
 
     void GetName(nsString& retval) const {
         retval = mName;
     }
 
-    JSObject* WrapObject(JSContext *cx);
+    JSObject* WrapObject(JSContext* cx);
 
    NS_INLINE_DECL_REFCOUNTING(WebGLActiveInfo)
 
 private:
     // Private destructor, to discourage deletion outside of Release():
     ~WebGLActiveInfo()
     {
     }
 
     GLint mSize;
     GLenum mType;
     nsString mName;
 };
 
 } // namespace mozilla
 
-#endif
+#endif // WEBGL_ACTIVE_INFO_H_
--- a/dom/canvas/WebGLBuffer.cpp
+++ b/dom/canvas/WebGLBuffer.cpp
@@ -5,80 +5,91 @@
 
 #include "WebGLBuffer.h"
 
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
 #include "WebGLElementArrayCache.h"
 
-using namespace mozilla;
+namespace mozilla {
 
-WebGLBuffer::WebGLBuffer(WebGLContext* context, GLuint buf)
+WebGLBuffer::WebGLBuffer(WebGLContext* webgl, GLuint buf)
     : WebGLBindableName<BufferBinding>(buf)
-    , WebGLContextBoundObject(context)
+    , WebGLContextBoundObject(webgl)
     , mByteLength(0)
 {
     mContext->mBuffers.insertBack(this);
 }
 
-WebGLBuffer::~WebGLBuffer() {
+WebGLBuffer::~WebGLBuffer()
+{
     DeleteOnce();
 }
 
 void
-WebGLBuffer::Delete() {
+WebGLBuffer::Delete()
+{
     mContext->MakeContextCurrent();
     mContext->gl->fDeleteBuffers(1, &mGLName);
     mByteLength = 0;
     mCache = nullptr;
     LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
 }
 
 void
-WebGLBuffer::OnTargetChanged() {
+WebGLBuffer::OnTargetChanged()
+{
     if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
         mCache = new WebGLElementArrayCache;
 }
 
 bool
-WebGLBuffer::ElementArrayCacheBufferData(const void* ptr, size_t buffer_size_in_bytes) {
+WebGLBuffer::ElementArrayCacheBufferData(const void* ptr,
+                                         size_t bufferSizeInBytes)
+{
     if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
-        return mCache->BufferData(ptr, buffer_size_in_bytes);
+        return mCache->BufferData(ptr, bufferSizeInBytes);
+
     return true;
 }
 
 void
-WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr, size_t update_size_in_bytes) {
+WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr,
+                                            size_t updateSizeInBytes)
+{
     if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
-        mCache->BufferSubData(pos, ptr, update_size_in_bytes);
+        mCache->BufferSubData(pos, ptr, updateSizeInBytes);
 }
 
 size_t
-WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
 {
-    size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(aMallocSizeOf) : 0;
-    return aMallocSizeOf(this) + sizeOfCache;
+    size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(mallocSizeOf)
+                                : 0;
+    return mallocSizeOf(this) + sizeOfCache;
 }
 
 bool
-WebGLBuffer::Validate(GLenum type, uint32_t max_allowed,
-                      size_t first, size_t count,
-                      uint32_t* out_upperBound)
+WebGLBuffer::Validate(GLenum type, uint32_t maxAllowed, size_t first,
+                      size_t count, uint32_t* const out_upperBound)
 {
-    return mCache->Validate(type, max_allowed, first, count, out_upperBound);
+    return mCache->Validate(type, maxAllowed, first, count, out_upperBound);
 }
 
 bool
 WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const
 {
     return mCache->BeenUsedWithMultipleTypes();
 }
 
 JSObject*
-WebGLBuffer::WrapObject(JSContext *cx) {
+WebGLBuffer::WrapObject(JSContext* cx)
+{
     return dom::WebGLBufferBinding::Wrap(cx, this);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)
+
+} // namespace mozilla
--- a/dom/canvas/WebGLBuffer.h
+++ b/dom/canvas/WebGLBuffer.h
@@ -1,68 +1,69 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef WEBGLBUFFER_H_
-#define WEBGLBUFFER_H_
+#ifndef WEBGL_BUFFER_H_
+#define WEBGL_BUFFER_H_
 
 #include "GLDefs.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsWrapperCache.h"
 #include "WebGLBindableName.h"
 #include "WebGLObjectModel.h"
+#include "WebGLStrongTypes.h"
 #include "WebGLTypes.h"
-#include "WebGLStrongTypes.h"
 
 namespace mozilla {
 
 class WebGLElementArrayCache;
 
 class WebGLBuffer MOZ_FINAL
     : public nsWrapperCache
     , public WebGLBindableName<BufferBinding>
     , public WebGLRefCountedObject<WebGLBuffer>
     , public LinkedListElement<WebGLBuffer>
     , public WebGLContextBoundObject
 {
 public:
-    explicit WebGLBuffer(WebGLContext* context, GLuint buf);
+    explicit WebGLBuffer(WebGLContext* webgl, GLuint buf);
 
     void Delete();
 
-    size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
 
     WebGLsizeiptr ByteLength() const { return mByteLength; }
-
     void SetByteLength(WebGLsizeiptr byteLength) { mByteLength = byteLength; }
 
-    bool ElementArrayCacheBufferData(const void* ptr, size_t buffer_size_in_bytes);
+    bool ElementArrayCacheBufferData(const void* ptr, size_t bufferSizeInBytes);
 
-    void ElementArrayCacheBufferSubData(size_t pos, const void* ptr, size_t update_size_in_bytes);
+    void ElementArrayCacheBufferSubData(size_t pos, const void* ptr,
+                                        size_t updateSizeInBytes);
 
     bool Validate(GLenum type, uint32_t max_allowed, size_t first, size_t count,
-                  uint32_t* out_upperBound);
+                  uint32_t* const out_upperBound);
 
     bool IsElementArrayUsedWithMultipleTypes() const;
 
-    WebGLContext *GetParentObject() const {
+    WebGLContext* GetParentObject() const {
         return Context();
-    }
+    };
 
-    virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
+    virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLBuffer)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLBuffer)
 
 protected:
     ~WebGLBuffer();
 
     virtual void OnTargetChanged() MOZ_OVERRIDE;
 
     WebGLsizeiptr mByteLength;
-
     nsAutoPtr<WebGLElementArrayCache> mCache;
 };
-}
-#endif //WEBGLBUFFER_H_
+
+} // namespace mozilla
+
+#endif // WEBGL_BUFFER_H_
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -1,230 +1,203 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 
-#include "WebGLContextLossHandler.h"
+#include "AccessCheck.h"
+#include "CanvasUtils.h"
+#include "gfxContext.h"
+#include "gfxCrashReporterUtils.h"
+#include "gfxPattern.h"
+#include "gfxPrefs.h"
+#include "gfxUtils.h"
+#include "GLBlitHelper.h"
+#include "GLContext.h"
+#include "GLContextProvider.h"
+#include "GLReadTexImageHelper.h"
+#include "ImageContainer.h"
+#include "ImageEncoder.h"
+#include "Layers.h"
+#include "mozilla/dom/BindingUtils.h"
+#include "mozilla/dom/HTMLVideoElement.h"
+#include "mozilla/dom/ImageData.h"
+#include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "mozilla/EnumeratedArrayCycleCollection.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/ProcessPriorityManager.h"
+#include "mozilla/Services.h"
+#include "mozilla/Telemetry.h"
+#include "nsContentUtils.h"
+#include "nsDisplayList.h"
+#include "nsError.h"
+#include "nsIClassInfoImpl.h"
+#include "nsIConsoleService.h"
+#include "nsIGfxInfo.h"
+#include "nsIObserverService.h"
+#include "nsIDOMEvent.h"
+#include "nsIVariant.h"
+#include "nsIWidget.h"
+#include "nsIXPConnect.h"
+#include "nsServiceManagerUtils.h"
+#include "nsSVGEffects.h"
+#include "prenv.h"
+#include <queue>
+#include "ScopedGLHelpers.h"
 #include "WebGL1Context.h"
 #include "WebGLBuffer.h"
+#include "WebGLContextLossHandler.h"
 #include "WebGLContextUtils.h"
 #include "WebGLExtensions.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLMemoryTracker.h"
 #include "WebGLObjectModel.h"
 #include "WebGLQuery.h"
 #include "WebGLSampler.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
 
-#include "GLBlitHelper.h"
-#include "AccessCheck.h"
-#include "nsIConsoleService.h"
-#include "nsServiceManagerUtils.h"
-#include "nsIClassInfoImpl.h"
-#include "nsContentUtils.h"
-#include "nsIXPConnect.h"
-#include "nsError.h"
-#include "nsIGfxInfo.h"
-#include "nsIWidget.h"
-
-#include "nsIVariant.h"
-
-#include "ImageEncoder.h"
-#include "ImageContainer.h"
-
-#include "gfxContext.h"
-#include "gfxPattern.h"
-#include "gfxPrefs.h"
-#include "gfxUtils.h"
-
-#include "CanvasUtils.h"
-#include "nsDisplayList.h"
-
-#include "GLContextProvider.h"
-#include "GLContext.h"
-#include "ScopedGLHelpers.h"
-#include "GLReadTexImageHelper.h"
-
-#include "gfxCrashReporterUtils.h"
-
-#include "nsSVGEffects.h"
-
-#include "prenv.h"
-
-#include "mozilla/Preferences.h"
-#include "mozilla/Services.h"
-#include "mozilla/Telemetry.h"
-
-#include "nsIObserverService.h"
-#include "nsIDOMEvent.h"
-#include "mozilla/Services.h"
-#include "mozilla/dom/WebGLRenderingContextBinding.h"
-#include "mozilla/dom/BindingUtils.h"
-#include "mozilla/dom/HTMLVideoElement.h"
-#include "mozilla/dom/ImageData.h"
-#include "mozilla/ProcessPriorityManager.h"
-#include "mozilla/EnumeratedArrayCycleCollection.h"
-
-#include "Layers.h"
-
 #ifdef MOZ_WIDGET_GONK
 #include "mozilla/layers/ShadowLayers.h"
 #endif
 
-#include <queue>
-
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
 using namespace mozilla::layers;
 
-WebGLObserver::WebGLObserver(WebGLContext* aContext)
-    : mContext(aContext)
+WebGLObserver::WebGLObserver(WebGLContext* webgl)
+    : mWebGL(webgl)
 {
 }
 
 WebGLObserver::~WebGLObserver()
 {
 }
 
 void
 WebGLObserver::Destroy()
 {
     UnregisterMemoryPressureEvent();
     UnregisterVisibilityChangeEvent();
-    mContext = nullptr;
+    mWebGL = nullptr;
 }
 
 void
 WebGLObserver::RegisterVisibilityChangeEvent()
 {
-    if (!mContext) {
+    if (!mWebGL)
         return;
-    }
 
-    HTMLCanvasElement* canvasElement = mContext->GetCanvas();
+    HTMLCanvasElement* canvas = mWebGL->GetCanvas();
+    MOZ_ASSERT(canvas);
 
-    MOZ_ASSERT(canvasElement);
-
-    if (canvasElement) {
-        nsIDocument* document = canvasElement->OwnerDoc();
+    if (canvas) {
+        nsIDocument* document = canvas->OwnerDoc();
 
         document->AddSystemEventListener(NS_LITERAL_STRING("visibilitychange"),
-                                         this,
-                                         true,
-                                         false);
+                                         this, true, false);
     }
 }
 
 void
 WebGLObserver::UnregisterVisibilityChangeEvent()
 {
-    if (!mContext) {
+    if (!mWebGL)
         return;
-    }
 
-    HTMLCanvasElement* canvasElement = mContext->GetCanvas();
+    HTMLCanvasElement* canvas = mWebGL->GetCanvas();
 
-    if (canvasElement) {
-        nsIDocument* document = canvasElement->OwnerDoc();
+    if (canvas) {
+        nsIDocument* document = canvas->OwnerDoc();
 
         document->RemoveSystemEventListener(NS_LITERAL_STRING("visibilitychange"),
-                                            this,
-                                            true);
+                                            this, true);
     }
 }
 
 void
 WebGLObserver::RegisterMemoryPressureEvent()
 {
-    if (!mContext) {
+    if (!mWebGL)
         return;
-    }
 
     nsCOMPtr<nsIObserverService> observerService =
         mozilla::services::GetObserverService();
 
     MOZ_ASSERT(observerService);
 
-    if (observerService) {
+    if (observerService)
         observerService->AddObserver(this, "memory-pressure", false);
-    }
 }
 
 void
 WebGLObserver::UnregisterMemoryPressureEvent()
 {
-    if (!mContext) {
+    if (!mWebGL)
         return;
-    }
 
     nsCOMPtr<nsIObserverService> observerService =
         mozilla::services::GetObserverService();
 
     // Do not assert on observerService here. This might be triggered by
     // the cycle collector at a late enough time, that XPCOM services are
     // no longer available. See bug 1029504.
-    if (observerService) {
+    if (observerService)
         observerService->RemoveObserver(this, "memory-pressure");
-    }
 }
 
 NS_IMETHODIMP
-WebGLObserver::Observe(nsISupports* aSubject,
-                       const char* aTopic,
-                       const char16_t* aSomeData)
+WebGLObserver::Observe(nsISupports*, const char* topic, const char16_t*)
 {
-    if (!mContext || strcmp(aTopic, "memory-pressure")) {
+    if (!mWebGL || strcmp(topic, "memory-pressure")) {
         return NS_OK;
     }
 
-    bool wantToLoseContext = mContext->mLoseContextOnMemoryPressure;
+    bool wantToLoseContext = mWebGL->mLoseContextOnMemoryPressure;
 
-    if (!mContext->mCanLoseContextInForeground &&
+    if (!mWebGL->mCanLoseContextInForeground &&
         ProcessPriorityManager::CurrentProcessIsForeground())
     {
         wantToLoseContext = false;
     }
 
-    if (wantToLoseContext) {
-        mContext->ForceLoseContext();
-    }
+    if (wantToLoseContext)
+        mWebGL->ForceLoseContext();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-WebGLObserver::HandleEvent(nsIDOMEvent* aEvent)
+WebGLObserver::HandleEvent(nsIDOMEvent* event)
 {
     nsAutoString type;
-    aEvent->GetType(type);
-    if (!mContext || !type.EqualsLiteral("visibilitychange")) {
+    event->GetType(type);
+    if (!mWebGL || !type.EqualsLiteral("visibilitychange"))
         return NS_OK;
-    }
 
-    HTMLCanvasElement* canvasElement = mContext->GetCanvas();
-
-    MOZ_ASSERT(canvasElement);
+    HTMLCanvasElement* canvas = mWebGL->GetCanvas();
+    MOZ_ASSERT(canvas);
 
-    if (canvasElement && !canvasElement->OwnerDoc()->Hidden()) {
-        mContext->ForceRestoreContext();
-    }
+    if (canvas && !canvas->OwnerDoc()->Hidden())
+        mWebGL->ForceRestoreContext();
 
     return NS_OK;
 }
 
 WebGLContextOptions::WebGLContextOptions()
-    : alpha(true), depth(true), stencil(false),
-      premultipliedAlpha(true), antialias(true),
-      preserveDrawingBuffer(false)
+    : alpha(true)
+    , depth(true)
+    , stencil(false)
+    , premultipliedAlpha(true)
+    , antialias(true)
+    , preserveDrawingBuffer(false)
 {
     // Set default alpha state based on preference.
     if (Preferences::GetBool("webgl.default-no-alpha", false))
         alpha = false;
 }
 
 WebGLContext::WebGLContext()
     : WebGLContextUnchecked(nullptr)
@@ -296,19 +269,19 @@ WebGLContext::WebGLContext()
     mContextStatus = ContextNotLost;
     mLoseContextOnMemoryPressure = false;
     mCanLoseContextInForeground = true;
     mRestoreWhenVisible = false;
 
     mAlreadyGeneratedWarnings = 0;
     mAlreadyWarnedAboutFakeVertexAttrib0 = false;
     mAlreadyWarnedAboutViewportLargerThanDest = false;
+
     mMaxWarnings = Preferences::GetInt("webgl.max-warnings-per-context", 32);
-    if (mMaxWarnings < -1)
-    {
+    if (mMaxWarnings < -1) {
         GenerateWarning("webgl.max-warnings-per-context size is too large (seems like a negative value wrapped)");
         mMaxWarnings = 0;
     }
 
     mContextObserver = new WebGLObserver(this);
     MOZ_RELEASE_ASSERT(mContextObserver, "Can't alloc WebGLContextObserver");
 
     mLastUseIndex = 0;
@@ -375,38 +348,36 @@ WebGLContext::DestroyResourcesAndContext
     while (!mSamplers.isEmpty())
         mSamplers.getLast()->DeleteOnce();
 
     mBlackOpaqueTexture2D = nullptr;
     mBlackOpaqueTextureCubeMap = nullptr;
     mBlackTransparentTexture2D = nullptr;
     mBlackTransparentTextureCubeMap = nullptr;
 
-    if (mFakeVertexAttrib0BufferObject) {
+    if (mFakeVertexAttrib0BufferObject)
         gl->fDeleteBuffers(1, &mFakeVertexAttrib0BufferObject);
-    }
 
     // disable all extensions except "WEBGL_lose_context". see bug #927969
     // spec: http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
     for (size_t i = 0; i < size_t(WebGLExtensionID::Max); ++i) {
         WebGLExtensionID extension = WebGLExtensionID(i);
 
         if (!IsExtensionEnabled(extension) || (extension == WebGLExtensionID::WEBGL_lose_context))
             continue;
 
         mExtensions[extension]->MarkLost();
         mExtensions[extension] = nullptr;
     }
 
     // We just got rid of everything, so the context had better
     // have been going away.
 #ifdef DEBUG
-    if (gl->DebugMode()) {
+    if (gl->DebugMode())
         printf_stderr("--- WebGL context destroyed: %p\n", gl.get());
-    }
 #endif
 
     gl = nullptr;
 }
 
 void
 WebGLContext::Invalidate()
 {
@@ -422,41 +393,38 @@ WebGLContext::Invalidate()
     mCanvasElement->InvalidateCanvasContent(nullptr);
 }
 
 //
 // nsICanvasRenderingContextInternal
 //
 
 NS_IMETHODIMP
-WebGLContext::SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions)
+WebGLContext::SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options)
 {
-    if (aOptions.isNullOrUndefined() && mOptionsFrozen) {
+    if (options.isNullOrUndefined() && mOptionsFrozen)
         return NS_OK;
-    }
 
     WebGLContextAttributes attributes;
-    NS_ENSURE_TRUE(attributes.Init(aCx, aOptions), NS_ERROR_UNEXPECTED);
+    NS_ENSURE_TRUE(attributes.Init(cx, options), NS_ERROR_UNEXPECTED);
 
     WebGLContextOptions newOpts;
 
     newOpts.stencil = attributes.mStencil;
     newOpts.depth = attributes.mDepth;
     newOpts.premultipliedAlpha = attributes.mPremultipliedAlpha;
     newOpts.antialias = attributes.mAntialias;
     newOpts.preserveDrawingBuffer = attributes.mPreserveDrawingBuffer;
 
-    if (attributes.mAlpha.WasPassed()) {
+    if (attributes.mAlpha.WasPassed())
         newOpts.alpha = attributes.mAlpha.Value();
-    }
 
     // Don't do antialiasing if we've disabled MSAA.
-    if (!gfxPrefs::MSAALevel()) {
+    if (!gfxPrefs::MSAALevel())
       newOpts.antialias = false;
-    }
 
 #if 0
     GenerateWarning("aaHint: %d stencil: %d depth: %d alpha: %d premult: %d preserve: %d\n",
                newOpts.antialias ? 1 : 0,
                newOpts.stencil ? 1 : 0,
                newOpts.depth ? 1 : 0,
                newOpts.alpha ? 1 : 0,
                newOpts.premultipliedAlpha ? 1 : 0,
@@ -510,18 +478,17 @@ IsFeatureInBlacklist(const nsCOMPtr<nsIG
     int32_t status;
     if (!NS_SUCCEEDED(gfxInfo->GetFeatureStatus(feature, &status)))
         return false;
 
     return status != nsIGfxInfo::FEATURE_STATUS_OK;
 }
 
 static already_AddRefed<GLContext>
-CreateHeadlessNativeGL(bool forceEnabled,
-                       const nsCOMPtr<nsIGfxInfo>& gfxInfo,
+CreateHeadlessNativeGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
                        WebGLContext* webgl)
 {
     if (!forceEnabled &&
         IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_OPENGL))
     {
         webgl->GenerateWarning("Refused to create native OpenGL context"
                                " because of blacklisting.");
         return nullptr;
@@ -536,18 +503,17 @@ CreateHeadlessNativeGL(bool forceEnabled
 
     return gl.forget();
 }
 
 // Note that we have a separate call for ANGLE and EGL, even though
 // right now, we get ANGLE implicitly by using EGL on Windows.
 // Eventually, we want to be able to pick ANGLE-EGL or native EGL.
 static already_AddRefed<GLContext>
-CreateHeadlessANGLE(bool forceEnabled,
-                    const nsCOMPtr<nsIGfxInfo>& gfxInfo,
+CreateHeadlessANGLE(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
                     WebGLContext* webgl)
 {
     nsRefPtr<GLContext> gl;
 
 #ifdef XP_WIN
     if (!forceEnabled &&
         IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_ANGLE))
     {
@@ -563,18 +529,17 @@ CreateHeadlessANGLE(bool forceEnabled,
     }
     MOZ_ASSERT(gl->IsANGLE());
 #endif
 
     return gl.forget();
 }
 
 static already_AddRefed<GLContext>
-CreateHeadlessEGL(bool forceEnabled,
-                  const nsCOMPtr<nsIGfxInfo>& gfxInfo,
+CreateHeadlessEGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
                   WebGLContext* webgl)
 {
     nsRefPtr<GLContext> gl;
 
 #ifdef ANDROID
     gl = gl::GLContextProviderEGL::CreateHeadless();
     if (!gl) {
         webgl->GenerateWarning("Error during EGL OpenGL init.");
@@ -583,26 +548,24 @@ CreateHeadlessEGL(bool forceEnabled,
     MOZ_ASSERT(!gl->IsANGLE());
 #endif
 
     return gl.forget();
 }
 
 
 static already_AddRefed<GLContext>
-CreateHeadlessGL(bool forceEnabled,
-                 const nsCOMPtr<nsIGfxInfo>& gfxInfo,
+CreateHeadlessGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
                  WebGLContext* webgl)
 {
     bool preferEGL = PR_GetEnv("MOZ_WEBGL_PREFER_EGL");
     bool disableANGLE = Preferences::GetBool("webgl.disable-angle", false);
 
-    if (PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL")) {
+    if (PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL"))
         disableANGLE = true;
-    }
 
     nsRefPtr<GLContext> gl;
 
     if (preferEGL)
         gl = CreateHeadlessEGL(forceEnabled, gfxInfo, webgl);
 
     if (!gl && !disableANGLE)
         gl = CreateHeadlessANGLE(forceEnabled, gfxInfo, webgl);
@@ -618,50 +581,48 @@ static bool
 CreateOffscreenWithCaps(GLContext* gl, const SurfaceCaps& caps)
 {
     gfx::IntSize dummySize(16, 16);
     return gl->InitOffscreen(dummySize, caps);
 }
 
 static void
 PopulateCapFallbackQueue(const SurfaceCaps& baseCaps,
-                         std::queue<SurfaceCaps>* fallbackCaps)
+                         std::queue<SurfaceCaps>* out_fallbackCaps)
 {
-    fallbackCaps->push(baseCaps);
+    out_fallbackCaps->push(baseCaps);
 
     // Dropping antialias drops our quality, but not our correctness.
     // The user basically doesn't have to handle if this fails, they
     // just get reduced quality.
     if (baseCaps.antialias) {
         SurfaceCaps nextCaps(baseCaps);
         nextCaps.antialias = false;
-        PopulateCapFallbackQueue(nextCaps, fallbackCaps);
+        PopulateCapFallbackQueue(nextCaps, out_fallbackCaps);
     }
 
     // If we have to drop one of depth or stencil, we'd prefer to keep
     // depth. However, the client app will need to handle if this
     // doesn't work.
     if (baseCaps.stencil) {
         SurfaceCaps nextCaps(baseCaps);
         nextCaps.stencil = false;
-        PopulateCapFallbackQueue(nextCaps, fallbackCaps);
+        PopulateCapFallbackQueue(nextCaps, out_fallbackCaps);
     }
 
     if (baseCaps.depth) {
         SurfaceCaps nextCaps(baseCaps);
         nextCaps.depth = false;
-        PopulateCapFallbackQueue(nextCaps, fallbackCaps);
+        PopulateCapFallbackQueue(nextCaps, out_fallbackCaps);
     }
 }
 
 static bool
-CreateOffscreen(GLContext* gl,
-                const WebGLContextOptions& options,
-                const nsCOMPtr<nsIGfxInfo>& gfxInfo,
-                WebGLContext* webgl,
+CreateOffscreen(GLContext* gl, const WebGLContextOptions& options,
+                const nsCOMPtr<nsIGfxInfo>& gfxInfo, WebGLContext* webgl,
                 layers::ISurfaceAllocator* surfAllocator)
 {
     SurfaceCaps baseCaps;
 
     baseCaps.color = true;
     baseCaps.alpha = options.alpha;
     baseCaps.antialias = options.antialias;
     baseCaps.depth = options.depth;
@@ -723,19 +684,18 @@ WebGLContext::CreateOffscreenGL(bool for
     layers::ISurfaceAllocator* surfAllocator = nullptr;
 #ifdef MOZ_WIDGET_GONK
     nsIWidget* docWidget = nsContentUtils::WidgetForDocument(mCanvasElement->OwnerDoc());
     if (docWidget) {
         layers::LayerManager* layerManager = docWidget->GetLayerManager();
         if (layerManager) {
             // XXX we really want "AsSurfaceAllocator" here for generality
             layers::ShadowLayerForwarder* forwarder = layerManager->AsShadowForwarder();
-            if (forwarder) {
+            if (forwarder)
                 surfAllocator = static_cast<layers::ISurfaceAllocator*>(forwarder);
-            }
         }
     }
 #endif
 
     gl = CreateHeadlessGL(forceEnabled, gfxInfo, this);
 
     do {
         if (!gl)
@@ -751,17 +711,18 @@ WebGLContext::CreateOffscreenGL(bool for
     } while (false);
 
     gl = nullptr;
     return false;
 }
 
 // Fallback for resizes:
 bool
-WebGLContext::ResizeBackbuffer(uint32_t requestedWidth, uint32_t requestedHeight)
+WebGLContext::ResizeBackbuffer(uint32_t requestedWidth,
+                               uint32_t requestedHeight)
 {
     uint32_t width = requestedWidth;
     uint32_t height = requestedHeight;
 
     bool resized = false;
     while (width || height) {
       width = width ? width : 1;
       height = height ? height : 1;
@@ -790,42 +751,40 @@ WebGLContext::ResizeBackbuffer(uint32_t 
         GenerateWarning("Requested size %dx%d was too large, but resize"
                           " to %dx%d succeeded.",
                         requestedWidth, requestedHeight,
                         width, height);
     }
     return true;
 }
 
-
 NS_IMETHODIMP
-WebGLContext::SetDimensions(int32_t sWidth, int32_t sHeight)
+WebGLContext::SetDimensions(int32_t signedWidth, int32_t signedHeight)
 {
     // Early error return cases
     if (!GetCanvas())
         return NS_ERROR_FAILURE;
 
-    if (sWidth < 0 || sHeight < 0) {
+    if (signedWidth < 0 || signedHeight < 0) {
         GenerateWarning("Canvas size is too large (seems like a negative value wrapped)");
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
-    uint32_t width = sWidth;
-    uint32_t height = sHeight;
+    uint32_t width = signedWidth;
+    uint32_t height = signedHeight;
 
     // Early success return cases
     GetCanvas()->InvalidateCanvas();
 
     // Zero-sized surfaces can cause problems.
-    if (width == 0) {
+    if (width == 0)
         width = 1;
-    }
-    if (height == 0) {
+
+    if (height == 0)
         height = 1;
-    }
 
     // If we already have a gl context, then we just need to resize it
     if (gl) {
         if ((uint32_t)mWidth == width &&
             (uint32_t)mHeight == height)
         {
             return NS_OK;
         }
@@ -896,32 +855,30 @@ WebGLContext::SetDimensions(int32_t sWid
     MOZ_ASSERT(gl);
 
     if (!ResizeBackbuffer(width, height)) {
         GenerateWarning("Initializing WebGL backbuffer failed.");
         return NS_ERROR_FAILURE;
     }
 
 #ifdef DEBUG
-    if (gl->DebugMode()) {
+    if (gl->DebugMode())
         printf_stderr("--- WebGL context created: %p\n", gl.get());
-    }
 #endif
 
     mResetLayer = true;
     mOptionsFrozen = true;
 
     // increment the generation number
     ++mGeneration;
 
     // Update our internal stuff:
     if (gl->WorkAroundDriverBugs()) {
-        if (!mOptions.alpha && gl->Caps().alpha) {
+        if (!mOptions.alpha && gl->Caps().alpha)
             mNeedsFakeNoAlpha = true;
-        }
     }
 
     // Update mOptions.
     mOptions.depth = gl->Caps().depth;
     mOptions.stencil = gl->Caps().stencil;
     mOptions.antialias = gl->Caps().antialias;
 
     MakeContextCurrent();
@@ -973,54 +930,52 @@ WebGLContext::ClearBackbufferIfNeeded()
     MOZ_ASSERT(fb == 0);
 #endif
 
     ClearScreen();
 
     mBackbufferNeedsClear = false;
 }
 
-void WebGLContext::LoseOldestWebGLContextIfLimitExceeded()
+void
+WebGLContext::LoseOldestWebGLContextIfLimitExceeded()
 {
 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
     // some mobile devices can't have more than 8 GL contexts overall
     const size_t kMaxWebGLContextsPerPrincipal = 2;
     const size_t kMaxWebGLContexts             = 4;
 #else
     const size_t kMaxWebGLContextsPerPrincipal = 16;
     const size_t kMaxWebGLContexts             = 32;
 #endif
     MOZ_ASSERT(kMaxWebGLContextsPerPrincipal < kMaxWebGLContexts);
 
     // it's important to update the index on a new context before losing old contexts,
     // otherwise new unused contexts would all have index 0 and we couldn't distinguish older ones
     // when choosing which one to lose first.
     UpdateLastUseIndex();
 
-    WebGLMemoryTracker::ContextsArrayType &contexts
-      = WebGLMemoryTracker::Contexts();
+    WebGLMemoryTracker::ContextsArrayType& contexts = WebGLMemoryTracker::Contexts();
 
     // quick exit path, should cover a majority of cases
-    if (contexts.Length() <= kMaxWebGLContextsPerPrincipal) {
+    if (contexts.Length() <= kMaxWebGLContextsPerPrincipal)
         return;
-    }
 
     // note that here by "context" we mean "non-lost context". See the check for
     // IsContextLost() below. Indeed, the point of this function is to maybe lose
     // some currently non-lost context.
 
     uint64_t oldestIndex = UINT64_MAX;
     uint64_t oldestIndexThisPrincipal = UINT64_MAX;
-    const WebGLContext *oldestContext = nullptr;
-    const WebGLContext *oldestContextThisPrincipal = nullptr;
+    const WebGLContext* oldestContext = nullptr;
+    const WebGLContext* oldestContextThisPrincipal = nullptr;
     size_t numContexts = 0;
     size_t numContextsThisPrincipal = 0;
 
     for(size_t i = 0; i < contexts.Length(); ++i) {
-
         // don't want to lose ourselves.
         if (contexts[i] == this)
             continue;
 
         if (contexts[i]->IsContextLost())
             continue;
 
         if (!contexts[i]->GetCanvas()) {
@@ -1032,18 +987,18 @@ void WebGLContext::LoseOldestWebGLContex
         }
 
         numContexts++;
         if (contexts[i]->mLastUseIndex < oldestIndex) {
             oldestIndex = contexts[i]->mLastUseIndex;
             oldestContext = contexts[i];
         }
 
-        nsIPrincipal *ourPrincipal = GetCanvas()->NodePrincipal();
-        nsIPrincipal *theirPrincipal = contexts[i]->GetCanvas()->NodePrincipal();
+        nsIPrincipal* ourPrincipal = GetCanvas()->NodePrincipal();
+        nsIPrincipal* theirPrincipal = contexts[i]->GetCanvas()->NodePrincipal();
         bool samePrincipal;
         nsresult rv = ourPrincipal->Equals(theirPrincipal, &samePrincipal);
         if (NS_SUCCEEDED(rv) && samePrincipal) {
             numContextsThisPrincipal++;
             if (contexts[i]->mLastUseIndex < oldestIndexThisPrincipal) {
                 oldestIndexThisPrincipal = contexts[i]->mLastUseIndex;
                 oldestContextThisPrincipal = contexts[i];
             }
@@ -1059,36 +1014,35 @@ void WebGLContext::LoseOldestWebGLContex
         GenerateWarning("Exceeded %d live WebGL contexts, losing the least recently used one.",
                         kMaxWebGLContexts);
         MOZ_ASSERT(oldestContext); // if we reach this point, this can't be null
         const_cast<WebGLContext*>(oldestContext)->LoseContext();
     }
 }
 
 void
-WebGLContext::GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat)
+WebGLContext::GetImageBuffer(uint8_t** out_imageBuffer, int32_t* out_format)
 {
-    *aImageBuffer = nullptr;
-    *aFormat = 0;
+    *out_imageBuffer = nullptr;
+    *out_format = 0;
 
     // Use GetSurfaceSnapshot() to make sure that appropriate y-flip gets applied
     bool premult;
     RefPtr<SourceSurface> snapshot =
       GetSurfaceSnapshot(mOptions.premultipliedAlpha ? nullptr : &premult);
-    if (!snapshot) {
+    if (!snapshot)
         return;
-    }
+
     MOZ_ASSERT(mOptions.premultipliedAlpha || !premult, "We must get unpremult when we ask for it!");
 
     RefPtr<DataSourceSurface> dataSurface = snapshot->GetDataSurface();
 
     DataSourceSurface::MappedSurface map;
-    if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
+    if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map))
         return;
-    }
 
     static const fallible_t fallible = fallible_t();
     uint8_t* imageBuffer = new (fallible) uint8_t[mWidth * mHeight * 4];
     if (!imageBuffer) {
         dataSurface->Unmap();
         return;
     }
     memcpy(imageBuffer, map.mData, mWidth * mHeight * 4);
@@ -1101,128 +1055,126 @@ WebGLContext::GetImageBuffer(uint8_t** a
         // we are automatically considered premult, and unpremult'd.
         // Yes, it is THAT silly.
         // Except for different lossy conversions by color,
         // we could probably just change the label, and not change the data.
         gfxUtils::ConvertBGRAtoRGBA(imageBuffer, mWidth * mHeight * 4);
         format = imgIEncoder::INPUT_FORMAT_RGBA;
     }
 
-    *aImageBuffer = imageBuffer;
-    *aFormat = format;
+    *out_imageBuffer = imageBuffer;
+    *out_format = format;
 }
 
 NS_IMETHODIMP
-WebGLContext::GetInputStream(const char* aMimeType,
-                             const char16_t* aEncoderOptions,
-                             nsIInputStream **aStream)
+WebGLContext::GetInputStream(const char* mimeType,
+                             const char16_t* encoderOptions,
+                             nsIInputStream** out_stream)
 {
     NS_ASSERTION(gl, "GetInputStream on invalid context?");
     if (!gl)
         return NS_ERROR_FAILURE;
 
     nsCString enccid("@mozilla.org/image/encoder;2?type=");
-    enccid += aMimeType;
+    enccid += mimeType;
     nsCOMPtr<imgIEncoder> encoder = do_CreateInstance(enccid.get());
-    if (!encoder) {
+    if (!encoder)
         return NS_ERROR_FAILURE;
-    }
 
     nsAutoArrayPtr<uint8_t> imageBuffer;
     int32_t format = 0;
     GetImageBuffer(getter_Transfers(imageBuffer), &format);
-    if (!imageBuffer) {
+    if (!imageBuffer)
         return NS_ERROR_FAILURE;
-    }
 
     return ImageEncoder::GetInputStream(mWidth, mHeight, imageBuffer, format,
-                                        encoder, aEncoderOptions, aStream);
+                                        encoder, encoderOptions, out_stream);
 }
 
-void WebGLContext::UpdateLastUseIndex()
+void
+WebGLContext::UpdateLastUseIndex()
 {
     static CheckedInt<uint64_t> sIndex = 0;
 
     sIndex++;
 
     // should never happen with 64-bit; trying to handle this would be riskier than
     // not handling it as the handler code would never get exercised.
-    if (!sIndex.isValid()) {
+    if (!sIndex.isValid())
         NS_RUNTIMEABORT("Can't believe it's been 2^64 transactions already!");
-    }
 
     mLastUseIndex = sIndex.value();
 }
 
 static uint8_t gWebGLLayerUserData;
 
 namespace mozilla {
 
-class WebGLContextUserData : public LayerUserData {
+class WebGLContextUserData : public LayerUserData
+{
 public:
-    explicit WebGLContextUserData(HTMLCanvasElement* aContent)
-        : mContent(aContent)
+    explicit WebGLContextUserData(HTMLCanvasElement* canvas)
+        : mCanvas(canvas)
     {}
 
     /* PreTransactionCallback gets called by the Layers code every time the
      * WebGL canvas is going to be composited.
      */
-    static void PreTransactionCallback(void* data)
-    {
+    static void PreTransactionCallback(void* data) {
         WebGLContextUserData* userdata = static_cast<WebGLContextUserData*>(data);
-        HTMLCanvasElement* canvas = userdata->mContent;
-        WebGLContext* context = static_cast<WebGLContext*>(canvas->GetContextAtIndex(0));
+        HTMLCanvasElement* canvas = userdata->mCanvas;
+        WebGLContext* webgl = static_cast<WebGLContext*>(canvas->GetContextAtIndex(0));
 
         // Present our screenbuffer, if needed.
-        context->PresentScreenBuffer();
-        context->mDrawCallsSinceLastFlush = 0;
+        webgl->PresentScreenBuffer();
+        webgl->mDrawCallsSinceLastFlush = 0;
     }
 
     /** DidTransactionCallback gets called by the Layers code everytime the WebGL canvas gets composite,
       * so it really is the right place to put actions that have to be performed upon compositing
       */
-    static void DidTransactionCallback(void* aData)
-    {
-        WebGLContextUserData *userdata = static_cast<WebGLContextUserData*>(aData);
-        HTMLCanvasElement *canvas = userdata->mContent;
-        WebGLContext *context = static_cast<WebGLContext*>(canvas->GetContextAtIndex(0));
+    static void DidTransactionCallback(void* data) {
+        WebGLContextUserData* userdata = static_cast<WebGLContextUserData*>(data);
+        HTMLCanvasElement* canvas = userdata->mCanvas;
+        WebGLContext* webgl = static_cast<WebGLContext*>(canvas->GetContextAtIndex(0));
 
         // Mark ourselves as no longer invalidated.
-        context->MarkContextClean();
+        webgl->MarkContextClean();
 
-        context->UpdateLastUseIndex();
+        webgl->UpdateLastUseIndex();
     }
 
 private:
-    nsRefPtr<HTMLCanvasElement> mContent;
+    nsRefPtr<HTMLCanvasElement> mCanvas;
 };
 
 } // end namespace mozilla
 
 already_AddRefed<layers::CanvasLayer>
-WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
-                             CanvasLayer *aOldLayer,
-                             LayerManager *aManager)
+WebGLContext::GetCanvasLayer(nsDisplayListBuilder* builder,
+                             CanvasLayer* oldLayer,
+                             LayerManager* manager)
 {
     if (IsContextLost())
         return nullptr;
 
-    if (!mResetLayer && aOldLayer &&
-        aOldLayer->HasUserData(&gWebGLLayerUserData)) {
-        nsRefPtr<layers::CanvasLayer> ret = aOldLayer;
+    if (!mResetLayer && oldLayer &&
+        oldLayer->HasUserData(&gWebGLLayerUserData)) {
+        nsRefPtr<layers::CanvasLayer> ret = oldLayer;
         return ret.forget();
     }
 
-    nsRefPtr<CanvasLayer> canvasLayer = aManager->CreateCanvasLayer();
+    nsRefPtr<CanvasLayer> canvasLayer = manager->CreateCanvasLayer();
     if (!canvasLayer) {
         NS_WARNING("CreateCanvasLayer returned null!");
         return nullptr;
     }
-    WebGLContextUserData *userData = nullptr;
-    if (aBuilder->IsPaintingToWindow()) {
+
+    WebGLContextUserData* userData = nullptr;
+    if (builder->IsPaintingToWindow()) {
       // Make the layer tell us whenever a transaction finishes (including
       // the current transaction), so we can clear our invalidation state and
       // start invalidating again. We need to do this for the layer that is
       // being painted to a window (there shouldn't be more than one at a time,
       // and if there is, flushing the invalidation state more often than
       // necessary is harmless).
 
       // The layer will be destroyed when we tear down the presentation
@@ -1250,17 +1202,17 @@ WebGLContext::GetCanvasLayer(nsDisplayLi
     canvasLayer->Updated();
 
     mResetLayer = false;
 
     return canvasLayer.forget();
 }
 
 void
-WebGLContext::GetContextAttributes(Nullable<dom::WebGLContextAttributes> &retval)
+WebGLContext::GetContextAttributes(Nullable<dom::WebGLContextAttributes>& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
     dom::WebGLContextAttributes& result = retval.SetValue();
 
     result.mAlpha.Construct(mOptions.alpha);
@@ -1282,21 +1234,22 @@ WebGLContext::MozGetUnderlyingParamStrin
 
     MakeContextCurrent();
 
     switch (pname) {
     case LOCAL_GL_VENDOR:
     case LOCAL_GL_RENDERER:
     case LOCAL_GL_VERSION:
     case LOCAL_GL_SHADING_LANGUAGE_VERSION:
-    case LOCAL_GL_EXTENSIONS: {
-        const char *s = (const char *) gl->fGetString(pname);
-        retval.Assign(NS_ConvertASCIItoUTF16(nsDependentCString(s)));
-    }
-        break;
+    case LOCAL_GL_EXTENSIONS:
+        {
+            const char* s = (const char*)gl->fGetString(pname);
+            retval.Assign(NS_ConvertASCIItoUTF16(nsDependentCString(s)));
+            break;
+        }
 
     default:
         return NS_ERROR_INVALID_ARG;
     }
 
     return NS_OK;
 }
 
@@ -1315,17 +1268,18 @@ WebGLContext::ClearScreen()
         clearMask |= LOCAL_GL_STENCIL_BUFFER_BIT;
 
     colorAttachmentsMask[0] = true;
 
     ForceClearFramebufferWithDefaultValues(clearMask, colorAttachmentsMask);
 }
 
 void
-WebGLContext::ForceClearFramebufferWithDefaultValues(GLbitfield mask, const bool colorAttachmentsMask[kMaxColorAttachments])
+WebGLContext::ForceClearFramebufferWithDefaultValues(GLbitfield mask,
+                                                     const bool colorAttachmentsMask[kMaxColorAttachments])
 {
     MakeContextCurrent();
 
     bool initializeColorBuffer = 0 != (mask & LOCAL_GL_COLOR_BUFFER_BIT);
     bool initializeDepthBuffer = 0 != (mask & LOCAL_GL_DEPTH_BUFFER_BIT);
     bool initializeStencilBuffer = 0 != (mask & LOCAL_GL_STENCIL_BUFFER_BIT);
     bool drawBuffersIsEnabled = IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers);
     bool shouldOverrideDrawBuffers = false;
@@ -1457,25 +1411,27 @@ WebGLContext::PresentScreenBuffer()
     }
 
     mShouldPresent = false;
 
     return true;
 }
 
 void
-WebGLContext::DummyFramebufferOperation(const char *info)
+WebGLContext::DummyFramebufferOperation(const char* funcName)
 {
     FBStatus status = CheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
-    if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE)
-        ErrorInvalidFramebufferOperation("%s: incomplete framebuffer", info);
+    if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
+        ErrorInvalidFramebufferOperation("%s: incomplete framebuffer",
+                                         funcName);
+    }
 }
 
 static bool
-CheckContextLost(GLContext* gl, bool* out_isGuilty)
+CheckContextLost(GLContext* gl, bool* const out_isGuilty)
 {
     MOZ_ASSERT(gl);
     MOZ_ASSERT(out_isGuilty);
 
     bool isEGL = gl->GetContextType() == gl::GLContextType::EGL;
 
     GLenum resetStatus = LOCAL_GL_NO_ERROR;
     if (gl->HasRobustness()) {
@@ -1538,26 +1494,26 @@ WebGLContext::TryToRestoreContext()
 void
 WebGLContext::RunContextLossTimer()
 {
     mContextLossHandler->RunTimer();
 }
 
 class UpdateContextLossStatusTask : public nsRunnable
 {
-    nsRefPtr<WebGLContext> mContext;
+    nsRefPtr<WebGLContext> mWebGL;
 
 public:
-    explicit UpdateContextLossStatusTask(WebGLContext* aContext)
-        : mContext(aContext)
+    explicit UpdateContextLossStatusTask(WebGLContext* webgl)
+        : mWebGL(webgl)
     {
     }
 
     NS_IMETHOD Run() {
-        mContext->UpdateContextLossStatus();
+        mWebGL->UpdateContextLossStatus();
 
         return NS_OK;
     }
 };
 
 void
 WebGLContext::EnqueueUpdateContextLossStatus()
 {
@@ -1708,20 +1664,23 @@ WebGLContext::ForceRestoreContext()
 
     mContextObserver->UnregisterVisibilityChangeEvent();
 
     // Queue up a task, since we know the status changed.
     EnqueueUpdateContextLossStatus();
 }
 
 void
-WebGLContext::MakeContextCurrent() const { gl->MakeCurrent(); }
+WebGLContext::MakeContextCurrent() const
+{
+    gl->MakeCurrent();
+}
 
 mozilla::TemporaryRef<mozilla::gfx::SourceSurface>
-WebGLContext::GetSurfaceSnapshot(bool* aPremultAlpha)
+WebGLContext::GetSurfaceSnapshot(bool* out_premultAlpha)
 {
     if (!gl)
         return nullptr;
 
     bool hasAlpha = mOptions.alpha;
     SurfaceFormat surfFormat = hasAlpha ? SurfaceFormat::B8G8R8A8
                                         : SurfaceFormat::B8G8R8X8;
     RefPtr<DataSourceSurface> surf;
@@ -1734,23 +1693,23 @@ WebGLContext::GetSurfaceSnapshot(bool* a
 
     gl->MakeCurrent();
     {
         ScopedBindFramebuffer autoFB(gl, 0);
         ClearBackbufferIfNeeded();
         ReadPixelsIntoDataSurface(gl, surf);
     }
 
-    if (aPremultAlpha) {
-        *aPremultAlpha = true;
+    if (out_premultAlpha) {
+        *out_premultAlpha = true;
     }
     bool srcPremultAlpha = mOptions.premultipliedAlpha;
     if (!srcPremultAlpha) {
-        if (aPremultAlpha) {
-            *aPremultAlpha = false;
+        if (out_premultAlpha) {
+            *out_premultAlpha = false;
         } else {
             gfxUtils::PremultiplyDataSurface(surf, surf);
         }
     }
 
     RefPtr<DrawTarget> dt =
         Factory::CreateDrawTarget(BackendType::CAIRO,
                                   IntSize(mWidth, mHeight),
@@ -1774,84 +1733,94 @@ WebGLContext::GetSurfaceSnapshot(bool* a
 void
 WebGLContext::DidRefresh()
 {
     if (gl) {
         gl->FlushIfHeavyGLCallsSinceLastFlush();
     }
 }
 
-bool WebGLContext::TexImageFromVideoElement(const TexImageTarget texImageTarget, GLint level,
-                              GLenum internalformat, GLenum format, GLenum type,
-                              mozilla::dom::Element& elt)
+bool
+WebGLContext::TexImageFromVideoElement(const TexImageTarget texImageTarget,
+                                       GLint level, GLenum internalFormat,
+                                       GLenum format, GLenum type,
+                                       mozilla::dom::Element& elt)
 {
-    if (type == LOCAL_GL_HALF_FLOAT_OES) {
+    if (type == LOCAL_GL_HALF_FLOAT_OES)
         type = LOCAL_GL_HALF_FLOAT;
-    }
 
     if (!ValidateTexImageFormatAndType(format, type,
-                                       WebGLTexImageFunc::TexImage, WebGLTexDimensions::Tex2D))
+                                       WebGLTexImageFunc::TexImage,
+                                       WebGLTexDimensions::Tex2D))
     {
         return false;
     }
 
     HTMLVideoElement* video = HTMLVideoElement::FromContentOrNull(&elt);
-    if (!video) {
+    if (!video)
         return false;
-    }
 
     uint16_t readyState;
     if (NS_SUCCEEDED(video->GetReadyState(&readyState)) &&
         readyState < nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA)
     {
         //No frame inside, just return
         return false;
     }
 
     // If it doesn't have a principal, just bail
     nsCOMPtr<nsIPrincipal> principal = video->GetCurrentPrincipal();
-    if (!principal) {
+    if (!principal)
         return false;
-    }
 
     mozilla::layers::ImageContainer* container = video->GetImageContainer();
-    if (!container) {
+    if (!container)
         return false;
-    }
 
     if (video->GetCORSMode() == CORS_NONE) {
         bool subsumes;
         nsresult rv = mCanvasElement->NodePrincipal()->Subsumes(principal, &subsumes);
         if (NS_FAILED(rv) || !subsumes) {
             GenerateWarning("It is forbidden to load a WebGL texture from a cross-domain element that has not been validated with CORS. "
                                 "See https://developer.mozilla.org/en/WebGL/Cross-Domain_Textures");
             return false;
         }
     }
 
     gl->MakeCurrent();
     nsRefPtr<mozilla::layers::Image> srcImage = container->LockCurrentImage();
-    WebGLTexture* tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
 
     const WebGLTexture::ImageInfo& info = tex->ImageInfoAt(texImageTarget, 0);
     bool dimensionsMatch = info.Width() == srcImage->GetSize().width &&
                            info.Height() == srcImage->GetSize().height;
     if (!dimensionsMatch) {
         // we need to allocation
-        gl->fTexImage2D(texImageTarget.get(), level, internalformat, srcImage->GetSize().width, srcImage->GetSize().height, 0, format, type, nullptr);
+        gl->fTexImage2D(texImageTarget.get(), level, internalFormat,
+                        srcImage->GetSize().width, srcImage->GetSize().height,
+                        0, format, type, nullptr);
     }
-    bool ok = gl->BlitHelper()->BlitImageToTexture(srcImage.get(), srcImage->GetSize(), tex->GLName(), texImageTarget.get(), mPixelStoreFlipY);
+
+    bool ok = gl->BlitHelper()->BlitImageToTexture(srcImage.get(),
+                                                   srcImage->GetSize(),
+                                                   tex->GLName(),
+                                                   texImageTarget.get(),
+                                                   mPixelStoreFlipY);
     if (ok) {
-        TexInternalFormat effectiveinternalformat =
-            EffectiveInternalFormatFromInternalFormatAndType(internalformat, type);
-        MOZ_ASSERT(effectiveinternalformat != LOCAL_GL_NONE);
-        tex->SetImageInfo(texImageTarget, level, srcImage->GetSize().width, srcImage->GetSize().height, 1,
-                          effectiveinternalformat, WebGLImageDataStatus::InitializedImageData);
+        TexInternalFormat effectiveInternalFormat =
+            EffectiveInternalFormatFromInternalFormatAndType(internalFormat,
+                                                             type);
+        MOZ_ASSERT(effectiveInternalFormat != LOCAL_GL_NONE);
+        tex->SetImageInfo(texImageTarget, level, srcImage->GetSize().width,
+                          srcImage->GetSize().height, 1,
+                          effectiveInternalFormat,
+                          WebGLImageDataStatus::InitializedImageData);
         tex->Bind(TexImageTargetToTexTarget(texImageTarget));
     }
+
     srcImage = nullptr;
     container->UnlockCurrentImage();
     return ok;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 WebGLContext::ScopedMaskWorkaround::ScopedMaskWorkaround(WebGLContext& webgl)
@@ -1877,32 +1846,32 @@ WebGLContext::ScopedMaskWorkaround::~Sco
 }
 ////////////////////////////////////////////////////////////////////////////////
 // XPCOM goop
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLContext)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLContext)
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLContext,
-  mCanvasElement,
-  mExtensions,
-  mBound2DTextures,
-  mBoundCubeMapTextures,
-  mBound3DTextures,
-  mBoundArrayBuffer,
-  mBoundTransformFeedbackBuffer,
-  mCurrentProgram,
-  mBoundFramebuffer,
-  mBoundRenderbuffer,
-  mBoundVertexArray,
-  mDefaultVertexArray,
-  mActiveOcclusionQuery,
-  mActiveTransformFeedbackQuery)
+                                      mCanvasElement,
+                                      mExtensions,
+                                      mBound2DTextures,
+                                      mBoundCubeMapTextures,
+                                      mBound3DTextures,
+                                      mBoundArrayBuffer,
+                                      mBoundTransformFeedbackBuffer,
+                                      mCurrentProgram,
+                                      mBoundFramebuffer,
+                                      mBoundRenderbuffer,
+                                      mBoundVertexArray,
+                                      mDefaultVertexArray,
+                                      mActiveOcclusionQuery,
+                                      mActiveTransformFeedbackQuery)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLContext)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsIDOMWebGLRenderingContext)
-  NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
-  NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
-  // If the exact way we cast to nsISupports here ever changes, fix our
-  // ToSupports() method.
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMWebGLRenderingContext)
+    NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+    NS_INTERFACE_MAP_ENTRY(nsIDOMWebGLRenderingContext)
+    NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
+    NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
+    // If the exact way we cast to nsISupports here ever changes, fix our
+    // ToSupports() method.
+    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMWebGLRenderingContext)
 NS_INTERFACE_MAP_END
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -61,53 +61,53 @@ class nsIDocShell;
 #define MINVALUE_GL_MAX_VARYING_VECTORS               8     // Page 164
 #define MINVALUE_GL_MAX_TEXTURE_IMAGE_UNITS           8     // Page 164
 #define MINVALUE_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS    0     // Page 164
 #define MINVALUE_GL_MAX_RENDERBUFFER_SIZE             1024  // Different from the spec, which sets it to 1 on page 164
 #define MINVALUE_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS  8     // Page 164
 
 namespace mozilla {
 
-class WebGLContextLossHandler;
-class WebGLObserver;
+class WebGLActiveInfo;
 class WebGLContextBoundObject;
-class WebGLActiveInfo;
+class WebGLContextLossHandler;
+class WebGLBuffer;
 class WebGLExtensionBase;
-class WebGLBuffer;
-class WebGLShader;
+class WebGLFramebuffer;
+class WebGLObserver;
 class WebGLProgram;
 class WebGLQuery;
-class WebGLUniformLocation;
-class WebGLFramebuffer;
 class WebGLRenderbuffer;
 class WebGLSampler;
+class WebGLShader;
 class WebGLShaderPrecisionFormat;
 class WebGLTexture;
+class WebGLUniformLocation;
 class WebGLVertexArray;
 struct WebGLVertexAttribData;
 
 namespace dom {
+class Element;
 class ImageData;
-class Element;
-
 struct WebGLContextAttributes;
 template<typename> struct Nullable;
 }
 
 namespace gfx {
 class SourceSurface;
 }
 
 typedef WebGLRefPtr<WebGLQuery> WebGLQueryRefPtr;
 
 WebGLTexelFormat GetWebGLTexelFormat(TexInternalFormat format);
 
 void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow);
 
-struct WebGLContextOptions {
+struct WebGLContextOptions
+{
     // these are defaults
     WebGLContextOptions();
 
     bool operator==(const WebGLContextOptions& other) const {
         return
             alpha == other.alpha &&
             depth == other.depth &&
             stencil == other.stencil &&
@@ -144,36 +144,36 @@ class WebGLIntOrFloat {
 public:
     explicit WebGLIntOrFloat(GLint i) : mType(Int) { mValue.i = i; }
     explicit WebGLIntOrFloat(GLfloat f) : mType(Float) { mValue.f = f; }
 
     GLint AsInt() const { return (mType == Int) ? mValue.i : NS_lroundf(mValue.f); }
     GLfloat AsFloat() const { return (mType == Float) ? mValue.f : GLfloat(mValue.i); }
 };
 
-class WebGLContext :
-    public nsIDOMWebGLRenderingContext,
-    public nsICanvasRenderingContextInternal,
-    public nsSupportsWeakReference,
-    public WebGLContextUnchecked,
-    public WebGLRectangleObject,
-    public nsWrapperCache,
-    public SupportsWeakPtr<WebGLContext>
+class WebGLContext
+    : public nsIDOMWebGLRenderingContext
+    , public nsICanvasRenderingContextInternal
+    , public nsSupportsWeakReference
+    , public WebGLContextUnchecked
+    , public WebGLRectangleObject
+    , public nsWrapperCache
+    , public SupportsWeakPtr<WebGLContext>
 {
     friend class WebGLContextUserData;
     friend class WebGLExtensionCompressedTextureATC;
     friend class WebGLExtensionCompressedTextureETC1;
     friend class WebGLExtensionCompressedTexturePVRTC;
     friend class WebGLExtensionCompressedTextureS3TC;
     friend class WebGLExtensionDepthTexture;
     friend class WebGLExtensionDrawBuffers;
     friend class WebGLExtensionLoseContext;
     friend class WebGLExtensionVertexArray;
+    friend class WebGLMemoryTracker;
     friend class WebGLObserver;
-    friend class WebGLMemoryTracker;
 
     enum {
         UNPACK_FLIP_Y_WEBGL = 0x9240,
         UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
         CONTEXT_LOST_WEBGL = 0x9242,
         UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
         BROWSER_DEFAULT_WEBGL = 0x9244,
         UNMASKED_VENDOR_WEBGL = 0x9245,
@@ -185,105 +185,120 @@ public:
 
     MOZ_DECLARE_REFCOUNTED_TYPENAME(WebGLContext)
 
     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
                                                            nsIDOMWebGLRenderingContext)
 
-    virtual JSObject* WrapObject(JSContext *cx) = 0;
+    virtual JSObject* WrapObject(JSContext* cx) = 0;
 
     NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT
 
     // nsICanvasRenderingContextInternal
 #ifdef DEBUG
     virtual int32_t GetWidth() const MOZ_OVERRIDE;
     virtual int32_t GetHeight() const MOZ_OVERRIDE;
 #endif
     NS_IMETHOD SetDimensions(int32_t width, int32_t height) MOZ_OVERRIDE;
-    NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) MOZ_OVERRIDE
-        { return NS_ERROR_NOT_IMPLEMENTED; }
-    NS_IMETHOD Reset() MOZ_OVERRIDE
-        { /* (InitializeWithSurface) */ return NS_ERROR_NOT_IMPLEMENTED; }
-    virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat);
-    NS_IMETHOD GetInputStream(const char* aMimeType,
-                              const char16_t* aEncoderOptions,
-                              nsIInputStream **aStream) MOZ_OVERRIDE;
-    mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha) MOZ_OVERRIDE;
+    NS_IMETHOD InitializeWithSurface(nsIDocShell*, gfxASurface*, int32_t,
+                                     int32_t) MOZ_OVERRIDE
+    {
+        return NS_ERROR_NOT_IMPLEMENTED;
+    }
+
+    NS_IMETHOD Reset() MOZ_OVERRIDE {
+        /* (InitializeWithSurface) */
+        return NS_ERROR_NOT_IMPLEMENTED;
+    }
 
-    NS_IMETHOD SetIsOpaque(bool b) MOZ_OVERRIDE { return NS_OK; };
+    virtual void GetImageBuffer(uint8_t** out_imageBuffer,
+                                int32_t* out_format) MOZ_OVERRIDE;
+    NS_IMETHOD GetInputStream(const char* mimeType,
+                              const char16_t* encoderOptions,
+                              nsIInputStream** out_stream) MOZ_OVERRIDE;
+
+    mozilla::TemporaryRef<mozilla::gfx::SourceSurface>
+    GetSurfaceSnapshot(bool* out_premultAlpha) MOZ_OVERRIDE;
+
+    NS_IMETHOD SetIsOpaque(bool) MOZ_OVERRIDE { return NS_OK; };
     bool GetIsOpaque() MOZ_OVERRIDE { return false; }
-    NS_IMETHOD SetContextOptions(JSContext* aCx,
-                                 JS::Handle<JS::Value> aOptions) MOZ_OVERRIDE;
+    NS_IMETHOD SetContextOptions(JSContext* cx,
+                                 JS::Handle<JS::Value> options) MOZ_OVERRIDE;
 
-    NS_IMETHOD SetIsIPC(bool b) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
+    NS_IMETHOD SetIsIPC(bool) MOZ_OVERRIDE {
+        return NS_ERROR_NOT_IMPLEMENTED;
+    }
 
     /**
      * An abstract base class to be implemented by callers wanting to be notified
      * that a refresh has occurred. Callers must ensure an observer is removed
      * before it is destroyed.
      */
     virtual void DidRefresh() MOZ_OVERRIDE;
 
-    NS_IMETHOD Redraw(const gfxRect&) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
+    NS_IMETHOD Redraw(const gfxRect&) MOZ_OVERRIDE {
+        return NS_ERROR_NOT_IMPLEMENTED;
+    }
 
     void SynthesizeGLError(GLenum err);
-    void SynthesizeGLError(GLenum err, const char *fmt, ...);
+    void SynthesizeGLError(GLenum err, const char* fmt, ...);
 
-    void ErrorInvalidEnum(const char *fmt = 0, ...);
-    void ErrorInvalidOperation(const char *fmt = 0, ...);
-    void ErrorInvalidValue(const char *fmt = 0, ...);
-    void ErrorInvalidFramebufferOperation(const char *fmt = 0, ...);
-    void ErrorInvalidEnumInfo(const char *info, GLenum enumvalue);
-    void ErrorOutOfMemory(const char *fmt = 0, ...);
+    void ErrorInvalidEnum(const char* fmt = 0, ...);
+    void ErrorInvalidOperation(const char* fmt = 0, ...);
+    void ErrorInvalidValue(const char* fmt = 0, ...);
+    void ErrorInvalidFramebufferOperation(const char* fmt = 0, ...);
+    void ErrorInvalidEnumInfo(const char* info, GLenum enumvalue);
+    void ErrorOutOfMemory(const char* fmt = 0, ...);
 
-    const char *ErrorName(GLenum error);
+    const char* ErrorName(GLenum error);
 
     /**
      * Return displayable name for GLenum.
      * This version is like gl::GLenumToStr but with out the GL_ prefix to
      * keep consistency with how errors are reported from WebGL.
      */
-
     // Returns nullptr if glenum is unknown.
     static const char* EnumName(GLenum glenum);
     // Returns hex formatted version of glenum if glenum is unknown.
     static void EnumName(GLenum glenum, nsACString* out_name);
 
     bool IsCompressedTextureFormat(GLenum format);
     bool IsTextureFormatCompressed(TexInternalFormat format);
 
-    void DummyFramebufferOperation(const char *info);
+    void DummyFramebufferOperation(const char* funcName);
 
-    WebGLTexture* activeBoundTextureForTarget(const TexTarget texTarget) const {
+    WebGLTexture* ActiveBoundTextureForTarget(const TexTarget texTarget) const {
         switch (texTarget.get()) {
-            case LOCAL_GL_TEXTURE_2D:
-                return mBound2DTextures[mActiveTexture];
-            case LOCAL_GL_TEXTURE_CUBE_MAP:
-                return mBoundCubeMapTextures[mActiveTexture];
-            case LOCAL_GL_TEXTURE_3D:
-                return mBound3DTextures[mActiveTexture];
-            default:
-                MOZ_CRASH("bad target");
+        case LOCAL_GL_TEXTURE_2D:
+            return mBound2DTextures[mActiveTexture];
+        case LOCAL_GL_TEXTURE_CUBE_MAP:
+            return mBoundCubeMapTextures[mActiveTexture];
+        case LOCAL_GL_TEXTURE_3D:
+            return mBound3DTextures[mActiveTexture];
+        default:
+            MOZ_CRASH("bad target");
         }
     }
 
     /* Use this function when you have the texture image target, for example:
      * GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_[POSITIVE|NEGATIVE]_[X|Y|Z], and
      * not the actual texture binding target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
      */
-    WebGLTexture* activeBoundTextureForTexImageTarget(const TexImageTarget texImgTarget) const {
+    WebGLTexture*
+    ActiveBoundTextureForTexImageTarget(const TexImageTarget texImgTarget) const
+    {
         const TexTarget texTarget = TexImageTargetToTexTarget(texImgTarget);
-        return activeBoundTextureForTarget(texTarget);
+        return ActiveBoundTextureForTarget(texTarget);
     }
 
-    already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
-                                                 CanvasLayer *aOldLayer,
-                                                 LayerManager *aManager) MOZ_OVERRIDE;
+    already_AddRefed<CanvasLayer>
+    GetCanvasLayer(nsDisplayListBuilder* builder, CanvasLayer* oldLayer,
+                   LayerManager* manager) MOZ_OVERRIDE;
 
     // Note that 'clean' here refers to its invalidation state, not the
     // contents of the buffer.
     void MarkContextClean() MOZ_OVERRIDE { mInvalidated = false; }
 
     gl::GLContext* GL() const { return gl; }
 
     bool IsPremultAlpha() const { return mOptions.premultipliedAlpha; }
@@ -298,17 +313,18 @@ public:
     const WebGLRectangleObject* CurValidFBRectObject() const;
 
     static const size_t kMaxColorAttachments = 16;
 
     // This is similar to GLContext::ClearSafely, but tries to minimize the
     // amount of work it does.
     // It only clears the buffers we specify, and can reset its state without
     // first having to query anything, as WebGL knows its state at all times.
-    void ForceClearFramebufferWithDefaultValues(GLbitfield mask, const bool colorAttachmentsMask[kMaxColorAttachments]);
+    void ForceClearFramebufferWithDefaultValues(GLbitfield mask,
+                                                const bool colorAttachmentsMask[kMaxColorAttachments]);
 
     // Calls ForceClearFramebufferWithDefaultValues() for the Context's 'screen'.
     void ClearScreen();
     void ClearBackbufferIfNeeded();
 
     bool MinCapabilityMode() const { return mMinCapability; }
 
     void RunContextLossTimer();
@@ -318,328 +334,349 @@ public:
     bool TryToRestoreContext();
 
     void AssertCachedBindings();
     void AssertCachedState();
 
     // WebIDL WebGLRenderingContext API
     dom::HTMLCanvasElement* GetCanvas() const { return mCanvasElement; }
     GLsizei DrawingBufferWidth() const { return IsContextLost() ? 0 : mWidth; }
-    GLsizei DrawingBufferHeight() const { return IsContextLost() ? 0 : mHeight; }
+    GLsizei DrawingBufferHeight() const {
+        return IsContextLost() ? 0 : mHeight;
+    }
 
-    void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
+    void
+    GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
+
     bool IsContextLost() const { return mContextStatus != ContextNotLost; }
-    void GetSupportedExtensions(JSContext *cx, dom::Nullable< nsTArray<nsString> > &retval);
-    void GetExtension(JSContext* cx, const nsAString& aName,
-                      JS::MutableHandle<JSObject*> aRetval,
-                      ErrorResult& rv);
+    void GetSupportedExtensions(JSContext* cx,
+                                dom::Nullable< nsTArray<nsString> >& retval);
+    void GetExtension(JSContext* cx, const nsAString& name,
+                      JS::MutableHandle<JSObject*> retval, ErrorResult& rv);
     void ActiveTexture(GLenum texture);
-    void AttachShader(WebGLProgram* program, WebGLShader* shader);
-    void BindAttribLocation(WebGLProgram* program, GLuint location,
+    void AttachShader(WebGLProgram* prog, WebGLShader* shader);
+    void BindAttribLocation(WebGLProgram* prog, GLuint location,
                             const nsAString& name);
-    void BindFramebuffer(GLenum target, WebGLFramebuffer* wfb);
-    void BindRenderbuffer(GLenum target, WebGLRenderbuffer* wrb);
-    void BindTexture(GLenum target, WebGLTexture *tex);
-    void BindVertexArray(WebGLVertexArray *vao);
+    void BindFramebuffer(GLenum target, WebGLFramebuffer* fb);
+    void BindRenderbuffer(GLenum target, WebGLRenderbuffer* fb);
+    void BindTexture(GLenum target, WebGLTexture* tex);
+    void BindVertexArray(WebGLVertexArray* vao);
     void BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
     void BlendEquation(GLenum mode);
     void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
     void BlendFunc(GLenum sfactor, GLenum dfactor);
     void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
                            GLenum srcAlpha, GLenum dstAlpha);
     GLenum CheckFramebufferStatus(GLenum target);
     void Clear(GLbitfield mask);
     void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
     void ClearDepth(GLclampf v);
     void ClearStencil(GLint v);
     void ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a);
     void CompileShader(WebGLShader* shader);
-    void CompressedTexImage2D(GLenum target, GLint level,
+    void CompressedTexImage2D(GLenum texImageTarget, GLint level,
                               GLenum internalformat, GLsizei width,
                               GLsizei height, GLint border,
                               const dom::ArrayBufferView& view);
-    void CompressedTexSubImage2D(GLenum target, GLint level,
-                                 GLint xoffset, GLint yoffset,
-                                 GLsizei width, GLsizei height,
-                                 GLenum format,
+    void CompressedTexSubImage2D(GLenum texImageTarget, GLint level,
+                                 GLint xoffset, GLint yoffset, GLsizei width,
+                                 GLsizei height, GLenum format,
                                  const dom::ArrayBufferView& view);
-    void CopyTexImage2D(GLenum target, GLint level,
-                        GLenum internalformat, GLint x, GLint y,
-                        GLsizei width, GLsizei height, GLint border);
-    void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset,
-                           GLint yoffset, GLint x, GLint y,
-                           GLsizei width, GLsizei height);
+    void CopyTexImage2D(GLenum texImageTarget, GLint level,
+                        GLenum internalformat, GLint x, GLint y, GLsizei width,
+                        GLsizei height, GLint border);
+    void CopyTexSubImage2D(GLenum texImageTarget, GLint level, GLint xoffset,
+                           GLint yoffset, GLint x, GLint y, GLsizei width,
+                           GLsizei height);
     already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
     already_AddRefed<WebGLProgram> CreateProgram();
     already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
     already_AddRefed<WebGLTexture> CreateTexture();
     already_AddRefed<WebGLShader> CreateShader(GLenum type);
     already_AddRefed<WebGLVertexArray> CreateVertexArray();
     void CullFace(GLenum face);
-    void DeleteFramebuffer(WebGLFramebuffer *fbuf);
-    void DeleteProgram(WebGLProgram *prog);
-    void DeleteRenderbuffer(WebGLRenderbuffer *rbuf);
-    void DeleteShader(WebGLShader *shader);
-    void DeleteVertexArray(WebGLVertexArray *vao);
-    void DeleteTexture(WebGLTexture *tex);
+    void DeleteFramebuffer(WebGLFramebuffer* fb);
+    void DeleteProgram(WebGLProgram* prog);
+    void DeleteRenderbuffer(WebGLRenderbuffer* rb);
+    void DeleteShader(WebGLShader* shader);
+    void DeleteVertexArray(WebGLVertexArray* vao);
+    void DeleteTexture(WebGLTexture* tex);
     void DepthFunc(GLenum func);
     void DepthMask(WebGLboolean b);
     void DepthRange(GLclampf zNear, GLclampf zFar);
-    void DetachShader(WebGLProgram *program, WebGLShader *shader);
+    void DetachShader(WebGLProgram* prog, WebGLShader* shader);
     void DrawBuffers(const dom::Sequence<GLenum>& buffers);
     void Flush();
     void Finish();
     void FramebufferRenderbuffer(GLenum target, GLenum attachment,
-                                 GLenum rbtarget, WebGLRenderbuffer *wrb);
+                                 GLenum rbTarget, WebGLRenderbuffer* rb);
     void FramebufferTexture2D(GLenum target, GLenum attachment,
-                              GLenum textarget, WebGLTexture *tobj,
+                              GLenum texImageTarget, WebGLTexture* tex,
                               GLint level);
 
     // Framebuffer validation
     bool ValidateFramebufferAttachment(GLenum attachment, const char* funcName);
 
     void FrontFace(GLenum mode);
     void GenerateMipmap(GLenum target);
-    already_AddRefed<WebGLActiveInfo> GetActiveAttrib(WebGLProgram *prog,
+    already_AddRefed<WebGLActiveInfo> GetActiveAttrib(WebGLProgram* prog,
                                                       GLuint index);
-    already_AddRefed<WebGLActiveInfo> GetActiveUniform(WebGLProgram *prog,
+    already_AddRefed<WebGLActiveInfo> GetActiveUniform(WebGLProgram* prog,
                                                        GLuint index);
-    void GetAttachedShaders(WebGLProgram* prog,
-                            dom::Nullable<nsTArray<nsRefPtr<WebGLShader>>>& retval);
+
+    void
+    GetAttachedShaders(WebGLProgram* prog,
+                       dom::Nullable<nsTArray<nsRefPtr<WebGLShader>>>& retval);
+
     GLint GetAttribLocation(WebGLProgram* prog, const nsAString& name);
     JS::Value GetBufferParameter(GLenum target, GLenum pname);
-    void GetBufferParameter(JSContext* /* unused */, GLenum target,
-                            GLenum pname,
-                            JS::MutableHandle<JS::Value> retval) {
+
+    void GetBufferParameter(JSContext*, GLenum target, GLenum pname,
+                            JS::MutableHandle<JS::Value> retval)
+    {
         retval.set(GetBufferParameter(target, pname));
     }
+
     GLenum GetError();
-    JS::Value GetFramebufferAttachmentParameter(JSContext* cx,
-                                                GLenum target,
-                                                GLenum attachment,
-                                                GLenum pname,
+    JS::Value GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
+                                                GLenum attachment, GLenum pname,
                                                 ErrorResult& rv);
-    void GetFramebufferAttachmentParameter(JSContext* cx,
-                                           GLenum target,
-                                           GLenum attachment,
-                                           GLenum pname,
+
+    void GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
+                                           GLenum attachment, GLenum pname,
                                            JS::MutableHandle<JS::Value> retval,
-                                           ErrorResult& rv) {
+                                           ErrorResult& rv)
+    {
         retval.set(GetFramebufferAttachmentParameter(cx, target, attachment,
                                                      pname, rv));
     }
-    JS::Value GetProgramParameter(WebGLProgram *prog, GLenum pname);
-    void  GetProgramParameter(JSContext* /* unused */, WebGLProgram *prog,
-                              GLenum pname,
-                              JS::MutableHandle<JS::Value> retval) {
+
+    JS::Value GetProgramParameter(WebGLProgram* prog, GLenum pname);
+
+    void  GetProgramParameter(JSContext*, WebGLProgram* prog, GLenum pname,
+                              JS::MutableHandle<JS::Value> retval)
+    {
         retval.set(GetProgramParameter(prog, pname));
     }
-    void GetProgramInfoLog(WebGLProgram *prog, nsACString& retval);
-    void GetProgramInfoLog(WebGLProgram *prog, nsAString& retval);
+
+    void GetProgramInfoLog(WebGLProgram* prog, nsACString& retval);
+    void GetProgramInfoLog(WebGLProgram* prog, nsAString& retval);
     JS::Value GetRenderbufferParameter(GLenum target, GLenum pname);
-    void GetRenderbufferParameter(JSContext* /* unused */,
-                                  GLenum target, GLenum pname,
-                                  JS::MutableHandle<JS::Value> retval) {
+
+    void GetRenderbufferParameter(JSContext*, GLenum target, GLenum pname,
+                                  JS::MutableHandle<JS::Value> retval)
+    {
         retval.set(GetRenderbufferParameter(target, pname));
     }
-    JS::Value GetShaderParameter(WebGLShader *shader, GLenum pname);
-    void GetShaderParameter(JSContext* /* unused */, WebGLShader *shader,
-                            GLenum pname,
-                            JS::MutableHandle<JS::Value> retval) {
+
+    JS::Value GetShaderParameter(WebGLShader* shader, GLenum pname);
+
+    void GetShaderParameter(JSContext*, WebGLShader* shader, GLenum pname,
+                            JS::MutableHandle<JS::Value> retval)
+    {
         retval.set(GetShaderParameter(shader, pname));
     }
+
     already_AddRefed<WebGLShaderPrecisionFormat>
-      GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
-    void GetShaderInfoLog(WebGLShader *shader, nsACString& retval);
-    void GetShaderInfoLog(WebGLShader *shader, nsAString& retval);
-    void GetShaderSource(WebGLShader *shader, nsAString& retval);
-    void GetShaderTranslatedSource(WebGLShader *shader, nsAString& retval);
+    GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
+
+    void GetShaderInfoLog(WebGLShader* shader, nsACString& retval);
+    void GetShaderInfoLog(WebGLShader* shader, nsAString& retval);
+    void GetShaderSource(WebGLShader* shader, nsAString& retval);
+    void GetShaderTranslatedSource(WebGLShader* shader, nsAString& retval);
     JS::Value GetTexParameter(GLenum target, GLenum pname);
-    void GetTexParameter(JSContext * /* unused */, GLenum target,
-                         GLenum pname,
-                         JS::MutableHandle<JS::Value> retval) {
+
+    void GetTexParameter(JSContext*, GLenum target, GLenum pname,
+                         JS::MutableHandle<JS::Value> retval)
+    {
         retval.set(GetTexParameter(target, pname));
     }
-    JS::Value GetUniform(JSContext* cx, WebGLProgram *prog,
-                         WebGLUniformLocation *location);
-    void GetUniform(JSContext* cx, WebGLProgram *prog,
-                    WebGLUniformLocation *location,
-                    JS::MutableHandle<JS::Value> retval) {
-        retval.set(GetUniform(cx, prog, location));
+
+    JS::Value GetUniform(JSContext* cx, WebGLProgram* prog,
+                         WebGLUniformLocation* loc);
+
+    void GetUniform(JSContext* cx, WebGLProgram* prog,
+                    WebGLUniformLocation* loc,
+                    JS::MutableHandle<JS::Value> retval)
+    {
+        retval.set(GetUniform(cx, prog, loc));
     }
+
     already_AddRefed<WebGLUniformLocation>
-      GetUniformLocation(WebGLProgram *prog, const nsAString& name);
+    GetUniformLocation(WebGLProgram* prog, const nsAString& name);
+
     void Hint(GLenum target, GLenum mode);
-    bool IsFramebuffer(WebGLFramebuffer *fb);
-    bool IsProgram(WebGLProgram *prog);
-    bool IsRenderbuffer(WebGLRenderbuffer *rb);
-    bool IsShader(WebGLShader *shader);
-    bool IsTexture(WebGLTexture *tex);
-    bool IsVertexArray(WebGLVertexArray *vao);
+    bool IsFramebuffer(WebGLFramebuffer* fb);
+    bool IsProgram(WebGLProgram* prog);
+    bool IsRenderbuffer(WebGLRenderbuffer* rb);
+    bool IsShader(WebGLShader* shader);
+    bool IsTexture(WebGLTexture* tex);
+    bool IsVertexArray(WebGLVertexArray* vao);
     void LineWidth(GLfloat width);
-    void LinkProgram(WebGLProgram *program);
+    void LinkProgram(WebGLProgram* prog);
     void PixelStorei(GLenum pname, GLint param);
     void PolygonOffset(GLfloat factor, GLfloat units);
     void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
                     GLenum format, GLenum type,
-                    const Nullable<dom::ArrayBufferView> &pixels,
+                    const Nullable<dom::ArrayBufferView>& pixels,
                     ErrorResult& rv);
-    void RenderbufferStorage(GLenum target, GLenum internalformat,
+    void RenderbufferStorage(GLenum target, GLenum internalFormat,
                              GLsizei width, GLsizei height);
     void SampleCoverage(GLclampf value, WebGLboolean invert);
     void Scissor(GLint x, GLint y, GLsizei width, GLsizei height);
-    void ShaderSource(WebGLShader *shader, const nsAString& source);
+    void ShaderSource(WebGLShader* shader, const nsAString& source);
     void StencilFunc(GLenum func, GLint ref, GLuint mask);
-    void StencilFuncSeparate(GLenum face, GLenum func, GLint ref,
-                             GLuint mask);
+    void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
     void StencilMask(GLuint mask);
     void StencilMaskSeparate(GLenum face, GLuint mask);
     void StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
     void StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail,
                            GLenum dppass);
-    void TexImage2D(GLenum target, GLint level,
-                    GLenum internalformat, GLsizei width,
-                    GLsizei height, GLint border, GLenum format,
-                    GLenum type,
-                    const Nullable<dom::ArrayBufferView> &pixels,
+    void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
+                    GLsizei width, GLsizei height, GLint border, GLenum format,
+                    GLenum type, const Nullable<dom::ArrayBufferView>& pixels,
                     ErrorResult& rv);
-    void TexImage2D(GLenum target, GLint level,
-                    GLenum internalformat, GLenum format, GLenum type,
-                    dom::ImageData* pixels, ErrorResult& rv);
+    void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
+                    GLenum format, GLenum type, dom::ImageData* pixels,
+                    ErrorResult& rv);
     // Allow whatever element types the bindings are willing to pass
     // us in TexImage2D
     bool TexImageFromVideoElement(TexImageTarget texImageTarget, GLint level,
-                                  GLenum internalformat, GLenum format, GLenum type,
-                                  mozilla::dom::Element& image);
+                                  GLenum internalFormat, GLenum format,
+                                  GLenum type, mozilla::dom::Element& image);
 
     template<class ElementType>
-    void TexImage2D(GLenum rawTexImgTarget, GLint level,
-                    GLenum internalformat, GLenum format, GLenum type,
+    void TexImage2D(GLenum rawTexImageTarget, GLint level,
+                    GLenum internalFormat, GLenum format, GLenum type,
                     ElementType& elt, ErrorResult& rv)
     {
         if (IsContextLost())
             return;
 
-        if (!ValidateTexImageTarget(rawTexImgTarget,
+        if (!ValidateTexImageTarget(rawTexImageTarget,
                                     WebGLTexImageFunc::TexImage,
                                     WebGLTexDimensions::Tex2D))
         {
-            return ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImgTarget);
+            ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget);
+            return;
         }
 
-        const TexImageTarget texImageTarget(rawTexImgTarget);
+        const TexImageTarget texImageTarget(rawTexImageTarget);
 
         if (level < 0)
             return ErrorInvalidValue("texImage2D: level is negative");
 
         const int32_t maxLevel = MaxTextureLevelForTexImageTarget(texImageTarget);
-        if (level > maxLevel)
-            return ErrorInvalidValue("texImage2D: level %d is too large, max is %d", level, maxLevel);
+        if (level > maxLevel) {
+            ErrorInvalidValue("texImage2D: level %d is too large, max is %d",
+                              level, maxLevel);
+            return;
+        }
 
-        WebGLTexture* tex = activeBoundTextureForTexImageTarget(texImageTarget);
+        WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
 
         if (!tex)
             return ErrorInvalidOperation("no texture is bound to this target");
 
         // Trying to handle the video by GPU directly first
-        if (TexImageFromVideoElement(texImageTarget, level, internalformat, format, type, elt)) {
+        if (TexImageFromVideoElement(texImageTarget, level, internalFormat,
+                                     format, type, elt))
+        {
             return;
         }
 
         RefPtr<gfx::DataSourceSurface> data;
         WebGLTexelFormat srcFormat;
         nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt);
-        rv = SurfaceFromElementResultToImageSurface(res, data,
-                                                    &srcFormat);
+        rv = SurfaceFromElementResultToImageSurface(res, data, &srcFormat);
         if (rv.Failed() || !data)
             return;
 
         gfx::IntSize size = data->GetSize();
         uint32_t byteLength = data->Stride() * size.height;
-        return TexImage2D_base(texImageTarget, level, internalformat,
-                               size.width, size.height, data->Stride(),
-                               0, format, type, data->GetData(), byteLength,
-                               js::Scalar::TypeMax, srcFormat, mPixelStorePremultiplyAlpha);
+        return TexImage2D_base(texImageTarget, level, internalFormat,
+                               size.width, size.height, data->Stride(), 0,
+                               format, type, data->GetData(), byteLength,
+                               js::Scalar::TypeMax, srcFormat,
+                               mPixelStorePremultiplyAlpha);
     }
 
     void TexParameterf(GLenum target, GLenum pname, GLfloat param) {
         TexParameter_base(target, pname, nullptr, &param);
     }
     void TexParameteri(GLenum target, GLenum pname, GLint param) {
         TexParameter_base(target, pname, &param, nullptr);
     }
 
-    void TexSubImage2D(GLenum target, GLint level,
-                       GLint xoffset, GLint yoffset,
-                       GLsizei width, GLsizei height, GLenum format,
-                       GLenum type,
-                       const Nullable<dom::ArrayBufferView> &pixels,
+    void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xoffset,
+                       GLint yoffset, GLsizei width, GLsizei height,
+                       GLenum format, GLenum type,
+                       const Nullable<dom::ArrayBufferView>& pixels,
                        ErrorResult& rv);
-    void TexSubImage2D(GLenum target, GLint level,
-                       GLint xoffset, GLint yoffset, GLenum format,
-                       GLenum type, dom::ImageData* pixels, ErrorResult& rv);
+    void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xoffset,
+                       GLint yoffset, GLenum format, GLenum type,
+                       dom::ImageData* pixels, ErrorResult& rv);
     // Allow whatever element types the bindings are willing to pass
     // us in TexSubImage2D
     template<class ElementType>
-    void TexSubImage2D(GLenum rawTexImageTarget,
-                       GLint level,
-                       GLint xoffset, GLint yoffset,
-                       GLenum format,
-                       GLenum type,
+    void TexSubImage2D(GLenum rawTexImageTarget, GLint level, GLint xoffset,
+                       GLint yoffset, GLenum format, GLenum type,
                        ElementType& elt, ErrorResult& rv)
     {
         if (IsContextLost())
             return;
 
         if (!ValidateTexImageTarget(rawTexImageTarget,
                                     WebGLTexImageFunc::TexSubImage,
                                     WebGLTexDimensions::Tex2D))
         {
-            return ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget);
+            ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget);
+            return;
         }
 
         const TexImageTarget texImageTarget(rawTexImageTarget);
 
         if (level < 0)
             return ErrorInvalidValue("texSubImage2D: level is negative");
 
         const int32_t maxLevel = MaxTextureLevelForTexImageTarget(texImageTarget);
-        if (level > maxLevel)
-            return ErrorInvalidValue("texSubImage2D: level %d is too large, max is %d", level, maxLevel);
+        if (level > maxLevel) {
+            ErrorInvalidValue("texSubImage2D: level %d is too large, max is %d",
+                              level, maxLevel);
+            return;
+        }
 
-        WebGLTexture* tex = activeBoundTextureForTexImageTarget(texImageTarget);
-        if (!tex) {
+        WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
+        if (!tex)
             return ErrorInvalidOperation("texSubImage2D: no texture bound on active texture unit");
-        }
-        const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(texImageTarget, level);
-        const TexInternalFormat internalformat = imageInfo.EffectiveInternalFormat();
+
+        const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level);
+        const TexInternalFormat internalFormat = imageInfo.EffectiveInternalFormat();
 
         // Trying to handle the video by GPU directly first
         if (TexImageFromVideoElement(texImageTarget, level,
-                                     internalformat.get(), format, type, elt))
+                                     internalFormat.get(), format, type, elt))
         {
             return;
         }
 
         RefPtr<gfx::DataSourceSurface> data;
         WebGLTexelFormat srcFormat;
         nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt);
-        rv = SurfaceFromElementResultToImageSurface(res, data,
-                                                    &srcFormat);
+        rv = SurfaceFromElementResultToImageSurface(res, data, &srcFormat);
         if (rv.Failed() || !data)
             return;
 
         gfx::IntSize size = data->GetSize();
         uint32_t byteLength = data->Stride() * size.height;
         return TexSubImage2D_base(texImageTarget.get(), level, xoffset, yoffset,
-                                  size.width, size.height,
-                                  data->Stride(), format, type,
-                                  data->GetData(), byteLength,
-                                  js::Scalar::TypeMax, srcFormat, mPixelStorePremultiplyAlpha);
-
+                                  size.width, size.height, data->Stride(),
+                                  format, type, data->GetData(), byteLength,
+                                  js::Scalar::TypeMax, srcFormat,
+                                  mPixelStorePremultiplyAlpha);
     }
 
     void Uniform1i(WebGLUniformLocation* loc, GLint x);
     void Uniform2i(WebGLUniformLocation* loc, GLint x, GLint y);
     void Uniform3i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z);
     void Uniform4i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z,
                    GLint w);
 
@@ -790,96 +827,101 @@ public:
     {
         UniformMatrix4fv_base(loc, transpose, value.Length(),
                               value.Elements());
     }
     void UniformMatrix4fv_base(WebGLUniformLocation* loc,
                                WebGLboolean transpose, size_t arrayLength,
                                const float* data);
 
-    void UseProgram(WebGLProgram *prog);
-    bool ValidateAttribArraySetter(const char* name, uint32_t cnt, uint32_t arrayLength);
+    void UseProgram(WebGLProgram* prog);
+    bool ValidateAttribArraySetter(const char* name, uint32_t count,
+                                   uint32_t arrayLength);
     bool ValidateUniformSetter(WebGLUniformLocation* loc, uint8_t setterSize,
                                GLenum setterType, const char* info,
                                GLuint* out_rawLoc);
     bool ValidateUniformArraySetter(WebGLUniformLocation* loc,
                                     uint8_t setterElemSize, GLenum setterType,
                                     size_t setterArraySize, const char* info,
                                     GLuint* out_rawLoc,
                                     GLsizei* out_numElementsToUpload);
     bool ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
                                           uint8_t setterDims, GLenum setterType,
                                           size_t setterArraySize,
                                           bool setterTranspose,
                                           const char* info, GLuint* out_rawLoc,
                                           GLsizei* out_numElementsToUpload);
-    void ValidateProgram(WebGLProgram *prog);
-    bool ValidateUniformLocation(const char* info, WebGLUniformLocation *location_object);
+    void ValidateProgram(WebGLProgram* prog);
+    bool ValidateUniformLocation(const char* info, WebGLUniformLocation* loc);
     bool ValidateSamplerUniformSetter(const char* info,
-                                    WebGLUniformLocation *location,
-                                    GLint value);
+                                      WebGLUniformLocation* loc, GLint value);
     void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
 // -----------------------------------------------------------------------------
 // WEBGL_lose_context
 public:
     void LoseContext();
     void RestoreContext();
 
 // -----------------------------------------------------------------------------
 // Buffer Objects (WebGLContextBuffers.cpp)
 public:
     void BindBuffer(GLenum target, WebGLBuffer* buf);
-    void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer);
-    void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer,
+    void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buf);
+    void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buf,
                          WebGLintptr offset, WebGLsizeiptr size);
     void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
-    void BufferData(GLenum target, const dom::ArrayBufferView &data,
+    void BufferData(GLenum target, const dom::ArrayBufferView& data,
                     GLenum usage);
-    void BufferData(GLenum target,
-                    const Nullable<dom::ArrayBuffer> &maybeData,
+    void BufferData(GLenum target, const Nullable<dom::ArrayBuffer>& maybeData,
                     GLenum usage);
     void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
-                       const dom::ArrayBufferView &data);
+                       const dom::ArrayBufferView& data);
     void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
-                       const Nullable<dom::ArrayBuffer> &maybeData);
+                       const Nullable<dom::ArrayBuffer>& maybeData);
     already_AddRefed<WebGLBuffer> CreateBuffer();
-    void DeleteBuffer(WebGLBuffer *buf);
-    bool IsBuffer(WebGLBuffer *buffer);
+    void DeleteBuffer(WebGLBuffer* buf);
+    bool IsBuffer(WebGLBuffer* buf);
 
 private:
     // ARRAY_BUFFER slot
     WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
 
     // TRANSFORM_FEEDBACK_BUFFER slot
     WebGLRefPtr<WebGLBuffer> mBoundTransformFeedbackBuffer;
 
     // these two functions emit INVALID_ENUM for invalid `target`.
-    WebGLRefPtr<WebGLBuffer>* GetBufferSlotByTarget(GLenum target, const char* infos);
-    WebGLRefPtr<WebGLBuffer>* GetBufferSlotByTargetIndexed(GLenum target, GLuint index, const char* infos);
-    bool ValidateBufferUsageEnum(GLenum target, const char* infos);
+    WebGLRefPtr<WebGLBuffer>* GetBufferSlotByTarget(GLenum target,
+                                                    const char* info);
+    WebGLRefPtr<WebGLBuffer>* GetBufferSlotByTargetIndexed(GLenum target,
+                                                           GLuint index,
+                                                           const char* info);
+    bool ValidateBufferUsageEnum(GLenum target, const char* info);
 
 // -----------------------------------------------------------------------------
 // Queries (WebGL2ContextQueries.cpp)
 protected:
     WebGLQueryRefPtr* GetQueryTargetSlot(GLenum target);
 
     WebGLQueryRefPtr mActiveOcclusionQuery;
     WebGLQueryRefPtr mActiveTransformFeedbackQuery;
 
 // -----------------------------------------------------------------------------
 // State and State Requests (WebGLContextState.cpp)
 public:
     void Disable(GLenum cap);
     void Enable(GLenum cap);
     bool GetStencilBits(GLint* out_stencilBits);
     JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
+
     void GetParameter(JSContext* cx, GLenum pname,
-                      JS::MutableHandle<JS::Value> retval, ErrorResult& rv) {
+                      JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
+    {
         retval.set(GetParameter(cx, pname, rv));
     }
+
     void GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index,
                              JS::MutableHandle<JS::Value> retval);
     bool IsEnabled(GLenum cap);
 
 private:
     // State tracking slots
     realGLboolean mDitherEnabled;
     realGLboolean mRasterizerDiscardEnabled;
@@ -887,65 +929,68 @@ private:
 
     bool ValidateCapabilityEnum(GLenum cap, const char* info);
     realGLboolean* GetStateTrackingSlot(GLenum cap);
 
 // -----------------------------------------------------------------------------
 // Vertices Feature (WebGLContextVertices.cpp)
 public:
     void DrawArrays(GLenum mode, GLint first, GLsizei count);
-    void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount);
-    void DrawElements(GLenum mode, GLsizei count, GLenum type, WebGLintptr byteOffset);
+    void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count,
+                             GLsizei primcount);
+    void DrawElements(GLenum mode, GLsizei count, GLenum type,
+                      WebGLintptr byteOffset);
     void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
                                WebGLintptr byteOffset, GLsizei primcount);
 
     void EnableVertexAttribArray(GLuint index);
     void DisableVertexAttribArray(GLuint index);
 
     JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
                               ErrorResult& rv);
+
     void GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
-                         JS::MutableHandle<JS::Value> retval,
-                         ErrorResult& rv) {
+                         JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
+    {
         retval.set(GetVertexAttrib(cx, index, pname, rv));
     }
+
     WebGLsizeiptr GetVertexAttribOffset(GLuint index, GLenum pname);
 
     void VertexAttrib1f(GLuint index, GLfloat x0);
     void VertexAttrib2f(GLuint index, GLfloat x0, GLfloat x1);
-    void VertexAttrib3f(GLuint index, GLfloat x0, GLfloat x1,
-                        GLfloat x2);
-    void VertexAttrib4f(GLuint index, GLfloat x0, GLfloat x1,
-                        GLfloat x2, GLfloat x3);
+    void VertexAttrib3f(GLuint index, GLfloat x0, GLfloat x1, GLfloat x2);
+    void VertexAttrib4f(GLuint index, GLfloat x0, GLfloat x1, GLfloat x2,
+                        GLfloat x3);
 
-    void VertexAttrib1fv(GLuint idx, const dom::Float32Array &arr) {
+    void VertexAttrib1fv(GLuint idx, const dom::Float32Array& arr) {
         arr.ComputeLengthAndData();
         VertexAttrib1fv_base(idx, arr.Length(), arr.Data());
     }
     void VertexAttrib1fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
         VertexAttrib1fv_base(idx, arr.Length(), arr.Elements());
     }
 
-    void VertexAttrib2fv(GLuint idx, const dom::Float32Array &arr) {
+    void VertexAttrib2fv(GLuint idx, const dom::Float32Array& arr) {
         arr.ComputeLengthAndData();
         VertexAttrib2fv_base(idx, arr.Length(), arr.Data());
     }
     void VertexAttrib2fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
         VertexAttrib2fv_base(idx, arr.Length(), arr.Elements());
     }
 
-    void VertexAttrib3fv(GLuint idx, const dom::Float32Array &arr) {
+    void VertexAttrib3fv(GLuint idx, const dom::Float32Array& arr) {
         arr.ComputeLengthAndData();
         VertexAttrib3fv_base(idx, arr.Length(), arr.Data());
     }
     void VertexAttrib3fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
         VertexAttrib3fv_base(idx, arr.Length(), arr.Elements());
     }
 
-    void VertexAttrib4fv(GLuint idx, const dom::Float32Array &arr) {
+    void VertexAttrib4fv(GLuint idx, const dom::Float32Array& arr) {
         arr.ComputeLengthAndData();
         VertexAttrib4fv_base(idx, arr.Length(), arr.Data());
     }
     void VertexAttrib4fv(GLuint idx, const dom::Sequence<GLfloat>& arr) {
         VertexAttrib4fv_base(idx, arr.Length(), arr.Elements());
     }
 
     void VertexAttribPointer(GLuint index, GLint size, GLenum type,
@@ -956,38 +1001,42 @@ public:
 private:
     // Cache the max number of vertices and instances that can be read from
     // bound VBOs (result of ValidateBuffers).
     bool mBufferFetchingIsVerified;
     bool mBufferFetchingHasPerVertex;
     uint32_t mMaxFetchedVertices;
     uint32_t mMaxFetchedInstances;
 
-    inline void InvalidateBufferFetching()
-    {
+    inline void InvalidateBufferFetching() {
         mBufferFetchingIsVerified = false;
         mBufferFetchingHasPerVertex = false;
         mMaxFetchedVertices = 0;
         mMaxFetchedInstances = 0;
     }
 
-    bool DrawArrays_check(GLint first, GLsizei count, GLsizei primcount, const char* info);
+    bool DrawArrays_check(GLint first, GLsizei count, GLsizei primcount,
+                          const char* info);
     bool DrawElements_check(GLsizei count, GLenum type, WebGLintptr byteOffset,
                             GLsizei primcount, const char* info,
                             GLuint* out_upperBound);
     bool DrawInstanced_check(const char* info);
     void Draw_cleanup();
 
-    void VertexAttrib1fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
-    void VertexAttrib2fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
-    void VertexAttrib3fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
-    void VertexAttrib4fv_base(GLuint idx, uint32_t arrayLength, const GLfloat* ptr);
+    void VertexAttrib1fv_base(GLuint index, uint32_t arrayLength,
+                              const GLfloat* ptr);
+    void VertexAttrib2fv_base(GLuint index, uint32_t arrayLength,
+                              const GLfloat* ptr);
+    void VertexAttrib3fv_base(GLuint index, uint32_t arrayLength,
+                              const GLfloat* ptr);
+    void VertexAttrib4fv_base(GLuint index, uint32_t arrayLength,
+                              const GLfloat* ptr);
 
-    bool ValidateBufferFetching(const char *info);
-    bool BindArrayAttribToLocation0(WebGLProgram *program);
+    bool ValidateBufferFetching(const char* info);
+    bool BindArrayAttribToLocation0(WebGLProgram* prog);
 
 // -----------------------------------------------------------------------------
 // PROTECTED
 protected:
     virtual ~WebGLContext();
 
     void SetFakeBlackStatus(WebGLContextFakeBlackStatus x) {
         mFakeBlackStatus = x;
@@ -998,26 +1047,27 @@ protected:
 
     void BindFakeBlackTextures();
     void UnbindFakeBlackTextures();
 
     WebGLVertexAttrib0Status WhatDoesVertexAttrib0Need();
     bool DoFakeVertexAttrib0(GLuint vertexCount);
     void UndoFakeVertexAttrib0();
 
-    static CheckedUint32 GetImageSize(GLsizei height,
-                                      GLsizei width,
-                                      GLsizei depth,
-                                      uint32_t pixelSize,
+    static CheckedUint32 GetImageSize(GLsizei height, GLsizei width,
+                                      GLsizei depth, uint32_t pixelSize,
                                       uint32_t alignment);
 
-    virtual JS::Value GetTexParameterInternal(const TexTarget& target, GLenum pname);
+    virtual JS::Value GetTexParameterInternal(const TexTarget& target,
+                                              GLenum pname);
 
     // Returns x rounded to the next highest multiple of y.
-    static CheckedUint32 RoundedToNextMultipleOf(CheckedUint32 x, CheckedUint32 y) {
+    static CheckedUint32 RoundedToNextMultipleOf(CheckedUint32 x,
+                                                 CheckedUint32 y)
+    {
         return ((x + y - 1) / y) * y;
     }
 
     CheckedUint32 mGeneration;
 
     WebGLContextOptions mOptions;
 
     bool mInvalidated;
@@ -1090,243 +1140,228 @@ protected:
         // The context is lost, an event has been sent to the script, and the
         // script correctly handled the event. We are waiting for the context to
         // be restored.
         ContextLostAwaitingRestore
     };
 
     // -------------------------------------------------------------------------
     // WebGL extensions (implemented in WebGLContextExtensions.cpp)
-    typedef EnumeratedArray<WebGLExtensionID,
-                            WebGLExtensionID::Max,
+    typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max,
                             nsRefPtr<WebGLExtensionBase>> ExtensionsArrayType;
 
     ExtensionsArrayType mExtensions;
 
     // enable an extension. the extension should not be enabled before.
     void EnableExtension(WebGLExtensionID ext);
 
     // Enable an extension if it's supported. Return the extension on success.
     WebGLExtensionBase* EnableSupportedExtension(JSContext* js,
                                                  WebGLExtensionID ext);
 
     // returns true if the extension has been enabled by calling getExtension.
     bool IsExtensionEnabled(WebGLExtensionID ext) const;
 
     // returns true if the extension is supported for this JSContext (this decides what getSupportedExtensions exposes)
-    bool IsExtensionSupported(JSContext *cx, WebGLExtensionID ext) const;
+    bool IsExtensionSupported(JSContext* cx, WebGLExtensionID ext) const;
     bool IsExtensionSupported(WebGLExtensionID ext) const;
 
     static const char* GetExtensionString(WebGLExtensionID ext);
 
     nsTArray<GLenum> mCompressedTextureFormats;
 
     // -------------------------------------------------------------------------
     // WebGL 2 specifics (implemented in WebGL2Context.cpp)
 
     virtual bool IsWebGL2() const = 0;
 
     bool InitWebGL2();
 
-
     // -------------------------------------------------------------------------
     // Validation functions (implemented in WebGLContextValidate.cpp)
     bool CreateOffscreenGL(bool forceEnabled);
     bool InitAndValidateGL();
     bool ResizeBackbuffer(uint32_t width, uint32_t height);
-    bool ValidateBlendEquationEnum(GLenum cap, const char *info);
-    bool ValidateBlendFuncDstEnum(GLenum mode, const char *info);
-    bool ValidateBlendFuncSrcEnum(GLenum mode, const char *info);
-    bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor, const char *info);
-    bool ValidateTextureTargetEnum(GLenum target, const char *info);
-    bool ValidateComparisonEnum(GLenum target, const char *info);
-    bool ValidateStencilOpEnum(GLenum action, const char *info);
-    bool ValidateFaceEnum(GLenum face, const char *info);
-    bool ValidateTexInputData(GLenum type,
-                              js::Scalar::Type jsArrayType,
-                              WebGLTexImageFunc func,
-                              WebGLTexDimensions dims);
-    bool ValidateDrawModeEnum(GLenum mode, const char *info);
+    bool ValidateBlendEquationEnum(GLenum cap, const char* info);
+    bool ValidateBlendFuncDstEnum(GLenum mode, const char* info);
+    bool ValidateBlendFuncSrcEnum(GLenum mode, const char* info);
+    bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor,
+                                             const char* info);
+    bool ValidateTextureTargetEnum(GLenum target, const char* info);
+    bool ValidateComparisonEnum(GLenum target, const char* info);
+    bool ValidateStencilOpEnum(GLenum action, const char* info);
+    bool ValidateFaceEnum(GLenum face, const char* info);
+    bool ValidateTexInputData(GLenum type, js::Scalar::Type jsArrayType,
+                              WebGLTexImageFunc func, WebGLTexDimensions dims);
+    bool ValidateDrawModeEnum(GLenum mode, const char* info);
     bool ValidateStencilParamsForDrawCall();
 
-    bool ValidateGLSLVariableName(const nsAString& name, const char *info);
+    bool ValidateGLSLVariableName(const nsAString& name, const char* info);
     bool ValidateGLSLCharacter(char16_t c);
-    bool ValidateGLSLString(const nsAString& string, const char *info);
+    bool ValidateGLSLString(const nsAString& string, const char* info);
 
-    bool ValidateCopyTexImage(GLenum internalformat,
-                              WebGLTexImageFunc func,
+    bool ValidateCopyTexImage(GLenum internalFormat, WebGLTexImageFunc func,
                               WebGLTexDimensions dims);
 
     bool ValidateSamplerParameterName(GLenum pname, const char* info);
     bool ValidateSamplerParameterParams(GLenum pname, const WebGLIntOrFloat& param, const char* info);
 
     bool ValidateTexImage(TexImageTarget texImageTarget,
                           GLint level, GLenum internalFormat,
                           GLint xoffset, GLint yoffset, GLint zoffset,
                           GLint width, GLint height, GLint depth,
                           GLint border, GLenum format, GLenum type,
-                          WebGLTexImageFunc func,
-                          WebGLTexDimensions dims);
-    bool ValidateTexImageTarget(GLenum target,
-                                WebGLTexImageFunc func,
+                          WebGLTexImageFunc func, WebGLTexDimensions dims);
+    bool ValidateTexImageTarget(GLenum texImageTarget, WebGLTexImageFunc func,
                                 WebGLTexDimensions dims);
-    bool ValidateTexImageFormat(GLenum internalformat,
-                                WebGLTexImageFunc func,
+    bool ValidateTexImageFormat(GLenum internalFormat, WebGLTexImageFunc func,
                                 WebGLTexDimensions dims);
-    bool ValidateTexImageType(GLenum type,
-                              WebGLTexImageFunc func,
+    bool ValidateTexImageType(GLenum type, WebGLTexImageFunc func,
                               WebGLTexDimensions dims);
-    bool ValidateTexImageFormatAndType(GLenum format,
-                                       GLenum type,
+    bool ValidateTexImageFormatAndType(GLenum format, GLenum type,
                                        WebGLTexImageFunc func,
                                        WebGLTexDimensions dims);
     bool ValidateCompTexImageInternalFormat(GLenum format,
                                             WebGLTexImageFunc func,
                                             WebGLTexDimensions dims);
     bool ValidateCopyTexImageInternalFormat(GLenum format,
                                             WebGLTexImageFunc func,
                                             WebGLTexDimensions dims);
-    bool ValidateTexImageSize(TexImageTarget target, GLint level,
+    bool ValidateTexImageSize(TexImageTarget texImageTarget, GLint level,
                               GLint width, GLint height, GLint depth,
-                              WebGLTexImageFunc func,
-                              WebGLTexDimensions dims);
-    bool ValidateTexSubImageSize(GLint x, GLint y, GLint z,
-                                 GLsizei width, GLsizei height, GLsizei depth,
-                                 GLsizei baseWidth, GLsizei baseHeight, GLsizei baseDepth,
-                                 WebGLTexImageFunc func,
+                              WebGLTexImageFunc func, WebGLTexDimensions dims);
+    bool ValidateTexSubImageSize(GLint x, GLint y, GLint z, GLsizei width,
+                                 GLsizei height, GLsizei depth,
+                                 GLsizei baseWidth, GLsizei baseHeight,
+                                 GLsizei baseDepth, WebGLTexImageFunc func,
                                  WebGLTexDimensions dims);
-    bool ValidateCompTexImageSize(GLint level,
-                                  GLenum internalformat,
-                                  GLint xoffset, GLint yoffset,
-                                  GLsizei width, GLsizei height,
-                                  GLsizei levelWidth, GLsizei levelHeight,
-                                  WebGLTexImageFunc func,
+    bool ValidateCompTexImageSize(GLint level, GLenum internalFormat,
+                                  GLint xoffset, GLint yoffset, GLsizei width,
+                                  GLsizei height, GLsizei levelWidth,
+                                  GLsizei levelHeight, WebGLTexImageFunc func,
                                   WebGLTexDimensions dims);
-    bool ValidateCompTexImageDataSize(GLint level,
-                                      GLenum internalformat,
+    bool ValidateCompTexImageDataSize(GLint level, GLenum internalFormat,
                                       GLsizei width, GLsizei height,
                                       uint32_t byteLength,
                                       WebGLTexImageFunc func,
                                       WebGLTexDimensions dims);
 
     void Invalidate();
     void DestroyResourcesAndContext();
 
     void MakeContextCurrent() const;
 
     // helpers
 
-    void TexImage2D_base(TexImageTarget target,
-                         GLint level,
-                         GLenum internalformat,
-                         GLsizei width, GLsizei height, GLsizei srcStrideOrZero, GLint border,
-                         GLenum format,
-                         GLenum type,
-                         void *data, uint32_t byteLength,
-                         js::Scalar::Type jsArrayType, // special value TypeMax used to mean no array
+    // If `isArrayType is TypeMax, it means no array.
+    void TexImage2D_base(TexImageTarget texImageTarget, GLint level,
+                         GLenum internalFormat, GLsizei width,
+                         GLsizei height, GLsizei srcStrideOrZero, GLint border,
+                         GLenum format, GLenum type, void* data,
+                         uint32_t byteLength, js::Scalar::Type jsArrayType,
                          WebGLTexelFormat srcFormat, bool srcPremultiplied);
-    void TexSubImage2D_base(TexImageTarget target, GLint level,
-                            GLint xoffset, GLint yoffset,
-                            GLsizei width, GLsizei height, GLsizei srcStrideOrZero,
-                            GLenum format,
-                            GLenum type,
-                            void *pixels, uint32_t byteLength,
-                            js::Scalar::Type jsArrayType, // special value TypeMax used to mean no array
+    void TexSubImage2D_base(TexImageTarget texImageTarget, GLint level,
+                            GLint xoffset, GLint yoffset, GLsizei width,
+                            GLsizei height, GLsizei srcStrideOrZero,
+                            GLenum format, GLenum type, void* pixels,
+                            uint32_t byteLength, js::Scalar::Type jsArrayType,
                             WebGLTexelFormat srcFormat, bool srcPremultiplied);
-    void TexParameter_base(GLenum target, GLenum pname,
-                           GLint *intParamPtr, GLfloat *floatParamPtr);
 
-    bool ConvertImage(size_t width, size_t height, size_t srcStride, size_t dstStride,
-                      const uint8_t* src, uint8_t *dst,
+    void TexParameter_base(GLenum target, GLenum pname,
+                           GLint* const out_intParam,
+                           GLfloat* const out_floatParam);
+
+    bool ConvertImage(size_t width, size_t height, size_t srcStride,
+                      size_t dstStride, const uint8_t* src, uint8_t* dst,
                       WebGLTexelFormat srcFormat, bool srcPremultiplied,
                       WebGLTexelFormat dstFormat, bool dstPremultiplied,
                       size_t dstTexelSize);
 
     template<class ElementType>
-    nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(ElementType* aElement) {
-        MOZ_ASSERT(aElement);
-        uint32_t flags =
-             nsLayoutUtils::SFE_WANT_IMAGE_SURFACE;
+    nsLayoutUtils::SurfaceFromElementResult
+    SurfaceFromElement(ElementType* element) {
+        MOZ_ASSERT(element);
 
+        uint32_t flags = nsLayoutUtils::SFE_WANT_IMAGE_SURFACE;
         if (mPixelStoreColorspaceConversion == LOCAL_GL_NONE)
             flags |= nsLayoutUtils::SFE_NO_COLORSPACE_CONVERSION;
         if (!mPixelStorePremultiplyAlpha)
             flags |= nsLayoutUtils::SFE_PREFER_NO_PREMULTIPLY_ALPHA;
-        return nsLayoutUtils::SurfaceFromElement(aElement, flags);
-    }
-    template<class ElementType>
-    nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(ElementType& aElement)
-    {
-      return SurfaceFromElement(&aElement);
+
+        return nsLayoutUtils::SurfaceFromElement(element, flags);
     }
 
-    nsresult SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res,
-                                                    RefPtr<gfx::DataSourceSurface>& imageOut,
-                                                    WebGLTexelFormat *format);
+    template<class ElementType>
+    nsLayoutUtils::SurfaceFromElementResult
+    SurfaceFromElement(ElementType& element) {
+       return SurfaceFromElement(&element);
+    }
+
+    nsresult
+    SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res,
+                                           RefPtr<gfx::DataSourceSurface>& imageOut,
+                                           WebGLTexelFormat* format);
 
     void CopyTexSubImage2D_base(TexImageTarget texImageTarget,
-                                GLint level,
-                                TexInternalFormat internalformat,
-                                GLint xoffset,
-                                GLint yoffset,
-                                GLint x,
-                                GLint y,
-                                GLsizei width,
-                                GLsizei height,
-                                bool sub);
+                                GLint level, TexInternalFormat internalFormat,
+                                GLint xoffset, GLint yoffset, GLint x, GLint y,
+                                GLsizei width, GLsizei height, bool isSub);
+
+    // Returns false if `object` is null or not valid.
+    template<class ObjectType>
+    bool ValidateObject(const char* info, ObjectType* object);
 
-    // Returns false if aObject is null or not valid
-    template<class ObjectType>
-    bool ValidateObject(const char* info, ObjectType *aObject);
-    // Returns false if aObject is not valid.  Considers null to be valid.
+    // Returns false if `object` is not valid.  Considers null to be valid.
     template<class ObjectType>
-    bool ValidateObjectAllowNull(const char* info, ObjectType *aObject);
-    // Returns false if aObject is not valid, but considers deleted
-    // objects and null objects valid.
+    bool ValidateObjectAllowNull(const char* info, ObjectType* object);
+
+    // Returns false if `object` is not valid, but considers deleted objects and
+    // null objects valid.
     template<class ObjectType>
-    bool ValidateObjectAllowDeletedOrNull(const char* info, ObjectType *aObject);
-    // Returns false if aObject is null or not valid, but considers deleted
+    bool ValidateObjectAllowDeletedOrNull(const char* info, ObjectType* object);
+
+    // Returns false if `object` is null or not valid, but considers deleted
     // objects valid.
     template<class ObjectType>
-    bool ValidateObjectAllowDeleted(const char* info, ObjectType *aObject);
+    bool ValidateObjectAllowDeleted(const char* info, ObjectType* object);
+
 private:
-    // Like ValidateObject, but only for cases when aObject is known
-    // to not be null already.
+    // Like ValidateObject, but only for cases when `object` is known to not be
+    // null already.
     template<class ObjectType>
-    bool ValidateObjectAssumeNonNull(const char* info, ObjectType *aObject);
+    bool ValidateObjectAssumeNonNull(const char* info, ObjectType* object);
 
 protected:
     int32_t MaxTextureSizeForTarget(TexTarget target) const {
-        return (target == LOCAL_GL_TEXTURE_2D) ? mGLMaxTextureSize : mGLMaxCubeMapTextureSize;
+        return (target == LOCAL_GL_TEXTURE_2D) ? mGLMaxTextureSize
+                                               : mGLMaxCubeMapTextureSize;
     }
 
-    int32_t MaxTextureLevelForTexImageTarget(TexImageTarget texImageTarget) const {
+    int32_t
+    MaxTextureLevelForTexImageTarget(TexImageTarget texImageTarget) const {
         const TexTarget target = TexImageTargetToTexTarget(texImageTarget);
-        return (target == LOCAL_GL_TEXTURE_2D) ? mGLMaxTextureSizeLog2 : mGLMaxCubeMapTextureSizeLog2;
+        return (target == LOCAL_GL_TEXTURE_2D) ? mGLMaxTextureSizeLog2
+                                               : mGLMaxCubeMapTextureSizeLog2;
     }
 
-    /** like glBufferData but if the call may change the buffer size, checks any GL error generated
-     * by this glBufferData call and returns it */
-    GLenum CheckedBufferData(GLenum target,
-                             GLsizeiptr size,
-                             const GLvoid *data,
+    /** Like glBufferData, but if the call may change the buffer size, checks
+     *  any GL error generated by this glBufferData call and returns it.
+     */
+    GLenum CheckedBufferData(GLenum target, GLsizeiptr size, const GLvoid* data,
                              GLenum usage);
-    /** like glTexImage2D but if the call may change the texture size, checks any GL error generated
-     * by this glTexImage2D call and returns it */
-    GLenum CheckedTexImage2D(TexImageTarget texImageTarget,
-                             GLint level,
-                             TexInternalFormat internalFormat,
-                             GLsizei width,
-                             GLsizei height,
-                             GLint border,
-                             TexFormat format,
-                             TexType type,
-                             const GLvoid *data);
 
-    void ForceLoseContext(bool simulateLosing = false);
+    /** Like glTexImage2D, but if the call may change the texture size, checks
+     * any GL error generated by this glTexImage2D call and returns it.
+     */
+    GLenum CheckedTexImage2D(TexImageTarget texImageTarget, GLint level,
+                             TexInternalFormat internalFormat, GLsizei width,
+                             GLsizei height, GLint border, TexFormat format,
+                             TexType type, const GLvoid* data);
+
+    void ForceLoseContext(bool simulateLoss = false);
     void ForceRestoreContext();
 
     nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DTextures;
     nsTArray<WebGLRefPtr<WebGLTexture> > mBoundCubeMapTextures;
     nsTArray<WebGLRefPtr<WebGLTexture> > mBound3DTextures;
 
     WebGLRefPtr<WebGLProgram> mCurrentProgram;
 
@@ -1346,52 +1381,57 @@ protected:
     LinkedList<WebGLVertexArray> mVertexArrays;
 
     // TODO(djg): Does this need a rethink? Should it be WebGL2Context?
     LinkedList<WebGLSampler> mSamplers;
 
     WebGLRefPtr<WebGLVertexArray> mDefaultVertexArray;
 
     // PixelStore parameters
-    uint32_t mPixelStorePackAlignment, mPixelStoreUnpackAlignment, mPixelStoreColorspaceConversion;
-    bool mPixelStoreFlipY, mPixelStorePremultiplyAlpha;
+    uint32_t mPixelStorePackAlignment;
+    uint32_t mPixelStoreUnpackAlignment;
+    uint32_t mPixelStoreColorspaceConversion;
+    bool mPixelStoreFlipY;
+    bool mPixelStorePremultiplyAlpha;
 
     WebGLContextFakeBlackStatus mFakeBlackStatus;
 
-    class FakeBlackTexture
-    {
-        gl::GLContext* mGL;
+    class FakeBlackTexture {
+        gl::GLContext* const mGL;
         GLuint mGLName;
 
     public:
         FakeBlackTexture(gl::GLContext* gl, TexTarget target, GLenum format);
         ~FakeBlackTexture();
         GLuint GLName() const { return mGLName; }
     };
 
-    UniquePtr<FakeBlackTexture> mBlackOpaqueTexture2D,
-                                mBlackOpaqueTextureCubeMap,
-                                mBlackTransparentTexture2D,
-                                mBlackTransparentTextureCubeMap;
+    UniquePtr<FakeBlackTexture> mBlackOpaqueTexture2D;
+    UniquePtr<FakeBlackTexture> mBlackOpaqueTextureCubeMap;
+    UniquePtr<FakeBlackTexture> mBlackTransparentTexture2D;
+    UniquePtr<FakeBlackTexture> mBlackTransparentTextureCubeMap;
 
-    void BindFakeBlackTexturesHelper(
-        GLenum target,
-        const nsTArray<WebGLRefPtr<WebGLTexture> >& boundTexturesArray,
-        UniquePtr<FakeBlackTexture> & opaqueTextureScopedPtr,
-        UniquePtr<FakeBlackTexture> & transparentTextureScopedPtr);
+    void
+    BindFakeBlackTexturesHelper(GLenum target,
+                                const nsTArray<WebGLRefPtr<WebGLTexture> >& boundTexturesArray,
+                                UniquePtr<FakeBlackTexture>& opaqueTextureScopedPtr,
+                                UniquePtr<FakeBlackTexture>& transparentTextureScopedPtr);
 
     GLfloat mVertexAttrib0Vector[4];
     GLfloat mFakeVertexAttrib0BufferObjectVector[4];
     size_t mFakeVertexAttrib0BufferObjectSize;
     GLuint mFakeVertexAttrib0BufferObject;
     WebGLVertexAttrib0Status mFakeVertexAttrib0BufferStatus;
 
-    GLint mStencilRefFront, mStencilRefBack;
-    GLuint mStencilValueMaskFront, mStencilValueMaskBack,
-           mStencilWriteMaskFront, mStencilWriteMaskBack;
+    GLint mStencilRefFront;
+    GLint mStencilRefBack;
+    GLuint mStencilValueMaskFront;
+    GLuint mStencilValueMaskBack;
+    GLuint mStencilWriteMaskFront;
+    GLuint mStencilWriteMaskBack;
     realGLboolean mColorWriteMask[4];
     realGLboolean mDepthWriteMask;
     GLfloat mColorClearValue[4];
     GLint mStencilClearValue;
     GLfloat mDepthClearValue;
 
     GLint mViewportX;
     GLint mViewportY;
@@ -1423,44 +1463,46 @@ protected:
         WebGLContext& mWebGL;
         const bool mNeedsChange;
 
         static bool NeedsChange(WebGLContext& webgl) {
             return webgl.mNeedsFakeNoAlpha &&
                    webgl.mColorWriteMask[3] != false;
         }
 
-        explicit ScopedMaskWorkaround(WebGLContext& aWebgl);
+        explicit ScopedMaskWorkaround(WebGLContext& webgl);
 
         ~ScopedMaskWorkaround();
     };
 
     void LoseOldestWebGLContextIfLimitExceeded();
     void UpdateLastUseIndex();
 
     template <typename WebGLObjectType>
-    JS::Value WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *, ErrorResult& rv) const;
+    JS::Value WebGLObjectAsJSValue(JSContext* cx, const WebGLObjectType*,
+                                   ErrorResult& rv) const;
     template <typename WebGLObjectType>
-    JSObject* WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *, ErrorResult& rv) const;
+    JSObject* WebGLObjectAsJSObject(JSContext* cx, const WebGLObjectType*,
+                                    ErrorResult& rv) const;
 
 #ifdef XP_MACOSX
     // see bug 713305. This RAII helper guarantees that we're on the discrete GPU, during its lifetime
     // Debouncing note: we don't want to switch GPUs too frequently, so try to not create and destroy
     // these objects at high frequency. Having WebGLContext's hold one such object seems fine,
     // because WebGLContext objects only go away during GC, which shouldn't happen too frequently.
     // If in the future GC becomes much more frequent, we may have to revisit then (maybe use a timer).
     ForceDiscreteGPUHelperCGL mForceDiscreteGPUHelper;
 #endif
 
     nsRefPtr<WebGLObserver> mContextObserver;
 
 public:
     // console logging helpers
-    void GenerateWarning(const char *fmt, ...);
-    void GenerateWarning(const char *fmt, va_list ap);
+    void GenerateWarning(const char* fmt, ...);
+    void GenerateWarning(const char* fmt, va_list ap);
 
     friend class WebGLTexture;
     friend class WebGLFramebuffer;
     friend class WebGLRenderbuffer;
     friend class WebGLProgram;
     friend class WebGLQuery;
     friend class WebGLBuffer;
     friend class WebGLSampler;
@@ -1468,113 +1510,112 @@ public:
     friend class WebGLUniformLocation;
     friend class WebGLVertexArray;
     friend class WebGLVertexArrayFake;
     friend class WebGLVertexArrayGL;
 };
 
 // used by DOM bindings in conjunction with GetParentObject
 inline nsISupports*
-ToSupports(WebGLContext* context)
+ToSupports(WebGLContext* webgl)
 {
-  return static_cast<nsIDOMWebGLRenderingContext*>(context);
+    return static_cast<nsIDOMWebGLRenderingContext*>(webgl);
 }
 
 /**
  ** Template implementations
  **/
 
 template<class ObjectType>
 inline bool
 WebGLContext::ValidateObjectAllowDeletedOrNull(const char* info,
-                                               ObjectType *aObject)
+                                               ObjectType* object)
 {
-    if (aObject && !aObject->IsCompatibleWithContext(this)) {
+    if (object && !object->IsCompatibleWithContext(this)) {
         ErrorInvalidOperation("%s: object from different WebGL context "
                               "(or older generation of this one) "
                               "passed as argument", info);
         return false;
     }
 
     return true;
 }
 
 template<class ObjectType>
 inline bool
-WebGLContext::ValidateObjectAssumeNonNull(const char* info, ObjectType *aObject)
+WebGLContext::ValidateObjectAssumeNonNull(const char* info, ObjectType* object)
 {
-    MOZ_ASSERT(aObject);
+    MOZ_ASSERT(object);
 
-    if (!ValidateObjectAllowDeletedOrNull(info, aObject))
+    if (!ValidateObjectAllowDeletedOrNull(info, object))
         return false;
 
-    if (aObject->IsDeleted()) {
+    if (object->IsDeleted()) {
         ErrorInvalidValue("%s: deleted object passed as argument", info);
         return false;
     }
 
     return true;
 }
 
 template<class ObjectType>
 inline bool
-WebGLContext::ValidateObjectAllowNull(const char* info, ObjectType *aObject)
+WebGLContext::ValidateObjectAllowNull(const char* info, ObjectType* object)
 {
-    if (!aObject) {
+    if (!object)
         return true;
-    }
 
-    return ValidateObjectAssumeNonNull(info, aObject);
+    return ValidateObjectAssumeNonNull(info, object);
 }
 
 template<class ObjectType>
 inline bool
-WebGLContext::ValidateObjectAllowDeleted(const char* info, ObjectType *aObject)
+WebGLContext::ValidateObjectAllowDeleted(const char* info, ObjectType* object)
 {
-    if (!aObject) {
+    if (!object) {
         ErrorInvalidValue("%s: null object passed as argument", info);
         return false;
     }
 
-    return ValidateObjectAllowDeletedOrNull(info, aObject);
+    return ValidateObjectAllowDeletedOrNull(info, object);
 }
 
 template<class ObjectType>
 inline bool
-WebGLContext::ValidateObject(const char* info, ObjectType *aObject)
+WebGLContext::ValidateObject(const char* info, ObjectType* object)
 {
-    if (!aObject) {
+    if (!object) {
         ErrorInvalidValue("%s: null object passed as argument", info);
         return false;
     }
 
-    return ValidateObjectAssumeNonNull(info, aObject);
+    return ValidateObjectAssumeNonNull(info, object);
 }
 
 // Listen visibilitychange and memory-pressure event for context lose/restore
 class WebGLObserver MOZ_FINAL
     : public nsIObserver
     , public nsIDOMEventListener
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
     NS_DECL_NSIDOMEVENTLISTENER
 
-    explicit WebGLObserver(WebGLContext* aContext);
+    explicit WebGLObserver(WebGLContext* webgl);
 
     void Destroy();
 
     void RegisterVisibilityChangeEvent();
     void UnregisterVisibilityChangeEvent();
 
     void RegisterMemoryPressureEvent();
     void UnregisterMemoryPressureEvent();
 
 private:
     ~WebGLObserver();
 
-    WebGLContext* mContext;
+    WebGLContext* mWebGL;
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/canvas/WebGLContextBuffers.cpp
+++ b/dom/canvas/WebGLContextBuffers.cpp
@@ -1,45 +1,46 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
+
 #include "GLContext.h"
 #include "WebGLBuffer.h"
 #include "WebGLVertexArray.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 void
-WebGLContext::BindBuffer(GLenum target, WebGLBuffer *buffer)
+WebGLContext::BindBuffer(GLenum target, WebGLBuffer* buffer)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowDeletedOrNull("bindBuffer", buffer))
         return;
 
     // silently ignore a deleted buffer
     if (buffer && buffer->IsDeleted())
         return;
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bindBuffer");
-
-    if (!bufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "bindBuffer");
+    if (!bufferSlot)
         return;
-    }
 
     if (buffer) {
         if (!buffer->HasEverBeenBound()) {
             buffer->BindTo(target);
         } else if (target != buffer->Target()) {
-            return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
+            ErrorInvalidOperation("bindBuffer: Buffer already bound to a"
+                                  " different target.");
+            return;
         }
     }
 
     *bufferSlot = buffer;
 
     MakeContextCurrent();
 
     gl->fBindBuffer(target, buffer ? buffer->GLName() : 0);
@@ -54,31 +55,35 @@ WebGLContext::BindBufferBase(GLenum targ
     if (!ValidateObjectAllowDeletedOrNull("bindBufferBase", buffer))
         return;
 
     // silently ignore a deleted buffer
     if (buffer && buffer->IsDeleted()) {
         return;
     }
 
-    WebGLRefPtr<WebGLBuffer>* indexedBufferSlot = GetBufferSlotByTargetIndexed(target, index, "bindBufferBase");
-
-    if (!indexedBufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* indexedBufferSlot;
+    indexedBufferSlot = GetBufferSlotByTargetIndexed(target, index,
+                                                     "bindBufferBase");
+    if (!indexedBufferSlot)
         return;
-    }
 
     if (buffer) {
         if (!buffer->HasEverBeenBound())
             buffer->BindTo(target);
 
-        if (target != buffer->Target())
-            return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
+        if (target != buffer->Target()) {
+            ErrorInvalidOperation("bindBuffer: Buffer already bound to a"
+                                  " different target.");
+            return;
+        }
     }
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bindBuffer");
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "bindBufferBase");
 
     MOZ_ASSERT(bufferSlot, "GetBufferSlotByTarget(Indexed) mismatch");
 
     *indexedBufferSlot = buffer;
     *bufferSlot = buffer;
 
     MakeContextCurrent();
 
@@ -94,61 +99,64 @@ WebGLContext::BindBufferRange(GLenum tar
 
     if (!ValidateObjectAllowDeletedOrNull("bindBufferRange", buffer))
         return;
 
     // silently ignore a deleted buffer
     if (buffer && buffer->IsDeleted())
         return;
 
-    WebGLRefPtr<WebGLBuffer>* indexedBufferSlot = GetBufferSlotByTargetIndexed(target, index, "bindBufferBase");
-
-    if (!indexedBufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* indexedBufferSlot;
+    indexedBufferSlot = GetBufferSlotByTargetIndexed(target, index,
+                                                     "bindBufferRange");
+    if (!indexedBufferSlot)
         return;
-    }
 
     if (buffer) {
         if (!buffer->HasEverBeenBound())
             buffer->BindTo(target);
 
-        if (target != buffer->Target())
-            return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
+        if (target != buffer->Target()) {
+            ErrorInvalidOperation("bindBuffer: Buffer already bound to a"
+                                  " different target.");
+            return;
+        }
 
         CheckedInt<WebGLsizeiptr> checked_neededByteLength = CheckedInt<WebGLsizeiptr>(offset) + size;
         if (!checked_neededByteLength.isValid() ||
             checked_neededByteLength.value() > buffer->ByteLength())
         {
             return ErrorInvalidValue("bindBufferRange: invalid range");
         }
     }
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bindBuffer");
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "BindBufferRange");
 
     MOZ_ASSERT(bufferSlot, "GetBufferSlotByTarget(Indexed) mismatch");
 
     *indexedBufferSlot = buffer;
     *bufferSlot = buffer;
 
     MakeContextCurrent();
 
-    gl->fBindBufferRange(target, index, buffer ? buffer->GLName() : 0, offset, size);
+    gl->fBindBufferRange(target, index, buffer ? buffer->GLName() : 0, offset,
+                         size);
 }
 
 void
-WebGLContext::BufferData(GLenum target, WebGLsizeiptr size,
-                         GLenum usage)
+WebGLContext::BufferData(GLenum target, WebGLsizeiptr size, GLenum usage)
 {
     if (IsContextLost())
         return;
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferData");
-
-    if (!bufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "bufferData");
+    if (!bufferSlot)
         return;
-    }
 
     if (size < 0)
         return ErrorInvalidValue("bufferData: negative size");
 
     if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
         return;
 
     // careful: WebGLsizeiptr is always 64-bit, but GLsizeiptr is like intptr_t.
@@ -177,34 +185,33 @@ WebGLContext::BufferData(GLenum target, 
     boundBuffer->SetByteLength(size);
     if (!boundBuffer->ElementArrayCacheBufferData(nullptr, size)) {
         return ErrorOutOfMemory("bufferData: out of memory");
     }
 }
 
 void
 WebGLContext::BufferData(GLenum target,
-                         const Nullable<ArrayBuffer> &maybeData,
+                         const dom::Nullable<dom::ArrayBuffer>& maybeData,
                          GLenum usage)
 {
     if (IsContextLost())
         return;
 
     if (maybeData.IsNull()) {
         // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
         return ErrorInvalidValue("bufferData: null object passed");
     }
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferData");
-
-    if (!bufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "bufferData");
+    if (!bufferSlot)
         return;
-    }
 
-    const ArrayBuffer& data = maybeData.Value();
+    const dom::ArrayBuffer& data = maybeData.Value();
     data.ComputeLengthAndData();
 
     // Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
     // is like intptr_t.
     if (!CheckedInt<GLsizeiptr>(data.Length()).isValid())
         return ErrorOutOfMemory("bufferData: bad size");
 
     if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
@@ -221,33 +228,31 @@ WebGLContext::BufferData(GLenum target,
     GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);
 
     if (error) {
         GenerateWarning("bufferData generated error %s", ErrorName(error));
         return;
     }
 
     boundBuffer->SetByteLength(data.Length());
-    if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length())) {
+    if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length()))
         return ErrorOutOfMemory("bufferData: out of memory");
-    }
 }
 
 void
-WebGLContext::BufferData(GLenum target, const ArrayBufferView& data,
+WebGLContext::BufferData(GLenum target, const dom::ArrayBufferView& data,
                          GLenum usage)
 {
     if (IsContextLost())
         return;
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferSubData");
-
-    if (!bufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "bufferSubData");
+    if (!bufferSlot)
         return;
-    }
 
     if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
         return;
 
     WebGLBuffer* boundBuffer = bufferSlot->get();
 
     if (!boundBuffer)
         return ErrorInvalidOperation("bufferData: no buffer bound!");
@@ -264,97 +269,109 @@ WebGLContext::BufferData(GLenum target, 
 
     GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);
     if (error) {
         GenerateWarning("bufferData generated error %s", ErrorName(error));
         return;
     }
 
     boundBuffer->SetByteLength(data.Length());
-    if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length())) {
+    if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length()))
         return ErrorOutOfMemory("bufferData: out of memory");
-    }
 }
 
 void
 WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
-                            const Nullable<ArrayBuffer> &maybeData)
+                            const dom::Nullable<dom::ArrayBuffer>& maybeData)
 {
     if (IsContextLost())
         return;
 
     if (maybeData.IsNull()) {
         // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
         return;
     }
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferSubData");
-
-    if (!bufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "bufferSubData");
+    if (!bufferSlot)
         return;
-    }
 
     if (byteOffset < 0)
         return ErrorInvalidValue("bufferSubData: negative offset");
 
     WebGLBuffer* boundBuffer = bufferSlot->get();
 
     if (!boundBuffer)
         return ErrorInvalidOperation("bufferData: no buffer bound!");
 
-    const ArrayBuffer& data = maybeData.Value();
+    const dom::ArrayBuffer& data = maybeData.Value();
     data.ComputeLengthAndData();
 
     CheckedInt<WebGLsizeiptr> checked_neededByteLength = CheckedInt<WebGLsizeiptr>(byteOffset) + data.Length();
-    if (!checked_neededByteLength.isValid())
-        return ErrorInvalidValue("bufferSubData: integer overflow computing the needed byte length");
+    if (!checked_neededByteLength.isValid()) {
+        ErrorInvalidValue("bufferSubData: Integer overflow computing the needed"
+                          " byte length.");
+        return;
+    }
 
-    if (checked_neededByteLength.value() > boundBuffer->ByteLength())
-        return ErrorInvalidValue("bufferSubData: not enough data - operation requires %d bytes, but buffer only has %d bytes",
-                                 checked_neededByteLength.value(), boundBuffer->ByteLength());
+    if (checked_neededByteLength.value() > boundBuffer->ByteLength()) {
+        ErrorInvalidValue("bufferSubData: Not enough data. Operation requires"
+                          " %d bytes, but buffer only has %d bytes.",
+                          checked_neededByteLength.value(),
+                          boundBuffer->ByteLength());
+        return;
+    }
+
+    boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(),
+                                                data.Length());
 
     MakeContextCurrent();
-
-    boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(), data.Length());
-
     gl->fBufferSubData(target, byteOffset, data.Length(), data.Data());
 }
 
 void
 WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
-                            const ArrayBufferView& data)
+                            const dom::ArrayBufferView& data)
 {
     if (IsContextLost())
         return;
 
-    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferSubData");
-
-    if (!bufferSlot) {
+    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target,
+                                                                 "bufferSubData");
+    if (!bufferSlot)
         return;
-    }
 
     if (byteOffset < 0)
         return ErrorInvalidValue("bufferSubData: negative offset");
 
     WebGLBuffer* boundBuffer = bufferSlot->get();
 
     if (!boundBuffer)
         return ErrorInvalidOperation("bufferSubData: no buffer bound!");
 
     data.ComputeLengthAndData();
 
     CheckedInt<WebGLsizeiptr> checked_neededByteLength = CheckedInt<WebGLsizeiptr>(byteOffset) + data.Length();
-    if (!checked_neededByteLength.isValid())
-        return ErrorInvalidValue("bufferSubData: integer overflow computing the needed byte length");
+    if (!checked_neededByteLength.isValid()) {
+        ErrorInvalidValue("bufferSubData: Integer overflow computing the needed"
+                          " byte length.");
+        return;
+    }
 
-    if (checked_neededByteLength.value() > boundBuffer->ByteLength())
-        return ErrorInvalidValue("bufferSubData: not enough data -- operation requires %d bytes, but buffer only has %d bytes",
-                                 checked_neededByteLength.value(), boundBuffer->ByteLength());
+    if (checked_neededByteLength.value() > boundBuffer->ByteLength()) {
+        ErrorInvalidValue("bufferSubData: Not enough data. Operation requires"
+                          " %d bytes, but buffer only has %d bytes.",
+                          checked_neededByteLength.value(),
+                          boundBuffer->ByteLength());
+        return;
+    }
 
-    boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(), data.Length());
+    boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(),
+                                                data.Length());
 
     MakeContextCurrent();
     gl->fBufferSubData(target, byteOffset, data.Length(), data.Data());
 }
 
 already_AddRefed<WebGLBuffer>
 WebGLContext::CreateBuffer()
 {
@@ -365,141 +382,147 @@ WebGLContext::CreateBuffer()
     MakeContextCurrent();
     gl->fGenBuffers(1, &buf);
 
     nsRefPtr<WebGLBuffer> globj = new WebGLBuffer(this, buf);
     return globj.forget();
 }
 
 void
-WebGLContext::DeleteBuffer(WebGLBuffer *buffer)
+WebGLContext::DeleteBuffer(WebGLBuffer* buffer)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowDeletedOrNull("deleteBuffer", buffer))
         return;
 
     if (!buffer || buffer->IsDeleted())
         return;
 
-    if (mBoundArrayBuffer == buffer) {
-        BindBuffer(LOCAL_GL_ARRAY_BUFFER,
-                   static_cast<WebGLBuffer*>(nullptr));
-    }
+    if (mBoundArrayBuffer == buffer)
+        BindBuffer(LOCAL_GL_ARRAY_BUFFER, static_cast<WebGLBuffer*>(nullptr));
 
     if (mBoundVertexArray->mElementArrayBuffer == buffer) {
         BindBuffer(LOCAL_GL_ELEMENT_ARRAY_BUFFER,
                    static_cast<WebGLBuffer*>(nullptr));
     }
 
     for (int32_t i = 0; i < mGLMaxVertexAttribs; i++) {
-        if (mBoundVertexArray->HasAttrib(i) && mBoundVertexArray->mAttribs[i].buf == buffer)
+        if (mBoundVertexArray->HasAttrib(i) &&
+            mBoundVertexArray->mAttribs[i].buf == buffer)
+        {
             mBoundVertexArray->mAttribs[i].buf = nullptr;
+        }
     }
 
     buffer->RequestDelete();
 }
 
 bool
-WebGLContext::IsBuffer(WebGLBuffer *buffer)
+WebGLContext::IsBuffer(WebGLBuffer* buffer)
 {
     if (IsContextLost())
         return false;
 
     return ValidateObjectAllowDeleted("isBuffer", buffer) &&
            !buffer->IsDeleted() &&
            buffer->HasEverBeenBound();
 }
 
 bool
-WebGLContext::ValidateBufferUsageEnum(GLenum target, const char *infos)
+WebGLContext::ValidateBufferUsageEnum(GLenum target, const char* info)
 {
     switch (target) {
-        case LOCAL_GL_STREAM_DRAW:
-        case LOCAL_GL_STATIC_DRAW:
-        case LOCAL_GL_DYNAMIC_DRAW:
-            return true;
-        default:
-            break;
+    case LOCAL_GL_STREAM_DRAW:
+    case LOCAL_GL_STATIC_DRAW:
+    case LOCAL_GL_DYNAMIC_DRAW:
+        return true;
+    default:
+        break;
     }
 
-    ErrorInvalidEnumInfo(infos, target);
+    ErrorInvalidEnumInfo(info, target);
     return false;
 }
 
 WebGLRefPtr<WebGLBuffer>*
-WebGLContext::GetBufferSlotByTarget(GLenum target, const char* infos)
+WebGLContext::GetBufferSlotByTarget(GLenum target, const char* info)
 {
     switch (target) {
-        case LOCAL_GL_ARRAY_BUFFER:
-            return &mBoundArrayBuffer;
+    case LOCAL_GL_ARRAY_BUFFER:
+        return &mBoundArrayBuffer;
 
-        case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
-            return &mBoundVertexArray->mElementArrayBuffer;
+    case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
+        return &mBoundVertexArray->mElementArrayBuffer;
 
-        case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
-            if (!IsWebGL2()) {
-                break;
-            }
-            return &mBoundTransformFeedbackBuffer;
+    case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
+        if (!IsWebGL2()) {
+            break;
+        }
+        return &mBoundTransformFeedbackBuffer;
 
-        default:
-            break;
+    default:
+        break;
     }
 
-    ErrorInvalidEnum("%s: target: invalid enum value 0x%x", infos, target);
+    ErrorInvalidEnum("%s: target: Invalid enum value 0x%x.", info, target);
     return nullptr;
 }
 
 WebGLRefPtr<WebGLBuffer>*
-WebGLContext::GetBufferSlotByTargetIndexed(GLenum target, GLuint index, const char* infos)
+WebGLContext::GetBufferSlotByTargetIndexed(GLenum target, GLuint index,
+                                           const char* info)
 {
     switch (target) {
-        case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
-            if (index >= mGLMaxTransformFeedbackSeparateAttribs) {
-                ErrorInvalidValue("%s: index should be less than MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", infos, index);
-                return nullptr;
-            }
-            return nullptr; // See bug 903594
+    case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
+        if (index >= mGLMaxTransformFeedbackSeparateAttribs) {
+            ErrorInvalidValue("%s: `index` should be less than"
+                              " MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS.", info,
+                              index);
+            return nullptr;
+        }
+        return nullptr; // See bug 903594
 
-        default:
-            break;
+    default:
+        break;
     }
 
-    ErrorInvalidEnum("%s: target: invalid enum value 0x%x", infos, target);
+    ErrorInvalidEnum("%s: target: invalid enum value 0x%x", info, target);
     return nullptr;
 }
 
 GLenum
-WebGLContext::CheckedBufferData(GLenum target,
-                                GLsizeiptr size,
-                                const GLvoid *data,
-                                GLenum usage)
+WebGLContext::CheckedBufferData(GLenum target, GLsizeiptr size,
+                                const GLvoid* data, GLenum usage)
 {
 #ifdef XP_MACOSX
     // bug 790879
     if (gl->WorkAroundDriverBugs() &&
         int64_t(size) > INT32_MAX) // the cast avoids a potential always-true warning on 32bit
     {
-        GenerateWarning("Rejecting valid bufferData call with size %lu to avoid a Mac bug", size);
+        GenerateWarning("Rejecting valid bufferData call with size %lu to avoid"
+                        " a Mac bug", size);
         return LOCAL_GL_INVALID_VALUE;
     }
 #endif
-    WebGLBuffer *boundBuffer = nullptr;
+
+    WebGLBuffer* boundBuffer = nullptr;
     if (target == LOCAL_GL_ARRAY_BUFFER) {
         boundBuffer = mBoundArrayBuffer;
     } else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
         boundBuffer = mBoundVertexArray->mElementArrayBuffer;
     }
-    MOZ_ASSERT(boundBuffer != nullptr, "no buffer bound for this target");
+    MOZ_ASSERT(boundBuffer, "No buffer bound for this target.");
 
     bool sizeChanges = uint32_t(size) != boundBuffer->ByteLength();
     if (sizeChanges) {
         GetAndFlushUnderlyingGLErrors();
         gl->fBufferData(target, size, data, usage);
         GLenum error = GetAndFlushUnderlyingGLErrors();
         return error;
     } else {
         gl->fBufferData(target, size, data, usage);
         return LOCAL_GL_NO_ERROR;
     }
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -403,29 +403,28 @@ void WebGLContext::Draw_cleanup()
 }
 
 /*
  * Verify that state is consistent for drawing, and compute max number of elements (maxAllowedCount)
  * that will be legal to be read from bound VBOs.
  */
 
 bool
-WebGLContext::ValidateBufferFetching(const char *info)
+WebGLContext::ValidateBufferFetching(const char* info)
 {
 #ifdef DEBUG
     GLint currentProgram = 0;
     MakeContextCurrent();
     gl->fGetIntegerv(LOCAL_GL_CURRENT_PROGRAM, &currentProgram);
     MOZ_ASSERT(GLuint(currentProgram) == mCurrentProgram->GLName(),
                "WebGL: current program doesn't agree with GL state");
 #endif
 
-    if (mBufferFetchingIsVerified) {
+    if (mBufferFetchingIsVerified)
         return true;
-    }
 
     bool hasPerVertex = false;
     uint32_t maxVertices = UINT32_MAX;
     uint32_t maxInstances = UINT32_MAX;
     uint32_t attribs = mBoundVertexArray->mAttribs.Length();
 
     for (uint32_t i = 0; i < attribs; ++i) {
         const WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[i];
@@ -730,17 +729,17 @@ WebGLContext::UnbindFakeBlackTextures()
             gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
             gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, mBoundCubeMapTextures[i]->GLName());
         }
     }
 
     gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture);
 }
 
-WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, TexTarget target, GLenum format)
+WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext* gl, TexTarget target, GLenum format)
     : mGL(gl)
     , mGLName(0)
 {
   MOZ_ASSERT(format == LOCAL_GL_RGB || format == LOCAL_GL_RGBA);
 
   mGL->MakeCurrent();
   GLuint formerBinding = 0;
   gl->GetUIntegerv(target == LOCAL_GL_TEXTURE_2D
--- a/dom/canvas/WebGLContextExtensions.cpp
+++ b/dom/canvas/WebGLContextExtensions.cpp
@@ -7,26 +7,25 @@
 #include "WebGLContextUtils.h"
 #include "WebGLExtensions.h"
 #include "GLContext.h"
 
 #include "nsString.h"
 #include "mozilla/Preferences.h"
 #include "AccessCheck.h"
 
-using namespace mozilla;
-using namespace mozilla::gl;
+namespace mozilla {
 
-/* static */ const char*
+/*static*/ const char*
 WebGLContext::GetExtensionString(WebGLExtensionID ext)
 {
-    typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max, const char*>
-            names_array_t;
+    typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max,
+                            const char*> names_array_t;
+
     static names_array_t sExtensionNamesEnumeratedArray;
-
     static bool initialized = false;
 
     if (!initialized) {
         initialized = true;
 
 #define WEBGL_EXTENSION_IDENTIFIER(x) \
         sExtensionNamesEnumeratedArray[WebGLExtensionID::x] = #x;
 
@@ -57,136 +56,140 @@ WebGLContext::GetExtensionString(WebGLEx
 
 #undef WEBGL_EXTENSION_IDENTIFIER
     }
 
     return sExtensionNamesEnumeratedArray[ext];
 }
 
 bool
-WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) const {
+WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) const
+{
     return mExtensions[ext];
 }
 
-bool WebGLContext::IsExtensionSupported(JSContext *cx, WebGLExtensionID ext) const
+bool WebGLContext::IsExtensionSupported(JSContext* cx,
+                                        WebGLExtensionID ext) const
 {
     bool allowPrivilegedExts = false;
 
     // Chrome contexts need access to debug information even when
     // webgl.disable-extensions is set. This is used in the graphics
     // section of about:support.
     if (xpc::AccessCheck::isChrome(js::GetContextCompartment(cx)))
         allowPrivilegedExts = true;
 
     if (Preferences::GetBool("webgl.enable-privileged-extensions", false))
         allowPrivilegedExts = true;
 
     if (allowPrivilegedExts) {
         switch (ext) {
-            case WebGLExtensionID::WEBGL_debug_renderer_info:
-                return true;
-            case WebGLExtensionID::WEBGL_debug_shaders:
-                return true;
-            default:
-                // For warnings-as-errors.
-                break;
+        case WebGLExtensionID::WEBGL_debug_renderer_info:
+            return true;
+        case WebGLExtensionID::WEBGL_debug_shaders:
+            return true;
+        default:
+            // For warnings-as-errors.
+            break;
         }
     }
 
     return IsExtensionSupported(ext);
 }
 
 bool WebGLContext::IsExtensionSupported(WebGLExtensionID ext) const
 {
-    if (mDisableExtensions) {
+    if (mDisableExtensions)
         return false;
-    }
 
     switch (ext) {
-        case WebGLExtensionID::EXT_blend_minmax:
-            return WebGLExtensionBlendMinMax::IsSupported(this);
-        case WebGLExtensionID::OES_element_index_uint:
-            return gl->IsSupported(GLFeature::element_index_uint);
-        case WebGLExtensionID::OES_standard_derivatives:
-            return gl->IsSupported(GLFeature::standard_derivatives);
-        case WebGLExtensionID::WEBGL_lose_context:
-            // We always support this extension.
+    case WebGLExtensionID::OES_vertex_array_object:
+    case WebGLExtensionID::WEBGL_lose_context:
+        // Always supported.
+        return true;
+
+    case WebGLExtensionID::EXT_blend_minmax:
+        return WebGLExtensionBlendMinMax::IsSupported(this);
+    case WebGLExtensionID::OES_element_index_uint:
+        return gl->IsSupported(gl::GLFeature::element_index_uint);
+    case WebGLExtensionID::OES_standard_derivatives:
+        return gl->IsSupported(gl::GLFeature::standard_derivatives);
+
+    case WebGLExtensionID::OES_texture_float:
+        return gl->IsSupported(gl::GLFeature::texture_float);
+    case WebGLExtensionID::OES_texture_float_linear:
+        return gl->IsSupported(gl::GLFeature::texture_float_linear);
+    case WebGLExtensionID::OES_texture_half_float:
+        // If we have Feature::texture_half_float, we must not be on ES2
+        // and need to translate HALF_FLOAT_OES -> HALF_FLOAT.  We do that
+        // right before making the relevant calls.
+        return gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float) ||
+               gl->IsSupported(gl::GLFeature::texture_half_float);
+
+    case WebGLExtensionID::OES_texture_half_float_linear:
+        return gl->IsSupported(gl::GLFeature::texture_half_float_linear);
+    case WebGLExtensionID::EXT_texture_filter_anisotropic:
+        return gl->IsExtensionSupported(gl::GLContext::EXT_texture_filter_anisotropic);
+    case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
+        if (gl->IsExtensionSupported(gl::GLContext::EXT_texture_compression_s3tc))
             return true;
-        case WebGLExtensionID::OES_texture_float:
-            return gl->IsSupported(GLFeature::texture_float);
-        case WebGLExtensionID::OES_texture_float_linear:
-            return gl->IsSupported(GLFeature::texture_float_linear);
-        case WebGLExtensionID::OES_texture_half_float:
-            // If we have Feature::texture_half_float, we must not be on ES2
-            // and need to translate HALF_FLOAT_OES -> HALF_FLOAT.  We do that
-            // right before making the relevant calls.
-            return gl->IsExtensionSupported(GLContext::OES_texture_half_float) ||
-                   gl->IsSupported(GLFeature::texture_half_float);
-        case WebGLExtensionID::OES_texture_half_float_linear:
-            return gl->IsSupported(GLFeature::texture_half_float_linear);
-        case WebGLExtensionID::OES_vertex_array_object:
-            return WebGLExtensionVertexArray::IsSupported(this);
-        case WebGLExtensionID::EXT_texture_filter_anisotropic:
-            return gl->IsExtensionSupported(GLContext::EXT_texture_filter_anisotropic);
-        case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
-            if (gl->IsExtensionSupported(GLContext::EXT_texture_compression_s3tc)) {
-                return true;
-            }
-            else if (gl->IsExtensionSupported(GLContext::EXT_texture_compression_dxt1) &&
-                     gl->IsExtensionSupported(GLContext::ANGLE_texture_compression_dxt3) &&
-                     gl->IsExtensionSupported(GLContext::ANGLE_texture_compression_dxt5))
-            {
-                return true;
-            }
+
+        return gl->IsExtensionSupported(gl::GLContext::EXT_texture_compression_dxt1) &&
+               gl->IsExtensionSupported(gl::GLContext::ANGLE_texture_compression_dxt3) &&
+               gl->IsExtensionSupported(gl::GLContext::ANGLE_texture_compression_dxt5);
+
+    case WebGLExtensionID::WEBGL_compressed_texture_atc:
+        return gl->IsExtensionSupported(gl::GLContext::AMD_compressed_ATC_texture);
+    case WebGLExtensionID::WEBGL_compressed_texture_etc1:
+        return gl->IsExtensionSupported(gl::GLContext::OES_compressed_ETC1_RGB8_texture);
+    case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
+        return gl->IsExtensionSupported(gl::GLContext::IMG_texture_compression_pvrtc);
+    case WebGLExtensionID::WEBGL_depth_texture:
+        // WEBGL_depth_texture supports DEPTH_STENCIL textures
+        if (!gl->IsSupported(gl::GLFeature::packed_depth_stencil))
             return false;
-        case WebGLExtensionID::WEBGL_compressed_texture_atc:
-            return gl->IsExtensionSupported(GLContext::AMD_compressed_ATC_texture);
-        case WebGLExtensionID::WEBGL_compressed_texture_etc1:
-            return gl->IsExtensionSupported(GLContext::OES_compressed_ETC1_RGB8_texture);
-        case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
-            return gl->IsExtensionSupported(GLContext::IMG_texture_compression_pvrtc);
-        case WebGLExtensionID::WEBGL_depth_texture:
-            // WEBGL_depth_texture supports DEPTH_STENCIL textures
-            if (!gl->IsSupported(GLFeature::packed_depth_stencil)) {
-                return false;
-            }
-            return gl->IsSupported(GLFeature::depth_texture) ||
-                   gl->IsExtensionSupported(GLContext::ANGLE_depth_texture);
-        case WebGLExtensionID::ANGLE_instanced_arrays:
-            return WebGLExtensionInstancedArrays::IsSupported(this);
-        case WebGLExtensionID::EXT_sRGB:
-            return WebGLExtensionSRGB::IsSupported(this);
-        case WebGLExtensionID::WEBGL_draw_buffers:
-            return WebGLExtensionDrawBuffers::IsSupported(this);
-        case WebGLExtensionID::EXT_frag_depth:
-            return WebGLExtensionFragDepth::IsSupported(this);
-        case WebGLExtensionID::EXT_shader_texture_lod:
-            return gl->IsExtensionSupported(GLContext::EXT_shader_texture_lod);
+
+        return gl->IsSupported(gl::GLFeature::depth_texture) ||
+               gl->IsExtensionSupported(gl::GLContext::ANGLE_depth_texture);
+
+    case WebGLExtensionID::ANGLE_instanced_arrays:
+        return WebGLExtensionInstancedArrays::IsSupported(this);
+    case WebGLExtensionID::EXT_sRGB:
+        return WebGLExtensionSRGB::IsSupported(this);
+    case WebGLExtensionID::WEBGL_draw_buffers:
+        return WebGLExtensionDrawBuffers::IsSupported(this);
+    case WebGLExtensionID::EXT_frag_depth:
+        return WebGLExtensionFragDepth::IsSupported(this);
+    case WebGLExtensionID::EXT_shader_texture_lod:
+        return gl->IsExtensionSupported(gl::GLContext::EXT_shader_texture_lod);
+
+    default:
+        // For warnings-as-errors.
+        break;
+    }
+
+    if (Preferences::GetBool("webgl.enable-draft-extensions", false) ||
+        IsWebGL2())
+    {
+        switch (ext) {
+        case WebGLExtensionID::EXT_color_buffer_half_float:
+            return WebGLExtensionColorBufferHalfFloat::IsSupported(this);
+        case WebGLExtensionID::WEBGL_color_buffer_float:
+            return WebGLExtensionColorBufferFloat::IsSupported(this);
         default:
             // For warnings-as-errors.
             break;
-    }
-
-    if (Preferences::GetBool("webgl.enable-draft-extensions", false) || IsWebGL2()) {
-        switch (ext) {
-            case WebGLExtensionID::EXT_color_buffer_half_float:
-                return WebGLExtensionColorBufferHalfFloat::IsSupported(this);
-            case WebGLExtensionID::WEBGL_color_buffer_float:
-                return WebGLExtensionColorBufferFloat::IsSupported(this);
-            default:
-                // For warnings-as-errors.
-                break;
         }
     }
 
     return false;
 }
 
 static bool
-CompareWebGLExtensionName(const nsACString& name, const char *other)
+CompareWebGLExtensionName(const nsACString& name, const char* other)
 {
     return name.Equals(other, nsCaseInsensitiveCStringComparator());
 }
 
 WebGLExtensionBase*
 WebGLContext::EnableSupportedExtension(JSContext* js, WebGLExtensionID ext)
 {
     if (!IsExtensionEnabled(ext)) {
@@ -195,205 +198,201 @@ WebGLContext::EnableSupportedExtension(J
 
         EnableExtension(ext);
     }
 
     return mExtensions[ext];
 }
 
 void
-WebGLContext::GetExtension(JSContext *cx, const nsAString& aName,
-                           JS::MutableHandle<JSObject*> aRetval,
-                           ErrorResult& rv)
+WebGLContext::GetExtension(JSContext* cx, const nsAString& wideName,
+                           JS::MutableHandle<JSObject*> retval, ErrorResult& rv)
 {
-    if (IsContextLost()) {
-        aRetval.set(nullptr);
+    retval.set(nullptr);
+
+    if (IsContextLost())
         return;
-    }
 
-    NS_LossyConvertUTF16toASCII name(aName);
+    NS_LossyConvertUTF16toASCII name(wideName);
 
     WebGLExtensionID ext = WebGLExtensionID::Unknown;
 
     // step 1: figure what extension is wanted
     for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
         WebGLExtensionID extension = WebGLExtensionID(i);
 
         if (CompareWebGLExtensionName(name, GetExtensionString(extension))) {
             ext = extension;
             break;
         }
     }
 
     if (ext == WebGLExtensionID::Unknown) {
-        /**
-         * We keep backward compatibility for these deprecated vendor-prefixed
-         * alias. Do not add new ones anymore. Hide it behind the
-         * webgl.enable-draft-extensions flag instead.
-         */
+        // We keep backward compatibility for these deprecated vendor-prefixed
+        // alias. Do not add new ones anymore. Hide it behind the
+        // webgl.enable-draft-extensions flag instead.
+
         if (CompareWebGLExtensionName(name, "MOZ_WEBGL_lose_context")) {
             ext = WebGLExtensionID::WEBGL_lose_context;
-        }
-        else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_s3tc")) {
+
+        } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_s3tc")) {
             ext = WebGLExtensionID::WEBGL_compressed_texture_s3tc;
-        }
-        else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_atc")) {
+
+        } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_atc")) {
             ext = WebGLExtensionID::WEBGL_compressed_texture_atc;
-        }
-        else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_pvrtc")) {
+
+        } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_pvrtc")) {
             ext = WebGLExtensionID::WEBGL_compressed_texture_pvrtc;
-        }
-        else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_depth_texture")) {
+
+        } else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_depth_texture")) {
             ext = WebGLExtensionID::WEBGL_depth_texture;
         }
 
         if (ext != WebGLExtensionID::Unknown) {
-            GenerateWarning("getExtension('%s'): MOZ_ prefixed WebGL extension strings are deprecated. "
-                            "Support for them will be removed in the future. Use unprefixed extension strings. "
-                            "To get draft extensions, set the webgl.enable-draft-extensions preference.",
+            GenerateWarning("getExtension('%s'): MOZ_ prefixed WebGL extension"
+                            " strings are deprecated. Support for them will be"
+                            " removed in the future. Use unprefixed extension"
+                            " strings. To get draft extensions, set the"
+                            " webgl.enable-draft-extensions preference.",
                             name.get());
         }
     }
 
-    if (ext == WebGLExtensionID::Unknown) {
-        aRetval.set(nullptr);
+    if (ext == WebGLExtensionID::Unknown)
         return;
-    }
 
     // step 2: check if the extension is supported
-    if (!IsExtensionSupported(cx, ext)) {
-        aRetval.set(nullptr);
+    if (!IsExtensionSupported(cx, ext))
         return;
-    }
 
     // step 3: if the extension hadn't been previously been created, create it now, thus enabling it
     WebGLExtensionBase* extObj = EnableSupportedExtension(cx, ext);
-    if (!extObj) {
-        aRetval.set(nullptr);
+    if (!extObj)
         return;
-    }
 
     // Step 4: Enable any implied extensions.
     switch (ext) {
     case WebGLExtensionID::OES_texture_float:
         EnableSupportedExtension(cx, WebGLExtensionID::WEBGL_color_buffer_float);
         break;
 
     case WebGLExtensionID::OES_texture_half_float:
         EnableSupportedExtension(cx, WebGLExtensionID::EXT_color_buffer_half_float);
         break;
 
     default:
         break;
     }
 
-    aRetval.set(WebGLObjectAsJSObject(cx, extObj, rv));
+    retval.set(WebGLObjectAsJSObject(cx, extObj, rv));
 }
 
 void
 WebGLContext::EnableExtension(WebGLExtensionID ext)
 {
     MOZ_ASSERT(IsExtensionEnabled(ext) == false);
 
     WebGLExtensionBase* obj = nullptr;
     switch (ext) {
-        case WebGLExtensionID::OES_element_index_uint:
-            obj = new WebGLExtensionElementIndexUint(this);
-            break;
-        case WebGLExtensionID::OES_standard_derivatives:
-            obj = new WebGLExtensionStandardDerivatives(this);
-            break;
-        case WebGLExtensionID::EXT_texture_filter_anisotropic:
-            obj = new WebGLExtensionTextureFilterAnisotropic(this);
-            break;
-        case WebGLExtensionID::WEBGL_lose_context:
-            obj = new WebGLExtensionLoseContext(this);
-            break;
-        case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
-            obj = new WebGLExtensionCompressedTextureS3TC(this);
-            break;
-        case WebGLExtensionID::WEBGL_compressed_texture_atc:
-            obj = new WebGLExtensionCompressedTextureATC(this);
-            break;
-        case WebGLExtensionID::WEBGL_compressed_texture_etc1:
-            obj = new WebGLExtensionCompressedTextureETC1(this);
-            break;
-        case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
-            obj = new WebGLExtensionCompressedTexturePVRTC(this);
-            break;
-        case WebGLExtensionID::WEBGL_debug_renderer_info:
-            obj = new WebGLExtensionDebugRendererInfo(this);
-            break;
-        case WebGLExtensionID::WEBGL_debug_shaders:
-            obj = new WebGLExtensionDebugShaders(this);
-            break;
-        case WebGLExtensionID::WEBGL_depth_texture:
-            obj = new WebGLExtensionDepthTexture(this);
-            break;
-        case WebGLExtensionID::OES_texture_float:
-            obj = new WebGLExtensionTextureFloat(this);
-            break;
-        case WebGLExtensionID::OES_texture_float_linear:
-            obj = new WebGLExtensionTextureFloatLinear(this);
-            break;
-        case WebGLExtensionID::OES_texture_half_float:
-            obj = new WebGLExtensionTextureHalfFloat(this);
-            break;
-        case WebGLExtensionID::OES_texture_half_float_linear:
-            obj = new WebGLExtensionTextureHalfFloatLinear(this);
-            break;
-        case WebGLExtensionID::WEBGL_color_buffer_float:
-            obj = new WebGLExtensionColorBufferFloat(this);
-            break;
-        case WebGLExtensionID::EXT_color_buffer_half_float:
-            obj = new WebGLExtensionColorBufferHalfFloat(this);
-            break;
-        case WebGLExtensionID::WEBGL_draw_buffers:
-            obj = new WebGLExtensionDrawBuffers(this);
-            break;
-        case WebGLExtensionID::OES_vertex_array_object:
-            obj = new WebGLExtensionVertexArray(this);
-            break;
-        case WebGLExtensionID::ANGLE_instanced_arrays:
-            obj = new WebGLExtensionInstancedArrays(this);
-            break;
-        case WebGLExtensionID::EXT_sRGB:
-            obj = new WebGLExtensionSRGB(this);
-            break;
-        case WebGLExtensionID::EXT_frag_depth:
-            obj = new WebGLExtensionFragDepth(this);
-            break;
-        case WebGLExtensionID::EXT_blend_minmax:
-            obj = new WebGLExtensionBlendMinMax(this);
-            break;
-        case WebGLExtensionID::EXT_shader_texture_lod:
-            obj = new WebGLExtensionShaderTextureLod(this);
-            break;
-        default:
-            MOZ_ASSERT(false, "should not get there.");
+    case WebGLExtensionID::OES_element_index_uint:
+        obj = new WebGLExtensionElementIndexUint(this);
+        break;
+    case WebGLExtensionID::OES_standard_derivatives:
+        obj = new WebGLExtensionStandardDerivatives(this);
+        break;
+    case WebGLExtensionID::EXT_texture_filter_anisotropic:
+        obj = new WebGLExtensionTextureFilterAnisotropic(this);
+        break;
+    case WebGLExtensionID::WEBGL_lose_context:
+        obj = new WebGLExtensionLoseContext(this);
+        break;
+    case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
+        obj = new WebGLExtensionCompressedTextureS3TC(this);
+        break;
+    case WebGLExtensionID::WEBGL_compressed_texture_atc:
+        obj = new WebGLExtensionCompressedTextureATC(this);
+        break;
+    case WebGLExtensionID::WEBGL_compressed_texture_etc1:
+        obj = new WebGLExtensionCompressedTextureETC1(this);
+        break;
+    case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
+        obj = new WebGLExtensionCompressedTexturePVRTC(this);
+        break;
+    case WebGLExtensionID::WEBGL_debug_renderer_info:
+        obj = new WebGLExtensionDebugRendererInfo(this);
+        break;
+    case WebGLExtensionID::WEBGL_debug_shaders:
+        obj = new WebGLExtensionDebugShaders(this);
+        break;
+    case WebGLExtensionID::WEBGL_depth_texture:
+        obj = new WebGLExtensionDepthTexture(this);
+        break;
+    case WebGLExtensionID::OES_texture_float:
+        obj = new WebGLExtensionTextureFloat(this);
+        break;
+    case WebGLExtensionID::OES_texture_float_linear:
+        obj = new WebGLExtensionTextureFloatLinear(this);
+        break;
+    case WebGLExtensionID::OES_texture_half_float:
+        obj = new WebGLExtensionTextureHalfFloat(this);
+        break;
+    case WebGLExtensionID::OES_texture_half_float_linear:
+        obj = new WebGLExtensionTextureHalfFloatLinear(this);
+        break;
+    case WebGLExtensionID::WEBGL_color_buffer_float:
+        obj = new WebGLExtensionColorBufferFloat(this);
+        break;
+    case WebGLExtensionID::EXT_color_buffer_half_float:
+        obj = new WebGLExtensionColorBufferHalfFloat(this);
+        break;
+    case WebGLExtensionID::WEBGL_draw_buffers:
+        obj = new WebGLExtensionDrawBuffers(this);
+        break;
+    case WebGLExtensionID::OES_vertex_array_object:
+        obj = new WebGLExtensionVertexArray(this);
+        break;
+    case WebGLExtensionID::ANGLE_instanced_arrays:
+        obj = new WebGLExtensionInstancedArrays(this);
+        break;
+    case WebGLExtensionID::EXT_sRGB:
+        obj = new WebGLExtensionSRGB(this);
+        break;
+    case WebGLExtensionID::EXT_frag_depth:
+        obj = new WebGLExtensionFragDepth(this);
+        break;
+    case WebGLExtensionID::EXT_blend_minmax:
+        obj = new WebGLExtensionBlendMinMax(this);
+        break;
+    case WebGLExtensionID::EXT_shader_texture_lod:
+        obj = new WebGLExtensionShaderTextureLod(this);
+        break;
+    default:
+        MOZ_ASSERT(false, "should not get there.");
+        break;
     }
 
     mExtensions[ext] = obj;
 }
 
 void
-WebGLContext::GetSupportedExtensions(JSContext *cx, Nullable< nsTArray<nsString> > &retval)
+WebGLContext::GetSupportedExtensions(JSContext* cx,
+                                     Nullable< nsTArray<nsString> >& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
     nsTArray<nsString>& arr = retval.SetValue();
 
-    for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++)
-    {
+    for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
         WebGLExtensionID extension = WebGLExtensionID(i);
 
         if (IsExtensionSupported(cx, extension)) {
-            arr.AppendElement(NS_ConvertUTF8toUTF16(GetExtensionString(extension)));
+            const char* extStr = GetExtensionString(extension);
+            arr.AppendElement(NS_ConvertUTF8toUTF16(extStr));
         }
     }
 
     /**
      * We keep backward compatibility for these deprecated vendor-prefixed
      * alias. Do not add new ones anymore. Hide it behind the
      * webgl.enable-draft-extensions flag instead.
      */
@@ -404,8 +403,9 @@ WebGLContext::GetSupportedExtensions(JSC
     if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_atc))
         arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_atc"));
     if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_pvrtc))
         arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_pvrtc"));
     if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_depth_texture))
         arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_depth_texture"));
 }
 
+} // namespace mozilla
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -50,17 +50,18 @@
 #include "mozilla/Endian.h"
 #include "mozilla/fallible.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::gl;
 using namespace mozilla::gfx;
 
-static bool BaseTypeAndSizeFromUniformType(GLenum uType, GLenum *baseType, GLint *unitSize);
+static bool BaseTypeAndSizeFromUniformType(GLenum uType, GLenum* baseType,
+                                           GLint* unitSize);
 
 const WebGLRectangleObject*
 WebGLContext::CurValidFBRectObject() const
 {
     const WebGLRectangleObject* rect = nullptr;
 
     if (mBoundFramebuffer) {
         // We don't really need to ask the driver.
@@ -96,17 +97,17 @@ WebGLContext::ActiveTexture(GLenum textu
     }
 
     MakeContextCurrent();
     mActiveTexture = texture - LOCAL_GL_TEXTURE0;
     gl->fActiveTexture(texture);
 }
 
 void
-WebGLContext::AttachShader(WebGLProgram *program, WebGLShader *shader)
+WebGLContext::AttachShader(WebGLProgram* program, WebGLShader* shader)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObject("attachShader: program", program) ||
         !ValidateObject("attachShader: shader", shader))
         return;
 
@@ -153,17 +154,17 @@ WebGLContext::BindAttribLocation(WebGLPr
         mappedName.Assign(cname);
     }
 
     MakeContextCurrent();
     gl->fBindAttribLocation(progname, location, mappedName.get());
 }
 
 void
-WebGLContext::BindFramebuffer(GLenum target, WebGLFramebuffer *wfb)
+WebGLContext::BindFramebuffer(GLenum target, WebGLFramebuffer* wfb)
 {
     if (IsContextLost())
         return;
 
     if (target != LOCAL_GL_FRAMEBUFFER)
         return ErrorInvalidEnum("bindFramebuffer: target must be GL_FRAMEBUFFER");
 
     if (!ValidateObjectAllowDeletedOrNull("bindFramebuffer", wfb))
@@ -182,17 +183,17 @@ WebGLContext::BindFramebuffer(GLenum tar
         GLuint framebuffername = wfb->GLName();
         gl->fBindFramebuffer(target, framebuffername);
     }
 
     mBoundFramebuffer = wfb;
 }
 
 void
-WebGLContext::BindRenderbuffer(GLenum target, WebGLRenderbuffer *wrb)
+WebGLContext::BindRenderbuffer(GLenum target, WebGLRenderbuffer* wrb)
 {
     if (IsContextLost())
         return;
 
     if (target != LOCAL_GL_RENDERBUFFER)
         return ErrorInvalidEnumInfo("bindRenderbuffer: target", target);
 
     if (!ValidateObjectAllowDeletedOrNull("bindRenderbuffer", wrb))
@@ -214,17 +215,17 @@ WebGLContext::BindRenderbuffer(GLenum ta
     } else {
         gl->fBindRenderbuffer(target, 0);
     }
 
     mBoundRenderbuffer = wrb;
 }
 
 void
-WebGLContext::BindTexture(GLenum rawTarget, WebGLTexture *newTex)
+WebGLContext::BindTexture(GLenum rawTarget, WebGLTexture* newTex)
 {
     if (IsContextLost())
         return;
 
      if (!ValidateObjectAllowDeletedOrNull("bindTexture", newTex))
         return;
 
     // Need to check rawTarget first before comparing against newTex->Target() as
@@ -398,17 +399,17 @@ WebGLContext::CopyTexSubImage2D_base(Tex
     if (!ValidateCopyTexImage(internalformat.get(), func, dims))
         return;
 
     if (!mBoundFramebuffer)
         ClearBackbufferIfNeeded();
 
     MakeContextCurrent();
 
-    WebGLTexture *tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
 
     if (!tex)
         return ErrorInvalidOperation("%s: no texture is bound to this target");
 
     if (tex->IsImmutable()) {
         if (!sub) {
             return ErrorInvalidOperation("copyTexImage2D: disallowed because the texture bound to this target has already been made immutable by texStorage2D");
         }
@@ -582,17 +583,17 @@ WebGLContext::CopyTexSubImage2D(GLenum r
         return ErrorInvalidValue("copyTexSubImage2D: 2^level exceeds maximum texture size");
 
     if (width < 0 || height < 0)
         return ErrorInvalidValue("copyTexSubImage2D: width and height may not be negative");
 
     if (xoffset < 0 || yoffset < 0)
         return ErrorInvalidValue("copyTexSubImage2D: xoffset and yoffset may not be negative");
 
-    WebGLTexture *tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
     if (!tex)
         return ErrorInvalidOperation("copyTexSubImage2D: no texture bound to this target");
 
     if (!tex->HasImageInfoAt(texImageTarget, level))
         return ErrorInvalidOperation("copyTexSubImage2D: no texture image previously defined for this level and face");
 
     const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level);
     GLsizei texWidth = imageInfo.Width();
@@ -681,17 +682,17 @@ WebGLContext::DeleteFramebuffer(WebGLFra
     fbuf->RequestDelete();
 
     if (mBoundFramebuffer == fbuf)
         BindFramebuffer(LOCAL_GL_FRAMEBUFFER,
                         static_cast<WebGLFramebuffer*>(nullptr));
 }
 
 void
-WebGLContext::DeleteRenderbuffer(WebGLRenderbuffer *rbuf)
+WebGLContext::DeleteRenderbuffer(WebGLRenderbuffer* rbuf)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowDeletedOrNull("deleteRenderbuffer", rbuf))
         return;
 
     if (!rbuf || rbuf->IsDeleted())
@@ -706,17 +707,17 @@ WebGLContext::DeleteRenderbuffer(WebGLRe
     if (mBoundRenderbuffer == rbuf)
         BindRenderbuffer(LOCAL_GL_RENDERBUFFER,
                          static_cast<WebGLRenderbuffer*>(nullptr));
 
     rbuf->RequestDelete();
 }
 
 void
-WebGLContext::DeleteTexture(WebGLTexture *tex)
+WebGLContext::DeleteTexture(WebGLTexture* tex)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowDeletedOrNull("deleteTexture", tex))
         return;
 
     if (!tex || tex->IsDeleted())
@@ -739,47 +740,47 @@ WebGLContext::DeleteTexture(WebGLTexture
         }
     }
     ActiveTexture(LOCAL_GL_TEXTURE0 + activeTexture);
 
     tex->RequestDelete();
 }
 
 void
-WebGLContext::DeleteProgram(WebGLProgram *prog)
+WebGLContext::DeleteProgram(WebGLProgram* prog)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowDeletedOrNull("deleteProgram", prog))
         return;
 
     if (!prog || prog->IsDeleted())
         return;
 
     prog->RequestDelete();
 }
 
 void
-WebGLContext::DeleteShader(WebGLShader *shader)
+WebGLContext::DeleteShader(WebGLShader* shader)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowDeletedOrNull("deleteShader", shader))
         return;
 
     if (!shader || shader->IsDeleted())
         return;
 
     shader->RequestDelete();
 }
 
 void
-WebGLContext::DetachShader(WebGLProgram *program, WebGLShader *shader)
+WebGLContext::DetachShader(WebGLProgram* program, WebGLShader* shader)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObject("detachShader: program", program) ||
         // it's valid to attempt to detach a deleted shader, since it's
         // still a shader
         !ValidateObjectAllowDeleted("detashShader: shader", shader))
@@ -811,17 +812,18 @@ WebGLContext::DepthRange(GLfloat zNear, 
     if (zNear > zFar)
         return ErrorInvalidOperation("depthRange: the near value is greater than the far value!");
 
     MakeContextCurrent();
     gl->fDepthRange(zNear, zFar);
 }
 
 void
-WebGLContext::FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum rbtarget, WebGLRenderbuffer *wrb)
+WebGLContext::FramebufferRenderbuffer(GLenum target, GLenum attachment,
+                                      GLenum rbtarget, WebGLRenderbuffer* wrb)
 {
     if (IsContextLost())
         return;
 
     if (!mBoundFramebuffer)
         return ErrorInvalidOperation("framebufferRenderbuffer: cannot modify framebuffer 0");
 
     if (target != LOCAL_GL_FRAMEBUFFER)
@@ -835,17 +837,17 @@ WebGLContext::FramebufferRenderbuffer(GL
 
     return mBoundFramebuffer->FramebufferRenderbuffer(attachment, rbtarget, wrb);
 }
 
 void
 WebGLContext::FramebufferTexture2D(GLenum target,
                                    GLenum attachment,
                                    GLenum textarget,
-                                   WebGLTexture *tobj,
+                                   WebGLTexture* tobj,
                                    GLint level)
 {
     if (IsContextLost())
         return;
 
     if (!mBoundFramebuffer)
         return ErrorInvalidOperation("framebufferRenderbuffer: cannot modify framebuffer 0");
 
@@ -879,17 +881,17 @@ WebGLContext::FrontFace(GLenum mode)
             return ErrorInvalidEnumInfo("frontFace: mode", mode);
     }
 
     MakeContextCurrent();
     gl->fFrontFace(mode);
 }
 
 already_AddRefed<WebGLActiveInfo>
-WebGLContext::GetActiveAttrib(WebGLProgram *prog, uint32_t index)
+WebGLContext::GetActiveAttrib(WebGLProgram* prog, uint32_t index)
 {
     if (IsContextLost())
         return nullptr;
 
     if (!ValidateObject("getActiveAttrib: program", prog))
         return nullptr;
 
     MakeContextCurrent();
@@ -933,17 +935,17 @@ WebGLContext::GenerateMipmap(GLenum rawT
     if (IsContextLost())
         return;
 
     if (!ValidateTextureTargetEnum(rawTarget, "generateMipmap"))
         return;
 
     const TexTarget target(rawTarget);
 
-    WebGLTexture *tex = activeBoundTextureForTarget(target);
+    WebGLTexture* tex = ActiveBoundTextureForTarget(target);
 
     if (!tex)
         return ErrorInvalidOperation("generateMipmap: No texture is bound to this target.");
 
     const TexImageTarget imageTarget = (target == LOCAL_GL_TEXTURE_2D)
                                                   ? LOCAL_GL_TEXTURE_2D
                                                   : LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X;
     if (!tex->IsMipmapRangeValid())
@@ -987,17 +989,17 @@ WebGLContext::GenerateMipmap(GLenum rawT
         gl->fGenerateMipmap(target.get());
         gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, tex->MinFilter().get());
     } else {
         gl->fGenerateMipmap(target.get());
     }
 }
 
 already_AddRefed<WebGLActiveInfo>
-WebGLContext::GetActiveUniform(WebGLProgram *prog, uint32_t index)
+WebGLContext::GetActiveUniform(WebGLProgram* prog, uint32_t index)
 {
     if (IsContextLost())
         return nullptr;
 
     if (!ValidateObject("getActiveUniform: program", prog))
         return nullptr;
 
     MakeContextCurrent();
@@ -1048,17 +1050,17 @@ WebGLContext::GetActiveUniform(WebGLProg
         reverseMappedName.AppendLiteral("[0]");
 
     nsRefPtr<WebGLActiveInfo> retActiveInfo =
         new WebGLActiveInfo(usize, utype, reverseMappedName);
     return retActiveInfo.forget();
 }
 
 void
-WebGLContext::GetAttachedShaders(WebGLProgram *prog,
+WebGLContext::GetAttachedShaders(WebGLProgram* prog,
                                  Nullable<nsTArray<nsRefPtr<WebGLShader>>>& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowNull("getAttachedShaders", prog))
         return;
@@ -1071,17 +1073,17 @@ WebGLContext::GetAttachedShaders(WebGLPr
     } else if (prog->AttachedShaders().Length() == 0) {
         retval.SetValue().TruncateLength(0);
     } else {
         retval.SetValue().AppendElements(prog->AttachedShaders());
     }
 }
 
 GLint
-WebGLContext::GetAttribLocation(WebGLProgram *prog, const nsAString& name)
+WebGLContext::GetAttribLocation(WebGLProgram* prog, const nsAString& name)
 {
     if (IsContextLost())
         return -1;
 
     if (!ValidateObject("getAttribLocation: program", prog))
         return -1;
 
     if (!ValidateGLSLVariableName(name, "getAttribLocation"))
@@ -1427,17 +1429,17 @@ WebGLContext::GetError()
     MakeContextCurrent();
     GetAndFlushUnderlyingGLErrors();
 
     err = GetAndClearError(&mUnderlyingGLError);
     return err;
 }
 
 JS::Value
-WebGLContext::GetProgramParameter(WebGLProgram *prog, GLenum pname)
+WebGLContext::GetProgramParameter(WebGLProgram* prog, GLenum pname)
 {
     if (IsContextLost())
         return JS::NullValue();
 
     if (!ValidateObjectAllowDeleted("getProgramParameter: program", prog))
         return JS::NullValue();
 
     GLuint progname = prog->GLName();
@@ -1483,28 +1485,28 @@ WebGLContext::GetProgramParameter(WebGLP
         default:
             ErrorInvalidEnumInfo("getProgramParameter: parameter", pname);
     }
 
     return JS::NullValue();
 }
 
 void
-WebGLContext::GetProgramInfoLog(WebGLProgram *prog, nsAString& retval)
+WebGLContext::GetProgramInfoLog(WebGLProgram* prog, nsAString& retval)
 {
     nsAutoCString s;
     GetProgramInfoLog(prog, s);
     if (s.IsVoid())
         retval.SetIsVoid(true);
     else
         CopyASCIItoUTF16(s, retval);
 }
 
 void
-WebGLContext::GetProgramInfoLog(WebGLProgram *prog, nsACString& retval)
+WebGLContext::GetProgramInfoLog(WebGLProgram* prog, nsACString& retval)
 {
     if (IsContextLost())
     {
         retval.SetIsVoid(true);
         return;
     }
 
     if (!ValidateObject("getProgramInfoLog: program", prog)) {
@@ -1535,33 +1537,33 @@ WebGLContext::GetProgramInfoLog(WebGLPro
     gl->fGetProgramInfoLog(progname, k, &k, (char*) retval.BeginWriting());
     retval.SetLength(k);
 }
 
 // here we have to support all pnames with both int and float params.
 // See this discussion:
 //  https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html
 void WebGLContext::TexParameter_base(GLenum rawTarget, GLenum pname,
-                                     GLint *intParamPtr,
-                                     GLfloat *floatParamPtr)
+                                     GLint* intParamPtr,
+                                     GLfloat* floatParamPtr)
 {
     MOZ_ASSERT(intParamPtr || floatParamPtr);
 
     if (IsContextLost())
         return;
 
     GLint intParam = intParamPtr ? *intParamPtr : GLint(*floatParamPtr);
     GLfloat floatParam = floatParamPtr ? *floatParamPtr : GLfloat(*intParamPtr);
 
     if (!ValidateTextureTargetEnum(rawTarget, "texParameter: target"))
         return;
 
     const TexTarget texTarget = TexTarget(rawTarget);
 
-    WebGLTexture *tex = activeBoundTextureForTarget(texTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTarget(texTarget);
     if (!tex)
         return ErrorInvalidOperation("texParameter: no texture is bound to this target");
 
     bool pnameAndParamAreIncompatible = false;
     bool paramValueInvalid = false;
 
     switch (pname) {
         case LOCAL_GL_TEXTURE_BASE_LEVEL:
@@ -1668,17 +1670,17 @@ WebGLContext::GetTexParameter(GLenum raw
 
     MakeContextCurrent();
 
     if (!ValidateTextureTargetEnum(rawTarget, "getTexParameter: target"))
         return JS::NullValue();
 
     const TexTarget target(rawTarget);
 
-    if (!activeBoundTextureForTarget(target)) {
+    if (!ActiveBoundTextureForTarget(target)) {
         ErrorInvalidOperation("getTexParameter: no texture bound");
         return JS::NullValue();
     }
 
     return GetTexParameterInternal(target, pname);
 }
 
 JS::Value
@@ -1707,18 +1709,18 @@ WebGLContext::GetTexParameterInternal(co
         default:
             ErrorInvalidEnumInfo("getTexParameter: parameter", pname);
     }
 
     return JS::NullValue();
 }
 
 JS::Value
-WebGLContext::GetUniform(JSContext* cx, WebGLProgram *prog,
-                         WebGLUniformLocation *location)
+WebGLContext::GetUniform(JSContext* cx, WebGLProgram* prog,
+                         WebGLUniformLocation* location)
 {
     if (IsContextLost())
         return JS::NullValue();
 
     if (!ValidateObject("getUniform: program", prog))
         return JS::NullValue();
 
     if (!ValidateObject("getUniform: location", location))
@@ -1844,17 +1846,17 @@ WebGLContext::GetUniform(JSContext* cx, 
         }
     }
 
     // Else preserving behavior, but I'm not sure this is correct per spec
     return JS::UndefinedValue();
 }
 
 already_AddRefed<WebGLUniformLocation>
-WebGLContext::GetUniformLocation(WebGLProgram *prog, const nsAString& name)
+WebGLContext::GetUniformLocation(WebGLProgram* prog, const nsAString& name)
 {
     if (IsContextLost())
         return nullptr;
 
     if (!ValidateObject("getUniformLocation: program", prog))
         return nullptr;
 
     if (!ValidateGLSLVariableName(name, "getUniformLocation"))
@@ -1900,69 +1902,70 @@ WebGLContext::Hint(GLenum target, GLenum
     if (!isValid)
         return ErrorInvalidEnum("hint: invalid hint");
 
     MakeContextCurrent();
     gl->fHint(target, mode);
 }
 
 bool
-WebGLContext::IsFramebuffer(WebGLFramebuffer *fb)
+WebGLContext::IsFramebuffer(WebGLFramebuffer* fb)
 {
     if (IsContextLost())
         return false;
 
     return ValidateObjectAllowDeleted("isFramebuffer", fb) &&
         !fb->IsDeleted() &&
         fb->HasEverBeenBound();
 }
 
 bool
-WebGLContext::IsProgram(WebGLProgram *prog)
+WebGLContext::IsProgram(WebGLProgram* prog)
 {
     if (IsContextLost())
         return false;
 
     return ValidateObjectAllowDeleted("isProgram", prog) && !prog->IsDeleted();
 }
 
 bool
-WebGLContext::IsRenderbuffer(WebGLRenderbuffer *rb)
+WebGLContext::IsRenderbuffer(WebGLRenderbuffer* rb)
 {
     if (IsContextLost())
         return false;
 
     return ValidateObjectAllowDeleted("isRenderBuffer", rb) &&
         !rb->IsDeleted() &&
         rb->HasEverBeenBound();
 }
 
 bool
-WebGLContext::IsShader(WebGLShader *shader)
+WebGLContext::IsShader(WebGLShader* shader)
 {
     if (IsContextLost())
         return false;
 
     return ValidateObjectAllowDeleted("isShader", shader) &&
         !shader->IsDeleted();
 }
 
 bool
-WebGLContext::IsTexture(WebGLTexture *tex)
+WebGLContext::IsTexture(WebGLTexture* tex)
 {
     if (IsContextLost())
         return false;
 
     return ValidateObjectAllowDeleted("isTexture", tex) &&
         !tex->IsDeleted() &&
         tex->HasEverBeenBound();
 }
 
 // Try to bind an attribute that is an array to location 0:
-bool WebGLContext::BindArrayAttribToLocation0(WebGLProgram *program)
+bool
+WebGLContext::BindArrayAttribToLocation0(WebGLProgram* program)
 {
     if (mBoundVertexArray->IsAttribArrayEnabled(0)) {
         return false;
     }
 
     GLint leastArrayLocation = -1;
 
     std::map<GLint, nsCString>::iterator itr;
@@ -2001,17 +2004,17 @@ LinkAndUpdateProgram(GLContext* gl, WebG
 
     if (!prog->UpdateInfo())
         return;
 
     prog->SetLinkStatus(true);
 }
 
 void
-WebGLContext::LinkProgram(WebGLProgram *program)
+WebGLContext::LinkProgram(WebGLProgram* program)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObject("linkProgram", program))
         return;
 
     InvalidateBufferFetching(); // we do it early in this function
@@ -2072,17 +2075,17 @@ WebGLContext::LinkProgram(WebGLProgram *
 
             for (size_t i = 0; i < program->AttachedShaders().Length(); i++) {
 
                 WebGLShader* shader = program->AttachedShaders()[i];
 
                 if (shader->CompileStatus())
                     continue;
 
-                const char *shaderTypeName = nullptr;
+                const char* shaderTypeName = nullptr;
                 if (shader->ShaderType() == LOCAL_GL_VERTEX_SHADER) {
                     shaderTypeName = "vertex";
                 } else if (shader->ShaderType() == LOCAL_GL_FRAGMENT_SHADER) {
                     shaderTypeName = "fragment";
                 } else {
                     // should have been validated earlier
                     MOZ_ASSERT(false);
                     shaderTypeName = "<unknown>";
@@ -2651,17 +2654,18 @@ WebGLContext::StencilOpSeparate(GLenum f
         return;
 
     MakeContextCurrent();
     gl->fStencilOpSeparate(face, sfail, dpfail, dppass);
 }
 
 nsresult
 WebGLContext::SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res,
-                                                     RefPtr<DataSourceSurface>& imageOut, WebGLTexelFormat *format)
+                                                     RefPtr<DataSourceSurface>& imageOut,
+                                                     WebGLTexelFormat* format)
 {
    *format = WebGLTexelFormat::None;
 
     if (!res.mSourceSurface)
         return NS_OK;
     RefPtr<DataSourceSurface> data = res.mSourceSurface->GetDataSurface();
     if (!data) {
         // SurfaceFromElement lied!
@@ -3053,17 +3057,17 @@ WebGLContext::UniformMatrix4fv_base(WebG
 
     MakeContextCurrent();
     gl->fUniformMatrix4fv(rawLoc, numElementsToUpload, false, data);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 void
-WebGLContext::UseProgram(WebGLProgram *prog)
+WebGLContext::UseProgram(WebGLProgram* prog)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowNull("useProgram", prog))
         return;
 
     MakeContextCurrent();
@@ -3076,17 +3080,17 @@ WebGLContext::UseProgram(WebGLProgram *p
         return ErrorInvalidOperation("useProgram: program was not linked successfully");
 
     gl->fUseProgram(progname);
 
     mCurrentProgram = prog;
 }
 
 void
-WebGLContext::ValidateProgram(WebGLProgram *prog)
+WebGLContext::ValidateProgram(WebGLProgram* prog)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObject("validateProgram", prog))
         return;
 
     MakeContextCurrent();
@@ -3140,17 +3144,17 @@ WebGLContext::Viewport(GLint x, GLint y,
 
     mViewportX = x;
     mViewportY = y;
     mViewportWidth = width;
     mViewportHeight = height;
 }
 
 void
-WebGLContext::CompileShader(WebGLShader *shader)
+WebGLContext::CompileShader(WebGLShader* shader)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObject("compileShader", shader))
         return;
 
     GLuint shadername = shader->GLName();
@@ -3226,17 +3230,17 @@ WebGLContext::CompileShader(WebGLShader 
 
     if (gl->WorkAroundDriverBugs()) {
         const uint32_t maxSourceLength = 0x3ffff;
         if (sourceCString.Length() > maxSourceLength)
             return ErrorInvalidValue("compileShader: source has more than %d characters",
                                      maxSourceLength);
     }
 
-    const char *s = sourceCString.get();
+    const char* s = sourceCString.get();
 
 #define WEBGL2_BYPASS_ANGLE
 #ifdef WEBGL2_BYPASS_ANGLE
     /*
      * The bypass don't bring a full support for GLSL ES 3.0, but the main purpose
      * is to natively bring gl_InstanceID (to do instanced rendering) and gl_FragData
      *
      * To remove the bypass code, just comment #define WEBGL2_BYPASS_ANGLE above
@@ -3246,34 +3250,34 @@ WebGLContext::CompileShader(WebGLShader 
      *      #version proto-200
      *
      * In this case, byPassANGLE == true and here is what we do :
      *  We create two shader source code:
      *    - one for the driver, that enable GL_EXT_gpu_shader4
      *    - one for the angle compilor, to get informations about vertex attributes
      *      and uniforms
      */
-    static const char *bypassPrefixSearch = "#version proto-200";
-    static const char *bypassANGLEPrefix[2] = {"precision mediump float;\n"
+    static const char* bypassPrefixSearch = "#version proto-200";
+    static const char* bypassANGLEPrefix[2] = {"precision mediump float;\n"
                                                "#define gl_VertexID 0\n"
                                                "#define gl_InstanceID 0\n",
 
                                                "precision mediump float;\n"
                                                "#extension GL_EXT_draw_buffers : enable\n"
                                                "#define gl_PrimitiveID 0\n"};
 
     const bool bypassANGLE = IsWebGL2() && (strstr(s, bypassPrefixSearch) != 0);
 
-    const char *angleShaderCode = s;
+    const char* angleShaderCode = s;
     nsTArray<char> bypassANGLEShaderCode;
     nsTArray<char> bypassDriverShaderCode;
 
     if (bypassANGLE) {
         const int bypassStage = (shader->ShaderType() == LOCAL_GL_FRAGMENT_SHADER) ? 1 : 0;
-        const char *originalShader = strstr(s, bypassPrefixSearch) + strlen(bypassPrefixSearch);
+        const char* originalShader = strstr(s, bypassPrefixSearch) + strlen(bypassPrefixSearch);
         int originalShaderSize = strlen(s) - (originalShader - s);
         int bypassShaderCodeSize = originalShaderSize + 4096 + 1;
 
         bypassANGLEShaderCode.SetLength(bypassShaderCodeSize);
         strcpy(bypassANGLEShaderCode.Elements(), bypassANGLEPrefix[bypassStage]);
         strcat(bypassANGLEShaderCode.Elements(), originalShader);
 
         bypassDriverShaderCode.SetLength(bypassShaderCodeSize);
@@ -3423,17 +3427,17 @@ WebGLContext::CompileShader(WebGLShader 
     size_t len = lenWithNull - 1;
 
     nsAutoCString translatedSrc;
     translatedSrc.SetLength(len); // Allocates len+1, for the null-term.
     ShGetObjectCode(compiler, translatedSrc.BeginWriting());
 
     CopyASCIItoUTF16(translatedSrc, shader->mTranslatedSource);
 
-    const char *ts = translatedSrc.get();
+    const char* ts = translatedSrc.get();
 
 #ifdef WEBGL2_BYPASS_ANGLE
     if (bypassANGLE) {
         const char* driverShaderCode = bypassDriverShaderCode.Elements();
         gl->fShaderSource(shadername, 1, (const GLchar**) &driverShaderCode, nullptr);
     } else {
         gl->fShaderSource(shadername, 1, &ts, nullptr);
     }
@@ -3485,17 +3489,17 @@ WebGLContext::CompressedTexImage2D(GLenu
 
     if (!ValidateCompTexImageSize(level, internalformat, 0, 0, width, height, width, height, func, dims))
     {
         return;
     }
 
     const TexImageTarget texImageTarget(rawTexImgTarget);
 
-    WebGLTexture* tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
     MOZ_ASSERT(tex);
     if (tex->IsImmutable()) {
         return ErrorInvalidOperation(
             "compressedTexImage2D: disallowed because the texture bound to "
             "this target has already been made immutable by texStorage2D");
     }
 
     MakeContextCurrent();
@@ -3527,17 +3531,17 @@ WebGLContext::CompressedTexSubImage2D(GL
                           0, LOCAL_GL_NONE, LOCAL_GL_NONE,
                           func, dims))
     {
         return;
     }
 
     const TexImageTarget texImageTarget(rawTexImgTarget);
 
-    WebGLTexture *tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
     MOZ_ASSERT(tex);
     WebGLTexture::ImageInfo& levelInfo = tex->ImageInfoAt(texImageTarget, level);
 
     if (internalformat != levelInfo.EffectiveInternalFormat()) {
         return ErrorInvalidOperation("compressedTexImage2D: internalformat does not match the existing image");
     }
 
     view.ComputeLengthAndData();
@@ -3567,17 +3571,17 @@ WebGLContext::CompressedTexSubImage2D(GL
         }
     }
 
     MakeContextCurrent();
     gl->fCompressedTexSubImage2D(texImageTarget.get(), level, xoffset, yoffset, width, height, internalformat, byteLength, view.Data());
 }
 
 JS::Value
-WebGLContext::GetShaderParameter(WebGLShader *shader, GLenum pname)
+WebGLContext::GetShaderParameter(WebGLShader* shader, GLenum pname)
 {
     if (IsContextLost())
         return JS::NullValue();
 
     if (!ValidateObject("getShaderParameter: shader", shader))
         return JS::NullValue();
 
     GLuint shadername = shader->GLName();
@@ -3605,28 +3609,28 @@ WebGLContext::GetShaderParameter(WebGLSh
         default:
             ErrorInvalidEnumInfo("getShaderParameter: parameter", pname);
     }
 
     return JS::NullValue();
 }
 
 void
-WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsAString& retval)
+WebGLContext::GetShaderInfoLog(WebGLShader* shader, nsAString& retval)
 {
     nsAutoCString s;
     GetShaderInfoLog(shader, s);
     if (s.IsVoid())
         retval.SetIsVoid(true);
     else
         CopyASCIItoUTF16(s, retval);
 }
 
 void
-WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsACString& retval)
+WebGLContext::GetShaderInfoLog(WebGLShader* shader, nsACString& retval)
 {
     if (IsContextLost())
     {
         retval.SetIsVoid(true);
         return;
     }
 
     if (!ValidateObject("getShaderInfoLog: shader", shader))
@@ -3701,31 +3705,31 @@ WebGLContext::GetShaderPrecisionFormat(G
     }
 
     nsRefPtr<WebGLShaderPrecisionFormat> retShaderPrecisionFormat
         = new WebGLShaderPrecisionFormat(this, range[0], range[1], precision);
     return retShaderPrecisionFormat.forget();
 }
 
 void
-WebGLContext::GetShaderSource(WebGLShader *shader, nsAString& retval)
+WebGLContext::GetShaderSource(WebGLShader* shader, nsAString& retval)
 {
     if (IsContextLost()) {
         retval.SetIsVoid(true);
         return;
     }
 
     if (!ValidateObject("getShaderSource: shader", shader))
         return;
 
     retval.Assign(shader->Source());
 }
 
 void
-WebGLContext::ShaderSource(WebGLShader *shader, const nsAString& source)
+WebGLContext::ShaderSource(WebGLShader* shader, const nsAString& source)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObject("shaderSource: shader", shader))
         return;
 
     // We're storing an actual instance of StripComments because, if we don't, the
@@ -3737,17 +3741,17 @@ WebGLContext::ShaderSource(WebGLShader *
         return;
 
     shader->SetSource(source);
 
     shader->SetNeedsTranslation();
 }
 
 void
-WebGLContext::GetShaderTranslatedSource(WebGLShader *shader, nsAString& retval)
+WebGLContext::GetShaderTranslatedSource(WebGLShader* shader, nsAString& retval)
 {
     if (IsContextLost()) {
         retval.SetIsVoid(true);
         return;
     }
 
     if (!ValidateObject("getShaderTranslatedSource: shader", shader))
         return;
@@ -3758,20 +3762,20 @@ WebGLContext::GetShaderTranslatedSource(
 GLenum WebGLContext::CheckedTexImage2D(TexImageTarget texImageTarget,
                                        GLint level,
                                        TexInternalFormat internalformat,
                                        GLsizei width,
                                        GLsizei height,
                                        GLint border,
                                        TexFormat format,
                                        TexType type,
-                                       const GLvoid *data)
+                                       const GLvoid* data)
 {
-    WebGLTexture *tex = activeBoundTextureForTexImageTarget(texImageTarget);
-    MOZ_ASSERT(tex != nullptr, "no texture bound");
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
+    MOZ_ASSERT(tex, "no texture bound");
 
     TexInternalFormat effectiveInternalFormat =
         EffectiveInternalFormatFromInternalFormatAndType(internalformat, type);
     bool sizeMayChange = true;
 
     if (tex->HasImageInfoAt(texImageTarget, level)) {
         const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level);
         sizeMayChange = width != imageInfo.Width() ||
@@ -3876,17 +3880,17 @@ WebGLContext::TexImage2D_base(TexImageTa
         return ErrorInvalidOperation("texImage2D: integer overflow computing the needed buffer size");
 
     uint32_t bytesNeeded = checked_neededByteLength.value();
 
     if (byteLength && byteLength < bytesNeeded)
         return ErrorInvalidOperation("texImage2D: not enough data for operation (need %d, have %d)",
                                  bytesNeeded, byteLength);
 
-    WebGLTexture *tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
 
     if (!tex)
         return ErrorInvalidOperation("texImage2D: no texture is bound to this target");
 
     if (tex->IsImmutable()) {
         return ErrorInvalidOperation(
             "texImage2D: disallowed because the texture "
             "bound to this target has already been made immutable by texStorage2D");
@@ -4026,28 +4030,25 @@ WebGLContext::TexSubImage2D_base(TexImag
                                  GLenum format, GLenum type,
                                  void* data, uint32_t byteLength,
                                  js::Scalar::Type jsArrayType,
                                  WebGLTexelFormat srcFormat, bool srcPremultiplied)
 {
     const WebGLTexImageFunc func = WebGLTexImageFunc::TexSubImage;
     const WebGLTexDimensions dims = WebGLTexDimensions::Tex2D;
 
-    if (type == LOCAL_GL_HALF_FLOAT_OES) {
+    if (type == LOCAL_GL_HALF_FLOAT_OES)
         type = LOCAL_GL_HALF_FLOAT;
-    }
-
-    WebGLTexture *tex = activeBoundTextureForTexImageTarget(texImageTarget);
-    if (!tex) {
+
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
+    if (!tex)
         return ErrorInvalidOperation("texSubImage2D: no texture bound on active texture unit");
-    }
-
-    if (!tex->HasImageInfoAt(texImageTarget, level)) {
+
+    if (!tex->HasImageInfoAt(texImageTarget, level))
         return ErrorInvalidOperation("texSubImage2D: no previously defined texture image");
-    }
 
     const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level);
     const TexInternalFormat existingEffectiveInternalFormat = imageInfo.EffectiveInternalFormat();
 
     if (!ValidateTexImage(texImageTarget, level,
                           existingEffectiveInternalFormat.get(),
                           xoffset, yoffset, 0,
                           width, height, 0,
@@ -4229,17 +4230,17 @@ WebGLContext::RestoreContext()
 
     if (!mAllowContextRestore)
         return ErrorInvalidOperation("restoreContext: Context cannot be restored.");
 
     ForceRestoreContext();
 }
 
 bool
-BaseTypeAndSizeFromUniformType(GLenum uType, GLenum *baseType, GLint *unitSize)
+BaseTypeAndSizeFromUniformType(GLenum uType, GLenum* baseType, GLint* unitSize)
 {
     switch (uType) {
         case LOCAL_GL_INT:
         case LOCAL_GL_INT_VEC2:
         case LOCAL_GL_INT_VEC3:
         case LOCAL_GL_INT_VEC4:
         case LOCAL_GL_SAMPLER_2D:
         case LOCAL_GL_SAMPLER_CUBE:
--- a/dom/canvas/WebGLContextLossHandler.cpp
+++ b/dom/canvas/WebGLContextLossHandler.cpp
@@ -36,19 +36,18 @@ WebGLContextLossHandler::StartTimer(unsi
     this->AddRef();
 
     mTimer->InitWithFuncCallback(StaticTimerCallback,
                                  static_cast<void*>(this),
                                  delayMS,
                                  nsITimer::TYPE_ONE_SHOT);
 }
 
-/* static */ void
-WebGLContextLossHandler::StaticTimerCallback(nsITimer*,
-                                             void* voidHandler)
+/*static*/ void
+WebGLContextLossHandler::StaticTimerCallback(nsITimer*, void* voidHandler)
 {
     typedef WebGLContextLossHandler T;
     T* handler = static_cast<T*>(voidHandler);
 
     handler->TimerCallback();
 
     // Release the AddRef from StartTimer.
     handler->Release();
--- a/dom/canvas/WebGLContextLossHandler.h
+++ b/dom/canvas/WebGLContextLossHandler.h
@@ -24,17 +24,17 @@ class WebGLContextLossHandler
     bool mIsTimerRunning;
     bool mShouldRunTimerAgain;
     bool mIsDisabled;
     DebugOnly<nsIThread*> mThread;
 
 public:
     NS_INLINE_DECL_REFCOUNTING(WebGLContextLossHandler)
 
-    explicit WebGLContextLossHandler(WebGLContext* aWebgl);
+    explicit WebGLContextLossHandler(WebGLContext* webgl);
 
     void RunTimer();
     void DisableTimer();
 
 protected:
     ~WebGLContextLossHandler();
 
     void StartTimer(unsigned long delayMS);
--- a/dom/canvas/WebGLContextNotSupported.cpp
+++ b/dom/canvas/WebGLContextNotSupported.cpp
@@ -1,10 +1,10 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIDOMWebGLRenderingContext.h"
 
-#define DUMMY(func,rtype)  nsresult func (rtype ** aResult) { return NS_ERROR_FAILURE; }
+#define DUMMY(func,rtype) nsresult func (rtype **) { return NS_ERROR_FAILURE; }
 
 DUMMY(NS_NewCanvasRenderingContextWebGL, nsIDOMWebGLRenderingContext)
--- a/dom/canvas/WebGLContextReporter.cpp
+++ b/dom/canvas/WebGLContextReporter.cpp
@@ -6,26 +6,26 @@
 #include "WebGLContext.h"
 #include "WebGLMemoryTracker.h"
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS(WebGLObserver, nsIObserver)
 
 NS_IMETHODIMP
-WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
-                                   nsISupports* aData, bool aAnonymize)
+WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* handleReport,
+                                   nsISupports* data, bool)
 {
-#define REPORT(_path, _kind, _units, _amount, _desc)                          \
-    do {                                                                      \
-      nsresult rv;                                                            \
-      rv = aHandleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
-                                   _kind, _units, _amount,                    \
-                                   NS_LITERAL_CSTRING(_desc), aData);         \
-      NS_ENSURE_SUCCESS(rv, rv);                                              \
+#define REPORT(_path, _kind, _units, _amount, _desc)                         \
+    do {                                                                     \
+      nsresult rv;                                                           \
+      rv = handleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
+                                   _kind, _units, _amount,                   \
+                                   NS_LITERAL_CSTRING(_desc), data);         \
+      NS_ENSURE_SUCCESS(rv, rv);                                             \
     } while (0)
 
     REPORT("webgl-texture-memory",
            KIND_OTHER, UNITS_BYTES, GetTextureMemoryUsed(),
            "Memory used by WebGL textures.The OpenGL"
            " implementation is free to store these textures in either video"
            " memory or main memory. This measurement is only a lower bound,"
            " actual memory usage may be higher for example if the storage"
@@ -84,17 +84,18 @@ WebGLMemoryTracker::CollectReports(nsIHa
 
     return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter)
 
 StaticRefPtr<WebGLMemoryTracker> WebGLMemoryTracker::sUniqueInstance;
 
-WebGLMemoryTracker* WebGLMemoryTracker::UniqueInstance()
+WebGLMemoryTracker*
+WebGLMemoryTracker::UniqueInstance()
 {
     if (!sUniqueInstance) {
         sUniqueInstance = new WebGLMemoryTracker;
         sUniqueInstance->InitMemoryReporter();
     }
     return sUniqueInstance;
 }
 
@@ -111,39 +112,41 @@ WebGLMemoryTracker::InitMemoryReporter()
 WebGLMemoryTracker::~WebGLMemoryTracker()
 {
     UnregisterWeakMemoryReporter(this);
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(WebGLBufferMallocSizeOf)
 
 int64_t
-WebGLMemoryTracker::GetBufferCacheMemoryUsed() {
-    const ContextsArrayType & contexts = Contexts();
+WebGLMemoryTracker::GetBufferCacheMemoryUsed()
+{
+    const ContextsArrayType& contexts = Contexts();
     int64_t result = 0;
     for(size_t i = 0; i < contexts.Length(); ++i) {
-        for (const WebGLBuffer *buffer = contexts[i]->mBuffers.getFirst();
+        for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
              buffer;
              buffer = buffer->getNext())
         {
             if (buffer->Target() == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
                 result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf);
         }
     }
     return result;
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf)
 
 int64_t
-WebGLMemoryTracker::GetShaderSize() {
-    const ContextsArrayType & contexts = Contexts();
+WebGLMemoryTracker::GetShaderSize()
+{
+    const ContextsArrayType& contexts = Contexts();
     int64_t result = 0;
     for(size_t i = 0; i < contexts.Length(); ++i) {
-        for (const WebGLShader *shader = contexts[i]->mShaders.getFirst();
+        for (const WebGLShader* shader = contexts[i]->mShaders.getFirst();
              shader;
              shader = shader->getNext())
         {
             result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf);
         }
     }
     return result;
 }
--- a/dom/canvas/WebGLContextUtils.cpp
+++ b/dom/canvas/WebGLContextUtils.cpp
@@ -1,37 +1,35 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 
-#include <stdarg.h>
-
 #include "GLContext.h"
 #include "jsapi.h"
+#include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/Preferences.h"
 #include "nsIDOMDataContainerEvent.h"
 #include "nsIDOMEvent.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIVariant.h"
 #include "nsPrintfCString.h"
 #include "nsServiceManagerUtils.h"
 #include "prprf.h"
+#include <stdarg.h>
 #include "WebGLBuffer.h"
 #include "WebGLExtensions.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLProgram.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
 #include "WebGLContextUtils.h"
 
-#include "mozilla/dom/ScriptSettings.h"
-
 namespace mozilla {
 
 using namespace gl;
 
 bool
 IsGLDepthFormat(TexInternalFormat internalformat)
 {
     TexInternalFormat unsizedformat = UnsizedInternalFormatFromInternalFormat(internalformat);
@@ -78,43 +76,43 @@ TexImageTargetToTexTarget(TexImageTarget
 }
 
 GLComponents::GLComponents(TexInternalFormat internalformat)
 {
     TexInternalFormat unsizedformat = UnsizedInternalFormatFromInternalFormat(internalformat);
     mComponents = 0;
 
     switch (unsizedformat.get()) {
-        case LOCAL_GL_RGBA:
-        case LOCAL_GL_RGBA4:
-        case LOCAL_GL_RGBA8:
-        case LOCAL_GL_RGB5_A1:
-        // Luminance + Alpha can be converted
-        // to and from RGBA
-        case LOCAL_GL_LUMINANCE_ALPHA:
-            mComponents |= Components::Alpha;
-        // Drops through
-        case LOCAL_GL_RGB:
-        case LOCAL_GL_RGB565:
-        // Luminance can be converted to and from RGB
-        case LOCAL_GL_LUMINANCE:
-            mComponents |= Components::Red | Components::Green | Components::Blue;
-            break;
-        case LOCAL_GL_ALPHA:
-            mComponents |= Components::Alpha;
-            break;
-        case LOCAL_GL_DEPTH_COMPONENT:
-            mComponents |= Components::Depth;
-            break;
-        case LOCAL_GL_DEPTH_STENCIL:
-            mComponents |= Components::Stencil;
-            break;
-        default:
-            MOZ_ASSERT(false, "Unhandled case - GLComponents");
-            break;
+    case LOCAL_GL_RGBA:
+    case LOCAL_GL_RGBA4:
+    case LOCAL_GL_RGBA8:
+    case LOCAL_GL_RGB5_A1:
+    // Luminance + Alpha can be converted
+    // to and from RGBA
+    case LOCAL_GL_LUMINANCE_ALPHA:
+        mComponents |= Components::Alpha;
+    // Drops through
+    case LOCAL_GL_RGB:
+    case LOCAL_GL_RGB565:
+    // Luminance can be converted to and from RGB
+    case LOCAL_GL_LUMINANCE:
+        mComponents |= Components::Red | Components::Green | Components::Blue;
+        break;
+    case LOCAL_GL_ALPHA:
+        mComponents |= Components::Alpha;
+        break;
+    case LOCAL_GL_DEPTH_COMPONENT:
+        mComponents |= Components::Depth;
+        break;
+    case LOCAL_GL_DEPTH_STENCIL:
+        mComponents |= Components::Stencil;
+        break;
+    default:
+        MOZ_ASSERT(false, "Unhandled case - GLComponents");
+        break;
     }
 }
 
 bool
 GLComponents::IsSubsetOf(const GLComponents& other) const
 {
     return (mComponents | other.mComponents) == other.mComponents;
 }
@@ -168,18 +166,18 @@ EffectiveInternalFormatFromUnsizedIntern
 #include "WebGLInternalFormatsTable.h"
 
     // If we're here, that means that type was incompatible with the given internalformat.
     return LOCAL_GL_NONE;
 }
 
 void
 UnsizedInternalFormatAndTypeFromEffectiveInternalFormat(TexInternalFormat effectiveinternalformat,
-                                                        TexInternalFormat* out_internalformat,
-                                                        TexType* out_type)
+                                                        TexInternalFormat* const out_internalformat,
+                                                        TexType* const out_type)
 {
     MOZ_ASSERT(TypeFromInternalFormat(effectiveinternalformat) != LOCAL_GL_NONE);
 
     MOZ_ASSERT(out_internalformat);
     MOZ_ASSERT(out_type);
 
     GLenum internalformat = LOCAL_GL_NONE;
     GLenum type = LOCAL_GL_NONE;
@@ -202,67 +200,66 @@ UnsizedInternalFormatAndTypeFromEffectiv
     *out_type = type;
 }
 
 TexInternalFormat
 EffectiveInternalFormatFromInternalFormatAndType(TexInternalFormat internalformat,
                                                  TexType type)
 {
     TexType typeOfInternalFormat = TypeFromInternalFormat(internalformat);
-    if (typeOfInternalFormat == LOCAL_GL_NONE) {
+    if (typeOfInternalFormat == LOCAL_GL_NONE)
         return EffectiveInternalFormatFromUnsizedInternalFormatAndType(internalformat, type);
-    } else if (typeOfInternalFormat == type) {
+
+    if (typeOfInternalFormat == type)
         return internalformat;
-    } else {
-        return LOCAL_GL_NONE;
-    }
+
+    return LOCAL_GL_NONE;
 }
 
 /**
  * Convert effective internalformat into GL function parameters
  * valid for underlying driver.
  */
 void
 DriverFormatsFromEffectiveInternalFormat(gl::GLContext* gl,
                                          TexInternalFormat effectiveinternalformat,
-                                         GLenum* out_driverInternalFormat,
-                                         GLenum* out_driverFormat,
-                                         GLenum* out_driverType)
+                                         GLenum* const out_driverInternalFormat,
+                                         GLenum* const out_driverFormat,
+                                         GLenum* const out_driverType)
 {
     MOZ_ASSERT(out_driverInternalFormat);
     MOZ_ASSERT(out_driverFormat);
     MOZ_ASSERT(out_driverType);
 
     TexInternalFormat unsizedinternalformat = LOCAL_GL_NONE;
     TexType type = LOCAL_GL_NONE;
 
     UnsizedInternalFormatAndTypeFromEffectiveInternalFormat(effectiveinternalformat,
-                                                            &unsizedinternalformat, &type);
+                                                            &unsizedinternalformat,
+                                                            &type);
 
     // driverType: almost always the generic type that we just got, except on ES
     // we must replace HALF_FLOAT by HALF_FLOAT_OES
     GLenum driverType = type.get();
-    if (gl->IsGLES() && type == LOCAL_GL_HALF_FLOAT) {
+    if (gl->IsGLES() && type == LOCAL_GL_HALF_FLOAT)
         driverType = LOCAL_GL_HALF_FLOAT_OES;
-    }
 
     // driverFormat: always just the unsized internalformat that we just got
     GLenum driverFormat = unsizedinternalformat.get();
 
     // driverInternalFormat: almost always the same as driverFormat, but on desktop GL,
     // in some cases we must pass a different value. On ES, they are equal by definition
     // as it is an error to pass internalformat!=format.
     GLenum driverInternalFormat = driverFormat;
     if (!gl->IsGLES()) {
         // Cases where desktop OpenGL requires a tweak to 'format'
-        if (driverFormat == LOCAL_GL_SRGB) {
+        if (driverFormat == LOCAL_GL_SRGB)
             driverFormat = LOCAL_GL_RGB;
-        } else if (driverFormat == LOCAL_GL_SRGB_ALPHA) {
+        else if (driverFormat == LOCAL_GL_SRGB_ALPHA)
             driverFormat = LOCAL_GL_RGBA;
-        }
 
         // WebGL2's new formats are not legal values for internalformat,
         // as using unsized internalformat is deprecated.
         if (driverFormat == LOCAL_GL_RED ||
             driverFormat == LOCAL_GL_RG ||
             driverFormat == LOCAL_GL_RED_INTEGER ||
             driverFormat == LOCAL_GL_RG_INTEGER ||
             driverFormat == LOCAL_GL_RGB_INTEGER ||
@@ -400,73 +397,73 @@ GetBitsPerTexel(TexInternalFormat effect
 
     default:
         MOZ_ASSERT(false, "Unhandled format");
         return 0;
     }
 }
 
 void
-WebGLContext::GenerateWarning(const char *fmt, ...)
+WebGLContext::GenerateWarning(const char* fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
 
     GenerateWarning(fmt, ap);
 
     va_end(ap);
 }
 
 void
-WebGLContext::GenerateWarning(const char *fmt, va_list ap)
+WebGLContext::GenerateWarning(const char* fmt, va_list ap)
 {
     if (!ShouldGenerateWarnings())
         return;
 
     mAlreadyGeneratedWarnings++;
 
     char buf[1024];
     PR_vsnprintf(buf, 1024, fmt, ap);
 
     // no need to print to stderr, as JS_ReportWarning takes care of this for us.
 
     AutoJSContext cx;
     JS_ReportWarning(cx, "WebGL: %s", buf);
     if (!ShouldGenerateWarnings()) {
         JS_ReportWarning(cx,
-            "WebGL: No further warnings will be reported for this WebGL context "
-            "(already reported %d warnings)", mAlreadyGeneratedWarnings);
+                         "WebGL: No further warnings will be reported for this"
+                         " WebGL context. (already reported %d warnings)",
+                         mAlreadyGeneratedWarnings);
     }
 }
 
 bool
 WebGLContext::ShouldGenerateWarnings() const
 {
-    if (mMaxWarnings == -1) {
+    if (mMaxWarnings == -1)
         return true;
-    }
 
     return mAlreadyGeneratedWarnings < mMaxWarnings;
 }
 
 CheckedUint32
-WebGLContext::GetImageSize(GLsizei height,
-                           GLsizei width,
-                           GLsizei depth,
-                           uint32_t pixelSize,
-                           uint32_t packOrUnpackAlignment)
+WebGLContext::GetImageSize(GLsizei height, GLsizei width, GLsizei depth,
+                           uint32_t pixelSize, uint32_t packOrUnpackAlignment)
 {
     CheckedUint32 checked_plainRowSize = CheckedUint32(width) * pixelSize;
 
     // alignedRowSize = row size rounded up to next multiple of packAlignment
     CheckedUint32 checked_alignedRowSize = RoundedToNextMultipleOf(checked_plainRowSize, packOrUnpackAlignment);
 
     // if height is 0, we don't need any memory to store this; without this check, we'll get an overflow
-    CheckedUint32 checked_2dImageSize
-        = height <= 0 ? 0 : (height-1) * checked_alignedRowSize + checked_plainRowSize;
+    CheckedUint32 checked_2dImageSize = 0;
+    if (height >= 1) {
+        checked_2dImageSize = (height-1) * checked_alignedRowSize +
+                              checked_plainRowSize;
+    }
 
     // FIXME - we should honor UNPACK_IMAGE_HEIGHT
     CheckedUint32 checked_imageSize = checked_2dImageSize * depth;
     return checked_imageSize;
 }
 
 void
 WebGLContext::SynthesizeGLError(GLenum err)
@@ -477,109 +474,109 @@ WebGLContext::SynthesizeGLError(GLenum e
      * We're signing up as a distributed implementation here, with
      * separate flags for WebGL and the underlying GLContext.
      */
     if (!mWebGLError)
         mWebGLError = err;
 }
 
 void
-WebGLContext::SynthesizeGLError(GLenum err, const char *fmt, ...)
+WebGLContext::SynthesizeGLError(GLenum err, const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(err);
 }
 
 void
-WebGLContext::ErrorInvalidEnum(const char *fmt, ...)
+WebGLContext::ErrorInvalidEnum(const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_INVALID_ENUM);
 }
 
 void
-WebGLContext::ErrorInvalidEnumInfo(const char *info, GLenum enumvalue)
+WebGLContext::ErrorInvalidEnumInfo(const char* info, GLenum enumvalue)
 {
     nsCString name;
     EnumName(enumvalue, &name);
 
     return ErrorInvalidEnum("%s: invalid enum value %s", info, name.get());
 }
 
 void
-WebGLContext::ErrorInvalidOperation(const char *fmt, ...)
+WebGLContext::ErrorInvalidOperation(const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_INVALID_OPERATION);
 }
 
 void
-WebGLContext::ErrorInvalidValue(const char *fmt, ...)
+WebGLContext::ErrorInvalidValue(const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_INVALID_VALUE);
 }
 
 void
-WebGLContext::ErrorInvalidFramebufferOperation(const char *fmt, ...)
+WebGLContext::ErrorInvalidFramebufferOperation(const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION);
 }
 
 void
-WebGLContext::ErrorOutOfMemory(const char *fmt, ...)
+WebGLContext::ErrorOutOfMemory(const char* fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_OUT_OF_MEMORY);
 }
 
-const char *
+const char*
 WebGLContext::ErrorName(GLenum error)
 {
     switch(error) {
-        case LOCAL_GL_INVALID_ENUM:
-            return "INVALID_ENUM";
-        case LOCAL_GL_INVALID_OPERATION:
-            return "INVALID_OPERATION";
-        case LOCAL_GL_INVALID_VALUE:
-            return "INVALID_VALUE";
-        case LOCAL_GL_OUT_OF_MEMORY:
-            return "OUT_OF_MEMORY";
-        case LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION:
-            return "INVALID_FRAMEBUFFER_OPERATION";
-        case LOCAL_GL_NO_ERROR:
-            return "NO_ERROR";
-        default:
-            MOZ_ASSERT(false);
-            return "[unknown WebGL error!]";
+    case LOCAL_GL_INVALID_ENUM:
+        return "INVALID_ENUM";
+    case LOCAL_GL_INVALID_OPERATION:
+        return "INVALID_OPERATION";
+    case LOCAL_GL_INVALID_VALUE:
+        return "INVALID_VALUE";
+    case LOCAL_GL_OUT_OF_MEMORY:
+        return "OUT_OF_MEMORY";
+    case LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION:
+        return "INVALID_FRAMEBUFFER_OPERATION";
+    case LOCAL_GL_NO_ERROR:
+        return "NO_ERROR";
+    default:
+        MOZ_ASSERT(false);
+        return "[unknown WebGL error]";
     }
 }
 
 // This version is 'fallible' and will return NULL if glenum is not recognized.
 const char*
 WebGLContext::EnumName(GLenum glenum)
 {
     switch (glenum) {
@@ -914,41 +911,41 @@ WebGLContext::EnumName(GLenum glenum, ns
         *out_name = enumAsHex;
     }
 }
 
 bool
 WebGLContext::IsCompressedTextureFormat(GLenum format)
 {
     switch (format) {
-        case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
-        case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
-        case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
-        case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
-        case LOCAL_GL_ATC_RGB:
-        case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
-        case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
-        case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
-        case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
-        case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
-        case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
-        case LOCAL_GL_ETC1_RGB8_OES:
-        case LOCAL_GL_COMPRESSED_R11_EAC:
-        case LOCAL_GL_COMPRESSED_SIGNED_R11_EAC:
-        case LOCAL_GL_COMPRESSED_RG11_EAC:
-        case LOCAL_GL_COMPRESSED_SIGNED_RG11_EAC:
-        case LOCAL_GL_COMPRESSED_RGB8_ETC2:
-        case LOCAL_GL_COMPRESSED_SRGB8_ETC2:
-        case LOCAL_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
-        case LOCAL_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
-        case LOCAL_GL_COMPRESSED_RGBA8_ETC2_EAC:
-        case LOCAL_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
-            return true;
-        default:
-            return false;
+    case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+    case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+    case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+    case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+    case LOCAL_GL_ATC_RGB:
+    case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
+    case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
+    case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
+    case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
+    case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
+    case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
+    case LOCAL_GL_ETC1_RGB8_OES:
+    case LOCAL_GL_COMPRESSED_R11_EAC:
+    case LOCAL_GL_COMPRESSED_SIGNED_R11_EAC:
+    case LOCAL_GL_COMPRESSED_RG11_EAC:
+    case LOCAL_GL_COMPRESSED_SIGNED_RG11_EAC:
+    case LOCAL_GL_COMPRESSED_RGB8_ETC2:
+    case LOCAL_GL_COMPRESSED_SRGB8_ETC2:
+    case LOCAL_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+    case LOCAL_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+    case LOCAL_GL_COMPRESSED_RGBA8_ETC2_EAC:
+    case LOCAL_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+        return true;
+    default:
+        return false;
     }
 }
 
 
 bool
 WebGLContext::IsTextureFormatCompressed(TexInternalFormat format)
 {
     return IsCompressedTextureFormat(format.get());
@@ -990,17 +987,18 @@ AssertUintParamCorrect(gl::GLContext* gl
     if (val != shadow) {
       printf_stderr("Failed 0x%04x shadow: Cached 0x%x/%u, should be 0x%x/%u.\n",
                     pname, shadow, shadow, val, val);
       MOZ_ASSERT(false, "Bad cached value.");
     }
 }
 
 void
-AssertMaskedUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint mask, GLuint shadow)
+AssertMaskedUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint mask,
+                             GLuint shadow)
 {
     GLuint val = 0;
     gl->GetUIntegerv(pname, &val);
 
     const GLuint valMasked = val & mask;
     const GLuint shadowMasked = shadow & mask;
 
     if (valMasked != shadowMasked) {
@@ -1035,21 +1033,21 @@ WebGLContext::AssertCachedBindings()
 
     bound = mCurrentProgram ? mCurrentProgram->GLName() : 0;
     AssertUintParamCorrect(gl, LOCAL_GL_CURRENT_PROGRAM, bound);
 
     // Textures
     GLenum activeTexture = mActiveTexture + LOCAL_GL_TEXTURE0;
     AssertUintParamCorrect(gl, LOCAL_GL_ACTIVE_TEXTURE, activeTexture);
 
-    WebGLTexture* curTex = activeBoundTextureForTarget(LOCAL_GL_TEXTURE_2D);
+    WebGLTexture* curTex = ActiveBoundTextureForTarget(LOCAL_GL_TEXTURE_2D);
     bound = curTex ? curTex->GLName() : 0;
     AssertUintParamCorrect(gl, LOCAL_GL_TEXTURE_BINDING_2D, bound);
 
-    curTex = activeBoundTextureForTarget(LOCAL_GL_TEXTURE_CUBE_MAP);
+    curTex = ActiveBoundTextureForTarget(LOCAL_GL_TEXTURE_CUBE_MAP);
     bound = curTex ? curTex->GLName() : 0;
     AssertUintParamCorrect(gl, LOCAL_GL_TEXTURE_BINDING_CUBE_MAP, bound);
 
     // Buffers
     bound = mBoundArrayBuffer ? mBoundArrayBuffer->GLName() : 0;
     AssertUintParamCorrect(gl, LOCAL_GL_ARRAY_BUFFER_BINDING, bound);
 
     MOZ_ASSERT(mBoundVertexArray);
--- a/dom/canvas/WebGLContextUtils.h
+++ b/dom/canvas/WebGLContextUtils.h
@@ -1,48 +1,49 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef WEBGLCONTEXTUTILS_H_
-#define WEBGLCONTEXTUTILS_H_
+#ifndef WEBGL_CONTEXT_UTILS_H_
+#define WEBGL_CONTEXT_UTILS_H_
 
 #include "WebGLContext.h"
 #include "WebGLStrongTypes.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/BindingUtils.h"
 
 namespace mozilla {
 
 bool IsGLDepthFormat(TexInternalFormat webGLFormat);
 bool IsGLDepthStencilFormat(TexInternalFormat webGLFormat);
 bool FormatHasAlpha(TexInternalFormat webGLFormat);
+
 void
 DriverFormatsFromEffectiveInternalFormat(gl::GLContext* gl,
                                          TexInternalFormat internalformat,
-                                         GLenum* out_driverInternalFormat,
-                                         GLenum* out_driverFormat,
-                                         GLenum* out_driverType);
+                                         GLenum* const out_driverInternalFormat,
+                                         GLenum* const out_driverFormat,
+                                         GLenum* const out_driverType);
 TexInternalFormat
 EffectiveInternalFormatFromInternalFormatAndType(TexInternalFormat internalformat,
                                                  TexType type);
 TexInternalFormat
 EffectiveInternalFormatFromUnsizedInternalFormatAndType(TexInternalFormat internalformat,
                                                         TexType type);
 void
 UnsizedInternalFormatAndTypeFromEffectiveInternalFormat(TexInternalFormat effectiveinternalformat,
-                                                        TexInternalFormat* out_internalformat,
-                                                        TexType* out_type);
-TexType
-TypeFromInternalFormat(TexInternalFormat internalformat);
+                                                        TexInternalFormat* const out_internalformat,
+                                                        TexType* const out_type);
+TexType TypeFromInternalFormat(TexInternalFormat internalformat);
+
 TexInternalFormat
 UnsizedInternalFormatFromInternalFormat(TexInternalFormat internalformat);
-size_t
-GetBitsPerTexel(TexInternalFormat effectiveinternalformat);
+
+size_t GetBitsPerTexel(TexInternalFormat effectiveinternalformat);
 
 // For use with the different texture calls, i.e.
 //   TexImage2D, CopyTex[Sub]Image2D, ...
 // that take a "target" parameter. This parameter is not always the same as
 // the texture binding location, like GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
 // For example, cube maps would pass GL_TEXTURE_CUBE_MAP_[POS|NEG]_[X|Y|Z]
 // instead of just GL_TEXTURE_CUBE_MAP.
 //
@@ -63,57 +64,58 @@ struct GLComponents
         Blue    = (1 << 2),
         Alpha   = (1 << 3),
         Stencil = (1 << 4),
         Depth   = (1 << 5),
     };
 
     GLComponents()
         : mComponents(0)
-    { }
+    {}
 
-    explicit GLComponents(TexInternalFormat aFormat);
+    explicit GLComponents(TexInternalFormat format);
 
     // Returns true iff other has all (or more) of
     // the components present in this GLComponents
     bool IsSubsetOf(const GLComponents& other) const;
 };
 
 template <typename WebGLObjectType>
 JS::Value
-WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const
+WebGLContext::WebGLObjectAsJSValue(JSContext* cx, const WebGLObjectType* object,
+                                   ErrorResult& rv) const
 {
-    if (!object) {
+    if (!object)
         return JS::NullValue();
-    }
+
     MOZ_ASSERT(this == object->Context());
     JS::Rooted<JS::Value> v(cx);
     JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
     JSAutoCompartment ac(cx, wrapper);
-    if (!dom::GetOrCreateDOMReflector(cx, const_cast<WebGLObjectType*>(object),
-                                      &v)) {
+    if (!dom::GetOrCreateDOMReflector(cx, const_cast<WebGLObjectType*>(object), &v)) {
         rv.Throw(NS_ERROR_FAILURE);
         return JS::NullValue();
     }
     return v;
 }
 
 template <typename WebGLObjectType>
 JSObject*
-WebGLContext::WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const
+WebGLContext::WebGLObjectAsJSObject(JSContext* cx,
+                                    const WebGLObjectType* object,
+                                    ErrorResult& rv) const
 {
     JS::Value v = WebGLObjectAsJSValue(cx, object, rv);
-    if (v.isNull()) {
+    if (v.isNull())
         return nullptr;
-    }
+
     return &v.toObject();
 }
 
 /**
  * Return the displayable name for the texture function that is the
  * source for validation.
  */
-const char*
-InfoFrom(WebGLTexImageFunc func, WebGLTexDimensions dims);
+const char* InfoFrom(WebGLTexImageFunc func, WebGLTexDimensions dims);
 
 } // namespace mozilla
 
-#endif // WEBGLCONTEXTUTILS_H_
+#endif // WEBGL_CONTEXT_UTILS_H_
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -24,42 +24,43 @@
 #include "WebGLUniformLocation.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
 
 #if defined(MOZ_WIDGET_COCOA)
 #include "nsCocoaFeatures.h"
 #endif
 
-using namespace mozilla;
+namespace mozilla {
 
 /**
  * Return the block size for format.
  */
 static void
-BlockSizeFor(GLenum format, GLint* blockWidth, GLint* blockHeight)
+BlockSizeFor(GLenum format, GLint* const out_blockWidth,
+             GLint* const out_blockHeight)
 {
-    MOZ_ASSERT(blockWidth && blockHeight);
+    MOZ_ASSERT(out_blockWidth && out_blockHeight);
 
     switch (format) {
     case LOCAL_GL_ATC_RGB:
     case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
     case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
     case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
     case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
     case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
     case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
-        if (blockWidth)
-            *blockWidth = 4;
-        if (blockHeight)
-            *blockHeight = 4;
+        *out_blockWidth = 4;
+        *out_blockHeight = 4;
         break;
 
     case LOCAL_GL_ETC1_RGB8_OES:
         // 4x4 blocks, but no 4-multiple requirement.
+        break;
+
     default:
         break;
     }
 }
 
 static bool
 IsCompressedFunc(WebGLTexImageFunc func)
 {
@@ -67,23 +68,26 @@ IsCompressedFunc(WebGLTexImageFunc func)
            func == WebGLTexImageFunc::CompTexSubImage;
 }
 
 /**
  * Same as ErrorInvalidEnum but uses WebGLContext::EnumName to print displayable
  * name for \a glenum.
  */
 static void
-ErrorInvalidEnumWithName(WebGLContext* ctx, const char* msg, GLenum glenum, WebGLTexImageFunc func, WebGLTexDimensions dims)
+ErrorInvalidEnumWithName(WebGLContext* ctx, const char* msg, GLenum glenum,
+                         WebGLTexImageFunc func, WebGLTexDimensions dims)
 {
     const char* name = WebGLContext::EnumName(glenum);
-    if (name)
+    if (name) {
         ctx->ErrorInvalidEnum("%s: %s %s", InfoFrom(func, dims), msg, name);
-    else
-        ctx->ErrorInvalidEnum("%s: %s 0x%04X", InfoFrom(func, dims), msg, glenum);
+    } else {
+        ctx->ErrorInvalidEnum("%s: %s 0x%04x", InfoFrom(func, dims), msg,
+                              glenum);
+    }
 }
 
 /**
  * Return true if the format is valid for source calls.
  */
 static bool
 IsAllowedFromSource(GLenum format, WebGLTexImageFunc func)
 {
@@ -135,230 +139,258 @@ IsSubFunc(WebGLTexImageFunc func)
  */
 static bool
 IsTexImageCubemapTarget(GLenum texImageTarget)
 {
     return (texImageTarget >= LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
             texImageTarget <= LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
 }
 
-bool WebGLContext::ValidateBlendEquationEnum(GLenum mode, const char *info)
+bool
+WebGLContext::ValidateBlendEquationEnum(GLenum mode, const char* info)
 {
     switch (mode) {
-        case LOCAL_GL_FUNC_ADD:
-        case LOCAL_GL_FUNC_SUBTRACT:
-        case LOCAL_GL_FUNC_REVERSE_SUBTRACT:
+    case LOCAL_GL_FUNC_ADD:
+    case LOCAL_GL_FUNC_SUBTRACT:
+    case LOCAL_GL_FUNC_REVERSE_SUBTRACT:
+        return true;
+
+    case LOCAL_GL_MIN:
+    case LOCAL_GL_MAX:
+        if (IsExtensionEnabled(WebGLExtensionID::EXT_blend_minmax))
             return true;
-        case LOCAL_GL_MIN:
-        case LOCAL_GL_MAX:
-            if (IsExtensionEnabled(WebGLExtensionID::EXT_blend_minmax)) {
-                return true;
-            }
-            break;
-        default:
-            break;
+
+        break;
+
+    default:
+        break;
     }
 
     ErrorInvalidEnumInfo(info, mode);
     return false;
 }
 
-bool WebGLContext::ValidateBlendFuncDstEnum(GLenum factor, const char *info)
+bool
+WebGLContext::ValidateBlendFuncDstEnum(GLenum factor, const char* info)
 {
     switch (factor) {
-        case LOCAL_GL_ZERO:
-        case LOCAL_GL_ONE:
-        case LOCAL_GL_SRC_COLOR:
-        case LOCAL_GL_ONE_MINUS_SRC_COLOR:
-        case LOCAL_GL_DST_COLOR:
-        case LOCAL_GL_ONE_MINUS_DST_COLOR:
-        case LOCAL_GL_SRC_ALPHA:
-        case LOCAL_GL_ONE_MINUS_SRC_ALPHA:
-        case LOCAL_GL_DST_ALPHA:
-        case LOCAL_GL_ONE_MINUS_DST_ALPHA:
-        case LOCAL_GL_CONSTANT_COLOR:
-        case LOCAL_GL_ONE_MINUS_CONSTANT_COLOR:
-        case LOCAL_GL_CONSTANT_ALPHA:
-        case LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA:
-            return true;
-        default:
-            ErrorInvalidEnumInfo(info, factor);
-            return false;
-    }
-}
+    case LOCAL_GL_ZERO:
+    case LOCAL_GL_ONE:
+    case LOCAL_GL_SRC_COLOR:
+    case LOCAL_GL_ONE_MINUS_SRC_COLOR:
+    case LOCAL_GL_DST_COLOR:
+    case LOCAL_GL_ONE_MINUS_DST_COLOR:
+    case LOCAL_GL_SRC_ALPHA:
+    case LOCAL_GL_ONE_MINUS_SRC_ALPHA:
+    case LOCAL_GL_DST_ALPHA:
+    case LOCAL_GL_ONE_MINUS_DST_ALPHA:
+    case LOCAL_GL_CONSTANT_COLOR:
+    case LOCAL_GL_ONE_MINUS_CONSTANT_COLOR:
+    case LOCAL_GL_CONSTANT_ALPHA:
+    case LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA:
+        return true;
 
-bool WebGLContext::ValidateBlendFuncSrcEnum(GLenum factor, const char *info)
-{
-    if (factor == LOCAL_GL_SRC_ALPHA_SATURATE)
-        return true;
-    else
-        return ValidateBlendFuncDstEnum(factor, info);
-}
-
-bool WebGLContext::ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor, const char *info)
-{
-    bool sfactorIsConstantColor = sfactor == LOCAL_GL_CONSTANT_COLOR ||
-                                    sfactor == LOCAL_GL_ONE_MINUS_CONSTANT_COLOR;
-    bool sfactorIsConstantAlpha = sfactor == LOCAL_GL_CONSTANT_ALPHA ||
-                                    sfactor == LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA;
-    bool dfactorIsConstantColor = dfactor == LOCAL_GL_CONSTANT_COLOR ||
-                                    dfactor == LOCAL_GL_ONE_MINUS_CONSTANT_COLOR;
-    bool dfactorIsConstantAlpha = dfactor == LOCAL_GL_CONSTANT_ALPHA ||
-                                    dfactor == LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA;
-    if ( (sfactorIsConstantColor && dfactorIsConstantAlpha) ||
-         (dfactorIsConstantColor && sfactorIsConstantAlpha) ) {
-        ErrorInvalidOperation("%s are mutually incompatible, see section 6.8 in the WebGL 1.0 spec", info);
+    default:
+        ErrorInvalidEnumInfo(info, factor);
         return false;
-    } else {
-        return true;
     }
 }
 
-bool WebGLContext::ValidateTextureTargetEnum(GLenum target, const char *info)
+bool
+WebGLContext::ValidateBlendFuncSrcEnum(GLenum factor, const char* info)
+{
+    if (factor == LOCAL_GL_SRC_ALPHA_SATURATE)
+        return true;
+
+    return ValidateBlendFuncDstEnum(factor, info);
+}
+
+bool
+WebGLContext::ValidateBlendFuncEnumsCompatibility(GLenum sfactor,
+                                                  GLenum dfactor,
+                                                  const char* info)
+{
+    bool sfactorIsConstantColor = sfactor == LOCAL_GL_CONSTANT_COLOR ||
+                                  sfactor == LOCAL_GL_ONE_MINUS_CONSTANT_COLOR;
+    bool sfactorIsConstantAlpha = sfactor == LOCAL_GL_CONSTANT_ALPHA ||
+                                  sfactor == LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA;
+    bool dfactorIsConstantColor = dfactor == LOCAL_GL_CONSTANT_COLOR ||
+                                  dfactor == LOCAL_GL_ONE_MINUS_CONSTANT_COLOR;
+    bool dfactorIsConstantAlpha = dfactor == LOCAL_GL_CONSTANT_ALPHA ||
+                                  dfactor == LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA;
+    if ( (sfactorIsConstantColor && dfactorIsConstantAlpha) ||
+         (dfactorIsConstantColor && sfactorIsConstantAlpha) )
+    {
+        ErrorInvalidOperation("%s are mutually incompatible, see section 6.8 in"
+                              " the WebGL 1.0 spec", info);
+        return false;
+    }
+
+    return true;
+}
+
+bool
+WebGLContext::ValidateTextureTargetEnum(GLenum target, const char* info)
 {
     switch (target) {
-        case LOCAL_GL_TEXTURE_2D:
-        case LOCAL_GL_TEXTURE_CUBE_MAP:
+    case LOCAL_GL_TEXTURE_2D:
+    case LOCAL_GL_TEXTURE_CUBE_MAP:
+        return true;
+
+    case LOCAL_GL_TEXTURE_3D:
+        if (IsWebGL2())
             return true;
-        case LOCAL_GL_TEXTURE_3D: {
-            const bool isValid = IsWebGL2();
-            if (!isValid) {
-                ErrorInvalidEnumInfo(info, target);
-            }
-            return isValid;
-        }
-        default:
-            ErrorInvalidEnumInfo(info, target);
-            return false;
+
+        break;
+
+    default:
+        break;
     }
+
+    ErrorInvalidEnumInfo(info, target);
+    return false;
 }
 
-bool WebGLContext::ValidateComparisonEnum(GLenum target, const char *info)
+bool
+WebGLContext::ValidateComparisonEnum(GLenum target, const char* info)
 {
     switch (target) {
-        case LOCAL_GL_NEVER:
-        case LOCAL_GL_LESS:
-        case LOCAL_GL_LEQUAL:
-        case LOCAL_GL_GREATER:
-        case LOCAL_GL_GEQUAL:
-        case LOCAL_GL_EQUAL:
-        case LOCAL_GL_NOTEQUAL:
-        case LOCAL_GL_ALWAYS:
-            return true;
-        default:
-            ErrorInvalidEnumInfo(info, target);
-            return false;
+    case LOCAL_GL_NEVER:
+    case LOCAL_GL_LESS:
+    case LOCAL_GL_LEQUAL:
+    case LOCAL_GL_GREATER:
+    case LOCAL_GL_GEQUAL:
+    case LOCAL_GL_EQUAL:
+    case LOCAL_GL_NOTEQUAL:
+    case LOCAL_GL_ALWAYS:
+        return true;
+
+    default:
+        ErrorInvalidEnumInfo(info, target);
+        return false;
     }
 }
 
-bool WebGLContext::ValidateStencilOpEnum(GLenum action, const char *info)
+bool
+WebGLContext::ValidateStencilOpEnum(GLenum action, const char* info)
 {
     switch (action) {
-        case LOCAL_GL_KEEP:
-        case LOCAL_GL_ZERO:
-        case LOCAL_GL_REPLACE:
-        case LOCAL_GL_INCR:
-        case LOCAL_GL_INCR_WRAP:
-        case LOCAL_GL_DECR:
-        case LOCAL_GL_DECR_WRAP:
-        case LOCAL_GL_INVERT:
-            return true;
-        default:
-            ErrorInvalidEnumInfo(info, action);
-            return false;
+    case LOCAL_GL_KEEP:
+    case LOCAL_GL_ZERO:
+    case LOCAL_GL_REPLACE:
+    case LOCAL_GL_INCR:
+    case LOCAL_GL_INCR_WRAP:
+    case LOCAL_GL_DECR:
+    case LOCAL_GL_DECR_WRAP:
+    case LOCAL_GL_INVERT:
+        return true;
+
+    default:
+        ErrorInvalidEnumInfo(info, action);
+        return false;
     }
 }
 
-bool WebGLContext::ValidateFaceEnum(GLenum face, const char *info)
+bool
+WebGLContext::ValidateFaceEnum(GLenum face, const char* info)
 {
     switch (face) {
-        case LOCAL_GL_FRONT:
-        case LOCAL_GL_BACK:
-        case LOCAL_GL_FRONT_AND_BACK:
-            return true;
-        default:
-            ErrorInvalidEnumInfo(info, face);
-            return false;
+    case LOCAL_GL_FRONT:
+    case LOCAL_GL_BACK:
+    case LOCAL_GL_FRONT_AND_BACK:
+        return true;
+
+    default:
+        ErrorInvalidEnumInfo(info, face);
+        return false;
     }
 }
 
-bool WebGLContext::ValidateDrawModeEnum(GLenum mode, const char *info)
+bool
+WebGLContext::ValidateDrawModeEnum(GLenum mode, const char* info)
 {
     switch (mode) {
-        case LOCAL_GL_TRIANGLES:
-        case LOCAL_GL_TRIANGLE_STRIP:
-        case LOCAL_GL_TRIANGLE_FAN:
-        case LOCAL_GL_POINTS:
-        case LOCAL_GL_LINE_STRIP:
-        case LOCAL_GL_LINE_LOOP:
-        case LOCAL_GL_LINES:
-            return true;
-        default:
-            ErrorInvalidEnumInfo(info, mode);
-            return false;
+    case LOCAL_GL_TRIANGLES:
+    case LOCAL_GL_TRIANGLE_STRIP:
+    case LOCAL_GL_TRIANGLE_FAN:
+    case LOCAL_GL_POINTS:
+    case LOCAL_GL_LINE_STRIP:
+    case LOCAL_GL_LINE_LOOP:
+    case LOCAL_GL_LINES:
+        return true;
+
+    default:
+        ErrorInvalidEnumInfo(info, mode);
+        return false;
     }
 }
 
-bool WebGLContext::ValidateGLSLVariableName(const nsAString& name, const char *info)
+bool
+WebGLContext::ValidateGLSLVariableName(const nsAString& name, const char* info)
 {
     if (name.IsEmpty())
         return false;
 
     const uint32_t maxSize = 256;
     if (name.Length() > maxSize) {
-        ErrorInvalidValue("%s: identifier is %d characters long, exceeds the maximum allowed length of %d characters",
-                          info, name.Length(), maxSize);
+        ErrorInvalidValue("%s: Identifier is %d characters long, exceeds the"
+                          " maximum allowed length of %d characters.", info,
+                          name.Length(), maxSize);
         return false;
     }
 
-    if (!ValidateGLSLString(name, info)) {
+    if (!ValidateGLSLString(name, info))
         return false;
-    }
 
     nsString prefix1 = NS_LITERAL_STRING("webgl_");
     nsString prefix2 = NS_LITERAL_STRING("_webgl_");
 
     if (Substring(name, 0, prefix1.Length()).Equals(prefix1) ||
         Substring(name, 0, prefix2.Length()).Equals(prefix2))
     {
-        ErrorInvalidOperation("%s: string contains a reserved GLSL prefix", info);
+        ErrorInvalidOperation("%s: String contains a reserved GLSL prefix.",
+                              info);
         return false;
     }
 
     return true;
 }
 
-bool WebGLContext::ValidateGLSLString(const nsAString& string, const char *info)
+bool WebGLContext::ValidateGLSLString(const nsAString& string, const char* info)
 {
     for (uint32_t i = 0; i < string.Length(); ++i) {
         if (!ValidateGLSLCharacter(string.CharAt(i))) {
-             ErrorInvalidValue("%s: string contains the illegal character '%d'", info, string.CharAt(i));
+             ErrorInvalidValue("%s: String contains the illegal character"
+                               " '%d'.", info, string.CharAt(i));
              return false;
         }
     }
 
     return true;
 }
 
 /**
  * Return true if the framebuffer attachment is valid. Attachment must
  * be one of depth/stencil/depth_stencil/color attachment.
  */
 bool
-WebGLContext::ValidateFramebufferAttachment(GLenum attachment, const char* funcName)
+WebGLContext::ValidateFramebufferAttachment(GLenum attachment,
+                                            const char* funcName)
 {
     if (!mBoundFramebuffer) {
         switch (attachment) {
-            case LOCAL_GL_COLOR:
-            case LOCAL_GL_DEPTH:
-            case LOCAL_GL_STENCIL:
-                return true;
-            default:
-                ErrorInvalidEnum("%s: attachment: invalid enum value 0x%x.", funcName, attachment);
-                return false;
+        case LOCAL_GL_COLOR:
+        case LOCAL_GL_DEPTH:
+        case LOCAL_GL_STENCIL:
+            return true;
+
+        default:
+            ErrorInvalidEnum("%s: attachment: invalid enum value 0x%x.",
+                             funcName, attachment);
+            return false;
         }
     }
 
     if (attachment == LOCAL_GL_DEPTH_ATTACHMENT ||
         attachment == LOCAL_GL_STENCIL_ATTACHMENT ||
         attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
     {
         return true;
@@ -369,17 +401,18 @@ WebGLContext::ValidateFramebufferAttachm
         colorAttachCount = mGLMaxColorAttachments;
 
     if (attachment >= LOCAL_GL_COLOR_ATTACHMENT0 &&
         attachment < GLenum(LOCAL_GL_COLOR_ATTACHMENT0 + colorAttachCount))
     {
         return true;
     }
 
-    ErrorInvalidEnum("%s: attachment: invalid enum value 0x%x.", funcName, attachment);
+    ErrorInvalidEnum("%s: attachment: invalid enum value 0x%x.", funcName,
+                     attachment);
     return false;
 }
 
 /**
  * Return true if pname is valid for GetSamplerParameter calls.
  */
 bool
 WebGLContext::ValidateSamplerParameterName(GLenum pname, const char* info)
@@ -490,17 +523,18 @@ WebGLContext::ValidateSamplerParameterPa
 }
 
 
 /**
  * Return true if format is a valid texture image format for source,
  * taking into account enabled WebGL extensions.
  */
 bool
-WebGLContext::ValidateTexImageFormat(GLenum format, WebGLTexImageFunc func, WebGLTexDimensions dims)
+WebGLContext::ValidateTexImageFormat(GLenum format, WebGLTexImageFunc func,
+                                     WebGLTexDimensions dims)
 {
     /* Core WebGL texture formats */
     if (format == LOCAL_GL_ALPHA ||
         format == LOCAL_GL_RGB ||
         format == LOCAL_GL_RGBA ||
         format == LOCAL_GL_LUMINANCE ||
         format == LOCAL_GL_LUMINANCE_ALPHA)
     {
@@ -510,79 +544,82 @@ WebGLContext::ValidateTexImageFormat(GLe
     /* WebGL2 new formats */
     if (format == LOCAL_GL_RED ||
         format == LOCAL_GL_RG ||
         format == LOCAL_GL_RED_INTEGER ||
         format == LOCAL_GL_RG_INTEGER ||
         format == LOCAL_GL_RGB_INTEGER ||
         format == LOCAL_GL_RGBA_INTEGER)
     {
-        bool valid = IsWebGL2();
-        if (!valid) {
-            ErrorInvalidEnum("%s:  invalid format %s: requires WebGL version 2.0 or newer",
-                             InfoFrom(func, dims), EnumName(format));
-        }
-        return valid;
+        if (IsWebGL2())
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid format %s: Requires WebGL version 2.0 or"
+                         " newer.", InfoFrom(func, dims), EnumName(format));
+        return false;
     }
 
     /* WEBGL_depth_texture added formats */
     if (format == LOCAL_GL_DEPTH_COMPONENT ||
         format == LOCAL_GL_DEPTH_STENCIL)
     {
         if (!IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture)) {
-            ErrorInvalidEnum("%s: invalid format %s: need WEBGL_depth_texture enabled",
+            ErrorInvalidEnum("%s: Invalid format %s: Requires that"
+                             " WEBGL_depth_texture is enabled.",
                              InfoFrom(func, dims), EnumName(format));
             return false;
         }
 
-        // If WEBGL_depth_texture is enabled, then it is not allowed to be used with the
-        // copyTexImage, or copyTexSubImage methods, and it is not allowed with
-        // texSubImage in WebGL1.
+        // If WEBGL_depth_texture is enabled, then it is not allowed to be used
+        // with the copyTexImage, or copyTexSubImage methods, and it is not
+        // allowed with texSubImage in WebGL1.
         if ((func == WebGLTexImageFunc::TexSubImage && !IsWebGL2()) ||
             func == WebGLTexImageFunc::CopyTexImage ||
             func == WebGLTexImageFunc::CopyTexSubImage)
         {
-            ErrorInvalidOperation("%s: format %s is not supported", InfoFrom(func, dims), EnumName(format));
+            ErrorInvalidOperation("%s: format %s is not supported",
+                                  InfoFrom(func, dims), EnumName(format));
             return false;
         }
 
         return true;
     }
 
     // Needs to be below the depth_texture check because an invalid operation
     // error needs to be generated instead of invalid enum.
-    /* Only core formats are valid for CopyTex(Sub)?Image */
-    // TODO: Revisit this once color_buffer_(half_)?float lands
+    // Only core formats are valid for CopyTex[Sub]Image.
+    // TODO: Revisit this once color_buffer_[half_]float lands.
     if (IsCopyFunc(func)) {
         ErrorInvalidEnumWithName(this, "invalid format", format, func, dims);
         return false;
     }
 
-    /* EXT_sRGB added formats */
+    // EXT_sRGB added formats
     if (format == LOCAL_GL_SRGB ||
         format == LOCAL_GL_SRGB_ALPHA)
     {
-        bool validFormat = IsExtensionEnabled(WebGLExtensionID::EXT_sRGB);
-        if (!validFormat)
-            ErrorInvalidEnum("%s: invalid format %s: need EXT_sRGB enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(format));
-        return validFormat;
+        if (IsExtensionEnabled(WebGLExtensionID::EXT_sRGB))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid format %s: Requires that EXT_sRGB is"
+                         " enabled.", InfoFrom(func, dims),
+                         WebGLContext::EnumName(format));
+        return false;
     }
 
     ErrorInvalidEnumWithName(this, "invalid format", format, func, dims);
-
     return false;
 }
 
 /**
  * Check if the given texture target is valid for TexImage.
  */
 bool
-WebGLContext::ValidateTexImageTarget(GLenum target,
-                                     WebGLTexImageFunc func, WebGLTexDimensions dims)
+WebGLContext::ValidateTexImageTarget(GLenum target, WebGLTexImageFunc func,
+                                     WebGLTexDimensions dims)
 {
     switch (dims) {
     case WebGLTexDimensions::Tex2D:
         if (target == LOCAL_GL_TEXTURE_2D ||
             IsTexImageCubemapTarget(target))
         {
             return true;
         }
@@ -606,18 +643,17 @@ WebGLContext::ValidateTexImageTarget(GLe
     return false;
 }
 
 /**
  * Return true if type is a valid texture image type for source,
  * taking into account enabled WebGL extensions.
  */
 bool
-WebGLContext::ValidateTexImageType(GLenum type,
-                                   WebGLTexImageFunc func,
+WebGLContext::ValidateTexImageType(GLenum type, WebGLTexImageFunc func,
                                    WebGLTexDimensions dims)
 {
     /* Core WebGL texture types */
     if (type == LOCAL_GL_UNSIGNED_BYTE ||
         type == LOCAL_GL_UNSIGNED_SHORT_5_6_5 ||
         type == LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 ||
         type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1)
     {
@@ -628,170 +664,179 @@ WebGLContext::ValidateTexImageType(GLenu
     if (type == LOCAL_GL_BYTE ||
         type == LOCAL_GL_SHORT ||
         type == LOCAL_GL_INT ||
         type == LOCAL_GL_FLOAT_32_UNSIGNED_INT_24_8_REV ||
         type == LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV ||
         type == LOCAL_GL_UNSIGNED_INT_10F_11F_11F_REV ||
         type == LOCAL_GL_UNSIGNED_INT_5_9_9_9_REV)
     {
-        bool validType = IsWebGL2();
-        if (!validType) {
-            ErrorInvalidEnum("%s: invalid type %s: requires WebGL version 2.0 or newer",
-                             InfoFrom(func, dims), WebGLContext::EnumName(type));
-        }
-        return validType;
+        if (IsWebGL2())
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid type %s: Requires WebGL version 2.0 or"
+                         " newer.", InfoFrom(func, dims),
+                         WebGLContext::EnumName(type));
+        return false;
     }
 
     /* OES_texture_float added types */
     if (type == LOCAL_GL_FLOAT) {
-        bool validType = IsExtensionEnabled(WebGLExtensionID::OES_texture_float);
-        if (!validType)
-            ErrorInvalidEnum("%s: invalid type %s: need OES_texture_float enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(type));
-        return validType;
+        if (IsExtensionEnabled(WebGLExtensionID::OES_texture_float))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid type %s: Requires that OES_texture_float"
+                         " is enabled.",
+                         InfoFrom(func, dims), WebGLContext::EnumName(type));
+        return false;
     }
 
     /* OES_texture_half_float add types */
     if (type == LOCAL_GL_HALF_FLOAT) {
-        bool validType = IsExtensionEnabled(WebGLExtensionID::OES_texture_half_float);
-        if (!validType)
-            ErrorInvalidEnum("%s: invalid type %s: need OES_texture_half_float enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(type));
-        return validType;
+        if (IsExtensionEnabled(WebGLExtensionID::OES_texture_half_float))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid type %s: Requires that"
+                         " OES_texture_half_float is enabled.",
+                         InfoFrom(func, dims), WebGLContext::EnumName(type));
+        return false;
     }
 
     /* WEBGL_depth_texture added types */
     if (type == LOCAL_GL_UNSIGNED_SHORT ||
         type == LOCAL_GL_UNSIGNED_INT ||
         type == LOCAL_GL_UNSIGNED_INT_24_8)
     {
-        bool validType = IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture);
-        if (!validType)
-            ErrorInvalidEnum("%s: invalid type %s: need WEBGL_depth_texture enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(type));
-        return validType;
+        if (IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid type %s: Requires that"
+                         " WEBGL_depth_texture is enabled.",
+                         InfoFrom(func, dims), WebGLContext::EnumName(type));
+        return false;
     }
 
     ErrorInvalidEnumWithName(this, "invalid type", type, func, dims);
     return false;
 }
 
 /**
  * Validate texture image sizing extra constraints for
  * CompressedTex(Sub)?Image.
  */
 // TODO: WebGL 2
 bool
-WebGLContext::ValidateCompTexImageSize(GLint level,
-                                       GLenum format,
+WebGLContext::ValidateCompTexImageSize(GLint level, GLenum format,
                                        GLint xoffset, GLint yoffset,
                                        GLsizei width, GLsizei height,
                                        GLsizei levelWidth, GLsizei levelHeight,
                                        WebGLTexImageFunc func,
                                        WebGLTexDimensions dims)
 {
     // Negative parameters must already have been handled above
     MOZ_ASSERT(xoffset >= 0 && yoffset >= 0 &&
                width >= 0 && height >= 0);
 
     if (xoffset + width > (GLint) levelWidth) {
-        ErrorInvalidValue("%s: xoffset + width must be <= levelWidth", InfoFrom(func, dims));
+        ErrorInvalidValue("%s: xoffset + width must be <= levelWidth.",
+                          InfoFrom(func, dims));
         return false;
     }
 
     if (yoffset + height > (GLint) levelHeight) {
-        ErrorInvalidValue("%s: yoffset + height must be <= levelHeight", InfoFrom(func, dims));
+        ErrorInvalidValue("%s: yoffset + height must be <= levelHeight.",
+                          InfoFrom(func, dims));
         return false;
     }
 
     GLint blockWidth = 1;
     GLint blockHeight = 1;
     BlockSizeFor(format, &blockWidth, &blockHeight);
 
-    /* If blockWidth || blockHeight != 1, then the compressed format
-     * had block-based constraints to be checked. (For example, PVRTC is compressed but
-     * isn't a block-based format)
-     */
+    // If blockWidth || blockHeight != 1, then the compressed format had
+    // block-based constraints to be checked. (For example, PVRTC is compressed
+    // but isn't a block-based format)
     if (blockWidth != 1 || blockHeight != 1) {
-        /* offsets must be multiple of block size */
+        // Offsets must be multiple of block size.
         if (xoffset % blockWidth != 0) {
-            ErrorInvalidOperation("%s: xoffset must be multiple of %d",
+            ErrorInvalidOperation("%s: xoffset must be multiple of %d.",
                                   InfoFrom(func, dims), blockWidth);
             return false;
         }
 
         if (yoffset % blockHeight != 0) {
-            ErrorInvalidOperation("%s: yoffset must be multiple of %d",
+            ErrorInvalidOperation("%s: yoffset must be multiple of %d.",
                                   InfoFrom(func, dims), blockHeight);
             return false;
         }
 
-        /* The size must be a multiple of blockWidth and blockHeight,
-         * or must be using offset+size that exactly hits the edge.
-         * Important for small mipmap levels.
-         */
-        /* https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/
-         * "When level equals zero width and height must be a multiple of 4. When
-         *  level is greater than 0 width and height must be 0, 1, 2 or a multiple of 4.
-         *  If they are not an INVALID_OPERATION error is generated."
+        /* The size must be a multiple of blockWidth and blockHeight, or must be
+         * using offset+size that exactly hits the edge. Important for small
+         * mipmap levels.
+         *
+         * From the WEBGL_compressed_texture_s3tc spec:
+         *     When level equals zero width and height must be a multiple of 4.
+         *     When level is greater than 0 width and height must be 0, 1, 2 or
+         *     a multiple of 4. If they are not an INVALID_OPERATION error is
+         *     generated."
          */
         if (level == 0) {
             if (width % blockWidth != 0) {
-                ErrorInvalidOperation("%s: width of level 0 must be multple of %d",
-                                      InfoFrom(func, dims), blockWidth);
+                ErrorInvalidOperation("%s: Width of level 0 must be a multiple"
+                                      " of %d.", InfoFrom(func, dims),
+                                      blockWidth);
                 return false;
             }
 
             if (height % blockHeight != 0) {
-                ErrorInvalidOperation("%s: height of level 0 must be multipel of %d",
-                                      InfoFrom(func, dims), blockHeight);
+                ErrorInvalidOperation("%s: Height of level 0 must be a multiple"
+                                      " of %d.", InfoFrom(func, dims),
+                                      blockHeight);
                 return false;
             }
-        }
-        else if (level > 0) {
+        } else if (level > 0) {
             if (width % blockWidth != 0 && width > 2) {
-                ErrorInvalidOperation("%s: width of level %d must be multiple"
-                                      " of %d or 0, 1, 2",
+                ErrorInvalidOperation("%s: Width of level %d must be a multiple"
+                                      " of %d, or be 0, 1, or 2.",
                                       InfoFrom(func, dims), level, blockWidth);
                 return false;
             }
 
             if (height % blockHeight != 0 && height > 2) {
-                ErrorInvalidOperation("%s: height of level %d must be multiple"
-                                      " of %d or 0, 1, 2",
+                ErrorInvalidOperation("%s: Height of level %d must be a"
+                                      " multiple of %d, or be 0, 1, or 2.",
                                       InfoFrom(func, dims), level, blockHeight);
                 return false;
             }
         }
 
         if (IsSubFunc(func)) {
             if ((xoffset % blockWidth) != 0) {
-                ErrorInvalidOperation("%s: xoffset must be multiple of %d",
+                ErrorInvalidOperation("%s: xoffset must be a multiple of %d.",
                                       InfoFrom(func, dims), blockWidth);
                 return false;
             }
 
             if (yoffset % blockHeight != 0) {
-                ErrorInvalidOperation("%s: yoffset must be multiple of %d",
+                ErrorInvalidOperation("%s: yoffset must be a multiple of %d.",
                                       InfoFrom(func, dims), blockHeight);
                 return false;
             }
         }
     }
 
     switch (format) {
     case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
     case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
     case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
     case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
-        if (!is_pot_assuming_nonnegative(width) ||
-            !is_pot_assuming_nonnegative(height))
+        if (!IsPOTAssumingNonnegative(width) ||
+            !IsPOTAssumingNonnegative(height))
         {
-            ErrorInvalidValue("%s: width and height must be powers of two",
+            ErrorInvalidValue("%s: Width and height must be powers of two.",
                               InfoFrom(func, dims));
             return false;
         }
     }
 
     return true;
 }
 
@@ -807,355 +852,380 @@ WebGLContext::ValidateCompTexImageDataSi
                                            WebGLTexDimensions dims)
 {
     // negative width and height must already have been handled above
     MOZ_ASSERT(width >= 0 && height >= 0);
 
     CheckedUint32 required_byteLength = 0;
 
     switch (format) {
-        case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
-        case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
-        case LOCAL_GL_ATC_RGB:
-        case LOCAL_GL_ETC1_RGB8_OES:
-        {
-            required_byteLength = ((CheckedUint32(width) + 3) / 4) * ((CheckedUint32(height) + 3) / 4) * 8;
-            break;
-        }
-        case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
-        case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
-        case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
-        case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
-        {
-            required_byteLength = ((CheckedUint32(width) + 3) / 4) * ((CheckedUint32(height) + 3) / 4) * 16;
-            break;
-        }
-        case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
-        case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
-        {
-            required_byteLength = CheckedUint32(std::max(width, 8)) * CheckedUint32(std::max(height, 8)) / 2;
-            break;
-        }
-        case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
-        case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
-        {
-            required_byteLength = CheckedUint32(std::max(width, 16)) * CheckedUint32(std::max(height, 8)) / 4;
-            break;
-        }
+    case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+    case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+    case LOCAL_GL_ATC_RGB:
+    case LOCAL_GL_ETC1_RGB8_OES:
+        required_byteLength = ((CheckedUint32(width) + 3) / 4) *
+                              ((CheckedUint32(height) + 3) / 4) * 8;
+        break;
+
+    case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+    case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+    case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
+    case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
+        required_byteLength = ((CheckedUint32(width) + 3) / 4) *
+                              ((CheckedUint32(height) + 3) / 4) * 16;
+        break;
+
+    case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
+    case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
+        required_byteLength = CheckedUint32(std::max(width, 8)) *
+                              CheckedUint32(std::max(height, 8)) / 2;
+        break;
+
+    case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
+    case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
+        required_byteLength = CheckedUint32(std::max(width, 16)) *
+                              CheckedUint32(std::max(height, 8)) / 4;
+        break;
     }
 
-    if (!required_byteLength.isValid() || required_byteLength.value() != byteLength) {
-        ErrorInvalidValue("%s: data size does not match dimensions", InfoFrom(func, dims));
+    if (!required_byteLength.isValid() ||
+        required_byteLength.value() != byteLength)
+    {
+        ErrorInvalidValue("%s: Data size does not match dimensions.",
+                          InfoFrom(func, dims));
         return false;
     }
 
     return true;
 }
 
 /**
  * Validate the width, height, and depth of a texture image, \return
  * true is valid, false otherwise.
  * Used by all the (Compressed|Copy)?Tex(Sub)?Image functions.
  * Target and level must have been validated before calling.
  */
 bool
 WebGLContext::ValidateTexImageSize(TexImageTarget texImageTarget, GLint level,
                                    GLint width, GLint height, GLint depth,
-                                   WebGLTexImageFunc func, WebGLTexDimensions dims)
+                                   WebGLTexImageFunc func,
+                                   WebGLTexDimensions dims)
 {
     MOZ_ASSERT(level >= 0, "level should already be validated");
 
     /* Bug 966630: maxTextureSize >> level runs into "undefined"
      * behaviour depending on ISA. For example, on Intel shifts
      * amounts are mod 64 (in 64-bit mode on 64-bit dest) and mod 32
      * otherwise. This means 16384 >> 0x10000001 == 8192 which isn't
      * what would be expected. Make the required behaviour explicit by
      * clamping to a shift of 31 bits if level is greater than that
      * ammount. This will give 0 that if (!maxAllowedSize) is
      * expecting.
      */
 
     if (level > 31)
         level = 31;
 
-    const GLuint maxTexImageSize = MaxTextureSizeForTarget(TexImageTargetToTexTarget(texImageTarget)) >> level;
+    auto texTarget = TexImageTargetToTexTarget(texImageTarget);
+    const GLuint maxTexImageSize = MaxTextureSizeForTarget(texTarget) >> level;
+
     const bool isCubemapTarget = IsTexImageCubemapTarget(texImageTarget.get());
     const bool isSub = IsSubFunc(func);
 
     if (!isSub && isCubemapTarget && (width != height)) {
         /* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
          *   "When the target parameter to TexImage2D is one of the
          *   six cube map two-dimensional image targets, the error
          *   INVALID_VALUE is generated if the width and height
          *   parameters are not equal."
          */
-        ErrorInvalidValue("%s: for cube map, width must equal height", InfoFrom(func, dims));
+        ErrorInvalidValue("%s: For cube maps, width must equal height.",
+                          InfoFrom(func, dims));
         return false;
     }
 
-    if (texImageTarget == LOCAL_GL_TEXTURE_2D || isCubemapTarget)
-    {
+    if (texImageTarget == LOCAL_GL_TEXTURE_2D || isCubemapTarget) {
         /* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
          *   "If wt and ht are the specified image width and height,
          *   and if either wt or ht are less than zero, then the error
          *   INVALID_VALUE is generated."
          */
         if (width < 0) {
-            ErrorInvalidValue("%s: width must be >= 0", InfoFrom(func, dims));
+            ErrorInvalidValue("%s: Width must be >= 0.", InfoFrom(func, dims));
             return false;
         }
 
         if (height < 0) {
-            ErrorInvalidValue("%s: height must be >= 0", InfoFrom(func, dims));
+            ErrorInvalidValue("%s: Height must be >= 0.", InfoFrom(func, dims));
             return false;
         }
 
         /* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
          *   "The maximum allowable width and height of a
          *   two-dimensional texture image must be at least 2**(k−lod)
          *   for image arrays of level zero through k, where k is the
          *   log base 2 of MAX_TEXTURE_SIZE. and lod is the
          *   level-of-detail of the image array. It may be zero for
          *   image arrays of any level-of-detail greater than k. The
          *   error INVALID_VALUE is generated if the specified image
          *   is too large to be stored under any conditions.
          */
         if (width > (int) maxTexImageSize) {
-            ErrorInvalidValue("%s: the maximum width for level %d is %u",
+            ErrorInvalidValue("%s: The maximum width for level %d is %u.",
                               InfoFrom(func, dims), level, maxTexImageSize);
             return false;
         }
 
         if (height > (int) maxTexImageSize) {
-            ErrorInvalidValue("%s: tex maximum height for level %d is %u",
+            ErrorInvalidValue("%s: The maximum height for level %d is %u.",
                               InfoFrom(func, dims), level, maxTexImageSize);
             return false;
         }
 
         /* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
          *   "If level is greater than zero, and either width or
          *   height is not a power-of-two, the error INVALID_VALUE is
          *   generated."
          *
          * This restriction does not apply to GL ES Version 3.0+.
          */
         if (!IsWebGL2() && level > 0) {
-            if (!is_pot_assuming_nonnegative(width)) {
-                ErrorInvalidValue("%s: level >= 0, width of %d must be a power of two.",
-                                  InfoFrom(func, dims), width);
+            if (!IsPOTAssumingNonnegative(width)) {
+                ErrorInvalidValue("%s: For level > 0, width of %d must be a"
+                                  " power of two.", InfoFrom(func, dims),
+                                  width);
                 return false;
             }
 
-            if (!is_pot_assuming_nonnegative(height)) {
-                ErrorInvalidValue("%s: level >= 0, height of %d must be a power of two.",
-                                  InfoFrom(func, dims), height);
+            if (!IsPOTAssumingNonnegative(height)) {
+                ErrorInvalidValue("%s: For level > 0, height of %d must be a"
+                                  " power of two.", InfoFrom(func, dims),
+                                  height);
                 return false;
             }
         }
     }
 
     // TODO: WebGL 2
     if (texImageTarget == LOCAL_GL_TEXTURE_3D) {
         if (depth < 0) {
-            ErrorInvalidValue("%s: depth must be >= 0", InfoFrom(func, dims));
+            ErrorInvalidValue("%s: Depth must be >= 0.", InfoFrom(func, dims));
             return false;
         }
 
-        if (!IsWebGL2() && !is_pot_assuming_nonnegative(depth)) {
-            ErrorInvalidValue("%s: level >= 0, depth of %d must be a power of two.",
+        if (!IsWebGL2() && !IsPOTAssumingNonnegative(depth)) {
+            ErrorInvalidValue("%s: Depth of %d must be a power of two.",
                               InfoFrom(func, dims), depth);
             return false;
         }
     }
 
     return true;
 }
 
 /**
  * Validate texture image sizing for Tex(Sub)?Image variants.
  */
 // TODO: WebGL 2. Update this to handle 3D textures.
 bool
-WebGLContext::ValidateTexSubImageSize(GLint xoffset, GLint yoffset, GLint /*zoffset*/,
-                                      GLsizei width, GLsizei height, GLsizei /*depth*/,
-                                      GLsizei baseWidth, GLsizei baseHeight, GLsizei /*baseDepth*/,
-                                      WebGLTexImageFunc func, WebGLTexDimensions dims)
+WebGLContext::ValidateTexSubImageSize(GLint xoffset, GLint yoffset,
+                                      GLint /*zoffset*/, GLsizei width,
+                                      GLsizei height, GLsizei /*depth*/,
+                                      GLsizei baseWidth, GLsizei baseHeight,
+                                      GLsizei /*baseDepth*/,
+                                      WebGLTexImageFunc func,
+                                      WebGLTexDimensions dims)
 {
     /* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
      *   "Taking wt and ht to be the specified width and height of the
      *   texture array, and taking x, y, w, and h to be the xoffset,
      *   yoffset, width, and height argument values, any of the
      *   following relationships generates the error INVALID_VALUE:
      *       x < 0
      *       x + w > wt
      *       y < 0
      *       y + h > ht"
      */
 
     if (xoffset < 0) {
-        ErrorInvalidValue("%s: xoffset must be >= 0", InfoFrom(func, dims));
+        ErrorInvalidValue("%s: xoffset must be >= 0.", InfoFrom(func, dims));
         return false;
     }
 
     if (yoffset < 0) {
-        ErrorInvalidValue("%s: yoffset must be >= 0", InfoFrom(func, dims));
+        ErrorInvalidValue("%s: yoffset must be >= 0.", InfoFrom(func, dims));
         return false;
     }
 
-    if (!CanvasUtils::CheckSaneSubrectSize(xoffset, yoffset, width, height, baseWidth, baseHeight)) {
-        ErrorInvalidValue("%s: subtexture rectangle out-of-bounds", InfoFrom(func, dims));
+    if (!CanvasUtils::CheckSaneSubrectSize(xoffset, yoffset, width, height,
+                                           baseWidth, baseHeight))
+    {
+        ErrorInvalidValue("%s: Subtexture rectangle out-of-bounds.",
+                          InfoFrom(func, dims));
         return false;
     }
 
     return true;
 }
 
 /**
  * Perform validation of format/type combinations for TexImage variants.
  * Returns true if the format/type is a valid combination, false otherwise.
  */
 bool
-WebGLContext::ValidateTexImageFormatAndType(GLenum format,
-                                            GLenum type,
+WebGLContext::ValidateTexImageFormatAndType(GLenum format, GLenum type,
                                             WebGLTexImageFunc func,
                                             WebGLTexDimensions dims)
 {
-    if (IsCompressedFunc(func) || IsCopyFunc(func))
-    {
+    if (IsCompressedFunc(func) || IsCopyFunc(func)) {
         MOZ_ASSERT(type == LOCAL_GL_NONE && format == LOCAL_GL_NONE);
         return true;
     }
+
     if (!ValidateTexImageFormat(format, func, dims) ||
         !ValidateTexImageType(type, func, dims))
     {
         return false;
     }
 
     // Here we're reinterpreting format as an unsized internalformat;
     // these are the same in practice and there's no point in having the
     // same code implemented twice.
     TexInternalFormat effective =
         EffectiveInternalFormatFromInternalFormatAndType(format, type);
-    bool validCombo = effective != LOCAL_GL_NONE;
+
+    if (effective != LOCAL_GL_NONE)
+        return true;
 
-    if (!validCombo)
-        ErrorInvalidOperation("%s: invalid combination of format %s and type %s",
-                              InfoFrom(func, dims), WebGLContext::EnumName(format), WebGLContext::EnumName(type));
-
-    return validCombo;
+    ErrorInvalidOperation("%s: Invalid combination of format %s and type %s.",
+                          InfoFrom(func, dims), WebGLContext::EnumName(format),
+                          WebGLContext::EnumName(type));
+    return false;
 }
 
 bool
 WebGLContext::ValidateCompTexImageInternalFormat(GLenum format,
                                                  WebGLTexImageFunc func,
                                                  WebGLTexDimensions dims)
 {
     if (!IsCompressedTextureFormat(format)) {
-        ErrorInvalidEnum("%s: invalid compressed texture format: %s",
+        ErrorInvalidEnum("%s: Invalid compressed texture format: %s",
                          InfoFrom(func, dims), WebGLContext::EnumName(format));
         return false;
     }
 
     /* WEBGL_compressed_texture_atc added formats */
     if (format == LOCAL_GL_ATC_RGB ||
         format == LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA ||
         format == LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA)
     {
-        bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_atc);
-        if (!validFormat)
-            ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_atc enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(format));
-        return validFormat;
+        if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_atc))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid format %s: Requires that"
+                         " WEBGL_compressed_texture_atc is enabled.",
+                         InfoFrom(func, dims), WebGLContext::EnumName(format));
+        return false;
     }
 
     // WEBGL_compressed_texture_etc1
     if (format == LOCAL_GL_ETC1_RGB8_OES) {
-        bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_etc1);
-        if (!validFormat)
-            ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_etc1 enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(format));
-        return validFormat;
+        if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_etc1))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid format %s: Requires that"
+                         " WEBGL_compressed_texture_etc1 is enabled.",
+                         InfoFrom(func, dims), WebGLContext::EnumName(format));
+        return false;
     }
 
 
     if (format == LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1 ||
         format == LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1 ||
         format == LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1 ||
         format == LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1)
     {
-        bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_pvrtc);
-        if (!validFormat)
-            ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_pvrtc enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(format));
-        return validFormat;
+        if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_pvrtc))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid format %s: Requires that"
+                         " WEBGL_compressed_texture_pvrtc is enabled.",
+                         InfoFrom(func, dims), WebGLContext::EnumName(format));
+        return false;
     }
 
 
     if (format == LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
         format == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
         format == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
         format == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
     {
-        bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_s3tc);
-        if (!validFormat)
-            ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_s3tc enabled",
-                             InfoFrom(func, dims), WebGLContext::EnumName(format));
-        return validFormat;
+        if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_s3tc))
+            return true;
+
+        ErrorInvalidEnum("%s: Invalid format %s: Requires that"
+                         " WEBGL_compressed_texture_s3tc is enabled.",
+                         InfoFrom(func, dims), WebGLContext::EnumName(format));
+        return false;
     }
 
+    MOZ_ASSERT(false);
     return false;
 }
 
 bool
 WebGLContext::ValidateCopyTexImageInternalFormat(GLenum format,
                                                  WebGLTexImageFunc func,
                                                  WebGLTexDimensions dims)
 {
-    bool valid = format == LOCAL_GL_RGBA ||
-                 format == LOCAL_GL_RGB ||
-                 format == LOCAL_GL_LUMINANCE_ALPHA ||
-                 format == LOCAL_GL_LUMINANCE ||
-                 format == LOCAL_GL_ALPHA;
-    if (!valid)
-    {
-        // in CopyTexImage, the internalformat is a function parameter,
-        // so a bad value is an INVALID_ENUM error.
-        // in CopyTexSubImage, the internalformat is part of existing state,
-        // so this is an INVALID_OPERATION error.
-        GenerateWarning("%s: invalid texture internal format: %s",
-                        InfoFrom(func, dims), WebGLContext::EnumName(format));
-        SynthesizeGLError(func == WebGLTexImageFunc::CopyTexImage
-                          ? LOCAL_GL_INVALID_ENUM
-                          : LOCAL_GL_INVALID_OPERATION);
+    switch (format) {
+    case LOCAL_GL_RGBA:
+    case LOCAL_GL_RGB:
+    case LOCAL_GL_LUMINANCE_ALPHA:
+    case LOCAL_GL_LUMINANCE:
+    case LOCAL_GL_ALPHA:
+        return true;
     }
-    return valid;
+    // In CopyTexImage, internalFormat is a function parameter,
+    // so a bad value is an INVALID_ENUM error.
+    // In CopyTexSubImage, internalFormat is part of existing state,
+    // so this is an INVALID_OPERATION error.
+    GenerateWarning("%s: Invalid texture internal format: %s",
+                    InfoFrom(func, dims), WebGLContext::EnumName(format));
+
+    GLenum error;
+    if (func == WebGLTexImageFunc::CopyTexImage)
+        error = LOCAL_GL_INVALID_ENUM;
+    else
+        error = LOCAL_GL_INVALID_OPERATION;
+
+    SynthesizeGLError(error);
+    return false;
 }
 /**
  * Return true if format, type and jsArrayType are a valid combination.
  * Also returns the size for texel of format and type (in bytes) via
  * \a texelSize.
  *
  * It is assumed that type has previously been validated.
  */
 bool
-WebGLContext::ValidateTexInputData(GLenum type,
-                                   js::Scalar::Type jsArrayType,
+WebGLContext::ValidateTexInputData(GLenum type, js::Scalar::Type jsArrayType,
                                    WebGLTexImageFunc func,
                                    WebGLTexDimensions dims)
 {
-    bool validInput = false;
-    const char invalidTypedArray[] = "%s: invalid typed array type for given texture data type";
+    // We're using js::Scalar::TypeMax as dummy value for when the tex source
+    // wasn't a typed array.
+    if (jsArrayType == js::Scalar::TypeMax)
+        return true;
 
-    // We're using js::Scalar::TypeMax as dummy value when the tex source wasn't a
-    // typed array.
-    if (jsArrayType == js::Scalar::TypeMax) {
-        return true;
-    }
+    const char invalidTypedArray[] = "%s: Invalid typed array type for given"
+                                     " texture data type.";
 
-    // First, we check for packed types
+    bool validInput = false;
     switch (type) {
     case LOCAL_GL_UNSIGNED_BYTE:
         validInput = jsArrayType == js::Scalar::Uint8;
         break;
 
     case LOCAL_GL_BYTE:
         validInput = jsArrayType == js::Scalar::Int8;
         break;
@@ -1197,245 +1267,275 @@ WebGLContext::ValidateTexInputData(GLenu
 
     return validInput;
 }
 
 /**
  * Checks specific for the CopyTex[Sub]Image2D functions.
  * Verifies:
  * - Framebuffer is complete and has valid read planes
- * - Copy format is a subset of framebuffer format (i.e. all required components are available)
+ * - Copy format is a subset of framebuffer format (i.e. all required components
+ *   are available)
  */
 bool
-WebGLContext::ValidateCopyTexImage(GLenum format,
-                                   WebGLTexImageFunc func,
+WebGLContext::ValidateCopyTexImage(GLenum format, WebGLTexImageFunc func,
                                    WebGLTexDimensions dims)
 {
     MOZ_ASSERT(IsCopyFunc(func));
 
     // Default framebuffer format
     GLenum fboFormat = mOptions.alpha ? LOCAL_GL_RGBA : LOCAL_GL_RGB;
 
     if (mBoundFramebuffer) {
         if (!mBoundFramebuffer->CheckAndInitializeAttachments()) {
-            ErrorInvalidFramebufferOperation("%s: incomplete framebuffer", InfoFrom(func, dims));
+            ErrorInvalidFramebufferOperation("%s: Incomplete framebuffer.",
+                                             InfoFrom(func, dims));
             return false;
         }
 
         GLenum readPlaneBits = LOCAL_GL_COLOR_BUFFER_BIT;
         if (!mBoundFramebuffer->HasCompletePlanes(readPlaneBits)) {
             ErrorInvalidOperation("%s: Read source attachment doesn't have the"
-                                  " correct color/depth/stencil type.", InfoFrom(func, dims));
+                                  " correct color/depth/stencil type.",
+                                  InfoFrom(func, dims));
             return false;
         }
 
-        // Get the correct format for the framebuffer, as it's not the default one
-        const WebGLFramebuffer::Attachment& color0 = mBoundFramebuffer->GetAttachment(LOCAL_GL_COLOR_ATTACHMENT0);
+        // Get the correct format for the framebuffer, as it's not the default
+        // one.
+        const WebGLFramebuffer::Attachment& color0 =
+            mBoundFramebuffer->GetAttachment(LOCAL_GL_COLOR_ATTACHMENT0);
+
         fboFormat = mBoundFramebuffer->GetFormatForAttachment(color0);
     }
 
-    // Make sure the format of the framebuffer is a superset of
-    // the format requested by the CopyTex[Sub]Image2D functions.
+    // Make sure the format of the framebuffer is a superset of the format
+    // requested by the CopyTex[Sub]Image2D functions.
     const GLComponents formatComps = GLComponents(format);
     const GLComponents fboComps = GLComponents(fboFormat);
     if (!formatComps.IsSubsetOf(fboComps)) {
-        ErrorInvalidOperation("%s: format %s is not a subset of the current framebuffer format, which is %s.",
-                              InfoFrom(func, dims), EnumName(format), EnumName(fboFormat));
+        ErrorInvalidOperation("%s: Format %s is not a subset of the current"
+                              " framebuffer format, which is %s.",
+                              InfoFrom(func, dims), EnumName(format),
+                              EnumName(fboFormat));
         return false;
     }
 
     return true;
 }
 
 /**
  * Test the gl(Copy|Compressed)?Tex[Sub]?Image[23]() parameters for errors.
- * Verifies each of the parameters against the WebGL standard and enabled extensions.
+ * Verifies each of the parameters against the WebGL standard and enabled
+ * extensions.
  */
 // TODO: Texture dims is here for future expansion in WebGL 2.0
 bool
-WebGLContext::ValidateTexImage(TexImageTarget texImageTarget,
-                               GLint level,
-                               GLenum internalFormat,
-                               GLint xoffset, GLint yoffset, GLint zoffset,
-                               GLint width, GLint height, GLint depth,
-                               GLint border,
-                               GLenum format,
-                               GLenum type,
+WebGLContext::ValidateTexImage(TexImageTarget texImageTarget, GLint level,
+                               GLenum internalFormat, GLint xoffset,
+                               GLint yoffset, GLint zoffset, GLint width,
+                               GLint height, GLint depth, GLint border,
+                               GLenum format, GLenum type,
                                WebGLTexImageFunc func,
                                WebGLTexDimensions dims)
 {
     const char* info = InfoFrom(func, dims);
 
-    /* Check level */
+    // Check level
     if (level < 0) {
-        ErrorInvalidValue("%s: level must be >= 0", info);
+        ErrorInvalidValue("%s: `level` must be >= 0.", info);
         return false;
     }
 
-    /* Check border */
+    // Check border
     if (border != 0) {
-        ErrorInvalidValue("%s: border must be 0", info);
+        ErrorInvalidValue("%s: `border` must be 0.", info);
         return false;
     }
 
-    /* Check incoming image format and type */
+    // Check incoming image format and type
     if (!ValidateTexImageFormatAndType(format, type, func, dims))
         return false;
 
     if (!TexInternalFormat::IsValueLegal(internalFormat)) {
-        ErrorInvalidEnum("%s: invalid internalformat enum %s", info, EnumName(internalFormat));
+        ErrorInvalidEnum("%s: Invalid `internalformat` enum %s.", info,
+                         EnumName(internalFormat));
         return false;
     }
     TexInternalFormat unsizedInternalFormat =
         UnsizedInternalFormatFromInternalFormat(internalFormat);
 
     if (IsCompressedFunc(func)) {
-        if (!ValidateCompTexImageInternalFormat(internalFormat, func, dims)) {
+        if (!ValidateCompTexImageInternalFormat(internalFormat, func, dims))
             return false;
-        }
+
     } else if (IsCopyFunc(func)) {
-        if (!ValidateCopyTexImageInternalFormat(unsizedInternalFormat.get(), func, dims)) {
+        if (!ValidateCopyTexImageInternalFormat(unsizedInternalFormat.get(),
+                                                func, dims))
+        {
             return false;
         }
     } else if (format != unsizedInternalFormat) {
         if (IsWebGL2()) {
-            // In WebGL2, it's OK to have internalformat != format if internalformat is the sized
-            // internal format corresponding to the (format, type) pair according to Table 3.2
-            // in the OpenGL ES 3.0.3 spec.
-            if (internalFormat != EffectiveInternalFormatFromInternalFormatAndType(format, type)) {
+            // In WebGL2, it's OK to have `internalFormat != format` if
+            // internalFormat is the sized internal format corresponding to the
+            // (format, type) pair according to Table 3.2 in the OpenGL ES 3.0.3
+            // spec.
+            auto effectiveFormat = EffectiveInternalFormatFromInternalFormatAndType(format,
+                                                                                    type);
+            if (internalFormat != effectiveFormat) {
                 bool exceptionallyAllowed = false;
                 if (internalFormat == LOCAL_GL_SRGB8_ALPHA8 &&
                     format == LOCAL_GL_RGBA &&
                     type == LOCAL_GL_UNSIGNED_BYTE)
                 {
                     exceptionallyAllowed = true;
                 }
                 else if (internalFormat == LOCAL_GL_SRGB8 &&
                          format == LOCAL_GL_RGB &&
                          type == LOCAL_GL_UNSIGNED_BYTE)
                 {
                     exceptionallyAllowed = true;
                 }
                 if (!exceptionallyAllowed) {
-                    ErrorInvalidOperation("%s: internalformat does not match format and type", info);
+                    ErrorInvalidOperation("%s: `internalformat` does not match"
+                                          " `format` and `type`.", info);
                     return false;
                 }
             }
         } else {
-            // in WebGL 1, format must be equal to internalformat
-            ErrorInvalidOperation("%s: internalformat does not match format", info);
+            // In WebGL 1, format must be equal to internalformat.
+            ErrorInvalidOperation("%s: `internalformat` does not match"
+                                  " `format`.", info);
             return false;
         }
     }
 
-    /* Check texture image size */
-    if (!ValidateTexImageSize(texImageTarget, level, width, height, 0, func, dims))
+    // Check texture image size
+    if (!ValidateTexImageSize(texImageTarget, level, width, height, 0, func,
+                              dims))
+    {
         return false;
+    }
 
     /* 5.14.8 Texture objects - WebGL Spec.
      *   "If an attempt is made to call these functions with no
      *    WebGLTexture bound (see above), an INVALID_OPERATION error
      *    is generated."
      */
-    WebGLTexture* tex = activeBoundTextureForTexImageTarget(texImageTarget);
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
     if (!tex) {
-        ErrorInvalidOperation("%s: no texture is bound to target %s",
-                              info, WebGLContext::EnumName(texImageTarget.get()));
+        ErrorInvalidOperation("%s: No texture is bound to target %s.", info,
+                              WebGLContext::EnumName(texImageTarget.get()));
         return false;
     }
 
     if (IsSubFunc(func)) {
         if (!tex->HasImageInfoAt(texImageTarget, level)) {
-            ErrorInvalidOperation("%s: no texture image previously defined for target %s at level %d",
-                                  info, WebGLContext::EnumName(texImageTarget.get()), level);
+            ErrorInvalidOperation("%s: No texture image previously defined for"
+                                  " target %s at level %d.", info,
+                                  WebGLContext::EnumName(texImageTarget.get()),
+                                                         level);
             return false;
         }
 
-        const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level);
-
-        if (!ValidateTexSubImageSize(xoffset, yoffset, zoffset,
-                                     width, height, depth,
-                                     imageInfo.Width(), imageInfo.Height(), 0,
-                                     func, dims))
+        const auto& imageInfo = tex->ImageInfoAt(texImageTarget, level);
+        if (!ValidateTexSubImageSize(xoffset, yoffset, zoffset, width, height,
+                                     depth, imageInfo.Width(),
+                                     imageInfo.Height(), 0, func, dims))
         {
             return false;
         }
     }
 
-    /* Additional checks for depth textures */
+    // Additional checks for depth textures
     if (texImageTarget != LOCAL_GL_TEXTURE_2D &&
         (format == LOCAL_GL_DEPTH_COMPONENT ||
          format == LOCAL_GL_DEPTH_STENCIL))
     {
-        ErrorInvalidOperation("%s: with format of %s target must be TEXTURE_2D",
+        ErrorInvalidOperation("%s: With format of %s, target must be"
+                              " TEXTURE_2D.", info,
+                              WebGLContext::EnumName(format));
+        return false;
+    }
+
+    // Additional checks for compressed textures
+    if (!IsAllowedFromSource(internalFormat, func)) {
+        ErrorInvalidOperation("%s: Invalid format %s for this operation.",
                               info, WebGLContext::EnumName(format));
         return false;
     }
 
-    /* Additional checks for compressed textures */
-    if (!IsAllowedFromSource(internalFormat, func)) {
-        ErrorInvalidOperation("%s: Invalid format %s for this operation",
-                              info, WebGLContext::EnumName(format));
-        return false;
-    }
-
-    /* Parameters are OK */
+    // Parameters are OK
     return true;
 }
 
 bool
-WebGLContext::ValidateUniformLocation(const char* info, WebGLUniformLocation *location_object)
+WebGLContext::ValidateUniformLocation(const char* info,
+                                      WebGLUniformLocation* loc)
 {
-    if (!ValidateObjectAllowNull(info, location_object))
+    if (!ValidateObjectAllowNull(info, loc))
         return false;
-    if (!location_object)
+
+    if (!loc)
         return false;
-    /* the need to check specifically for !mCurrentProgram here is explained in bug 657556 */
+
+    // The need to check specifically for !mCurrentProgram here is explained in
+    // bug 657556.
     if (!mCurrentProgram) {
-        ErrorInvalidOperation("%s: no program is currently bound", info);
+        ErrorInvalidOperation("%s: No program is currently bound.", info);
         return false;
     }
-    if (mCurrentProgram != location_object->Program()) {
-        ErrorInvalidOperation("%s: this uniform location doesn't correspond to the current program", info);
+
+    if (mCurrentProgram != loc->Program()) {
+        ErrorInvalidOperation("%s: This uniform location doesn't correspond to"
+                              " the current program.", info);
         return false;
     }
-    if (mCurrentProgram->Generation() != location_object->ProgramGeneration()) {
-        ErrorInvalidOperation("%s: This uniform location is obsolete since the program has been relinked", info);
+
+    if (mCurrentProgram->Generation() != loc->ProgramGeneration()) {
+        ErrorInvalidOperation("%s: This uniform location is obsolete since the"
+                              " program has been relinked.", info);
         return false;
     }
+
     return true;
 }
 
 bool
-WebGLContext::ValidateSamplerUniformSetter(const char* info, WebGLUniformLocation *location, GLint value)
+WebGLContext::ValidateSamplerUniformSetter(const char* info,
+                                           WebGLUniformLocation* loc,
+                                           GLint value)
 {
-    if (location->Info().type != LOCAL_GL_SAMPLER_2D &&
-        location->Info().type != LOCAL_GL_SAMPLER_CUBE)
+    if (loc->Info().type != LOCAL_GL_SAMPLER_2D &&
+        loc->Info().type != LOCAL_GL_SAMPLER_CUBE)
     {
         return true;
     }
 
     if (value >= 0 && value < mGLMaxTextureUnits)
         return true;
 
-    ErrorInvalidValue("%s: this uniform location is a sampler, but %d is not a valid texture unit",
-                      info, value);
+    ErrorInvalidValue("%s: This uniform location is a sampler, but %d is not a"
+                      " valid texture unit.", info, value);
     return false;
 }
 
 bool
-WebGLContext::ValidateAttribArraySetter(const char* name, uint32_t cnt, uint32_t arrayLength)
+WebGLContext::ValidateAttribArraySetter(const char* name, uint32_t cnt,
+                                        uint32_t arrayLength)
 {
-    if (IsContextLost()) {
+    if (IsContextLost())
+        return false;
+
+    if (arrayLength < cnt) {
+        ErrorInvalidOperation("%s: Array must be >= %d elements.", name, cnt);
         return false;
     }
-    if (arrayLength < cnt) {
-        ErrorInvalidOperation("%s: array must be >= %d elements", name, cnt);
-        return false;
-    }
+
     return true;
 }
 
 static bool
 IsUniformSetterTypeValid(GLenum setterType, GLenum uniformType)
 {
     switch (uniformType) {
     case LOCAL_GL_BOOL:
@@ -1529,20 +1629,22 @@ WebGLContext::ValidateUniformSetter(WebG
         return false;
 
     *out_rawLoc = loc->Location();
     return true;
 }
 
 bool
 WebGLContext::ValidateUniformArraySetter(WebGLUniformLocation* loc,
-                                         uint8_t setterElemSize, GLenum setterType,
+                                         uint8_t setterElemSize,
+                                         GLenum setterType,
                                          size_t setterArraySize,
-                                         const char* info, GLuint* out_rawLoc,
-                                         GLsizei* out_numElementsToUpload)
+                                         const char* info,
+                                         GLuint* const out_rawLoc,
+                                         GLsizei* const out_numElementsToUpload)
 {
     if (IsContextLost())
         return false;
 
     if (!ValidateUniformLocation(info, loc))
         return false;
 
     if (!CheckUniformSizeAndType(*this, loc, setterElemSize, setterType, info))
@@ -1562,18 +1664,18 @@ WebGLContext::ValidateUniformArraySetter
 
 bool
 WebGLContext::ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
                                                uint8_t setterDims,
                                                GLenum setterType,
                                                size_t setterArraySize,
                                                bool setterTranspose,
                                                const char* info,
-                                               GLuint* out_rawLoc,
-                                               GLsizei* out_numElementsToUpload)
+                                               GLuint* const out_rawLoc,
+                                               GLsizei* const out_numElementsToUpload)
 {
     uint8_t setterElemSize = setterDims * setterDims;
 
     if (IsContextLost())
         return false;
 
     if (!ValidateUniformLocation(info, loc))
         return false;
@@ -1593,66 +1695,74 @@ WebGLContext::ValidateUniformMatrixArray
     }
 
     *out_rawLoc = loc->Location();
     *out_numElementsToUpload = std::min((size_t)loc->Info().arraySize,
                                         setterArraySize / setterElemSize);
     return true;
 }
 
-bool WebGLContext::ValidateStencilParamsForDrawCall()
+bool
+WebGLContext::ValidateStencilParamsForDrawCall()
 {
-  const char *msg = "%s set different front and back stencil %s. Drawing in this configuration is not allowed.";
-  if (mStencilRefFront != mStencilRefBack) {
-      ErrorInvalidOperation(msg, "stencilFuncSeparate", "reference values");
-      return false;
-  }
-  if (mStencilValueMaskFront != mStencilValueMaskBack) {
-      ErrorInvalidOperation(msg, "stencilFuncSeparate", "value masks");
-      return false;
-  }
-  if (mStencilWriteMaskFront != mStencilWriteMaskBack) {
-      ErrorInvalidOperation(msg, "stencilMaskSeparate", "write masks");
-      return false;
-  }
-  return true;
+    const char msg[] = "%s set different front and back stencil %s. Drawing in"
+                       " this configuration is not allowed.";
+
+    if (mStencilRefFront != mStencilRefBack) {
+        ErrorInvalidOperation(msg, "stencilFuncSeparate", "reference values");
+        return false;
+    }
+
+    if (mStencilValueMaskFront != mStencilValueMaskBack) {
+        ErrorInvalidOperation(msg, "stencilFuncSeparate", "value masks");
+        return false;
+    }
+
+    if (mStencilWriteMaskFront != mStencilWriteMaskBack) {
+        ErrorInvalidOperation(msg, "stencilMaskSeparate", "write masks");
+        return false;
+    }
+
+    return true;
 }
 
-static inline int32_t floorPOT(int32_t x)
+static inline int32_t
+FloorPOT(int32_t x)
 {
     MOZ_ASSERT(x > 0);
     int32_t pot = 1;
     while (pot < 0x40000000) {
         if (x < pot*2)
             break;
         pot *= 2;
     }
     return pot;
 }
 
 bool
 WebGLContext::InitAndValidateGL()
 {
-    if (!gl) return false;
+    if (!gl)
+        return false;
 
     GLenum error = gl->fGetError();
     if (error != LOCAL_GL_NO_ERROR) {
-        GenerateWarning("GL error 0x%x occurred during OpenGL context initialization, before WebGL initialization!", error);
+        GenerateWarning("GL error 0x%x occurred during OpenGL context"
+                        " initialization, before WebGL initialization!", error);
         return false;
     }
 
     mMinCapability = Preferences::GetBool("webgl.min_capability_mode", false);
     mDisableExtensions = Preferences::GetBool("webgl.disable-extensions", false);
     mLoseContextOnMemoryPressure = Preferences::GetBool("webgl.lose-context-on-memory-pressure", false);
     mCanLoseContextInForeground = Preferences::GetBool("webgl.can-lose-context-in-foreground", true);
     mRestoreWhenVisible = Preferences::GetBool("webgl.restore-context-when-visible", true);
 
-    if (MinCapabilityMode()) {
-      mDisableFragHighP = true;
-    }
+    if (MinCapabilityMode())
+        mDisableFragHighP = true;
 
     // These are the default values, see 6.2 State tables in the
     // OpenGL ES 2.0.25 spec.
     mColorWriteMask[0] = 1;
     mColorWriteMask[1] = 1;
     mColorWriteMask[2] = 1;
     mColorWriteMask[3] = 1;
     mDepthWriteMask = 1;
@@ -1706,40 +1816,41 @@ WebGLContext::InitAndValidateGL()
     mCurrentProgram = nullptr;
 
     mBoundFramebuffer = nullptr;
     mBoundRenderbuffer = nullptr;
 
     MakeContextCurrent();
 
     // on desktop OpenGL, we always keep vertex attrib 0 array enabled
-    if (!gl->IsGLES()) {
+    if (!gl->IsGLES())
         gl->fEnableVertexAttribArray(0);
-    }
 
-    if (MinCapabilityMode()) {
+    if (MinCapabilityMode())
         mGLMaxVertexAttribs = MINVALUE_GL_MAX_VERTEX_ATTRIBS;
-    } else {
+    else
         gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_ATTRIBS, &mGLMaxVertexAttribs);
-    }
+
     if (mGLMaxVertexAttribs < 8) {
-        GenerateWarning("GL_MAX_VERTEX_ATTRIBS: %d is < 8!", mGLMaxVertexAttribs);
+        GenerateWarning("GL_MAX_VERTEX_ATTRIBS: %d is < 8!",
+                        mGLMaxVertexAttribs);
         return false;
     }
 
     // Note: GL_MAX_TEXTURE_UNITS is fixed at 4 for most desktop hardware,
     // even though the hardware supports much more.  The
     // GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS value is the accurate value.
-    if (MinCapabilityMode()) {
+    if (MinCapabilityMode())
         mGLMaxTextureUnits = MINVALUE_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS;
-    } else {
+    else
         gl->fGetIntegerv(LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGLMaxTextureUnits);
-    }
+
     if (mGLMaxTextureUnits < 8) {
-        GenerateWarning("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d is < 8!", mGLMaxTextureUnits);
+        GenerateWarning("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d is < 8!",
+                        mGLMaxTextureUnits);
         return false;
     }
 
     mBound2DTextures.SetLength(mGLMaxTextureUnits);
     mBoundCubeMapTextures.SetLength(mGLMaxTextureUnits);
     mBound3DTextures.SetLength(mGLMaxTextureUnits);
 
     if (MinCapabilityMode()) {
@@ -1764,108 +1875,120 @@ WebGLContext::InitAndValidateGL()
     }
 
     mGLMaxCubeMapTextureSizeLog2 = 0;
     tempSize = mGLMaxCubeMapTextureSize;
     while (tempSize >>= 1) {
         ++mGLMaxCubeMapTextureSizeLog2;
     }
 
-    mGLMaxTextureSize = floorPOT(mGLMaxTextureSize);
-    mGLMaxRenderbufferSize = floorPOT(mGLMaxRenderbufferSize);
+    mGLMaxTextureSize = FloorPOT(mGLMaxTextureSize);
+    mGLMaxRenderbufferSize = FloorPOT(mGLMaxRenderbufferSize);
 
     if (MinCapabilityMode()) {
         mGLMaxFragmentUniformVectors = MINVALUE_GL_MAX_FRAGMENT_UNIFORM_VECTORS;
         mGLMaxVertexUniformVectors = MINVALUE_GL_MAX_VERTEX_UNIFORM_VECTORS;
         mGLMaxVaryingVectors = MINVALUE_GL_MAX_VARYING_VECTORS;
     } else {
         if (gl->IsSupported(gl::GLFeature::ES2_compatibility)) {
             gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGLMaxFragmentUniformVectors);
             gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_VECTORS, &mGLMaxVertexUniformVectors);
             gl->fGetIntegerv(LOCAL_GL_MAX_VARYING_VECTORS, &mGLMaxVaryingVectors);
         } else {
             gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &mGLMaxFragmentUniformVectors);
             mGLMaxFragmentUniformVectors /= 4;
             gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_COMPONENTS, &mGLMaxVertexUniformVectors);
             mGLMaxVertexUniformVectors /= 4;
 
-            // we are now going to try to read GL_MAX_VERTEX_OUTPUT_COMPONENTS and GL_MAX_FRAGMENT_INPUT_COMPONENTS,
-            // however these constants only entered the OpenGL standard at OpenGL 3.2. So we will try reading,
-            // and check OpenGL error for INVALID_ENUM.
-
-            // On the public_webgl list, "problematic GetParameter pnames" thread, the following formula was given:
-            //   mGLMaxVaryingVectors = min (GL_MAX_VERTEX_OUTPUT_COMPONENTS, GL_MAX_FRAGMENT_INPUT_COMPONENTS) / 4
+            /* We are now going to try to read GL_MAX_VERTEX_OUTPUT_COMPONENTS
+             * and GL_MAX_FRAGMENT_INPUT_COMPONENTS, however these constants
+             * only entered the OpenGL standard at OpenGL 3.2. So we will try
+             * reading, and check OpenGL error for INVALID_ENUM.
+             *
+             * On the public_webgl list, "problematic GetParameter pnames"
+             * thread, the following formula was given:
+             *   maxVaryingVectors = min(GL_MAX_VERTEX_OUTPUT_COMPONENTS,
+             *                           GL_MAX_FRAGMENT_INPUT_COMPONENTS) / 4
+             */
             GLint maxVertexOutputComponents = 0;
             GLint maxFragmentInputComponents = 0;
 
             const bool ok = (gl->GetPotentialInteger(LOCAL_GL_MAX_VERTEX_OUTPUT_COMPONENTS,
                                                      &maxVertexOutputComponents) &&
                              gl->GetPotentialInteger(LOCAL_GL_MAX_FRAGMENT_INPUT_COMPONENTS,
                                                      &maxFragmentInputComponents));
 
             if (ok) {
                 mGLMaxVaryingVectors = std::min(maxVertexOutputComponents,
                                                 maxFragmentInputComponents) / 4;
             } else {
                 mGLMaxVaryingVectors = 16;
-                // = 64/4, 64 is the min value for maxVertexOutputComponents in OpenGL 3.2 spec
+                // 16 = 64/4, and 64 is the min value for
+                // maxVertexOutputComponents in the OpenGL 3.2 spec.
             }
         }
     }
 
     // Always 1 for GLES2
     mMaxFramebufferColorAttachments = 1;
 
     if (!gl->IsGLES()) {
         // gl_PointSize is always available in ES2 GLSL, but has to be
         // specifically enabled on desktop GLSL.
         gl->fEnable(LOCAL_GL_VERTEX_PROGRAM_POINT_SIZE);
 
-        // gl_PointCoord is always available in ES2 GLSL and in newer desktop GLSL versions, but apparently
-        // not in OpenGL 2 and apparently not (due to a driver bug) on certain NVIDIA setups. See:
-        //   http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=261472
-        // Note that this used to cause crashes on old ATI drivers... hopefully not a significant
-        // problem anymore. See bug 602183.
+        /* gl_PointCoord is always available in ES2 GLSL and in newer desktop
+         * GLSL versions, but apparently not in OpenGL 2 and apparently not (due
+         * to a driver bug) on certain NVIDIA setups. See:
+         *   http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=261472
+         *
+         * Note that this used to cause crashes on old ATI drivers... Hopefully
+         * not a significant anymore. See bug 602183.
+         */
         gl->fEnable(LOCAL_GL_POINT_SPRITE);
     }
 
 #ifdef XP_MACOSX
     if (gl->WorkAroundDriverBugs() &&
         gl->Vendor() == gl::GLVendor::ATI &&
         !nsCocoaFeatures::IsAtLeastVersion(10,9))
     {
-        // The Mac ATI driver, in all known OSX version up to and including 10.8,
-        // renders points sprites upside-down. Apple bug 11778921
-        gl->fPointParameterf(LOCAL_GL_POINT_SPRITE_COORD_ORIGIN, LOCAL_GL_LOWER_LEFT);
+        // The Mac ATI driver, in all known OSX version up to and including
+        // 10.8, renders points sprites upside-down. (Apple bug 11778921)
+        gl->fPointParameterf(LOCAL_GL_POINT_SPRITE_COORD_ORIGIN,
+                             LOCAL_GL_LOWER_LEFT);
     }
 #endif
 
     // Check the shader validator pref
     NS_ENSURE_TRUE(Preferences::GetRootBranch(), false);
 
-    mShaderValidation =
-        Preferences::GetBool("webgl.shader_validator", mShaderValidation);
+    mShaderValidation = Preferences::GetBool("webgl.shader_validator",
+                                             mShaderValidation);
 
     // initialize shader translator
     if (mShaderValidation) {
         if (!ShInitialize()) {
             GenerateWarning("GLSL translator initialization failed!");
             return false;
         }
     }
 
-    // Mesa can only be detected with the GL_VERSION string, of the form "2.1 Mesa 7.11.0"
-    mIsMesa = strstr((const char *)(gl->fGetString(LOCAL_GL_VERSION)), "Mesa");
+    // Mesa can only be detected with the GL_VERSION string, of the form
+    // "2.1 Mesa 7.11.0"
+    const char* versionStr = (const char*)(gl->fGetString(LOCAL_GL_VERSION));
+    mIsMesa = strstr(versionStr, "Mesa");
 
     // Notice that the point of calling fGetError here is not only to check for
     // errors, but also to reset the error flags so that a subsequent WebGL
     // getError call will give the correct result.
     error = gl->fGetError();
     if (error != LOCAL_GL_NO_ERROR) {
-        GenerateWarning("GL error 0x%x occurred during WebGL context initialization!", error);
+        GenerateWarning("GL error 0x%x occurred during WebGL context"
+                        " initialization!", error);
         return false;
     }
 
     if (IsWebGL2() &&
         !InitWebGL2())
     {
         // Todo: Bug 898404: Only allow WebGL2 on GL>=3.0 on desktop GL.
         return false;
@@ -1875,14 +1998,15 @@ WebGLContext::InitAndValidateGL()
     for (int32_t index = 0; index < mGLMaxVertexAttribs; ++index) {
         VertexAttrib4f(index, 0, 0, 0, 1);
     }
 
     mDefaultVertexArray = WebGLVertexArray::Create(this);
     mDefaultVertexArray->mAttribs.SetLength(mGLMaxVertexAttribs);
     mBoundVertexArray = mDefaultVertexArray;
 
-    if (mLoseContextOnMemoryPressure) {
+    if (mLoseContextOnMemoryPressure)
         mContextObserver->RegisterMemoryPressureEvent();
-    }
 
     return true;
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContextVertexArray.cpp
+++ b/dom/canvas/WebGLContextVertexArray.cpp
@@ -1,23 +1,24 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
+
+#include "GLContext.h"
 #include "WebGLBuffer.h"
-#include "WebGLVertexAttribData.h"
 #include "WebGLVertexArray.h"
-#include "GLContext.h"
+#include "WebGLVertexAttribData.h"
 
-using namespace mozilla;
+namespace mozilla {
 
 void
-WebGLContext::BindVertexArray(WebGLVertexArray *array)
+WebGLContext::BindVertexArray(WebGLVertexArray* array)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array))
         return;
 
     if (array && array->IsDeleted()) {
@@ -54,17 +55,17 @@ WebGLContext::CreateVertexArray()
 
     MakeContextCurrent();
     globj->GenVertexArray();
 
     return globj.forget();
 }
 
 void
-WebGLContext::DeleteVertexArray(WebGLVertexArray *array)
+WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
 {
     if (IsContextLost())
         return;
 
     if (array == nullptr)
         return;
 
     if (array->IsDeleted())
@@ -72,20 +73,22 @@ WebGLContext::DeleteVertexArray(WebGLVer
 
     if (mBoundVertexArray == array)
         BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
 
     array->RequestDelete();
 }
 
 bool
-WebGLContext::IsVertexArray(WebGLVertexArray *array)
+WebGLContext::IsVertexArray(WebGLVertexArray* array)
 {
     if (IsContextLost())
         return false;
 
     if (!array)
         return false;
 
     return ValidateObjectAllowDeleted("isVertexArray", array) &&
            !array->IsDeleted() &&
            array->HasEverBeenBound();
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContextVertices.cpp
+++ b/dom/canvas/WebGLContextVertices.cpp
@@ -432,17 +432,17 @@ WebGLContext::VertexAttribPointer(GLuint
 
     InvalidateBufferFetching();
 
     /* XXX make work with bufferSubData & heterogeneous types
      if (type != mBoundArrayBuffer->GLType())
      return ErrorInvalidOperation("vertexAttribPointer: type must match bound VBO type: %d != %d", type, mBoundArrayBuffer->GLType());
      */
 
-    WebGLVertexAttribData &vd = mBoundVertexArray->mAttribs[index];
+    WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
 
     vd.buf = mBoundArrayBuffer;
     vd.stride = stride;
     vd.size = size;
     vd.byteOffset = byteOffset;
     vd.type = type;
     vd.normalized = normalized;
 
--- a/dom/canvas/WebGLElementArrayCache.cpp
+++ b/dom/canvas/WebGLElementArrayCache.cpp
@@ -1,592 +1,635 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLElementArrayCache.h"
 
-#include "mozilla/Assertions.h"
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/MathAlgorithms.h"
-
+#include <algorithm>
 #include <cstdlib>
 #include <cstring>
 #include <limits>
-#include <algorithm>
+#include "mozilla/Assertions.h"
+#include "mozilla/MathAlgorithms.h"
+#include "mozilla/MemoryReporting.h"
 
 namespace mozilla {
 
 static void
-UpdateUpperBound(uint32_t* out_upperBound, uint32_t newBound)
+UpdateUpperBound(uint32_t* const out_upperBound, uint32_t newBound)
 {
-  MOZ_ASSERT(out_upperBound);
-  *out_upperBound = std::max(*out_upperBound, newBound);
+    MOZ_ASSERT(out_upperBound);
+    *out_upperBound = std::max(*out_upperBound, newBound);
 }
 
-/*
- * WebGLElementArrayCacheTree contains most of the implementation of WebGLElementArrayCache,
- * which performs WebGL element array buffer validation for drawElements.
+/* WebGLElementArrayCacheTree contains most of the implementation of
+ * WebGLElementArrayCache, which performs WebGL element array buffer validation
+ * for drawElements.
  *
- * Attention: Here lie nontrivial data structures, bug-prone algorithms, and non-canonical tweaks!
- * Whence the explanatory comments, and compiled unit test.
+ * Attention: Here lie nontrivial data structures, bug-prone algorithms, and
+ * non-canonical tweaks! Whence the explanatory comments, and compiled unit
+ * test.
  *
  * *** What problem are we solving here? ***
  *
- * WebGL::DrawElements has to validate that the elements are in range wrt the current vertex attribs.
- * This boils down to the problem, given an array of integers, of computing the maximum in an arbitrary
- * sub-array. The naive algorithm has linear complexity; this has been a major performance problem,
- * see bug 569431. In that bug, we took the approach of caching the max for the whole array, which
- * does cover most cases (DrawElements typically consumes the whole element array buffer) but doesn't
- * help in other use cases:
- *  - when doing "partial DrawElements" i.e. consuming only part of the element array buffer
- *  - when doing frequent "partial buffer updates" i.e. bufferSubData calls updating parts of the
- *    element array buffer
+ * WebGL::DrawElements has to validate that the elements are in range wrt the
+ * current vertex attribs. This boils down to the problem, given an array of
+ * integers, of computing the maximum in an arbitrary sub-array. The naive
+ * algorithm has linear complexity; this has been a major performance problem,
+ * see bug 569431. In that bug, we took the approach of caching the max for the
+ * whole array, which does cover most cases (DrawElements typically consumes the
+ * whole element array buffer) but doesn't help in other use cases:
+ *  - when doing "partial DrawElements" i.e. consuming only part of the element
+ *    array buffer
+ *  - when doing frequent "partial buffer updates" i.e. bufferSubData calls
+ *    updating parts of the element array buffer
  *
- * *** The solution: a binary tree ***
- *
- * The solution implemented here is to use a binary tree as the cache data structure. Each tree node
- * contains the max of its two children nodes. In this way, finding the maximum in any contiguous sub-array
- * has log complexity instead of linear complexity.
+ * *** The solution: A binary tree ***
  *
- * Simplistically, if the element array is
+ * The solution implemented here is to use a binary tree as the cache data
+ * structure. Each tree node contains the max of its two children nodes. In this
+ * way, finding the maximum in any contiguous sub-array has log complexity
+ * instead of linear complexity.
  *
- *     1   4   3   2
+ * Simplistically, if the element array is:
  *
- * then the corresponding tree is
+ *    [1   4   3   2]
+ *
+ * then the corresponding tree is:
  *
  *           4
  *         _/ \_
  *       4       3
  *      / \     / \
  *     1   4   3   2
  *
- * In practice, the bottom-most levels of the tree are both the largest to store (because they
- * have more nodes), and the least useful performance-wise (because each node in the bottom
- * levels concerns only few entries in the elements array buffer, it is cheap to compute).
+ * In practice, the bottom-most levels of the tree are both the largest to store
+ * (because they have more nodes), and the least useful performance-wise
+ * (because each node in the bottom levels concerns only few entries in the
+ * elements array buffer, it is cheap to compute).
  *
- * For this reason, we stop the tree a few levels above, so that each tree leaf actually corresponds
- * to more than one element array entry.
+ * For this reason, we stop the tree a few levels above, so that each tree leaf
+ * actually corresponds to more than one element array entry.
  *
- * The number of levels that we "drop" is |sSkippedBottomTreeLevels| and the number of element array entries
- * that each leaf corresponds to, is |sElementsPerLeaf|. This being a binary tree, we have
+ * The number of levels that we "drop" is |kSkippedBottomTreeLevels| and the
+ * number of element array entries that each leaf corresponds to, is
+ * |kElementsPerLeaf|. This being a binary tree, we have:
  *
- *   sElementsPerLeaf = 2 ^ sSkippedBottomTreeLevels.
+ *   kElementsPerLeaf = 2 ^ kSkippedBottomTreeLevels.
  *
  * *** Storage layout of the binary tree ***
  *
- * We take advantage of the specifics of the situation to avoid generalist tree storage and instead
- * store the tree entries in a vector, mTreeData.
+ * We take advantage of the specifics of the situation to avoid generalist tree
+ * storage and instead store the tree entries in a vector, mTreeData.
  *
- * TreeData is always a vector of length
+ * TreeData is always a vector of length:
  *
  *    2 * (number of leaves).
  *
- * Its data layout is as follows: mTreeData[0] is unused, mTreeData[1] is the root node,
- * then at offsets 2..3 is the tree level immediately below the root node, then at offsets 4..7
- * is the tree level below that, etc.
+ * Its data layout is as follows: mTreeData[0] is unused, mTreeData[1] is the
+ * root node, then at offsets 2..3 is the tree level immediately below the root
+ * node, then at offsets 4..7 is the tree level below that, etc.
  *
- * The figure below illustrates this by writing at each tree node the offset into mTreeData at
- * which it is stored:
+ * The figure below illustrates this by writing at each tree node the offset
+ * into mTreeData at which it is stored:
  *
  *           1
  *         _/ \_
  *       2       3
  *      / \     / \
  *     4   5   6   7
  *    ...
  *
- * Thus, under the convention that the root level is level 0, we see that level N is stored at offsets
+ * Thus, under the convention that the root level is level 0, we see that level
+ * N is stored at offsets:
  *
  *    [ 2^n .. 2^(n+1) - 1 ]
  *
- * in mTreeData. Likewise, all the usual tree operations have simple mathematical expressions in
- * terms of mTreeData offsets, see all the methods such as ParentNode, LeftChildNode, etc.
+ * in mTreeData. Likewise, all the usual tree operations have simple
+ * mathematical expressions in terms of mTreeData offsets, see all the methods
+ * such as ParentNode, LeftChildNode, etc.
  *
- * *** Design constraint: element types aren't known at buffer-update time ***
+ * *** Design constraint: Element types aren't known at buffer-update time ***
  *
- * Note that a key constraint that we're operating under, is that we don't know the types of the elements
- * by the time WebGL bufferData/bufferSubData methods are called. The type of elements is only
- * specified in the drawElements call. This means that we may potentially have to store caches for
- * multiple element types, for the same element array buffer. Since we don't know yet how many
- * element types we'll eventually support (extensions add more), the concern about memory usage is serious.
- * This is addressed by sSkippedBottomTreeLevels as explained above. Of course, in the typical
- * case where each element array buffer is only ever used with one type, this is also addressed
- * by having WebGLElementArrayCache lazily create trees for each type only upon first use.
+ * Note that a key constraint that we're operating under, is that we don't know
+ * the types of the elements by the time WebGL bufferData/bufferSubData methods
+ * are called. The type of elements is only specified in the drawElements call.
+ * This means that we may potentially have to store caches for multiple element
+ * types, for the same element array buffer. Since we don't know yet how many
+ * element types we'll eventually support (extensions add more), the concern
+ * about memory usage is serious. This is addressed by kSkippedBottomTreeLevels
+ * as explained above. Of course, in the typical case where each element array
+ * buffer is only ever used with one type, this is also addressed by having
+ * WebGLElementArrayCache lazily create trees for each type only upon first use.
  *
- * Another consequence of this constraint is that when updating the trees, we have to update
- * all existing trees. So if trees for types uint8_t, uint16_t and uint32_t have ever been constructed for this buffer,
- * every subsequent update will have to update all trees even if one of the types is never
- * used again. That's inefficient, but content should not put indices of different types in the
- * same element array buffer anyways. Different index types can only be consumed in separate
- * drawElements calls, so nothing particular is to be achieved by lumping them in the same
- * buffer object.
+ * Another consequence of this constraint is that when updating the trees, we
+ * have to update all existing trees. So if trees for types uint8_t, uint16_t
+ * and uint32_t have ever been constructed for this buffer, every subsequent
+ * update will have to update all trees even if one of the types is never used
+ * again. That's inefficient, but content should not put indices of different
+ * types in the same element array buffer anyways. Different index types can
+ * only be consumed in separate drawElements calls, so nothing particular is
+ * to be achieved by lumping them in the same buffer object.
  */
 template<typename T>
 struct WebGLElementArrayCacheTree
 {
-  // A too-high sSkippedBottomTreeLevels would harm the performance of small drawElements calls
-  // A too-low sSkippedBottomTreeLevels would cause undue memory usage.
-  // The current value has been validated by some benchmarking. See bug 732660.
-  static const size_t sSkippedBottomTreeLevels = 3;
-  static const size_t sElementsPerLeaf = 1 << sSkippedBottomTreeLevels;
-  static const size_t sElementsPerLeafMask = sElementsPerLeaf - 1; // sElementsPerLeaf is POT
+    /* A too-high kSkippedBottomTreeLevels would harm the performance of small
+     * drawElements calls. A too-low kSkippedBottomTreeLevels would cause undue
+     * memory usage. The current value has been validated by some benchmarking.
+     * See bug 732660.
+     */
+    static const size_t kSkippedBottomTreeLevels = 3;
+    static const size_t kElementsPerLeaf = 1 << kSkippedBottomTreeLevels;
+    // Since kElementsPerLeaf is POT:
+    static const size_t kElementsPerLeafMask = kElementsPerLeaf - 1;
 
 private:
-
-  // The WebGLElementArrayCache that owns this tree
-  WebGLElementArrayCache& mParent;
+    // The WebGLElementArrayCache that owns this tree:
+    WebGLElementArrayCache& mParent;
 
-  // The tree's internal data storage. Its length is 2 * (number of leaves)
-  // because of its data layout explained in the above class comment.
-  FallibleTArray<T> mTreeData;
+    // The tree's internal data storage. Its length is 2 * (number of leaves)
+    // because of its data layout explained in the above class comment.
+    FallibleTArray<T> mTreeData;
 
 public:
-  // Constructor. Takes a reference to the WebGLElementArrayCache that is to be
-  // the parent. Does not initialize the tree. Should be followed by a call
-  // to Update() to attempt initializing the tree.
-  explicit WebGLElementArrayCacheTree(WebGLElementArrayCache& aValue)
-    : mParent(aValue)
-  {
-  }
+    // Constructor. Takes a reference to the WebGLElementArrayCache that is to be
+    // the parent. Does not initialize the tree. Should be followed by a call
+    // to Update() to attempt initializing the tree.
+    explicit WebGLElementArrayCacheTree(WebGLElementArrayCache& value)
+        : mParent(value)
+    {
+    }
 
-  T GlobalMaximum() const {
-    return mTreeData[1];
-  }
+    T GlobalMaximum() const {
+        return mTreeData[1];
+    }
 
-  // returns the index of the parent node; if treeIndex=1 (the root node),
-  // the return value is 0.
-  static size_t ParentNode(size_t treeIndex) {
-    MOZ_ASSERT(treeIndex > 1);
-    return treeIndex >> 1;
-  }
+    // returns the index of the parent node; if treeIndex=1 (the root node),
+    // the return value is 0.
+    static size_t ParentNode(size_t treeIndex) {
+        MOZ_ASSERT(treeIndex > 1);
+        return treeIndex >> 1;
+    }
 
-  static bool IsRightNode(size_t treeIndex) {
-    MOZ_ASSERT(treeIndex > 1);
-    return treeIndex & 1;
-  }
+    static bool IsRightNode(size_t treeIndex) {
+        MOZ_ASSERT(treeIndex > 1);
+        return treeIndex & 1;
+    }
 
-  static bool IsLeftNode(size_t treeIndex) {
-    MOZ_ASSERT(treeIndex > 1);
-    return !IsRightNode(treeIndex);
-  }
+    static bool IsLeftNode(size_t treeIndex) {
+        MOZ_ASSERT(treeIndex > 1);
+        return !IsRightNode(treeIndex);
+    }
 
-  static size_t SiblingNode(size_t treeIndex) {
-    MOZ_ASSERT(treeIndex > 1);
-    return treeIndex ^ 1;
-  }
+    static size_t SiblingNode(size_t treeIndex) {
+        MOZ_ASSERT(treeIndex > 1);
+        return treeIndex ^ 1;
+    }
 
-  static size_t LeftChildNode(size_t treeIndex) {
-    MOZ_ASSERT(treeIndex);
-    return treeIndex << 1;
-  }
+    static size_t LeftChildNode(size_t treeIndex) {
+        MOZ_ASSERT(treeIndex);
+        return treeIndex << 1;
+    }
+
+    static size_t RightChildNode(size_t treeIndex) {
+        MOZ_ASSERT(treeIndex);
+        return SiblingNode(LeftChildNode(treeIndex));
+    }
 
-  static size_t RightChildNode(size_t treeIndex) {
-    MOZ_ASSERT(treeIndex);
-    return SiblingNode(LeftChildNode(treeIndex));
-  }
+    static size_t LeftNeighborNode(size_t treeIndex, size_t distance = 1) {
+        MOZ_ASSERT(treeIndex > 1);
+        return treeIndex - distance;
+    }
 
-  static size_t LeftNeighborNode(size_t treeIndex, size_t distance = 1) {
-    MOZ_ASSERT(treeIndex > 1);
-    return treeIndex - distance;
-  }
+    static size_t RightNeighborNode(size_t treeIndex, size_t distance = 1) {
+        MOZ_ASSERT(treeIndex > 1);
+        return treeIndex + distance;
+    }
 
-  static size_t RightNeighborNode(size_t treeIndex, size_t distance = 1) {
-    MOZ_ASSERT(treeIndex > 1);
-    return treeIndex + distance;
-  }
+    size_t NumLeaves() const {
+        // See class comment for why we the tree storage size is 2 * numLeaves.
+        return mTreeData.Length() >> 1;
+    }
 
-  size_t NumLeaves() const {
-    // see class comment for why we the tree storage size is 2 * numLeaves
-    return mTreeData.Length() >> 1;
-  }
+    size_t LeafForElement(size_t element) const {
+        size_t leaf = element / kElementsPerLeaf;
+        MOZ_ASSERT(leaf < NumLeaves());
+        return leaf;
+    }
 
-  size_t LeafForElement(size_t element) const {
-    size_t leaf = element / sElementsPerLeaf;
-    MOZ_ASSERT(leaf < NumLeaves());
-    return leaf;
-  }
+    size_t LeafForByte(size_t byte) const {
+        return LeafForElement(byte / sizeof(T));
+    }
 
-  size_t LeafForByte(size_t byte) const {
-    return LeafForElement(byte / sizeof(T));
-  }
+    // Returns the index, into the tree storage, where a given leaf is stored.
+    size_t TreeIndexForLeaf(size_t leaf) const {
+        // See above class comment. The tree storage is an array of length
+        // 2 * numLeaves. The leaves are stored in its second half.
+        return leaf + NumLeaves();
+    }
 
-  // Returns the index, into the tree storage, where a given leaf is stored
-  size_t TreeIndexForLeaf(size_t leaf) const {
-    // See above class comment. The tree storage is an array of length 2 * numLeaves.
-    // The leaves are stored in its second half.
-    return leaf + NumLeaves();
-  }
+    static size_t LastElementUnderSameLeaf(size_t element) {
+        return element | kElementsPerLeafMask;
+    }
+
+    static size_t FirstElementUnderSameLeaf(size_t element) {
+        return element & ~kElementsPerLeafMask;
+    }
 
-  static size_t LastElementUnderSameLeaf(size_t element) {
-    return element | sElementsPerLeafMask;
-  }
+    static size_t NextMultipleOfElementsPerLeaf(size_t numElements) {
+        MOZ_ASSERT(numElements >= 1);
+        return ((numElements - 1) | kElementsPerLeafMask) + 1;
+    }
 
-  static size_t FirstElementUnderSameLeaf(size_t element) {
-    return element & ~sElementsPerLeafMask;
-  }
+    bool Validate(T maxAllowed, size_t firstLeaf, size_t lastLeaf,
+                  uint32_t* const out_upperBound)
+    {
+        size_t firstTreeIndex = TreeIndexForLeaf(firstLeaf);
+        size_t lastTreeIndex  = TreeIndexForLeaf(lastLeaf);
 
-  static size_t NextMultipleOfElementsPerLeaf(size_t numElements) {
-    MOZ_ASSERT(numElements >= 1);
-    return ((numElements - 1) | sElementsPerLeafMask) + 1;
-  }
-
-  bool Validate(T maxAllowed, size_t firstLeaf, size_t lastLeaf,
-                uint32_t* out_upperBound)
-  {
-    size_t firstTreeIndex = TreeIndexForLeaf(firstLeaf);
-    size_t lastTreeIndex  = TreeIndexForLeaf(lastLeaf);
+        while (true) {
+            // Given that we tweak these values in nontrivial ways, it doesn't
+            // hurt to do this sanity check.
+            MOZ_ASSERT(firstTreeIndex <= lastTreeIndex);
 
-    while (true) {
-      // given that we tweak these values in nontrivial ways, it doesn't hurt to do
-      // this sanity check
-      MOZ_ASSERT(firstTreeIndex <= lastTreeIndex);
+            // Final case where there is only one node to validate at the
+            // current tree level:
+            if (lastTreeIndex == firstTreeIndex) {
+                const T& curData = mTreeData[firstTreeIndex];
+                UpdateUpperBound(out_upperBound, curData);
+                return curData <= maxAllowed;
+            }
 
-      // final case where there is only 1 node to validate at the current tree level
-      if (lastTreeIndex == firstTreeIndex) {
-        const T& curData = mTreeData[firstTreeIndex];
-        UpdateUpperBound(out_upperBound, curData);
-        return curData <= maxAllowed;
-      }
+            // If the first node at current tree level is a right node, handle
+            // it individually and replace it with its right neighbor, which is
+            // a left node.
+            if (IsRightNode(firstTreeIndex)) {
+                const T& curData = mTreeData[firstTreeIndex];
+                UpdateUpperBound(out_upperBound, curData);
+                if (curData > maxAllowed)
+                  return false;
 
-      // if the first node at current tree level is a right node, handle it individually
-      // and replace it with its right neighbor, which is a left node
-      if (IsRightNode(firstTreeIndex)) {
-        const T& curData = mTreeData[firstTreeIndex];
-        UpdateUpperBound(out_upperBound, curData);
-        if (curData > maxAllowed)
-          return false;
-        firstTreeIndex = RightNeighborNode(firstTreeIndex);
-      }
+                firstTreeIndex = RightNeighborNode(firstTreeIndex);
+            }
 
-      // if the last node at current tree level is a left node, handle it individually
-      // and replace it with its left neighbor, which is a right node
-      if (IsLeftNode(lastTreeIndex)) {
-        const T& curData = mTreeData[lastTreeIndex];
-        UpdateUpperBound(out_upperBound, curData);
-        if (curData > maxAllowed)
-          return false;
-        lastTreeIndex = LeftNeighborNode(lastTreeIndex);
-      }
+            // If the last node at current tree level is a left node, handle it
+            // individually and replace it with its left neighbor, which is a
+            // right node.
+            if (IsLeftNode(lastTreeIndex)) {
+                const T& curData = mTreeData[lastTreeIndex];
+                UpdateUpperBound(out_upperBound, curData);
+                if (curData > maxAllowed)
+                    return false;
+
+                lastTreeIndex = LeftNeighborNode(lastTreeIndex);
+            }
 
-      // at this point it can happen that firstTreeIndex and lastTreeIndex "crossed" each
-      // other. That happens if firstTreeIndex was a right node and lastTreeIndex was its
-      // right neighor: in that case, both above tweaks happened and as a result, they ended
-      // up being swapped: lastTreeIndex is now the _left_ neighbor of firstTreeIndex.
-      // When that happens, there is nothing left to validate.
-      if (lastTreeIndex == LeftNeighborNode(firstTreeIndex)) {
-        return true;
-      }
+            /* At this point it can happen that firstTreeIndex and lastTreeIndex
+             * "crossed" eachother. That happens if firstTreeIndex was a right
+             * node and lastTreeIndex was its right neighor: In that case, both
+             * above tweaks happened and as a result, they ended up being
+             * swapped: LastTreeIndex is now the _left_ neighbor of
+             * firstTreeIndex. When that happens, there is nothing left to
+             * validate.
+             */
+            if (lastTreeIndex == LeftNeighborNode(firstTreeIndex))
+                return true;
 
-      // walk up 1 level
-      firstTreeIndex = ParentNode(firstTreeIndex);
-      lastTreeIndex = ParentNode(lastTreeIndex);
+            // Walk up one level.
+            firstTreeIndex = ParentNode(firstTreeIndex);
+            lastTreeIndex = ParentNode(lastTreeIndex);
+        }
     }
-  }
 
-  // Updates the tree from the parent's buffer contents. Fallible, as it
-  // may have to resize the tree storage.
-  bool Update(size_t firstByte, size_t lastByte);
+    // Updates the tree from the parent's buffer contents. Fallible, as it
+    // may have to resize the tree storage.
+    bool Update(size_t firstByte, size_t lastByte);
 
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
-  {
-    return aMallocSizeOf(this) + mTreeData.SizeOfExcludingThis(aMallocSizeOf);
-  }
+    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
+    {
+        return mallocSizeOf(this) + mTreeData.SizeOfExcludingThis(mallocSizeOf);
+    }
 };
 
 // TreeForType: just a template helper to select the right tree object for a given
 // element type.
 template<typename T>
 struct TreeForType {};
 
 template<>
 struct TreeForType<uint8_t>
 {
-  static ScopedDeletePtr<WebGLElementArrayCacheTree<uint8_t>>&
-  Value(WebGLElementArrayCache *b) {
-    return b->mUint8Tree;
-  }
+    static ScopedDeletePtr<WebGLElementArrayCacheTree<uint8_t>>&