Bug 1318507 - Minimize WebGL idl divergence. (flattened) - r=qdot a=gchang
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 15 Dec 2016 18:33:48 -0800
changeset 374078 15cb38704cedd92177f9912af58e594351e66850
parent 374077 253b34072aeb84b850a7fa014875b4d97f08cbb2
child 374079 33ed433e98aa16b1bda2e66b70049df5d69b10b2
push id35
push userfmarier@mozilla.com
push dateThu, 09 Feb 2017 06:52:49 +0000
reviewersqdot, gchang
bugs1318507
milestone52.0a2
Bug 1318507 - Minimize WebGL idl divergence. (flattened) - r=qdot a=gchang MozReview-Commit-ID: C8ap7ZHZSv9
dom/canvas/WebGL2Context.h
dom/canvas/WebGL2ContextPrograms.cpp
dom/canvas/WebGL2ContextQueries.cpp
dom/canvas/WebGL2ContextSamplers.cpp
dom/canvas/WebGL2ContextSync.cpp
dom/canvas/WebGL2ContextTransformFeedback.cpp
dom/canvas/WebGL2ContextUniforms.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextBuffers.cpp
dom/canvas/WebGLContextGL.cpp
dom/canvas/WebGLContextUnchecked.cpp
dom/canvas/WebGLContextUnchecked.h
dom/canvas/WebGLContextValidate.cpp
dom/canvas/WebGLExtensionDebugShaders.cpp
dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
dom/canvas/WebGLExtensions.h
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLProgram.h
dom/canvas/WebGLSampler.cpp
dom/canvas/WebGLSampler.h
dom/canvas/WebGLUniformLocation.cpp
dom/canvas/WebGLUniformLocation.h
dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-and-buffer-sub-data.html
dom/canvas/test/webgl-conf/checkout/conformance/context/context-lost.html
dom/canvas/test/webgl-conf/checkout/conformance/misc/error-reporting.html
dom/canvas/test/webgl-conf/checkout/conformance/misc/null-object-behaviour.html
dom/canvas/test/webgl-conf/checkout/conformance/programs/get-active-test.html
dom/canvas/test/webgl-conf/checkout/conformance2/context/constants-and-properties-2.html
dom/canvas/test/webgl-conf/checkout/js/tests/gl-object-get-calls.js
dom/canvas/test/webgl-mochitest/test_sab_with_webgl.html
dom/webidl/WebGL2RenderingContext.webidl
dom/webidl/WebGLRenderingContext.webidl
--- a/dom/canvas/WebGL2Context.h
+++ b/dom/canvas/WebGL2Context.h
@@ -197,19 +197,26 @@ public:
         const TexImageSourceAdapter src(anySrc, &out_error);
         TexSubImage3D(target, level, xOffset, yOffset, zOffset, width, height, depth,
                       unpackFormat, unpackType, src);
     }
 
     void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
                        GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
                        GLenum unpackFormat, GLenum unpackType,
-                       const dom::ArrayBufferView& srcView, GLuint srcElemOffset,
-                       ErrorResult&)
+                       const dom::Nullable<dom::ArrayBufferView>& maybeSrcView,
+                       GLuint srcElemOffset, ErrorResult&)
     {
+        if (IsContextLost())
+            return;
+
+        if (!ValidateNonNull("texSubImage3D", maybeSrcView))
+            return;
+        const auto& srcView = maybeSrcView.Value();
+
         const TexImageSourceAdapter src(srcView, srcElemOffset);
         TexSubImage3D(target, level, xOffset, yOffset, zOffset, width, height, depth,
                       unpackFormat, unpackType, src);
     }
 
 protected:
     void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
                        GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
@@ -219,17 +226,17 @@ protected:
         const uint8_t funcDims = 3;
         TexSubImage(funcName, funcDims, target, level, xOffset, yOffset, zOffset, width,
                     height, depth, unpackFormat, unpackType, src);
     }
 
 public:
     // -------------------------------------------------------------------------
     // Programs and shaders - WebGL2ContextPrograms.cpp
-    GLint GetFragDataLocation(WebGLProgram* program, const nsAString& name);
+    GLint GetFragDataLocation(const WebGLProgram& program, const nsAString& name);
 
 
     // -------------------------------------------------------------------------
     // Uniforms and attributes - WebGL2ContextUniforms.cpp
     void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
 
     ////////////////
 
@@ -304,78 +311,77 @@ public:
 
     // -------------------------------------------------------------------------
     // Sampler Objects - WebGL2ContextSamplers.cpp
 
     already_AddRefed<WebGLSampler> CreateSampler();
     void DeleteSampler(WebGLSampler* sampler);
     bool IsSampler(WebGLSampler* sampler);
     void BindSampler(GLuint unit, WebGLSampler* sampler);
-    void SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param);
-    void SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Int32Array& param);
-    void SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLint>& param);
-    void SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param);
-    void SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Float32Array& param);
-    void SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLfloat>& param);
-    void GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval);
+    void SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint param);
+    void SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat param);
+    void GetSamplerParameter(JSContext*, const WebGLSampler& sampler, GLenum pname,
+                             JS::MutableHandleValue retval);
 
 
     // -------------------------------------------------------------------------
     // Sync objects - WebGL2ContextSync.cpp
 
     already_AddRefed<WebGLSync> FenceSync(GLenum condition, GLbitfield flags);
     bool IsSync(WebGLSync* sync);
     void DeleteSync(WebGLSync* sync);
-    GLenum ClientWaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout);
-    void WaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout);
-    void GetSyncParameter(JSContext*, WebGLSync* sync, GLenum pname, JS::MutableHandleValue retval);
+    GLenum ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 timeout);
+    void WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout);
+    void GetSyncParameter(JSContext*, const WebGLSync& sync, GLenum pname,
+                          JS::MutableHandleValue retval);
 
 
     // -------------------------------------------------------------------------
     // Transform Feedback - WebGL2ContextTransformFeedback.cpp
 
     already_AddRefed<WebGLTransformFeedback> CreateTransformFeedback();
     void DeleteTransformFeedback(WebGLTransformFeedback* tf);
     bool IsTransformFeedback(WebGLTransformFeedback* tf);
     void BindTransformFeedback(GLenum target, WebGLTransformFeedback* tf);
     void BeginTransformFeedback(GLenum primitiveMode);
     void EndTransformFeedback();
     void PauseTransformFeedback();
     void ResumeTransformFeedback();
-    void TransformFeedbackVaryings(WebGLProgram* program, const dom::Sequence<nsString>& varyings, GLenum bufferMode);
-    already_AddRefed<WebGLActiveInfo> GetTransformFeedbackVarying(WebGLProgram* program, GLuint index);
+    void TransformFeedbackVaryings(WebGLProgram& program,
+                                   const dom::Sequence<nsString>& varyings,
+                                   GLenum bufferMode);
+    already_AddRefed<WebGLActiveInfo>
+    GetTransformFeedbackVarying(const WebGLProgram& program, GLuint index);
 
 
     // -------------------------------------------------------------------------
     // Uniform Buffer Objects and Transform Feedback Buffers - WebGL2ContextUniforms.cpp
     // TODO(djg): Implemented in WebGLContext
 /*
     void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer);
     void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer, GLintptr offset, GLsizeiptr size);
 */
     virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) override;
     void GetIndexedParameter(JSContext* cx, GLenum target, GLuint index,
                              JS::MutableHandleValue retval, ErrorResult& rv);
-    void GetUniformIndices(WebGLProgram* program,
+    void GetUniformIndices(const WebGLProgram& program,
                            const dom::Sequence<nsString>& uniformNames,
                            dom::Nullable< nsTArray<GLuint> >& retval);
-    void GetActiveUniforms(JSContext* cx,
-                           WebGLProgram* program,
-                           const dom::Sequence<GLuint>& uniformIndices,
-                           GLenum pname,
+    void GetActiveUniforms(JSContext* cx, const WebGLProgram& program,
+                           const dom::Sequence<GLuint>& uniformIndices, GLenum pname,
                            JS::MutableHandleValue retval);
 
-    GLuint GetUniformBlockIndex(WebGLProgram* program, const nsAString& uniformBlockName);
-    void GetActiveUniformBlockParameter(JSContext*, WebGLProgram* program,
+    GLuint GetUniformBlockIndex(const WebGLProgram& program,
+                                const nsAString& uniformBlockName);
+    void GetActiveUniformBlockParameter(JSContext*, const WebGLProgram& program,
                                         GLuint uniformBlockIndex, GLenum pname,
-                                        JS::MutableHandleValue retval,
-                                        ErrorResult& rv);
-    void GetActiveUniformBlockName(WebGLProgram* program, GLuint uniformBlockIndex,
+                                        JS::MutableHandleValue retval, ErrorResult& rv);
+    void GetActiveUniformBlockName(const WebGLProgram& program, GLuint uniformBlockIndex,
                                    nsAString& retval);
-    void UniformBlockBinding(WebGLProgram* program, GLuint uniformBlockIndex,
+    void UniformBlockBinding(WebGLProgram& program, GLuint uniformBlockIndex,
                              GLuint uniformBlockBinding);
 
 
     // -------------------------------------------------------------------------
     // Vertex Array Object - WebGL2ContextVAOs.cpp
     // TODO(djg): Implemented in WebGLContext
 /*
     already_AddRefed<WebGLVertexArrayObject> CreateVertexArray();
--- a/dom/canvas/WebGL2ContextPrograms.cpp
+++ b/dom/canvas/WebGL2ContextPrograms.cpp
@@ -9,20 +9,20 @@
 #include "WebGLProgram.h"
 
 namespace mozilla {
 
 // -------------------------------------------------------------------------
 // Programs and shaders
 
 GLint
-WebGL2Context::GetFragDataLocation(WebGLProgram* prog, const nsAString& name)
+WebGL2Context::GetFragDataLocation(const WebGLProgram& prog, const nsAString& name)
 {
     if (IsContextLost())
         return -1;
 
-    if (!ValidateObject("getFragDataLocation: program", prog))
+    if (!ValidateObjectRef("getFragDataLocation: program", prog))
         return -1;
 
-    return prog->GetFragDataLocation(name);
+    return prog.GetFragDataLocation(name);
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGL2ContextQueries.cpp
+++ b/dom/canvas/WebGL2ContextQueries.cpp
@@ -105,41 +105,41 @@ WebGLContext::IsQuery(const WebGLQuery* 
 
     if (!ValidateObjectAllowDeleted("isQuery", query))
         return false;
 
     return query->IsQuery();
 }
 
 void
-WebGLContext::BeginQuery(GLenum target, WebGLQuery* query, const char* funcName)
+WebGLContext::BeginQuery(GLenum target, WebGLQuery& query, const char* funcName)
 {
     if (!funcName) {
         funcName = "beginQuery";
     }
 
     if (IsContextLost())
         return;
 
-    if (!ValidateObjectAllowDeleted(funcName, query))
+    if (!ValidateObjectAllowDeleted(funcName, &query))
         return;
 
-    if (query->IsDeleted())
+    if (query.IsDeleted())
         return ErrorInvalidOperation("%s: Cannot begin a deleted query.", funcName);
 
     const auto& slot = ValidateQuerySlotByTarget(funcName, target);
     if (!slot)
         return;
 
     if (*slot)
         return ErrorInvalidOperation("%s: Query target already active.", funcName);
 
     ////
 
-    query->BeginQuery(target, *slot);
+    query.BeginQuery(target, *slot);
 }
 
 void
 WebGLContext::EndQuery(GLenum target, const char* funcName)
 {
     if (!funcName) {
         funcName = "endQuery";
     }
@@ -222,29 +222,29 @@ WebGLContext::GetQuery(JSContext* cx, GL
         break;
     }
 
     ErrorInvalidEnum("%s: Bad pname.", funcName);
     return;
 }
 
 void
-WebGLContext::GetQueryParameter(JSContext*, const WebGLQuery* query, GLenum pname,
+WebGLContext::GetQueryParameter(JSContext*, const WebGLQuery& query, GLenum pname,
                                 JS::MutableHandleValue retval, const char* funcName)
 {
     if (!funcName) {
         funcName = "getQueryParameter";
     }
 
     retval.setNull();
     if (IsContextLost())
         return;
 
-    if (!ValidateObjectAllowDeleted(funcName, query))
+    if (!ValidateObjectAllowDeleted(funcName, &query))
         return;
 
-    if (query->IsDeleted())
+    if (query.IsDeleted())
         return ErrorInvalidOperation("%s: Query must not be deleted.", funcName);
 
-    query->GetQueryParameter(pname, retval);
+    query.GetQueryParameter(pname, retval);
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGL2ContextSamplers.cpp
+++ b/dom/canvas/WebGL2ContextSamplers.cpp
@@ -75,163 +75,91 @@ WebGL2Context::BindSampler(GLuint unit, 
         return;
 
     if (GLint(unit) >= mGLMaxTextureUnits)
         return ErrorInvalidValue("bindSampler: unit must be < %d", mGLMaxTextureUnits);
 
     if (sampler && sampler->IsDeleted())
         return ErrorInvalidOperation("bindSampler: binding deleted sampler");
 
-    WebGLContextUnchecked::BindSampler(unit, sampler);
+    ////
+
+    gl->MakeCurrent();
+    gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
+
     InvalidateResolveCacheForTextureWithTexUnit(unit);
-
     mBoundSamplers[unit] = sampler;
 }
 
 void
-WebGL2Context::SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param)
+WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint paramInt)
 {
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameteri: invalid sampler");
-
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameteri"))
-        return;
-
-    sampler->SamplerParameter1i(pname, param);
-    WebGLContextUnchecked::SamplerParameteri(sampler, pname, param);
-}
-
-void
-WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Int32Array& param)
-{
+    const char funcName[] = "samplerParameteri";
     if (IsContextLost())
         return;
 
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
-
-    param.ComputeLengthAndData();
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param.Data()[0]), "samplerParameteriv"))
+    if (!ValidateObjectRef(funcName, sampler))
         return;
 
-    sampler->SamplerParameter1i(pname, param.Data()[0]);
-    WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Data());
-}
-
-void
-WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLint>& param)
-{
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
-
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param[0]), "samplerParameteriv"))
-        return;
-
-    sampler->SamplerParameter1i(pname, param[0]);
-    WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Elements());
+    sampler.SamplerParameter(funcName, pname, paramInt);
 }
 
 void
-WebGL2Context::SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param)
+WebGL2Context::SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat paramFloat)
 {
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameterf: invalid sampler");
-
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameterf"))
-        return;
-
-    sampler->SamplerParameter1f(pname, param);
-    WebGLContextUnchecked::SamplerParameterf(sampler, pname, param);
-}
-
-void
-WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Float32Array& param)
-{
+    const char funcName[] = "samplerParameterf";
     if (IsContextLost())
         return;
 
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
-
-    param.ComputeLengthAndData();
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param.Data()[0]), "samplerParameterfv"))
+    if (!ValidateObjectRef(funcName, sampler))
         return;
 
-    sampler->SamplerParameter1f(pname, param.Data()[0]);
-    WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Data());
+    sampler.SamplerParameter(funcName, pname, WebGLIntOrFloat(paramFloat).AsInt());
 }
 
 void
-WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLfloat>& param)
+WebGL2Context::GetSamplerParameter(JSContext*, const WebGLSampler& sampler, GLenum pname,
+                                   JS::MutableHandleValue retval)
 {
-    if (IsContextLost())
-        return;
-
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
-
-    if (param.Length() < 1)
-        return /* TODO(djg): Error message */;
-
-    /* TODO(djg): All of these calls in ES3 only take 1 param */
-    if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param[0]), "samplerParameterfv"))
-        return;
-
-    sampler->SamplerParameter1f(pname, param[0]);
-    WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Elements());
-}
-
-void
-WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval)
-{
+    const char funcName[] = "getSamplerParameter";
     retval.setNull();
 
     if (IsContextLost())
         return;
 
-    if (!sampler || sampler->IsDeleted())
-        return ErrorInvalidOperation("getSamplerParameter: invalid sampler");
+    if (!ValidateObjectRef(funcName, sampler))
+        return;
 
-    if (!ValidateSamplerParameterName(pname, "getSamplerParameter"))
-        return;
+    ////
+
+    gl->MakeCurrent();
 
     switch (pname) {
     case LOCAL_GL_TEXTURE_MIN_FILTER:
     case LOCAL_GL_TEXTURE_MAG_FILTER:
     case LOCAL_GL_TEXTURE_WRAP_S:
     case LOCAL_GL_TEXTURE_WRAP_T:
     case LOCAL_GL_TEXTURE_WRAP_R:
     case LOCAL_GL_TEXTURE_COMPARE_MODE:
     case LOCAL_GL_TEXTURE_COMPARE_FUNC:
-        retval.set(JS::Int32Value(
-            WebGLContextUnchecked::GetSamplerParameteriv(sampler, pname)));
+        {
+            GLint param = 0;
+            gl->fGetSamplerParameteriv(sampler.mGLName, pname, &param);
+            retval.set(JS::Int32Value(param));
+        }
         return;
 
     case LOCAL_GL_TEXTURE_MIN_LOD:
     case LOCAL_GL_TEXTURE_MAX_LOD:
-        retval.set(JS::Float32Value(
-            WebGLContextUnchecked::GetSamplerParameterfv(sampler, pname)));
+        {
+            GLfloat param = 0;
+            gl->fGetSamplerParameterfv(sampler.mGLName, pname, &param);
+            retval.set(JS::Float32Value(param));
+        }
+        return;
+
+    default:
+        ErrorInvalidEnum("%s: invalid pname: %s", funcName, EnumName(pname));
         return;
     }
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGL2ContextSync.cpp
+++ b/dom/canvas/WebGL2ContextSync.cpp
@@ -54,81 +54,83 @@ WebGL2Context::DeleteSync(WebGLSync* syn
 
     if (!sync || sync->IsDeleted())
         return;
 
     sync->RequestDelete();
 }
 
 GLenum
-WebGL2Context::ClientWaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout)
+WebGL2Context::ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 timeout)
 {
+    const char funcName[] = "clientWaitSync";
     if (IsContextLost())
         return LOCAL_GL_WAIT_FAILED;
 
-    if (!sync || sync->IsDeleted()) {
-        ErrorInvalidValue("clientWaitSync: sync is not a sync object.");
+    if (!ValidateObjectRef(funcName, sync))
         return LOCAL_GL_WAIT_FAILED;
-    }
 
     if (flags != 0 && flags != LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT) {
-        ErrorInvalidValue("clientWaitSync: flag must be SYNC_FLUSH_COMMANDS_BIT or 0");
+        ErrorInvalidValue("%s: `flags` must be SYNC_FLUSH_COMMANDS_BIT or 0.", funcName);
         return LOCAL_GL_WAIT_FAILED;
     }
 
     MakeContextCurrent();
-    return gl->fClientWaitSync(sync->mGLName, flags, timeout);
+    return gl->fClientWaitSync(sync.mGLName, flags, timeout);
 }
 
 void
-WebGL2Context::WaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout)
+WebGL2Context::WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout)
 {
+    const char funcName[] = "waitSync";
     if (IsContextLost())
         return;
 
-    if (!sync || sync->IsDeleted()) {
-        ErrorInvalidValue("waitSync: sync is not a sync object.");
+    if (!ValidateObjectRef(funcName, sync))
+        return;
+
+    if (flags != 0) {
+        ErrorInvalidValue("%s: `flags` must be 0.", funcName);
         return;
     }
 
-    if (flags != 0) {
-        ErrorInvalidValue("waitSync: flags must be 0");
-        return;
-    }
-
-    if (timeout != LOCAL_GL_TIMEOUT_IGNORED) {
-        ErrorInvalidValue("waitSync: timeout must be TIMEOUT_IGNORED");
+    if (timeout != -1) {
+        ErrorInvalidValue("%s: `timeout` must be TIMEOUT_IGNORED.", funcName);
         return;
     }
 
     MakeContextCurrent();
-    gl->fWaitSync(sync->mGLName, flags, timeout);
+    gl->fWaitSync(sync.mGLName, flags, LOCAL_GL_TIMEOUT_IGNORED);
 }
 
 void
-WebGL2Context::GetSyncParameter(JSContext*, WebGLSync* sync, GLenum pname, JS::MutableHandleValue retval)
+WebGL2Context::GetSyncParameter(JSContext*, const WebGLSync& sync, GLenum pname,
+                                JS::MutableHandleValue retval)
 {
+    const char funcName[] = "getSyncParameter";
+    retval.setNull();
     if (IsContextLost())
         return;
 
-    if (!sync || sync->IsDeleted()) {
-        ErrorInvalidValue("getSyncParameter: sync is not a sync object.");
+    if (!ValidateObjectRef(funcName, sync))
         return;
-    }
 
-    retval.set(JS::NullValue());
+    ////
+
+    gl->MakeCurrent();
 
     GLint result = 0;
     switch (pname) {
     case LOCAL_GL_OBJECT_TYPE:
     case LOCAL_GL_SYNC_STATUS:
     case LOCAL_GL_SYNC_CONDITION:
     case LOCAL_GL_SYNC_FLAGS:
-        MakeContextCurrent();
-        gl->fGetSynciv(sync->mGLName, pname, 1, nullptr, &result);
+        gl->fGetSynciv(sync.mGLName, pname, 1, nullptr, &result);
         retval.set(JS::Int32Value(result));
         return;
+
+    default:
+        ErrorInvalidEnum("%s: Invalid pname 0x%04x", funcName, pname);
+        return;
     }
-
-    ErrorInvalidEnum("getSyncParameter: Invalid pname 0x%04x", pname);
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGL2ContextTransformFeedback.cpp
+++ b/dom/canvas/WebGL2ContextTransformFeedback.cpp
@@ -131,34 +131,34 @@ WebGL2Context::ResumeTransformFeedback()
 {
     if (IsContextLost())
         return;
 
     mBoundTransformFeedback->ResumeTransformFeedback();
 }
 
 void
-WebGL2Context::TransformFeedbackVaryings(WebGLProgram* program,
+WebGL2Context::TransformFeedbackVaryings(WebGLProgram& program,
                                          const dom::Sequence<nsString>& varyings,
                                          GLenum bufferMode)
 {
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("transformFeedbackVaryings: program", program))
+    if (!ValidateObjectRef("transformFeedbackVaryings: program", program))
         return;
 
-    program->TransformFeedbackVaryings(varyings, bufferMode);
+    program.TransformFeedbackVaryings(varyings, bufferMode);
 }
 
 already_AddRefed<WebGLActiveInfo>
-WebGL2Context::GetTransformFeedbackVarying(WebGLProgram* program, GLuint index)
+WebGL2Context::GetTransformFeedbackVarying(const WebGLProgram& program, GLuint index)
 {
     if (IsContextLost())
         return nullptr;
 
-    if (!ValidateObject("getTransformFeedbackVarying: program", program))
+    if (!ValidateObjectRef("getTransformFeedbackVarying: program", program))
         return nullptr;
 
-    return program->GetTransformFeedbackVarying(index);
+    return program.GetTransformFeedbackVarying(index);
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGL2ContextUniforms.cpp
+++ b/dom/canvas/WebGL2ContextUniforms.cpp
@@ -125,31 +125,31 @@ WebGL2Context::GetIndexedParameter(JSCon
         ret = JS::NumberValue(binding.mRangeSize);
         break;
     }
 
     retval.set(ret);
 }
 
 void
-WebGL2Context::GetUniformIndices(WebGLProgram* program,
+WebGL2Context::GetUniformIndices(const WebGLProgram& program,
                                  const dom::Sequence<nsString>& uniformNames,
                                  dom::Nullable< nsTArray<GLuint> >& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("getUniformIndices: program", program))
+    if (!ValidateObjectRef("getUniformIndices: program", program))
         return;
 
     if (!uniformNames.Length())
         return;
 
-    program->GetUniformIndices(uniformNames, retval);
+    program.GetUniformIndices(uniformNames, retval);
 }
 
 static bool
 ValidateUniformEnum(WebGLContext* webgl, GLenum pname, const char* info)
 {
     switch (pname) {
     case LOCAL_GL_UNIFORM_TYPE:
     case LOCAL_GL_UNIFORM_SIZE:
@@ -162,149 +162,139 @@ ValidateUniformEnum(WebGLContext* webgl,
 
     default:
         webgl->ErrorInvalidEnum("%s: invalid pname: %s", info, webgl->EnumName(pname));
         return false;
     }
 }
 
 void
-WebGL2Context::GetActiveUniforms(JSContext* cx,
-                                 WebGLProgram* program,
+WebGL2Context::GetActiveUniforms(JSContext* cx, const WebGLProgram& program,
                                  const dom::Sequence<GLuint>& uniformIndices,
-                                 GLenum pname,
-                                 JS::MutableHandleValue retval)
+                                 GLenum pname, JS::MutableHandleValue retval)
 {
-    retval.set(JS::NullValue());
+    const char funcName[] = "getActiveUniforms";
+    retval.setNull();
     if (IsContextLost())
         return;
 
-    if (!ValidateUniformEnum(this, pname, "getActiveUniforms"))
+    if (!ValidateUniformEnum(this, pname, funcName))
         return;
 
-    if (!ValidateObject("getActiveUniforms: program", program))
-        return;
-
-    size_t count = uniformIndices.Length();
-    if (!count)
+    if (!ValidateObjectRef("getActiveUniforms: program", program))
         return;
 
-    GLuint progname = program->mGLName;
-    Vector<GLint> samples;
-    if (!samples.resize(count)) {
+    const auto& count = uniformIndices.Length();
+
+    JS::Rooted<JSObject*> array(cx, JS_NewArrayObject(cx, count));
+    UniquePtr<GLint[]> samples(new GLint[count]);
+    if (!array || !samples) {
+        ErrorOutOfMemory("%s: Failed to allocate buffers.", funcName);
         return;
     }
+    retval.setObject(*array);
 
     MakeContextCurrent();
-    gl->fGetActiveUniformsiv(progname, count, uniformIndices.Elements(), pname,
-                             samples.begin());
-
-    JS::Rooted<JSObject*> array(cx, JS_NewArrayObject(cx, count));
-    if (!array) {
-        return;
-    }
+    gl->fGetActiveUniformsiv(program.mGLName, count, uniformIndices.Elements(), pname,
+                             samples.get());
 
     switch (pname) {
     case LOCAL_GL_UNIFORM_TYPE:
     case LOCAL_GL_UNIFORM_SIZE:
     case LOCAL_GL_UNIFORM_BLOCK_INDEX:
     case LOCAL_GL_UNIFORM_OFFSET:
     case LOCAL_GL_UNIFORM_ARRAY_STRIDE:
     case LOCAL_GL_UNIFORM_MATRIX_STRIDE:
-        for (uint32_t i = 0; i < count; ++i) {
+        for (size_t i = 0; i < count; ++i) {
             JS::RootedValue value(cx);
             value = JS::Int32Value(samples[i]);
-            if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE)) {
+            if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE))
                 return;
-            }
         }
         break;
     case LOCAL_GL_UNIFORM_IS_ROW_MAJOR:
-        for (uint32_t i = 0; i < count; ++i) {
+        for (size_t i = 0; i < count; ++i) {
             JS::RootedValue value(cx);
             value = JS::BooleanValue(samples[i]);
-            if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE)) {
+            if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE))
                 return;
-            }
         }
         break;
 
     default:
-        return;
+        MOZ_CRASH("Invalid pname");
     }
-
-    retval.setObjectOrNull(array);
 }
 
 GLuint
-WebGL2Context::GetUniformBlockIndex(WebGLProgram* program,
+WebGL2Context::GetUniformBlockIndex(const WebGLProgram& program,
                                     const nsAString& uniformBlockName)
 {
     if (IsContextLost())
         return 0;
 
-    if (!ValidateObject("getUniformBlockIndex: program", program))
+    if (!ValidateObjectRef("getUniformBlockIndex: program", program))
         return 0;
 
-    return program->GetUniformBlockIndex(uniformBlockName);
+    return program.GetUniformBlockIndex(uniformBlockName);
 }
 
 void
-WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, WebGLProgram* program,
+WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, const WebGLProgram& program,
                                               GLuint uniformBlockIndex, GLenum pname,
                                               JS::MutableHandleValue out_retval,
                                               ErrorResult& out_error)
 {
-    out_retval.set(JS::NullValue());
+    out_retval.setNull();
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("getActiveUniformBlockParameter: program", program))
+    if (!ValidateObjectRef("getActiveUniformBlockParameter: program", program))
         return;
 
     MakeContextCurrent();
 
     switch(pname) {
     case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
     case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
     case LOCAL_GL_UNIFORM_BLOCK_BINDING:
     case LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE:
     case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
-        out_retval.set(program->GetActiveUniformBlockParam(uniformBlockIndex, pname));
+        out_retval.set(program.GetActiveUniformBlockParam(uniformBlockIndex, pname));
         return;
 
     case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
-        out_retval.set(program->GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex,
-                                                                    &out_error));
+        out_retval.set(program.GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex,
+                                                                   &out_error));
         return;
     }
 
     ErrorInvalidEnumInfo("getActiveUniformBlockParameter: parameter", pname);
 }
 
 void
-WebGL2Context::GetActiveUniformBlockName(WebGLProgram* program, GLuint uniformBlockIndex,
-                                         nsAString& retval)
+WebGL2Context::GetActiveUniformBlockName(const WebGLProgram& program,
+                                         GLuint uniformBlockIndex, nsAString& retval)
 {
     retval.SetIsVoid(true);
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("getActiveUniformBlockName: program", program))
+    if (!ValidateObjectRef("getActiveUniformBlockName: program", program))
         return;
 
-    program->GetActiveUniformBlockName(uniformBlockIndex, retval);
+    program.GetActiveUniformBlockName(uniformBlockIndex, retval);
 }
 
 void
-WebGL2Context::UniformBlockBinding(WebGLProgram* program, GLuint uniformBlockIndex,
+WebGL2Context::UniformBlockBinding(WebGLProgram& program, GLuint uniformBlockIndex,
                                    GLuint uniformBlockBinding)
 {
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("uniformBlockBinding: program", program))
+    if (!ValidateObjectRef("uniformBlockBinding: program", program))
         return;
 
-    program->UniformBlockBinding(uniformBlockIndex, uniformBlockBinding);
+    program.UniformBlockBinding(uniformBlockIndex, uniformBlockBinding);
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -158,29 +158,29 @@ struct WebGLContextOptions
     bool antialias;
     bool preserveDrawingBuffer;
     bool failIfMajorPerformanceCaveat;
 };
 
 // From WebGLContextUtils
 TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
 
-class WebGLIntOrFloat {
-    enum {
+struct WebGLIntOrFloat {
+    const enum {
         Int,
         Float,
         Uint
     } mType;
+
     union {
         GLint i;
         GLfloat f;
         GLuint u;
     } mValue;
 
-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); }
 };
 
 struct IndexedBufferBinding
@@ -483,77 +483,77 @@ public:
     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& name,
                       JS::MutableHandle<JSObject*> retval, ErrorResult& rv);
-    void AttachShader(WebGLProgram* prog, WebGLShader* shader);
-    void BindAttribLocation(WebGLProgram* prog, GLuint location,
+    void AttachShader(WebGLProgram& prog, WebGLShader& shader);
+    void BindAttribLocation(WebGLProgram& prog, GLuint location,
                             const nsAString& name);
     void BindFramebuffer(GLenum target, WebGLFramebuffer* fb);
     void BindRenderbuffer(GLenum target, WebGLRenderbuffer* fb);
     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 CompileShader(WebGLShader& shader);
     void CompileShaderANGLE(WebGLShader* shader);
     void CompileShaderBypass(WebGLShader* shader, const nsCString& shaderSource);
     already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
     already_AddRefed<WebGLProgram> CreateProgram();
     already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
     already_AddRefed<WebGLShader> CreateShader(GLenum type);
     already_AddRefed<WebGLVertexArray> CreateVertexArray();
     void CullFace(GLenum face);
     void DeleteFramebuffer(WebGLFramebuffer* fb);
     void DeleteProgram(WebGLProgram* prog);
     void DeleteRenderbuffer(WebGLRenderbuffer* rb);
     void DeleteShader(WebGLShader* shader);
     void DeleteVertexArray(WebGLVertexArray* vao);
     void DepthFunc(GLenum func);
     void DepthMask(WebGLboolean b);
     void DepthRange(GLclampf zNear, GLclampf zFar);
-    void DetachShader(WebGLProgram* prog, WebGLShader* shader);
+    void DetachShader(WebGLProgram& prog, const WebGLShader& shader);
     void DrawBuffers(const dom::Sequence<GLenum>& buffers);
     void Flush();
     void Finish();
     void FramebufferRenderbuffer(GLenum target, GLenum attachment,
                                  GLenum rbTarget, WebGLRenderbuffer* rb);
     void FramebufferTexture2D(GLenum target, GLenum attachment,
                               GLenum texImageTarget, WebGLTexture* tex,
                               GLint level);
 
     // Framebuffer validation
     bool ValidateFramebufferAttachment(const WebGLFramebuffer* fb, GLenum attachment,
                                        const char* funcName,
                                        bool badColorAttachmentIsInvalidOp = false);
 
     void FrontFace(GLenum mode);
-    already_AddRefed<WebGLActiveInfo> GetActiveAttrib(WebGLProgram* prog,
+    already_AddRefed<WebGLActiveInfo> GetActiveAttrib(const WebGLProgram& prog,
                                                       GLuint index);
-    already_AddRefed<WebGLActiveInfo> GetActiveUniform(WebGLProgram* prog,
+    already_AddRefed<WebGLActiveInfo> GetActiveUniform(const WebGLProgram& prog,
                                                        GLuint index);
 
     void
-    GetAttachedShaders(WebGLProgram* prog,
+    GetAttachedShaders(const WebGLProgram& prog,
                        dom::Nullable<nsTArray<RefPtr<WebGLShader>>>& retval);
 
-    GLint GetAttribLocation(WebGLProgram* prog, const nsAString& name);
+    GLint GetAttribLocation(const WebGLProgram& prog, const nsAString& name);
     JS::Value GetBufferParameter(GLenum target, GLenum pname);
 
     void GetBufferParameter(JSContext*, GLenum target, GLenum pname,
                             JS::MutableHandle<JS::Value> retval)
     {
         retval.set(GetBufferParameter(target, pname));
     }
 
@@ -566,71 +566,70 @@ public:
                                            GLenum attachment, GLenum pname,
                                            JS::MutableHandle<JS::Value> retval,
                                            ErrorResult& rv)
     {
         retval.set(GetFramebufferAttachmentParameter(cx, target, attachment,
                                                      pname, rv));
     }
 
-    JS::Value GetProgramParameter(WebGLProgram* prog, GLenum pname);
+    JS::Value GetProgramParameter(const WebGLProgram& prog, GLenum pname);
 
-    void  GetProgramParameter(JSContext*, WebGLProgram* prog, GLenum pname,
+    void  GetProgramParameter(JSContext*, const 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(const WebGLProgram& prog, nsACString& retval);
+    void GetProgramInfoLog(const WebGLProgram& prog, nsAString& retval);
     JS::Value GetRenderbufferParameter(GLenum target, GLenum pname);
 
     void GetRenderbufferParameter(JSContext*, GLenum target, GLenum pname,
                                   JS::MutableHandle<JS::Value> retval)
     {
         retval.set(GetRenderbufferParameter(target, pname));
     }
 
-    JS::Value GetShaderParameter(WebGLShader* shader, GLenum pname);
+    JS::Value GetShaderParameter(const WebGLShader& shader, GLenum pname);
 
-    void GetShaderParameter(JSContext*, WebGLShader* shader, GLenum pname,
+    void GetShaderParameter(JSContext*, const 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);
+    void GetShaderInfoLog(const WebGLShader& shader, nsACString& retval);
+    void GetShaderInfoLog(const WebGLShader& shader, nsAString& retval);
+    void GetShaderSource(const WebGLShader& shader, nsAString& retval);
 
-    JS::Value GetUniform(JSContext* cx, WebGLProgram* prog,
-                         WebGLUniformLocation* loc);
+    JS::Value GetUniform(JSContext* cx, const WebGLProgram& prog,
+                         const WebGLUniformLocation& loc);
 
-    void GetUniform(JSContext* cx, WebGLProgram* prog,
-                    WebGLUniformLocation* loc,
+    void GetUniform(JSContext* cx, const WebGLProgram& prog,
+                    const WebGLUniformLocation& loc,
                     JS::MutableHandle<JS::Value> retval)
     {
         retval.set(GetUniform(cx, prog, loc));
     }
 
     already_AddRefed<WebGLUniformLocation>
-    GetUniformLocation(WebGLProgram* prog, const nsAString& name);
+    GetUniformLocation(const 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 IsVertexArray(WebGLVertexArray* vao);
     void LineWidth(GLfloat width);
-    void LinkProgram(WebGLProgram* prog);
+    void LinkProgram(WebGLProgram& prog);
     void PixelStorei(GLenum pname, GLint param);
     void PolygonOffset(GLfloat factor, GLfloat units);
 
     already_AddRefed<layers::SharedSurfaceTextureClient> GetVRFrame();
     bool StartVRPresentation();
 protected:
     bool ReadPixels_SharedPrecheck(ErrorResult* const out_error);
     void ReadPixelsImpl(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
@@ -663,17 +662,17 @@ public:
                              GLsizei width, GLsizei height);
 protected:
     void RenderbufferStorage_base(const char* funcName, GLenum target,
                                   GLsizei samples, GLenum internalformat,
                                   GLsizei width, GLsizei height);
 public:
     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 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);
 
@@ -864,17 +863,17 @@ public:
     bool ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
                                           uint8_t setterCols,
                                           uint8_t setterRows,
                                           GLenum setterType,
                                           uint32_t setterArraySize,
                                           bool setterTranspose,
                                           const char* funcName,
                                           uint32_t* out_numElementsToUpload);
-    void ValidateProgram(WebGLProgram* prog);
+    void ValidateProgram(const WebGLProgram& prog);
     bool ValidateUniformLocation(const char* info, WebGLUniformLocation* loc);
     bool ValidateSamplerUniformSetter(const char* info,
                                       WebGLUniformLocation* loc, GLint value);
     void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
 // -----------------------------------------------------------------------------
 // WEBGL_lose_context
 public:
     void LoseContext();
@@ -887,32 +886,31 @@ public:
     void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buf,
                          WebGLintptr offset, WebGLsizeiptr size);
 
 private:
     void BufferDataImpl(GLenum target, size_t dataLen, const uint8_t* data, GLenum usage);
 
 public:
     void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
+    void BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeSrc,
+                    GLenum usage);
     void BufferData(GLenum target, const dom::ArrayBufferView& srcData, GLenum usage,
                     GLuint srcElemOffset = 0, GLuint srcElemCountOverride = 0);
-    void BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeData,
-                    GLenum usage);
-    void BufferData(GLenum target, const dom::SharedArrayBuffer& data, GLenum usage);
 
 private:
     void BufferSubDataImpl(GLenum target, WebGLsizeiptr dstByteOffset,
                            size_t srcDataLen, const uint8_t* srcData);
 
 public:
     void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
                        const dom::ArrayBufferView& src, GLuint srcElemOffset = 0,
                        GLuint srcElemCountOverride = 0);
     void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
-                       const dom::Nullable<dom::ArrayBuffer>& maybeSrc);
+                       const dom::ArrayBuffer& src);
     void BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
                        const dom::SharedArrayBuffer& src);
 
     already_AddRefed<WebGLBuffer> CreateBuffer();
     void DeleteBuffer(WebGLBuffer* buf);
     bool IsBuffer(WebGLBuffer* buf);
 
 protected:
@@ -939,21 +937,21 @@ protected:
 
     WebGLRefPtr<WebGLQuery>*
     ValidateQuerySlotByTarget(const char* funcName, GLenum target);
 
 public:
     already_AddRefed<WebGLQuery> CreateQuery(const char* funcName = nullptr);
     void DeleteQuery(WebGLQuery* query, const char* funcName = nullptr);
     bool IsQuery(const WebGLQuery* query, const char* funcName = nullptr);
-    void BeginQuery(GLenum target, WebGLQuery* query, const char* funcName = nullptr);
+    void BeginQuery(GLenum target, WebGLQuery& query, const char* funcName = nullptr);
     void EndQuery(GLenum target, const char* funcName = nullptr);
     void GetQuery(JSContext* cx, GLenum target, GLenum pname,
                   JS::MutableHandleValue retval, const char* funcName = nullptr);
-    void GetQueryParameter(JSContext* cx, const WebGLQuery* query, GLenum pname,
+    void GetQueryParameter(JSContext* cx, const WebGLQuery& query, GLenum pname,
                            JS::MutableHandleValue retval, const char* funcName = nullptr);
 
 
 // -----------------------------------------------------------------------------
 // State and State Requests (WebGLContextState.cpp)
 public:
     void Disable(GLenum cap);
     void Enable(GLenum cap);
@@ -1522,19 +1520,16 @@ protected:
     bool ValidateAttribPointer(bool integerMode, GLuint index, GLint size, GLenum type,
                                WebGLboolean normalized, GLsizei stride,
                                WebGLintptr byteOffset, const char* info);
     bool ValidateStencilParamsForDrawCall();
 
     bool ValidateCopyTexImage(TexInternalFormat srcFormat, TexInternalFormat dstformat,
                               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 ValidateTexImageFormat(GLenum internalFormat, WebGLTexImageFunc func,
                                 WebGLTexDimensions dims);
@@ -1594,16 +1589,25 @@ protected:
         if (MOZ_UNLIKELY(val < 0)) {
             ErrorInvalidValue("%s: `%s` must be non-negative.", funcName, argName);
             return false;
         }
         return true;
     }
 
 public:
+    template<typename T>
+    bool ValidateNonNull(const char* funcName, const dom::Nullable<T>& maybe) {
+        if (maybe.IsNull()) {
+            ErrorInvalidValue("%s: `null` is invalid.", funcName);
+            return false;
+        }
+        return true;
+    }
+
     bool ValidateArrayBufferView(const char* funcName, const dom::ArrayBufferView& view,
                                  GLuint elemOffset, GLuint elemCountOverride,
                                  uint8_t** const out_bytes, size_t* const out_byteLen);
 
 protected:
     ////
 
     void Invalidate();
@@ -1615,21 +1619,25 @@ protected:
 
     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);
 
     //////
-
+public:
     // Returns false if `object` is null or not valid.
     template<class ObjectType>
     bool ValidateObject(const char* info, const ObjectType* object);
 
+    // Returns false if `object` is not valid.
+    template<class ObjectType>
+    bool ValidateObjectRef(const char* info, const ObjectType& object);
+
     // Returns false if `object` is not valid.  Considers null to be valid.
     template<class ObjectType>
     bool ValidateObjectAllowNull(const char* info, const 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, const ObjectType* object);
@@ -1924,18 +1932,17 @@ ToSupports(WebGLContext* webgl)
 }
 
 /**
  ** Template implementations
  **/
 
 template<class ObjectType>
 inline bool
-WebGLContext::ValidateObjectAllowDeletedOrNull(const char* info,
-                                               const ObjectType* object)
+WebGLContext::ValidateObjectAllowDeletedOrNull(const char* info, const ObjectType* object)
 {
     if (object && !object->IsCompatibleWithContext(this)) {
         ErrorInvalidOperation("%s: object from different WebGL context "
                               "(or older generation of this one) "
                               "passed as argument", info);
         return false;
     }
 
@@ -1988,16 +1995,24 @@ WebGLContext::ValidateObject(const char*
     if (!object) {
         ErrorInvalidValue("%s: null object passed as argument", info);
         return false;
     }
 
     return ValidateObjectAssumeNonNull(info, object);
 }
 
+template<class ObjectType>
+inline bool
+WebGLContext::ValidateObjectRef(const char* info, const ObjectType& object)
+{
+    MOZ_ASSERT(bool(&object));
+    return ValidateObjectAssumeNonNull(info, &object);
+}
+
 // Returns `value` rounded to the next highest multiple of `multiple`.
 // AKA PadToAlignment, StrideForAlignment.
 template<typename V, typename M>
 V
 RoundUpToMultipleOf(const V& value, const M& multiple)
 {
     return ((value + multiple - 1) / multiple) * multiple;
 }
--- a/dom/canvas/WebGLContextBuffers.cpp
+++ b/dom/canvas/WebGLContextBuffers.cpp
@@ -330,35 +330,25 @@ WebGLContext::BufferData(GLenum target, 
     const UniqueBuffer zeroBuffer(calloc(size, 1));
     if (!zeroBuffer)
         return ErrorOutOfMemory("%s: Failed to allocate zeros.", funcName);
 
     BufferDataImpl(target, size_t(size), (const uint8_t*)zeroBuffer.get(), usage);
 }
 
 void
-WebGLContext::BufferData(GLenum target, const dom::SharedArrayBuffer& src, GLenum usage)
-{
-    if (IsContextLost())
-        return;
-
-    src.ComputeLengthAndData();
-    BufferDataImpl(target, src.LengthAllowShared(), src.DataAllowShared(), usage);
-}
-
-void
 WebGLContext::BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeSrc,
                          GLenum usage)
 {
     if (IsContextLost())
         return;
 
-    if (maybeSrc.IsNull())
-        return ErrorInvalidValue("bufferData: null object passed");
-    auto& src = maybeSrc.Value();
+    if (!ValidateNonNull("bufferData", maybeSrc))
+        return;
+    const auto& src = maybeSrc.Value();
 
     src.ComputeLengthAndData();
     BufferDataImpl(target, src.LengthAllowShared(), src.DataAllowShared(), usage);
 }
 
 void
 WebGLContext::BufferData(GLenum target, const dom::ArrayBufferView& src, GLenum usage,
                          GLuint srcElemOffset, GLuint srcElemCountOverride)
@@ -418,33 +408,17 @@ WebGLContext::BufferSubDataImpl(GLenum t
     gl->fBufferSubData(target, dstByteOffset, glDataLen, data);
 
     // Warning: Possibly shared memory.  See bug 1225033.
     buffer->ElementArrayCacheBufferSubData(dstByteOffset, data, size_t(glDataLen));
 }
 
 void
 WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
-                            const dom::Nullable<dom::ArrayBuffer>& maybeSrc)
-{
-    if (IsContextLost())
-        return;
-
-    if (maybeSrc.IsNull())
-        return ErrorInvalidValue("BufferSubData: returnedData is null.");
-    auto& src = maybeSrc.Value();
-
-    src.ComputeLengthAndData();
-    BufferSubDataImpl(target, dstByteOffset, src.LengthAllowShared(),
-                      src.DataAllowShared());
-}
-
-void
-WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
-                            const dom::SharedArrayBuffer& src)
+                            const dom::ArrayBuffer& src)
 {
     if (IsContextLost())
         return;
 
     src.ComputeLengthAndData();
     BufferSubDataImpl(target, dstByteOffset, src.LengthAllowShared(),
                       src.DataAllowShared());
 }
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -82,41 +82,41 @@ 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))
+    if (!ValidateObjectRef("attachShader: program", program) ||
+        !ValidateObjectRef("attachShader: shader", shader))
     {
         return;
     }
 
-    program->AttachShader(shader);
+    program.AttachShader(&shader);
 }
 
 void
-WebGLContext::BindAttribLocation(WebGLProgram* prog, GLuint location,
+WebGLContext::BindAttribLocation(WebGLProgram& prog, GLuint location,
                                  const nsAString& name)
 {
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("bindAttribLocation: program", prog))
+    if (!ValidateObjectRef("bindAttribLocation: program", prog))
         return;
 
-    prog->BindAttribLocation(location, name);
+    prog.BindAttribLocation(location, name);
 }
 
 void
 WebGLContext::BindFramebuffer(GLenum target, WebGLFramebuffer* wfb)
 {
     if (IsContextLost())
         return;
 
@@ -431,30 +431,30 @@ WebGLContext::DeleteShader(WebGLShader* 
 
     if (!shader || shader->IsDeleted())
         return;
 
     shader->RequestDelete();
 }
 
 void
-WebGLContext::DetachShader(WebGLProgram* program, WebGLShader* shader)
+WebGLContext::DetachShader(WebGLProgram& program, const WebGLShader& shader)
 {
     if (IsContextLost())
         return;
 
     // It's valid to attempt to detach a deleted shader, since it's still a
     // shader.
-    if (!ValidateObject("detachShader: program", program) ||
-        !ValidateObjectAllowDeleted("detashShader: shader", shader))
+    if (!ValidateObjectRef("detachShader: program", program) ||
+        !ValidateObjectAllowDeleted("detachShader: shader", &shader))
     {
         return;
     }
 
-    program->DetachShader(shader);
+    program.DetachShader(&shader);
 }
 
 void
 WebGLContext::DepthFunc(GLenum func)
 {
     if (IsContextLost())
         return;
 
@@ -559,68 +559,63 @@ WebGLContext::FrontFace(GLenum mode)
             return ErrorInvalidEnumInfo("frontFace: mode", mode);
     }
 
     MakeContextCurrent();
     gl->fFrontFace(mode);
 }
 
 already_AddRefed<WebGLActiveInfo>
-WebGLContext::GetActiveAttrib(WebGLProgram* prog, GLuint index)
+WebGLContext::GetActiveAttrib(const WebGLProgram& prog, GLuint index)
 {
     if (IsContextLost())
         return nullptr;
 
-    if (!ValidateObject("getActiveAttrib: program", prog))
+    if (!ValidateObjectRef("getActiveAttrib: program", prog))
         return nullptr;
 
-    return prog->GetActiveAttrib(index);
+    return prog.GetActiveAttrib(index);
 }
 
 already_AddRefed<WebGLActiveInfo>
-WebGLContext::GetActiveUniform(WebGLProgram* prog, GLuint index)
+WebGLContext::GetActiveUniform(const WebGLProgram& prog, GLuint index)
 {
     if (IsContextLost())
         return nullptr;
 
-    if (!ValidateObject("getActiveUniform: program", prog))
+    if (!ValidateObjectRef("getActiveUniform: program", prog))
         return nullptr;
 
-    return prog->GetActiveUniform(index);
+    return prog.GetActiveUniform(index);
 }
 
 void
-WebGLContext::GetAttachedShaders(WebGLProgram* prog,
+WebGLContext::GetAttachedShaders(const WebGLProgram& prog,
                                  dom::Nullable<nsTArray<RefPtr<WebGLShader>>>& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
-    if (!prog) {
-        ErrorInvalidValue("getAttachedShaders: Invalid program.");
+    if (!ValidateObjectRef("getAttachedShaders", prog))
         return;
-    }
-
-    if (!ValidateObject("getAttachedShaders", prog))
-        return;
-
-    prog->GetAttachedShaders(&retval.SetValue());
+
+    prog.GetAttachedShaders(&retval.SetValue());
 }
 
 GLint
-WebGLContext::GetAttribLocation(WebGLProgram* prog, const nsAString& name)
+WebGLContext::GetAttribLocation(const WebGLProgram& prog, const nsAString& name)
 {
     if (IsContextLost())
         return -1;
 
-    if (!ValidateObject("getAttribLocation: program", prog))
+    if (!ValidateObjectRef("getAttribLocation: program", prog))
         return -1;
 
-    return prog->GetAttribLocation(name);
+    return prog.GetAttribLocation(name);
 }
 
 JS::Value
 WebGLContext::GetBufferParameter(GLenum target, GLenum pname)
 {
     if (IsContextLost())
         return JS::NullValue();
 
@@ -905,72 +900,70 @@ WebGLContext::GetError()
     MakeContextCurrent();
     GetAndFlushUnderlyingGLErrors();
 
     err = GetAndClearError(&mUnderlyingGLError);
     return err;
 }
 
 JS::Value
-WebGLContext::GetProgramParameter(WebGLProgram* prog, GLenum pname)
+WebGLContext::GetProgramParameter(const WebGLProgram& prog, GLenum pname)
 {
     if (IsContextLost())
         return JS::NullValue();
 
-    if (!ValidateObjectAllowDeleted("getProgramParameter: program", prog))
+    if (!ValidateObjectAllowDeleted("getProgramParameter: program", &prog))
         return JS::NullValue();
 
-    return prog->GetProgramParameter(pname);
+    return prog.GetProgramParameter(pname);
 }
 
 void
-WebGLContext::GetProgramInfoLog(WebGLProgram* prog, nsAString& retval)
+WebGLContext::GetProgramInfoLog(const WebGLProgram& prog, nsAString& retval)
 {
     retval.SetIsVoid(true);
 
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("getProgramInfoLog: program", prog))
+    if (!ValidateObjectRef("getProgramInfoLog: program", prog))
         return;
 
-    prog->GetProgramInfoLog(&retval);
-
-    retval.SetIsVoid(false);
+    prog.GetProgramInfoLog(&retval);
 }
 
 JS::Value
-WebGLContext::GetUniform(JSContext* js, WebGLProgram* prog,
-                         WebGLUniformLocation* loc)
+WebGLContext::GetUniform(JSContext* js, const WebGLProgram& prog,
+                         const WebGLUniformLocation& loc)
 {
     if (IsContextLost())
         return JS::NullValue();
 
-    if (!ValidateObject("getUniform: `program`", prog))
+    if (!ValidateObjectRef("getUniform: `program`", prog))
         return JS::NullValue();
 
-    if (!ValidateObject("getUniform: `location`", loc))
+    if (!ValidateObjectRef("getUniform: `location`", loc))
         return JS::NullValue();
 
-    if (!loc->ValidateForProgram(prog, "getUniform"))
+    if (!loc.ValidateForProgram(&prog, "getUniform"))
         return JS::NullValue();
 
-    return loc->GetUniform(js);
+    return loc.GetUniform(js);
 }
 
 already_AddRefed<WebGLUniformLocation>
-WebGLContext::GetUniformLocation(WebGLProgram* prog, const nsAString& name)
+WebGLContext::GetUniformLocation(const WebGLProgram& prog, const nsAString& name)
 {
     if (IsContextLost())
         return nullptr;
 
-    if (!ValidateObject("getUniformLocation: program", prog))
+    if (!ValidateObjectRef("getUniformLocation: program", prog))
         return nullptr;
 
-    return prog->GetUniformLocation(name);
+    return prog.GetUniformLocation(name);
 }
 
 void
 WebGLContext::Hint(GLenum target, GLenum mode)
 {
     if (IsContextLost())
         return;
 
@@ -1055,39 +1048,39 @@ WebGLContext::IsShader(WebGLShader* shad
     if (IsContextLost())
         return false;
 
     return ValidateObjectAllowDeleted("isShader", shader) &&
         !shader->IsDeleted();
 }
 
 void
-WebGLContext::LinkProgram(WebGLProgram* prog)
+WebGLContext::LinkProgram(WebGLProgram& prog)
 {
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("linkProgram", prog))
+    if (!ValidateObjectRef("linkProgram", prog))
         return;
 
-    prog->LinkProgram();
-
-    if (!prog->IsLinked()) {
+    prog.LinkProgram();
+
+    if (!prog.IsLinked()) {
         // If we failed to link, but `prog == mCurrentProgram`, we are *not* supposed to
         // null out mActiveProgramLinkInfo.
         return;
     }
 
-    if (prog == mCurrentProgram) {
-        mActiveProgramLinkInfo = prog->LinkInfo();
+    if (&prog == mCurrentProgram) {
+        mActiveProgramLinkInfo = prog.LinkInfo();
 
         if (gl->WorkAroundDriverBugs() &&
             gl->Vendor() == gl::GLVendor::NVIDIA)
         {
-            gl->fUseProgram(prog->mGLName);
+            gl->fUseProgram(prog.mGLName);
         }
     }
 }
 
 void
 WebGLContext::PixelStorei(GLenum pname, GLint param)
 {
     if (IsContextLost())
@@ -2121,25 +2114,25 @@ WebGLContext::UseProgram(WebGLProgram* p
 
     if (prog->UseProgram()) {
         mCurrentProgram = prog;
         mActiveProgramLinkInfo = mCurrentProgram->LinkInfo();
     }
 }
 
 void
-WebGLContext::ValidateProgram(WebGLProgram* prog)
+WebGLContext::ValidateProgram(const WebGLProgram& prog)
 {
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("validateProgram", prog))
+    if (!ValidateObjectRef("validateProgram", prog))
         return;
 
-    prog->ValidateProgram();
+    prog.ValidateProgram();
 }
 
 already_AddRefed<WebGLFramebuffer>
 WebGLContext::CreateFramebuffer()
 {
     if (IsContextLost())
         return nullptr;
 
@@ -2176,53 +2169,51 @@ 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))
+    if (!ValidateObjectRef("compileShader", shader))
         return;
 
-    shader->CompileShader();
+    shader.CompileShader();
 }
 
 JS::Value
-WebGLContext::GetShaderParameter(WebGLShader* shader, GLenum pname)
+WebGLContext::GetShaderParameter(const WebGLShader& shader, GLenum pname)
 {
     if (IsContextLost())
         return JS::NullValue();
 
-    if (!ValidateObject("getShaderParameter: shader", shader))
+    if (!ValidateObjectRef("getShaderParameter: shader", shader))
         return JS::NullValue();
 
-    return shader->GetShaderParameter(pname);
+    return shader.GetShaderParameter(pname);
 }
 
 void
-WebGLContext::GetShaderInfoLog(WebGLShader* shader, nsAString& retval)
+WebGLContext::GetShaderInfoLog(const WebGLShader& shader, nsAString& retval)
 {
     retval.SetIsVoid(true);
 
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("getShaderInfoLog: shader", shader))
+    if (!ValidateObjectRef("getShaderInfoLog: shader", shader))
         return;
 
-    shader->GetShaderInfoLog(&retval);
-
-    retval.SetIsVoid(false);
+    shader.GetShaderInfoLog(&retval);
 }
 
 already_AddRefed<WebGLShaderPrecisionFormat>
 WebGLContext::GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype)
 {
     if (IsContextLost())
         return nullptr;
 
@@ -2264,53 +2255,39 @@ WebGLContext::GetShaderPrecisionFormat(G
     }
 
     RefPtr<WebGLShaderPrecisionFormat> retShaderPrecisionFormat
         = new WebGLShaderPrecisionFormat(this, range[0], range[1], precision);
     return retShaderPrecisionFormat.forget();
 }
 
 void
-WebGLContext::GetShaderSource(WebGLShader* shader, nsAString& retval)
+WebGLContext::GetShaderSource(const WebGLShader& shader, nsAString& retval)
 {
     retval.SetIsVoid(true);
 
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("getShaderSource: shader", shader))
+    if (!ValidateObjectRef("getShaderSource: shader", shader))
         return;
 
-    shader->GetShaderSource(&retval);
+    shader.GetShaderSource(&retval);
 }
 
 void
-WebGLContext::ShaderSource(WebGLShader* shader, const nsAString& source)
+WebGLContext::ShaderSource(WebGLShader& shader, const nsAString& source)
 {
     if (IsContextLost())
         return;
 
-    if (!ValidateObject("shaderSource: shader", shader))
+    if (!ValidateObjectRef("shaderSource: shader", shader))
         return;
 
-    shader->ShaderSource(source);
-}
-
-void
-WebGLContext::GetShaderTranslatedSource(WebGLShader* shader, nsAString& retval)
-{
-    retval.SetIsVoid(true);
-
-    if (IsContextLost())
-        return;
-
-    if (!ValidateObject("getShaderTranslatedSource: shader", shader))
-        return;
-
-    shader->GetShaderTranslatedSource(&retval);
+    shader.ShaderSource(source);
 }
 
 void
 WebGLContext::LoseContext()
 {
     if (IsContextLost())
         return ErrorInvalidOperation("loseContext: Context is already lost.");
 
--- a/dom/canvas/WebGLContextUnchecked.cpp
+++ b/dom/canvas/WebGLContextUnchecked.cpp
@@ -11,84 +11,9 @@
 
 namespace mozilla {
 
 WebGLContextUnchecked::WebGLContextUnchecked(gl::GLContext* _gl)
     : mGL_OnlyClearInDestroyResourcesAndContext(_gl)
     , gl(mGL_OnlyClearInDestroyResourcesAndContext) // const reference
 { }
 
-// -----------------------------------------------------------------------------
-// Sampler Objects
-
-void
-WebGLContextUnchecked::BindSampler(GLuint unit, WebGLSampler* sampler)
-{
-    gl->MakeCurrent();
-    gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
-}
-
-GLint
-WebGLContextUnchecked::GetSamplerParameteriv(WebGLSampler* sampler,
-                                             GLenum pname)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-
-    GLint param = 0;
-    gl->MakeCurrent();
-    gl->fGetSamplerParameteriv(sampler->mGLName, pname, &param);
-
-    return param;
-}
-
-GLfloat
-WebGLContextUnchecked::GetSamplerParameterfv(WebGLSampler* sampler,
-                                             GLenum pname)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-
-    GLfloat param = 0.0f;
-    gl->MakeCurrent();
-    gl->fGetSamplerParameterfv(sampler->mGLName, pname, &param);
-    return param;
-}
-
-void
-WebGLContextUnchecked::SamplerParameteri(WebGLSampler* sampler,
-                                         GLenum pname,
-                                         GLint param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameteri(sampler->mGLName, pname, param);
-}
-
-void
-WebGLContextUnchecked::SamplerParameteriv(WebGLSampler* sampler,
-                                          GLenum pname,
-                                          const GLint* param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameteriv(sampler->mGLName, pname, param);
-}
-
-void
-WebGLContextUnchecked::SamplerParameterf(WebGLSampler* sampler,
-                                         GLenum pname,
-                                         GLfloat param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameterf(sampler->mGLName, pname, param);
-}
-
-void
-WebGLContextUnchecked::SamplerParameterfv(WebGLSampler* sampler,
-                                          GLenum pname,
-                                          const GLfloat* param)
-{
-    MOZ_ASSERT(sampler, "Did you validate?");
-    gl->MakeCurrent();
-    gl->fSamplerParameterfv(sampler->mGLName, pname, param);
-}
-
 } // namespace mozilla
--- a/dom/canvas/WebGLContextUnchecked.h
+++ b/dom/canvas/WebGLContextUnchecked.h
@@ -15,28 +15,16 @@ namespace mozilla {
 class WebGLBuffer;
 class WebGLSampler;
 
 class WebGLContextUnchecked
 {
 public:
     explicit WebGLContextUnchecked(gl::GLContext* gl);
 
-    // -------------------------------------------------------------------------
-    // Sampler Objects
-    void BindSampler(GLuint unit, WebGLSampler* sampler);
-
-    GLint   GetSamplerParameteriv(WebGLSampler* sampler, GLenum pname);
-    GLfloat GetSamplerParameterfv(WebGLSampler* sampler, GLenum pname);
-
-    void SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param);
-    void SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const GLint* param);
-    void SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param);
-    void SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const GLfloat* param);
-
 protected:
     // We've had issues in the past with nulling `gl` without actually releasing
     // all of our resources. This construction ensures that we are aware that we
     // should only null `gl` in DestroyResourcesAndContext.
     RefPtr<gl::GLContext> mGL_OnlyClearInDestroyResourcesAndContext;
 public:
     // Grab a const reference so we can see changes, but can't make changes.
     const decltype(mGL_OnlyClearInDestroyResourcesAndContext)& gl;
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -235,127 +235,16 @@ WebGLContext::ValidateFramebufferAttachm
         ErrorInvalidOperation("%s: Bad color attachment: COLOR_ATTACHMENT%u. (0x%04x)",
                               funcName, offset, attachment);
     } else {
         ErrorInvalidEnum("%s: attachment: Bad attachment 0x%x.", funcName, attachment);
     }
     return false;
 }
 
-/**
- * Return true if pname is valid for GetSamplerParameter calls.
- */
-bool
-WebGLContext::ValidateSamplerParameterName(GLenum pname, const char* info)
-{
-    switch (pname) {
-    case LOCAL_GL_TEXTURE_MIN_FILTER:
-    case LOCAL_GL_TEXTURE_MAG_FILTER:
-    case LOCAL_GL_TEXTURE_WRAP_S:
-    case LOCAL_GL_TEXTURE_WRAP_T:
-    case LOCAL_GL_TEXTURE_WRAP_R:
-    case LOCAL_GL_TEXTURE_MIN_LOD:
-    case LOCAL_GL_TEXTURE_MAX_LOD:
-    case LOCAL_GL_TEXTURE_COMPARE_MODE:
-    case LOCAL_GL_TEXTURE_COMPARE_FUNC:
-        return true;
-
-    default:
-        ErrorInvalidEnum("%s: invalid pname: %s", info, EnumName(pname));
-        return false;
-    }
-}
-
-/**
- * Return true if pname and param are valid combination for SamplerParameter calls.
- */
-bool
-WebGLContext::ValidateSamplerParameterParams(GLenum pname, const WebGLIntOrFloat& param, const char* info)
-{
-    const GLenum p = param.AsInt();
-
-    switch (pname) {
-    case LOCAL_GL_TEXTURE_MIN_FILTER:
-        switch (p) {
-        case LOCAL_GL_NEAREST:
-        case LOCAL_GL_LINEAR:
-        case LOCAL_GL_NEAREST_MIPMAP_NEAREST:
-        case LOCAL_GL_NEAREST_MIPMAP_LINEAR:
-        case LOCAL_GL_LINEAR_MIPMAP_NEAREST:
-        case LOCAL_GL_LINEAR_MIPMAP_LINEAR:
-            return true;
-
-        default:
-            ErrorInvalidEnum("%s: invalid param: %s", info, EnumName(p));
-            return false;
-        }
-
-    case LOCAL_GL_TEXTURE_MAG_FILTER:
-        switch (p) {
-        case LOCAL_GL_NEAREST:
-        case LOCAL_GL_LINEAR:
-            return true;
-
-        default:
-            ErrorInvalidEnum("%s: invalid param: %s", info, EnumName(p));
-            return false;
-        }
-
-    case LOCAL_GL_TEXTURE_WRAP_S:
-    case LOCAL_GL_TEXTURE_WRAP_T:
-    case LOCAL_GL_TEXTURE_WRAP_R:
-        switch (p) {
-        case LOCAL_GL_CLAMP_TO_EDGE:
-        case LOCAL_GL_REPEAT:
-        case LOCAL_GL_MIRRORED_REPEAT:
-            return true;
-
-        default:
-            ErrorInvalidEnum("%s: invalid param: %s", info, EnumName(p));
-            return false;
-        }
-
-    case LOCAL_GL_TEXTURE_MIN_LOD:
-    case LOCAL_GL_TEXTURE_MAX_LOD:
-        return true;
-
-    case LOCAL_GL_TEXTURE_COMPARE_MODE:
-        switch (param.AsInt()) {
-        case LOCAL_GL_NONE:
-        case LOCAL_GL_COMPARE_REF_TO_TEXTURE:
-            return true;
-
-        default:
-            ErrorInvalidEnum("%s: invalid param: %s", info, EnumName(p));
-            return false;
-        }
-
-    case LOCAL_GL_TEXTURE_COMPARE_FUNC:
-        switch (p) {
-        case LOCAL_GL_LEQUAL:
-        case LOCAL_GL_GEQUAL:
-        case LOCAL_GL_LESS:
-        case LOCAL_GL_GREATER:
-        case LOCAL_GL_EQUAL:
-        case LOCAL_GL_NOTEQUAL:
-        case LOCAL_GL_ALWAYS:
-        case LOCAL_GL_NEVER:
-            return true;
-
-        default:
-            ErrorInvalidEnum("%s: invalid param: %s", info, EnumName(p));
-            return false;
-        }
-
-    default:
-        ErrorInvalidEnum("%s: invalid pname: %s", info, EnumName(pname));
-        return false;
-    }
-}
-
 bool
 WebGLContext::ValidateUniformLocation(WebGLUniformLocation* loc, const char* funcName)
 {
     /* GLES 2.0.25, p38:
      *   If the value of location is -1, the Uniform* commands will silently
      *   ignore the data passed in, and the current uniform values will not be
      *   changed.
      */
--- a/dom/canvas/WebGLExtensionDebugShaders.cpp
+++ b/dom/canvas/WebGLExtensionDebugShaders.cpp
@@ -2,42 +2,48 @@
 /* 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 "WebGLExtensions.h"
 
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLShader.h"
 
 namespace mozilla {
 
 WebGLExtensionDebugShaders::WebGLExtensionDebugShaders(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
 }
 
 WebGLExtensionDebugShaders::~WebGLExtensionDebugShaders()
 {
 }
 
 // If no source has been defined, compileShader() has not been called, or the
 // translation has failed for shader, an empty string is returned; otherwise,
 // return the translated source.
 void
-WebGLExtensionDebugShaders::GetTranslatedShaderSource(WebGLShader* shader,
-                                                      nsAString& retval)
+WebGLExtensionDebugShaders::GetTranslatedShaderSource(const WebGLShader& shader,
+                                                      nsAString& retval) const
 {
     retval.SetIsVoid(true);
 
     if (mIsLost) {
         mContext->ErrorInvalidOperation("%s: Extension is lost.",
                                         "getTranslatedShaderSource");
         return;
     }
 
-    retval.SetIsVoid(false);
-    mContext->GetShaderTranslatedSource(shader, retval);
+    if (mContext->IsContextLost())
+        return;
+
+    if (!mContext->ValidateObjectRef("getShaderTranslatedSource: shader", shader))
+        return;
+
+    shader.GetShaderTranslatedSource(&retval);
 }
 
 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDebugShaders, WEBGL_debug_shaders)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
+++ b/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
@@ -52,17 +52,17 @@ WebGLExtensionDisjointTimerQuery::IsQuer
     const char funcName[] = "isQueryEXT";
     if (mIsLost)
         return false;
 
     return mContext->IsQuery(query, funcName);
 }
 
 void
-WebGLExtensionDisjointTimerQuery::BeginQueryEXT(GLenum target, WebGLQuery* query) const
+WebGLExtensionDisjointTimerQuery::BeginQueryEXT(GLenum target, WebGLQuery& query) const
 {
     const char funcName[] = "beginQueryEXT";
     if (mIsLost)
         return;
 
     mContext->BeginQuery(target, query, funcName);
 }
 
@@ -72,43 +72,43 @@ WebGLExtensionDisjointTimerQuery::EndQue
     const char funcName[] = "endQueryEXT";
     if (mIsLost)
         return;
 
     mContext->EndQuery(target, funcName);
 }
 
 void
-WebGLExtensionDisjointTimerQuery::QueryCounterEXT(WebGLQuery* query, GLenum target) const
+WebGLExtensionDisjointTimerQuery::QueryCounterEXT(WebGLQuery& query, GLenum target) const
 {
     const char funcName[] = "queryCounterEXT";
     if (mIsLost)
         return;
 
-    if (!mContext->ValidateObject(funcName, query))
+    if (!mContext->ValidateObjectRef(funcName, query))
         return;
 
-    query->QueryCounter(funcName, target);
+    query.QueryCounter(funcName, target);
 }
 
 void
 WebGLExtensionDisjointTimerQuery::GetQueryEXT(JSContext* cx, GLenum target, GLenum pname,
                                               JS::MutableHandleValue retval) const
 {
     const char funcName[] = "getQueryEXT";
     retval.setNull();
     if (mIsLost)
         return;
 
     mContext->GetQuery(cx, target, pname, retval, funcName);
 }
 
 void
 WebGLExtensionDisjointTimerQuery::GetQueryObjectEXT(JSContext* cx,
-                                                    const WebGLQuery* query, GLenum pname,
+                                                    const WebGLQuery& query, GLenum pname,
                                                     JS::MutableHandleValue retval) const
 {
     const char funcName[] = "getQueryObjectEXT";
     retval.setNull();
     if (mIsLost)
         return;
 
     mContext->GetQueryParameter(cx, query, pname, retval, funcName);
--- a/dom/canvas/WebGLExtensions.h
+++ b/dom/canvas/WebGLExtensions.h
@@ -122,17 +122,17 @@ public:
 
 class WebGLExtensionDebugShaders
     : public WebGLExtensionBase
 {
 public:
     explicit WebGLExtensionDebugShaders(WebGLContext*);
     virtual ~WebGLExtensionDebugShaders();
 
-    void GetTranslatedShaderSource(WebGLShader* shader, nsAString& retval);
+    void GetTranslatedShaderSource(const WebGLShader& shader, nsAString& retval) const;
 
     DECL_WEBGL_EXTENSION_GOOP
 };
 
 class WebGLExtensionDepthTexture
     : public WebGLExtensionBase
 {
 public:
@@ -367,22 +367,22 @@ class WebGLExtensionDisjointTimerQuery
 {
 public:
     explicit WebGLExtensionDisjointTimerQuery(WebGLContext* webgl);
     virtual ~WebGLExtensionDisjointTimerQuery();
 
     already_AddRefed<WebGLQuery> CreateQueryEXT() const;
     void DeleteQueryEXT(WebGLQuery* query) const;
     bool IsQueryEXT(const WebGLQuery* query) const;
-    void BeginQueryEXT(GLenum target, WebGLQuery* query) const;
+    void BeginQueryEXT(GLenum target, WebGLQuery& query) const;
     void EndQueryEXT(GLenum target) const;
-    void QueryCounterEXT(WebGLQuery* query, GLenum target) const;
+    void QueryCounterEXT(WebGLQuery& query, GLenum target) const;
     void GetQueryEXT(JSContext* cx, GLenum target, GLenum pname,
                      JS::MutableHandleValue retval) const;
-    void GetQueryObjectEXT(JSContext* cx, const WebGLQuery* query,
+    void GetQueryObjectEXT(JSContext* cx, const WebGLQuery& query,
                            GLenum pname, JS::MutableHandleValue retval) const;
 
     static bool IsSupported(const WebGLContext*);
 
     DECL_WEBGL_EXTENSION_GOOP
 };
 
 } // namespace mozilla
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -532,17 +532,17 @@ WebGLProgram::BindAttribLocation(GLuint 
     const bool wasInserted = res.second;
     if (!wasInserted) {
         auto itr = res.first;
         itr->second = loc;
     }
 }
 
 void
-WebGLProgram::DetachShader(WebGLShader* shader)
+WebGLProgram::DetachShader(const WebGLShader* shader)
 {
     MOZ_ASSERT(shader);
 
     WebGLRefPtr<WebGLShader>* shaderSlot;
     switch (shader->mType) {
     case LOCAL_GL_VERTEX_SHADER:
         shaderSlot = &mVertShader;
         break;
--- a/dom/canvas/WebGLProgram.h
+++ b/dom/canvas/WebGLProgram.h
@@ -140,17 +140,17 @@ public:
 
     explicit WebGLProgram(WebGLContext* webgl);
 
     void Delete();
 
     // GL funcs
     void AttachShader(WebGLShader* shader);
     void BindAttribLocation(GLuint index, const nsAString& name);
-    void DetachShader(WebGLShader* shader);
+    void DetachShader(const WebGLShader* shader);
     already_AddRefed<WebGLActiveInfo> GetActiveAttrib(GLuint index) const;
     already_AddRefed<WebGLActiveInfo> GetActiveUniform(GLuint index) const;
     void GetAttachedShaders(nsTArray<RefPtr<WebGLShader>>* const out) const;
     GLint GetAttribLocation(const nsAString& name) const;
     GLint GetFragDataLocation(const nsAString& name) const;
     void GetProgramInfoLog(nsAString* const out) const;
     JS::Value GetProgramParameter(GLenum pname) const;
     GLuint GetUniformBlockIndex(const nsAString& name) const;
--- a/dom/canvas/WebGLSampler.cpp
+++ b/dom/canvas/WebGLSampler.cpp
@@ -48,116 +48,161 @@ WebGLSampler::GetParentObject() const
 }
 
 JSObject*
 WebGLSampler::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
     return dom::WebGLSamplerBinding::Wrap(cx, this, givenProto);
 }
 
-void
-WebGLSampler::SamplerParameter1i(GLenum pname, GLint param)
+static bool
+ValidateSamplerParameterParams(WebGLContext* webgl, const char* funcName, GLenum pname,
+                               GLint paramInt)
 {
     switch (pname) {
     case LOCAL_GL_TEXTURE_MIN_FILTER:
-        mMinFilter = param;
+        switch (paramInt) {
+        case LOCAL_GL_NEAREST:
+        case LOCAL_GL_LINEAR:
+        case LOCAL_GL_NEAREST_MIPMAP_NEAREST:
+        case LOCAL_GL_NEAREST_MIPMAP_LINEAR:
+        case LOCAL_GL_LINEAR_MIPMAP_NEAREST:
+        case LOCAL_GL_LINEAR_MIPMAP_LINEAR:
+            return true;
+
+        default:
+            break;
+        }
         break;
 
     case LOCAL_GL_TEXTURE_MAG_FILTER:
-        mMagFilter = param;
+        switch (paramInt) {
+        case LOCAL_GL_NEAREST:
+        case LOCAL_GL_LINEAR:
+            return true;
+
+        default:
+            break;
+        }
         break;
 
     case LOCAL_GL_TEXTURE_WRAP_S:
-        mWrapS = param;
+    case LOCAL_GL_TEXTURE_WRAP_T:
+    case LOCAL_GL_TEXTURE_WRAP_R:
+        switch (paramInt) {
+        case LOCAL_GL_CLAMP_TO_EDGE:
+        case LOCAL_GL_REPEAT:
+        case LOCAL_GL_MIRRORED_REPEAT:
+            return true;
+
+        default:
+            break;
+        }
+        break;
+
+    case LOCAL_GL_TEXTURE_MIN_LOD:
+    case LOCAL_GL_TEXTURE_MAX_LOD:
+        return true;
+
+    case LOCAL_GL_TEXTURE_COMPARE_MODE:
+        switch (paramInt) {
+        case LOCAL_GL_NONE:
+        case LOCAL_GL_COMPARE_REF_TO_TEXTURE:
+            return true;
+
+        default:
+            break;
+        }
+        break;
+
+    case LOCAL_GL_TEXTURE_COMPARE_FUNC:
+        switch (paramInt) {
+        case LOCAL_GL_LEQUAL:
+        case LOCAL_GL_GEQUAL:
+        case LOCAL_GL_LESS:
+        case LOCAL_GL_GREATER:
+        case LOCAL_GL_EQUAL:
+        case LOCAL_GL_NOTEQUAL:
+        case LOCAL_GL_ALWAYS:
+        case LOCAL_GL_NEVER:
+            return true;
+
+        default:
+            break;
+        }
+        break;
+
+    default:
+        webgl->ErrorInvalidEnum("%s: invalid pname: %s", funcName,
+                                webgl->EnumName(pname));
+        return false;
+    }
+
+    webgl->ErrorInvalidEnum("%s: invalid param: %s", funcName, webgl->EnumName(paramInt));
+    return false;
+}
+
+void
+WebGLSampler::SamplerParameter(const char* funcName, GLenum pname, GLint paramInt)
+{
+    if (!ValidateSamplerParameterParams(mContext, funcName, pname, paramInt))
+        return;
+
+    switch (pname) {
+    case LOCAL_GL_TEXTURE_MIN_FILTER:
+        mMinFilter = paramInt;
+        break;
+
+    case LOCAL_GL_TEXTURE_MAG_FILTER:
+        mMagFilter = paramInt;
+        break;
+
+    case LOCAL_GL_TEXTURE_WRAP_S:
+        mWrapS = paramInt;
         break;
 
     case LOCAL_GL_TEXTURE_WRAP_T:
-        mWrapT = param;
+        mWrapT = paramInt;
         break;
 
     case LOCAL_GL_TEXTURE_WRAP_R:
-        mWrapR = param;
+        mWrapR = paramInt;
         break;
 
     case LOCAL_GL_TEXTURE_COMPARE_MODE:
-        mCompareMode = param;
+        mCompareMode = paramInt;
         break;
 
     case LOCAL_GL_TEXTURE_COMPARE_FUNC:
-        mCompareFunc = param;
+        mCompareFunc = paramInt;
         break;
 
     case LOCAL_GL_TEXTURE_MIN_LOD:
-        mMinLod = param;
+        mMinLod = paramInt;
         break;
 
     case LOCAL_GL_TEXTURE_MAX_LOD:
-        mMaxLod = param;
+        mMaxLod = paramInt;
         break;
 
     default:
         MOZ_CRASH("GFX: Unhandled pname");
         break;
     }
 
     for (uint32_t i = 0; i < mContext->mBoundSamplers.Length(); ++i) {
         if (this == mContext->mBoundSamplers[i])
             mContext->InvalidateResolveCacheForTextureWithTexUnit(i);
     }
+
+    ////
+
+    mContext->gl->MakeCurrent();
+    mContext->gl->fSamplerParameteri(mGLName, pname, paramInt);
 }
 
-void
-WebGLSampler::SamplerParameter1f(GLenum pname, GLfloat param)
-{
-    switch (pname) {
-    case LOCAL_GL_TEXTURE_MIN_LOD:
-        mMinLod = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_MAX_LOD:
-        mMaxLod = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_WRAP_S:
-        mWrapS = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_WRAP_T:
-        mWrapT = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_WRAP_R:
-        mWrapR = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_MAG_FILTER:
-        mMagFilter = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_MIN_FILTER:
-        mMinFilter = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_COMPARE_MODE:
-        mCompareMode = param;
-        break;
-
-    case LOCAL_GL_TEXTURE_COMPARE_FUNC:
-        mCompareFunc = param;
-        break;
-
-    default:
-        MOZ_CRASH("GFX: Unhandled pname");
-        break;
-    }
-
-    for (uint32_t i = 0; i < mContext->mBoundSamplers.Length(); ++i) {
-        if (this == mContext->mBoundSamplers[i])
-            mContext->InvalidateResolveCacheForTextureWithTexUnit(i);
-    }
-}
-
+////
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLSampler)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLSampler, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLSampler, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLSampler.h
+++ b/dom/canvas/WebGLSampler.h
@@ -27,21 +27,19 @@ public:
 
     const GLuint mGLName;
 
     void Delete();
     WebGLContext* GetParentObject() const;
 
     virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
-    void SamplerParameter1i(GLenum pname, GLint param);
-    void SamplerParameter1f(GLenum pname, GLfloat param);
+    void SamplerParameter(const char* funcName, GLenum pname, GLint paramInt);
 
 private:
-
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLSampler)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLSampler)
 
     TexMinFilter mMinFilter;
     TexMagFilter mMagFilter;
     TexWrap mWrapS;
     TexWrap mWrapT;
     TexWrap mWrapR;
--- a/dom/canvas/WebGLUniformLocation.cpp
+++ b/dom/canvas/WebGLUniformLocation.cpp
@@ -24,17 +24,18 @@ WebGLUniformLocation::WebGLUniformLocati
     , mLoc(loc)
     , mArrayIndex(arrayIndex)
 { }
 
 WebGLUniformLocation::~WebGLUniformLocation()
 { }
 
 bool
-WebGLUniformLocation::ValidateForProgram(WebGLProgram* prog, const char* funcName) const
+WebGLUniformLocation::ValidateForProgram(const WebGLProgram* prog,
+                                         const char* funcName) const
 {
     // Check the weak-pointer.
     if (!mLinkInfo) {
         mContext->ErrorInvalidOperation("%s: This uniform location is obsolete because"
                                         " its program has been successfully relinked.",
                                         funcName);
         return false;
     }
--- a/dom/canvas/WebGLUniformLocation.h
+++ b/dom/canvas/WebGLUniformLocation.h
@@ -47,17 +47,17 @@ public:
     const GLuint mLoc;
     const size_t mArrayIndex;
 
     //////
 
     WebGLUniformLocation(WebGLContext* webgl, const webgl::LinkedProgramInfo* linkInfo,
                          webgl::UniformInfo* info, GLuint loc, size_t arrayIndex);
 
-    bool ValidateForProgram(WebGLProgram* prog, const char* funcName) const;
+    bool ValidateForProgram(const WebGLProgram* prog, const char* funcName) const;
     bool ValidateSizeAndType(uint8_t setterElemSize, GLenum setterType,
                              const char* funcName) const;
     bool ValidateArrayLength(uint8_t setterElemSize, size_t setterArraySize,
                              const char* funcName) const;
 
     JS::Value GetUniform(JSContext* js) const;
 
     // Needed for certain helper functions like ValidateObject.
--- a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-and-buffer-sub-data.html
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/buffer-data-and-buffer-sub-data.html
@@ -46,17 +46,17 @@ debug('Regression test for <a href="http
 var wtu = WebGLTestUtils;
 var gl = wtu.create3DContext();
 if (!gl) {
     testFailed("WebGL context does not exist");
 } else {
     testPassed("WebGL context exists");
 
     bufferDataTest();
-    bufferDataSizesTest();    
+    bufferDataSizesTest();
 
     bufferSubDataTest();
 }
 
 function bufferDataTest() {
     debug("");
     debug("Test bufferData without ArrayBuffer input");
 
@@ -158,32 +158,29 @@ function bufferSubDataTest() {
     gl.bufferSubData(gl.ARRAY_BUFFER, -10, new Float32Array(8));
     wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
         "calling bufferSubData with ArrayBufferView when offset is negative should generate INVALID_VALUE");
 
     gl.bufferSubData(gl.ARRAY_BUFFER, 10, array);
     wtu.glErrorShouldBe(gl, gl.NO_ERROR,
         "calling bufferSubData with ArrayBuffer should succeed");
 
-    gl.bufferSubData(gl.ARRAY_BUFFER, 10, null);
-    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
-        "calling bufferSubData when BufferDataSource is null should generate INVALID_VALUE");
-
-    wtu.shouldGenerateGLError(gl, gl.INVALID_VALUE, "gl.bufferSubData(gl.ARRAY_BUFFER, 10, undefined)");
-
     gl.bufferSubData(gl.ARRAY_BUFFER, 10, new Float32Array(0));
     wtu.glErrorShouldBe(gl, gl.NO_ERROR,
         "calling bufferSubData with zero-sized ArrayBufferView should succeed");
 
     // Arguments that are not ArrayBuffers, null or undefined should throw a TypeError exception
     shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, 42);");
     shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, 5.5);");
     shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, \"5.5\");");
     shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, [4]);");
     shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, { mynumber: 42});");
+    shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, null)");
+    shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, undefined)");
+    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should generate no GL error");
 
     gl.bindBuffer(gl.ARRAY_BUFFER, null);
 }
 
 var successfullyParsed = true;
 </script>
 
 <script src="../../js/js-test-post.js"></script>
--- a/dom/canvas/test/webgl-conf/checkout/conformance/context/context-lost.html
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/context/context-lost.html
@@ -80,16 +80,19 @@ function init()
     }
     extension = gl.getExtension(extensionName);
 
     // need an extension that exposes new API methods.
     OES_vertex_array_object = wtu.getExtensionWithKnownPrefixes(gl, "OES_vertex_array_object");
 
     canvas.addEventListener("webglcontextlost", testLostContext, false);
 
+    // We need to initialize |uniformLocation| before losing context.
+    // Otherwise gl.getUniform() when context is lost will throw.
+    uniformLocation = gl.getUniformLocation(program, "tex");
     loseContext();
 }
 
 function loseContext()
 {
     debug("");
     debug("Lose context");
 
@@ -238,24 +241,24 @@ function testLostContext()
         "gl.stencilFuncSeparate(gl.FRONT, gl.NEVER, 0, 0)",
         "gl.stencilMask(0)",
         "gl.stencilMaskSeparate(gl.FRONT, 0)",
         "gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP)",
         "gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP)",
         "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
         "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imageData)",
         "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image)",
-        "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas)",
+        "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d)",
         "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video)",
         "gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)",
         "gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)",
         "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
         "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData)",
         "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image)",
-        "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, canvas)",
+        "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d)",
         "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, video)",
         "gl.uniform1f(uniformLocation, 0)",
         "gl.uniform1fv(uniformLocation, float32array)",
         "gl.uniform1fv(uniformLocation, [0])",
         "gl.uniform1i(uniformLocation, 0)",
         "gl.uniform1iv(uniformLocation, int32array)",
         "gl.uniform1iv(uniformLocation, [0])",
         "gl.uniform2f(uniformLocation, 0, 0)",
--- a/dom/canvas/test/webgl-conf/checkout/conformance/misc/error-reporting.html
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/misc/error-reporting.html
@@ -46,31 +46,29 @@ var program = wtu.loadStandardProgram(co
 // of many synthetic GL errors. This test verifies the raising of certain
 // known real GL errors, and contains a few regression tests for bugs
 // discovered in the synthetic error generation and in the WebGL
 // implementation itself.
 
 wtu.glErrorShouldBe(context, context.NO_ERROR);
 
 debug("Testing getActiveAttrib");
-// Synthetic OpenGL error
-shouldBeNull("context.getActiveAttrib(null, 2)");
-wtu.glErrorShouldBe(context, context.INVALID_VALUE);
+shouldThrow("context.getActiveAttrib(null, 2)");
+wtu.glErrorShouldBe(context, context.NO_ERROR);
 // Error state should be clear by this point
 wtu.glErrorShouldBe(context, context.NO_ERROR);
 // Real OpenGL error
 shouldBeNull("context.getActiveAttrib(program, 2)");
 wtu.glErrorShouldBe(context, context.INVALID_VALUE);
 // Error state should be clear by this point
 wtu.glErrorShouldBe(context, context.NO_ERROR);
 
 debug("Testing getActiveUniform");
-// Synthetic OpenGL error
-shouldBeNull("context.getActiveUniform(null, 0)");
-wtu.glErrorShouldBe(context, context.INVALID_VALUE);
+shouldThrow("context.getActiveUniform(null, 0)");
+wtu.glErrorShouldBe(context, context.NO_ERROR);
 // Error state should be clear by this point
 wtu.glErrorShouldBe(context, context.NO_ERROR);
 // Real OpenGL error
 shouldBeNull("context.getActiveUniform(program, 50)");
 wtu.glErrorShouldBe(context, context.INVALID_VALUE);
 // Error state should be clear by this point
 wtu.glErrorShouldBe(context, context.NO_ERROR);
 
--- a/dom/canvas/test/webgl-conf/checkout/conformance/misc/null-object-behaviour.html
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/misc/null-object-behaviour.html
@@ -44,47 +44,47 @@ description("Tests calling WebGL APIs wi
 
 var context = wtu.create3DContext();
 var program = wtu.loadStandardProgram(context);
 var shader = wtu.loadStandardVertexShader(context);
 var shouldGenerateGLError = wtu.shouldGenerateGLError;
 
 assertMsg(program != null, "Program Compiled");
 assertMsg(shader != null, "Shader Compiled");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.compileShader(undefined)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.linkProgram(undefined)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader(undefined, undefined)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader(program, undefined)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.attachShader(undefined, shader)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.detachShader(program, undefined)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.detachShader(undefined, shader)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.shaderSource(undefined, undefined)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.shaderSource(undefined, 'foo')");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.bindAttribLocation(undefined, 0, 'foo')");
+shouldThrow("context.compileShader(undefined)");
+shouldThrow("context.linkProgram(undefined)");
+shouldThrow("context.attachShader(undefined, undefined)");
+shouldThrow("context.attachShader(program, undefined)");
+shouldThrow("context.attachShader(undefined, shader)");
+shouldThrow("context.detachShader(program, undefined)");
+shouldThrow("context.detachShader(undefined, shader)");
+shouldThrow("context.shaderSource(undefined, undefined)");
+shouldThrow("context.shaderSource(undefined, 'foo')");
+shouldThrow("context.bindAttribLocation(undefined, 0, 'foo')");
 shouldThrow("context.bindBuffer(context.ARRAY_BUFFER, 0)");
 shouldThrow("context.bindFramebuffer(context.FRAMEBUFFER, 0)");
 shouldThrow("context.bindRenderbuffer(context.RENDERBUFFER, 0)");
 shouldThrow("context.bindTexture(context.TEXTURE_2D, 0)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindBuffer(context.ARRAY_BUFFER, null)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindFramebuffer(context.FRAMEBUFFER, null)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindRenderbuffer(context.RENDERBUFFER, null)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindTexture(context.TEXTURE_2D, null)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindBuffer(context.ARRAY_BUFFER, undefined)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindFramebuffer(context.FRAMEBUFFER, undefined)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindRenderbuffer(context.RENDERBUFFER, undefined)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.bindTexture(context.TEXTURE_2D, undefined)");
 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, null)");
 shouldGenerateGLError(context, context.INVALID_OPERATION, "context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, null, 0)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.getProgramParameter(undefined, 0)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.getProgramInfoLog(undefined, 0)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderParameter(undefined, 0)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderInfoLog(undefined, 0)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.getShaderSource(undefined)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.getUniform(undefined, null)");
-shouldGenerateGLError(context, context.INVALID_VALUE, "context.getUniformLocation(undefined, 'foo')");
+shouldThrow("context.getProgramParameter(undefined, 0)");
+shouldThrow("context.getProgramInfoLog(undefined, 0)");
+shouldThrow("context.getShaderParameter(undefined, 0)");
+shouldThrow("context.getShaderInfoLog(undefined, 0)");
+shouldThrow("context.getShaderSource(undefined)");
+shouldThrow("context.getUniform(undefined, null)");
+shouldThrow("context.getUniformLocation(undefined, 'foo')");
 
 debug("");
 debug("check with bindings");
 context.bindBuffer(context.ARRAY_BUFFER, context.createBuffer());
 context.bindTexture(context.TEXTURE_2D, context.createTexture());
 shouldGenerateGLError(context, context.NO_ERROR, "context.bufferData(context.ARRAY_BUFFER, 1, context.STATIC_DRAW)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.getBufferParameter(context.ARRAY_BUFFER, context.BUFFER_SIZE)");
 shouldGenerateGLError(context, context.NO_ERROR, "context.texImage2D(context.TEXTURE_2D, 0, context.RGBA, 1, 1, 0, context.RGBA, context.UNSIGNED_BYTE, new Uint8Array([0,0,0,0]))");
--- a/dom/canvas/test/webgl-conf/checkout/conformance/programs/get-active-test.html
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/programs/get-active-test.html
@@ -52,18 +52,18 @@ var program2 = wtu.loadProgramFromFile(c
 wtu.glErrorShouldBe(context, context.NO_ERROR);
 shouldBe("context.getActiveUniform(program, 0).name", "'u_modelViewProjMatrix'");
 shouldBe("context.getActiveUniform(program, 0).type", "context.FLOAT_MAT4");
 shouldBe("context.getActiveUniform(program, 0).size", "1");
 shouldBeNull("context.getActiveUniform(program, 1)");
 wtu.glErrorShouldBe(context, context.INVALID_VALUE);
 shouldBeNull("context.getActiveUniform(program, -1)");
 wtu.glErrorShouldBe(context, context.INVALID_VALUE);
-shouldBeNull("context.getActiveUniform(null, 0)");
-wtu.glErrorShouldBe(context, context.INVALID_VALUE);
+shouldThrow("context.getActiveUniform(null, 0)");
+wtu.glErrorShouldBe(context, context.NO_ERROR);
 
 // we don't know the order the attribs will appear.
 var info = [
   context.getActiveAttrib(program, 0),
   context.getActiveAttrib(program, 1)
 ];
 for (var ii = 0; ii < info.length; ++ii)
     shouldBeNonNull("info[ii]");
@@ -109,18 +109,18 @@ for (var ii = 0; ii < info2.length; ++ii
     shouldBe("info2[ii].type", "expected2[ii].type");
     shouldBe("info2[ii].size", "expected2[ii].size");
 }
 
 shouldBeNull("context.getActiveAttrib(program, 2)");
 wtu.glErrorShouldBe(context, context.INVALID_VALUE);
 shouldBeNull("context.getActiveAttrib(program, -1)");
 wtu.glErrorShouldBe(context, context.INVALID_VALUE);
-shouldBeNull("context.getActiveAttrib(null, 0)");
-wtu.glErrorShouldBe(context, context.INVALID_VALUE);
+shouldThrow("context.getActiveAttrib(null, 0)");
+wtu.glErrorShouldBe(context, context.NO_ERROR);
 
 wtu.glErrorShouldBe(context2, context.NO_ERROR);
 
 debug("Check trying to get attribs from different context");
 shouldBeNull("context2.getActiveAttrib(program, 0)");
 wtu.glErrorShouldBe(context2, context2.INVALID_OPERATION);
 shouldBeNull("context2.getActiveUniform(program, 0)");
 wtu.glErrorShouldBe(context2, context2.INVALID_OPERATION);
--- a/dom/canvas/test/webgl-conf/checkout/conformance2/context/constants-and-properties-2.html
+++ b/dom/canvas/test/webgl-conf/checkout/conformance2/context/constants-and-properties-2.html
@@ -41,131 +41,131 @@
 "use strict";
 description("This test ensures that the WebGL context has all the constants and (non-function) properties in the specification.");
 
 var constants = {
     /* ClearBufferMask */
 DEPTH_BUFFER_BIT               : 0x00000100,
 STENCIL_BUFFER_BIT             : 0x00000400,
 COLOR_BUFFER_BIT               : 0x00004000,
-    
+
     /* BeginMode */
 POINTS                         : 0x0000,
 LINES                          : 0x0001,
 LINE_LOOP                      : 0x0002,
 LINE_STRIP                     : 0x0003,
 TRIANGLES                      : 0x0004,
 TRIANGLE_STRIP                 : 0x0005,
 TRIANGLE_FAN                   : 0x0006,
-    
+
     /* AlphaFunction (not supported in ES20) */
     /*      NEVER */
     /*      LESS */
     /*      EQUAL */
     /*      LEQUAL */
     /*      GREATER */
     /*      NOTEQUAL */
     /*      GEQUAL */
     /*      ALWAYS */
-    
+
     /* BlendingFactorDest */
 ZERO                           : 0,
 ONE                            : 1,
 SRC_COLOR                      : 0x0300,
 ONE_MINUS_SRC_COLOR            : 0x0301,
 SRC_ALPHA                      : 0x0302,
 ONE_MINUS_SRC_ALPHA            : 0x0303,
 DST_ALPHA                      : 0x0304,
 ONE_MINUS_DST_ALPHA            : 0x0305,
-    
+
     /* BlendingFactorSrc */
     /*      ZERO */
     /*      ONE */
 DST_COLOR                      : 0x0306,
 ONE_MINUS_DST_COLOR            : 0x0307,
 SRC_ALPHA_SATURATE             : 0x0308,
     /*      SRC_ALPHA */
     /*      ONE_MINUS_SRC_ALPHA */
     /*      DST_ALPHA */
     /*      ONE_MINUS_DST_ALPHA */
-    
+
     /* BlendEquationSeparate */
 FUNC_ADD                       : 0x8006,
 BLEND_EQUATION                 : 0x8009,
 BLEND_EQUATION_RGB             : 0x8009,   /* same as BLEND_EQUATION */
 BLEND_EQUATION_ALPHA           : 0x883D,
-    
+
     /* BlendSubtract */
 FUNC_SUBTRACT                  : 0x800A,
 FUNC_REVERSE_SUBTRACT          : 0x800B,
-    
+
     /* Separate Blend Functions */
 BLEND_DST_RGB                  : 0x80C8,
 BLEND_SRC_RGB                  : 0x80C9,
 BLEND_DST_ALPHA                : 0x80CA,
 BLEND_SRC_ALPHA                : 0x80CB,
 CONSTANT_COLOR                 : 0x8001,
 ONE_MINUS_CONSTANT_COLOR       : 0x8002,
 CONSTANT_ALPHA                 : 0x8003,
 ONE_MINUS_CONSTANT_ALPHA       : 0x8004,
 BLEND_COLOR                    : 0x8005,
-    
+
     /* Buffer Objects */
 ARRAY_BUFFER                   : 0x8892,
 ELEMENT_ARRAY_BUFFER           : 0x8893,
 ARRAY_BUFFER_BINDING           : 0x8894,
 ELEMENT_ARRAY_BUFFER_BINDING   : 0x8895,
-    
+
 STREAM_DRAW                    : 0x88E0,
 STATIC_DRAW                    : 0x88E4,
 DYNAMIC_DRAW                   : 0x88E8,
-    
+
 BUFFER_SIZE                    : 0x8764,
 BUFFER_USAGE                   : 0x8765,
-    
+
 CURRENT_VERTEX_ATTRIB          : 0x8626,
-    
+
     /* CullFaceMode */
 FRONT                          : 0x0404,
 BACK                           : 0x0405,
 FRONT_AND_BACK                 : 0x0408,
-    
+
     /* DepthFunction */
     /*      NEVER */
     /*      LESS */
     /*      EQUAL */
     /*      LEQUAL */
     /*      GREATER */
     /*      NOTEQUAL */
     /*      GEQUAL */
     /*      ALWAYS */
-    
+
     /* EnableCap */
     /* TEXTURE_2D */
 CULL_FACE                      : 0x0B44,
 BLEND                          : 0x0BE2,
 DITHER                         : 0x0BD0,
 STENCIL_TEST                   : 0x0B90,
 DEPTH_TEST                     : 0x0B71,
 SCISSOR_TEST                   : 0x0C11,
 POLYGON_OFFSET_FILL            : 0x8037,
 SAMPLE_ALPHA_TO_COVERAGE       : 0x809E,
 SAMPLE_COVERAGE                : 0x80A0,
-    
+
     /* ErrorCode */
 NO_ERROR                       : 0,
 INVALID_ENUM                   : 0x0500,
 INVALID_VALUE                  : 0x0501,
 INVALID_OPERATION              : 0x0502,
 OUT_OF_MEMORY                  : 0x0505,
-    
+
     /* FrontFaceDirection */
 CW                             : 0x0900,
 CCW                            : 0x0901,
-    
+
     /* GetPName */
 LINE_WIDTH                     : 0x0B21,
 ALIASED_POINT_SIZE_RANGE       : 0x846D,
 ALIASED_LINE_WIDTH_RANGE       : 0x846E,
 CULL_FACE_MODE                 : 0x0B45,
 FRONT_FACE                     : 0x0B46,
 DEPTH_RANGE                    : 0x0B70,
 DEPTH_WRITEMASK                : 0x0B72,
@@ -205,56 +205,56 @@ STENCIL_BITS                   : 0x0D57,
 POLYGON_OFFSET_UNITS           : 0x2A00,
     /*      POLYGON_OFFSET_FILL */
 POLYGON_OFFSET_FACTOR          : 0x8038,
 TEXTURE_BINDING_2D             : 0x8069,
 SAMPLE_BUFFERS                 : 0x80A8,
 SAMPLES                        : 0x80A9,
 SAMPLE_COVERAGE_VALUE          : 0x80AA,
 SAMPLE_COVERAGE_INVERT         : 0x80AB,
-    
+
     /* GetTextureParameter */
     /*      TEXTURE_MAG_FILTER */
     /*      TEXTURE_MIN_FILTER */
     /*      TEXTURE_WRAP_S */
     /*      TEXTURE_WRAP_T */
-    
+
 COMPRESSED_TEXTURE_FORMATS     : 0x86A3,
-    
+
     /* HintMode */
 DONT_CARE                      : 0x1100,
 FASTEST                        : 0x1101,
 NICEST                         : 0x1102,
-    
+
     /* HintTarget */
 GENERATE_MIPMAP_HINT            : 0x8192,
-    
+
     /* DataType */
 BYTE                           : 0x1400,
 UNSIGNED_BYTE                  : 0x1401,
 SHORT                          : 0x1402,
 UNSIGNED_SHORT                 : 0x1403,
 INT                            : 0x1404,
 UNSIGNED_INT                   : 0x1405,
 FLOAT                          : 0x1406,
-    
+
     /* PixelFormat */
 DEPTH_COMPONENT                : 0x1902,
 ALPHA                          : 0x1906,
 RGB                            : 0x1907,
 RGBA                           : 0x1908,
 LUMINANCE                      : 0x1909,
 LUMINANCE_ALPHA                : 0x190A,
-    
+
     /* PixelType */
     /*      UNSIGNED_BYTE */
 UNSIGNED_SHORT_4_4_4_4         : 0x8033,
 UNSIGNED_SHORT_5_5_5_1         : 0x8034,
 UNSIGNED_SHORT_5_6_5           : 0x8363,
-    
+
     /* Shaders */
 FRAGMENT_SHADER                  : 0x8B30,
 VERTEX_SHADER                    : 0x8B31,
 MAX_VERTEX_ATTRIBS               : 0x8869,
 MAX_VERTEX_UNIFORM_VECTORS       : 0x8DFB,
 MAX_VARYING_VECTORS              : 0x8DFC,
 MAX_COMBINED_TEXTURE_IMAGE_UNITS : 0x8B4D,
 MAX_VERTEX_TEXTURE_IMAGE_UNITS   : 0x8B4C,
@@ -264,74 +264,74 @@ SHADER_TYPE                      : 0x8B4
 DELETE_STATUS                    : 0x8B80,
 LINK_STATUS                      : 0x8B82,
 VALIDATE_STATUS                  : 0x8B83,
 ATTACHED_SHADERS                 : 0x8B85,
 ACTIVE_UNIFORMS                  : 0x8B86,
 ACTIVE_ATTRIBUTES                : 0x8B89,
 SHADING_LANGUAGE_VERSION         : 0x8B8C,
 CURRENT_PROGRAM                  : 0x8B8D,
-    
+
     /* StencilFunction */
 NEVER                          : 0x0200,
 LESS                           : 0x0201,
 EQUAL                          : 0x0202,
 LEQUAL                         : 0x0203,
 GREATER                        : 0x0204,
 NOTEQUAL                       : 0x0205,
 GEQUAL                         : 0x0206,
 ALWAYS                         : 0x0207,
-    
+
     /* StencilOp */
     /*      ZERO */
 KEEP                           : 0x1E00,
 REPLACE                        : 0x1E01,
 INCR                           : 0x1E02,
 DECR                           : 0x1E03,
 INVERT                         : 0x150A,
 INCR_WRAP                      : 0x8507,
 DECR_WRAP                      : 0x8508,
-    
+
     /* StringName */
 VENDOR                         : 0x1F00,
 RENDERER                       : 0x1F01,
 VERSION                        : 0x1F02,
-    
+
     /* TextureMagFilter */
 NEAREST                        : 0x2600,
 LINEAR                         : 0x2601,
-    
+
     /* TextureMinFilter */
     /*      NEAREST */
     /*      LINEAR */
 NEAREST_MIPMAP_NEAREST         : 0x2700,
 LINEAR_MIPMAP_NEAREST          : 0x2701,
 NEAREST_MIPMAP_LINEAR          : 0x2702,
 LINEAR_MIPMAP_LINEAR           : 0x2703,
-    
+
     /* TextureParameterName */
 TEXTURE_MAG_FILTER             : 0x2800,
 TEXTURE_MIN_FILTER             : 0x2801,
 TEXTURE_WRAP_S                 : 0x2802,
 TEXTURE_WRAP_T                 : 0x2803,
-    
+
     /* TextureTarget */
 TEXTURE_2D                     : 0x0DE1,
 TEXTURE                        : 0x1702,
-    
+
 TEXTURE_CUBE_MAP               : 0x8513,
 TEXTURE_BINDING_CUBE_MAP       : 0x8514,
 TEXTURE_CUBE_MAP_POSITIVE_X    : 0x8515,
 TEXTURE_CUBE_MAP_NEGATIVE_X    : 0x8516,
 TEXTURE_CUBE_MAP_POSITIVE_Y    : 0x8517,
 TEXTURE_CUBE_MAP_NEGATIVE_Y    : 0x8518,
 TEXTURE_CUBE_MAP_POSITIVE_Z    : 0x8519,
 TEXTURE_CUBE_MAP_NEGATIVE_Z    : 0x851A,
 MAX_CUBE_MAP_TEXTURE_SIZE      : 0x851C,
-    
+
     /* TextureUnit */
 TEXTURE0                       : 0x84C0,
 TEXTURE1                       : 0x84C1,
 TEXTURE2                       : 0x84C2,
 TEXTURE3                       : 0x84C3,
 TEXTURE4                       : 0x84C4,
 TEXTURE5                       : 0x84C5,
 TEXTURE6                       : 0x84C6,
@@ -356,103 +356,103 @@ TEXTURE24                      : 0x84D8,
 TEXTURE25                      : 0x84D9,
 TEXTURE26                      : 0x84DA,
 TEXTURE27                      : 0x84DB,
 TEXTURE28                      : 0x84DC,
 TEXTURE29                      : 0x84DD,
 TEXTURE30                      : 0x84DE,
 TEXTURE31                      : 0x84DF,
 ACTIVE_TEXTURE                 : 0x84E0,
-    
+
     /* TextureWrapMode */
 REPEAT                         : 0x2901,
 CLAMP_TO_EDGE                  : 0x812F,
 MIRRORED_REPEAT                : 0x8370,
-    
+
     /* Uniform Types */
 FLOAT_VEC2                     : 0x8B50,
 FLOAT_VEC3                     : 0x8B51,
 FLOAT_VEC4                     : 0x8B52,
 INT_VEC2                       : 0x8B53,
 INT_VEC3                       : 0x8B54,
 INT_VEC4                       : 0x8B55,
 BOOL                           : 0x8B56,
 BOOL_VEC2                      : 0x8B57,
 BOOL_VEC3                      : 0x8B58,
 BOOL_VEC4                      : 0x8B59,
 FLOAT_MAT2                     : 0x8B5A,
 FLOAT_MAT3                     : 0x8B5B,
 FLOAT_MAT4                     : 0x8B5C,
 SAMPLER_2D                     : 0x8B5E,
 SAMPLER_CUBE                   : 0x8B60,
-    
+
     /* Vertex Arrays */
 VERTEX_ATTRIB_ARRAY_ENABLED        : 0x8622,
 VERTEX_ATTRIB_ARRAY_SIZE           : 0x8623,
 VERTEX_ATTRIB_ARRAY_STRIDE         : 0x8624,
 VERTEX_ATTRIB_ARRAY_TYPE           : 0x8625,
 VERTEX_ATTRIB_ARRAY_NORMALIZED     : 0x886A,
 VERTEX_ATTRIB_ARRAY_POINTER        : 0x8645,
 VERTEX_ATTRIB_ARRAY_BUFFER_BINDING : 0x889F,
-    
+
     /* Shader Source */
 COMPILE_STATUS                 : 0x8B81,
-    
+
     /* Shader Precision-Specified Types */
 LOW_FLOAT                      : 0x8DF0,
 MEDIUM_FLOAT                   : 0x8DF1,
 HIGH_FLOAT                     : 0x8DF2,
 LOW_INT                        : 0x8DF3,
 MEDIUM_INT                     : 0x8DF4,
 HIGH_INT                       : 0x8DF5,
-    
+
     /* Framebuffer Object. */
 FRAMEBUFFER                    : 0x8D40,
 RENDERBUFFER                   : 0x8D41,
-    
+
 RGBA4                          : 0x8056,
 RGB5_A1                        : 0x8057,
 RGB565                         : 0x8D62,
 DEPTH_COMPONENT16              : 0x81A5,
 STENCIL_INDEX                  : 0x1901,
 STENCIL_INDEX8                 : 0x8D48,
 DEPTH_STENCIL                  : 0x84F9,
-    
+
 RENDERBUFFER_WIDTH             : 0x8D42,
 RENDERBUFFER_HEIGHT            : 0x8D43,
 RENDERBUFFER_INTERNAL_FORMAT   : 0x8D44,
 RENDERBUFFER_RED_SIZE          : 0x8D50,
 RENDERBUFFER_GREEN_SIZE        : 0x8D51,
 RENDERBUFFER_BLUE_SIZE         : 0x8D52,
 RENDERBUFFER_ALPHA_SIZE        : 0x8D53,
 RENDERBUFFER_DEPTH_SIZE        : 0x8D54,
 RENDERBUFFER_STENCIL_SIZE      : 0x8D55,
-    
+
 FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE           : 0x8CD0,
 FRAMEBUFFER_ATTACHMENT_OBJECT_NAME           : 0x8CD1,
 FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL         : 0x8CD2,
 FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE : 0x8CD3,
-    
+
 COLOR_ATTACHMENT0              : 0x8CE0,
 DEPTH_ATTACHMENT               : 0x8D00,
 STENCIL_ATTACHMENT             : 0x8D20,
 DEPTH_STENCIL_ATTACHMENT       : 0x821A,
-    
+
 NONE                           : 0,
-    
+
 FRAMEBUFFER_COMPLETE                      : 0x8CD5,
 FRAMEBUFFER_INCOMPLETE_ATTACHMENT         : 0x8CD6,
 FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : 0x8CD7,
 FRAMEBUFFER_INCOMPLETE_DIMENSIONS         : 0x8CD9,
 FRAMEBUFFER_UNSUPPORTED                   : 0x8CDD,
-  
+
 FRAMEBUFFER_BINDING            : 0x8CA6,
 RENDERBUFFER_BINDING           : 0x8CA7,
 MAX_RENDERBUFFER_SIZE          : 0x84E8,
-    
+
 INVALID_FRAMEBUFFER_OPERATION  : 0x0506,
 
 IMPLEMENTATION_COLOR_READ_TYPE : 0x8B9A,
 IMPLEMENTATION_COLOR_READ_FORMAT : 0x8B9B,
 
 /* WebGL-specific enums */
 UNPACK_FLIP_Y_WEBGL                : 0x9240,
 UNPACK_PREMULTIPLY_ALPHA_WEBGL     : 0x9241,
@@ -710,36 +710,23 @@ CONDITION_SATISFIED : 0x911C,
 WAIT_FAILED : 0x911D,
 SYNC_FLUSH_COMMANDS_BIT : 0x00000001,
 TIMEOUT_IGNORED : -1,
 VERTEX_ATTRIB_ARRAY_DIVISOR : 0x88FE,
 ANY_SAMPLES_PASSED : 0x8C2F,
 ANY_SAMPLES_PASSED_CONSERVATIVE : 0x8D6A,
 SAMPLER_BINDING : 0x8919,
 RGB10_A2UI : 0x906F,
-GREEN : 0x1904,
-BLUE : 0x1905,
 INT_2_10_10_10_REV : 0x8D9F,
 TRANSFORM_FEEDBACK : 0x8E22,
 TRANSFORM_FEEDBACK_PAUSED : 0x8E23,
 TRANSFORM_FEEDBACK_ACTIVE : 0x8E24,
 TRANSFORM_FEEDBACK_BINDING : 0x8E25,
-COMPRESSED_R11_EAC : 0x9270,
-COMPRESSED_SIGNED_R11_EAC : 0x9271,
-COMPRESSED_RG11_EAC : 0x9272,
-COMPRESSED_SIGNED_RG11_EAC : 0x9273,
-COMPRESSED_RGB8_ETC2 : 0x9274,
-COMPRESSED_SRGB8_ETC2 : 0x9275,
-COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9276,
-COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9277,
-COMPRESSED_RGBA8_ETC2_EAC : 0x9278,
-COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : 0x9279,
 TEXTURE_IMMUTABLE_FORMAT : 0x912F,
 MAX_ELEMENT_INDEX : 0x8D6B,
-NUM_SAMPLE_COUNTS : 0x9380,
 TEXTURE_IMMUTABLE_LEVELS : 0x82DF,
 
 /* WebGL-specific enums */
 MAX_CLIENT_WAIT_TIMEOUT_WEBGL: 0x9247
 };
 
 // Other non-function properties on the WebGL object
 var otherProperties = {
--- a/dom/canvas/test/webgl-conf/checkout/js/tests/gl-object-get-calls.js
+++ b/dom/canvas/test/webgl-conf/checkout/js/tests/gl-object-get-calls.js
@@ -310,18 +310,18 @@ var standardFrag = wtu.loadStandardFragm
 var standardProgram = gl.createProgram();
 gl.attachShader(standardProgram, standardVert);
 gl.attachShader(standardProgram, standardFrag);
 gl.linkProgram(standardProgram);
 var shaders = gl.getAttachedShaders(standardProgram);
 shouldBe('shaders.length', '2');
 shouldBeTrue('shaders[0] == standardVert && shaders[1] == standardFrag || shaders[1] == standardVert && shaders[0] == standardFrag');
 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
-gl.getAttachedShaders(null);
-wtu.glErrorShouldBe(gl, gl.INVALID_VALUE);
+shouldThrow('gl.getAttachedShaders(null)');
+wtu.glErrorShouldBe(gl, gl.NO_ERROR);
 shouldThrow('gl.getAttachedShaders(standardVert)');
 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
 
 debug("");
 debug("Test getProgramParameter");
 shouldBe('gl.getProgramParameter(standardProgram, gl.DELETE_STATUS)', 'false');
 shouldBe('gl.getProgramParameter(standardProgram, gl.LINK_STATUS)', 'true');
 shouldBe('typeof gl.getProgramParameter(standardProgram, gl.VALIDATE_STATUS)', '"boolean"');
--- a/dom/canvas/test/webgl-mochitest/test_sab_with_webgl.html
+++ b/dom/canvas/test/webgl-mochitest/test_sab_with_webgl.html
@@ -94,19 +94,19 @@ function TestScreenColor(gl, r, g, b, a)
   gl.useProgram(prog);
 
   // Test gl.bufferData(), gl.bufferSubData() and gl.readPixels() APIs with SAB as input.
   var arr = new SharedArrayBuffer(8*4);
   var view = new Float32Array(arr);
   view.set(new Float32Array([-1, -1, 1, -1, -1,  1, 1,  1]));
   var vb = gl.createBuffer();
   gl.bindBuffer(gl.ARRAY_BUFFER, vb);
-  gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW);
+  gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW);
   ok(gl.getError() == 0, 'bufferData with SAB as input parameter works ok.');
-  gl.bufferSubData(gl.ARRAY_BUFFER, 0, arr);
+  gl.bufferSubData(gl.ARRAY_BUFFER, 0, view);
   ok(gl.getError() == 0, 'bufferSubData with SAB as input parameter works ok.');
   gl.enableVertexAttribArray(0);
   gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
   gl.clearColor(0, 0, 0, 1.0);
   gl.clear(gl.COLOR_BUFFER_BIT);
   gl.uniform4f(prog.uFragColor, 0.2, 0.4, 0.6, 1.0);
   gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
   var arr = new Uint8Array(4);
@@ -148,17 +148,17 @@ function TestScreenColor(gl, r, g, b, a)
     return;
   }
 
   var arr = new SharedArrayBuffer(8*4);
   var view = new Float32Array(arr);
   view.set(new Float32Array([-1, -1, 1, -1, -1,  1, 1,  1]));
   var vb = gl.createBuffer();
   gl.bindBuffer(gl.ARRAY_BUFFER, vb);
-  gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW);
+  gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW);
 
   var arr2 = new SharedArrayBuffer(8*4);
   var view2 = new Float32Array(arr2);
   gl.getBufferSubData(gl.ARRAY_BUFFER, 0, view2);
   var equal = true;
   for(var i = 0; i < 8; ++i) {
     if (view[i] != view2[i]) equal = false;
   }
--- a/dom/webidl/WebGL2RenderingContext.webidl
+++ b/dom/webidl/WebGL2RenderingContext.webidl
@@ -277,57 +277,42 @@ interface WebGL2RenderingContext : WebGL
     const GLenum CONDITION_SATISFIED                           = 0x911C;
     const GLenum WAIT_FAILED                                   = 0x911D;
     const GLenum SYNC_FLUSH_COMMANDS_BIT                       = 0x00000001;
     const GLenum VERTEX_ATTRIB_ARRAY_DIVISOR                   = 0x88FE;
     const GLenum ANY_SAMPLES_PASSED                            = 0x8C2F;
     const GLenum ANY_SAMPLES_PASSED_CONSERVATIVE               = 0x8D6A;
     const GLenum SAMPLER_BINDING                               = 0x8919;
     const GLenum RGB10_A2UI                                    = 0x906F;
-    const GLenum GREEN                                         = 0x1904;
-    const GLenum BLUE                                          = 0x1905;
     const GLenum INT_2_10_10_10_REV                            = 0x8D9F;
     const GLenum TRANSFORM_FEEDBACK                            = 0x8E22;
     const GLenum TRANSFORM_FEEDBACK_PAUSED                     = 0x8E23;
     const GLenum TRANSFORM_FEEDBACK_ACTIVE                     = 0x8E24;
     const GLenum TRANSFORM_FEEDBACK_BINDING                    = 0x8E25;
-    const GLenum COMPRESSED_R11_EAC                            = 0x9270;
-    const GLenum COMPRESSED_SIGNED_R11_EAC                     = 0x9271;
-    const GLenum COMPRESSED_RG11_EAC                           = 0x9272;
-    const GLenum COMPRESSED_SIGNED_RG11_EAC                    = 0x9273;
-    const GLenum COMPRESSED_RGB8_ETC2                          = 0x9274;
-    const GLenum COMPRESSED_SRGB8_ETC2                         = 0x9275;
-    const GLenum COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2      = 0x9276;
-    const GLenum COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2     = 0x9277;
-    const GLenum COMPRESSED_RGBA8_ETC2_EAC                     = 0x9278;
-    const GLenum COMPRESSED_SRGB8_ALPHA8_ETC2_EAC              = 0x9279;
     const GLenum TEXTURE_IMMUTABLE_FORMAT                      = 0x912F;
     const GLenum MAX_ELEMENT_INDEX                             = 0x8D6B;
-    const GLenum NUM_SAMPLE_COUNTS                             = 0x9380;
     const GLenum TEXTURE_IMMUTABLE_LEVELS                      = 0x82DF;
 
     const GLint64 TIMEOUT_IGNORED                              = -1;
 
     /* WebGL-specific enums */
     const GLenum MAX_CLIENT_WAIT_TIMEOUT_WEBGL                 = 0x9247;
 
     /* Buffer objects */
     // WebGL1:
     void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
-    void bufferData(GLenum target, ArrayBufferView data, GLenum usage);
-    void bufferData(GLenum target, ArrayBuffer? data, GLenum usage);
-    void bufferData(GLenum target, SharedArrayBuffer data, GLenum usage);
-    void bufferSubData(GLenum target, GLintptr offset, ArrayBufferView data);
-    void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer? data);
-    void bufferSubData(GLenum target, GLintptr offset, SharedArrayBuffer data);
+    void bufferData(GLenum target, ArrayBuffer? srcData, GLenum usage);
+    //void bufferData(GLenum target, ArrayBufferView srcData, GLenum usage);
+    void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer srcData);
+    //void bufferSubData(GLenum target, GLintptr offset, ArrayBufferView srcData);
     // WebGL2:
-    void bufferData(GLenum target, ArrayBufferView srcData, GLenum usage, GLuint srcOffset,
-                    optional GLuint length = 0);
+    void bufferData(GLenum target, ArrayBufferView srcData, GLenum usage,
+                    optional GLuint srcOffset = 0, optional GLuint length = 0);
     void bufferSubData(GLenum target, GLintptr dstByteOffset, ArrayBufferView srcData,
-                       GLuint srcOffset, optional GLuint length = 0);
+                       optional GLuint srcOffset = 0, optional GLuint length = 0);
 
     void copyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset,
                            GLintptr writeOffset, GLsizeiptr size);
     // MapBufferRange, in particular its read-only and write-only modes,
     // can not be exposed safely to JavaScript. GetBufferSubData
     // replaces it for the purpose of fetching data back from the GPU.
     void getBufferSubData(GLenum target, GLintptr srcByteOffset, ArrayBufferView dstData,
                           optional GLuint dstOffset = 0, optional GLuint length = 0);
@@ -360,28 +345,32 @@ interface WebGL2RenderingContext : WebGL
                       GLsizei height, GLsizei depth);
 
     // WebGL1 legacy entrypoints:
     [Throws] // Another overhead throws.
     void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLsizei width, GLsizei height, GLint border, GLenum format,
                     GLenum type, ArrayBufferView? pixels);
     [Throws]
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, HTMLCanvasElement source); // May throw DOMException
     [Throws]
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, HTMLImageElement source); // May throw DOMException
     [Throws]
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, HTMLVideoElement source); // May throw DOMException
     [Throws] // Another overhead throws.
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, ImageData source);
 
+    [Throws] // Another overhead throws.
+    void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
+                       GLsizei width, GLsizei height,
+                       GLenum format, GLenum type, ArrayBufferView? pixels);
     [Throws]
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                        GLenum format, GLenum type, HTMLCanvasElement source); // May throw DOMException
     [Throws]
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                        GLenum format, GLenum type, HTMLImageElement source); // May throw DOMException
     [Throws]
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
@@ -459,17 +448,17 @@ interface WebGL2RenderingContext : WebGL
                        HTMLVideoElement source); // May throw DOMException
     [Throws] // Another overhead throws.
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
                        GLsizei height, GLenum format, GLenum type,
                        ImageData source);
     [Throws] // Another overhead throws.
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
                        GLsizei height, GLenum format, GLenum type, ArrayBufferView srcData,
-                       optional GLuint srcOffset = 0);
+                       GLuint srcOffset);
 
     [Throws] // Another overhead throws.
     void texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
                        GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
                        GLintptr pboOffset);
     [Throws]
     void texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
                        GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
@@ -484,50 +473,52 @@ interface WebGL2RenderingContext : WebGL
                        HTMLVideoElement source); // May throw DOMException
     [Throws] // Another overhead throws.
     void texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
                        GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
                        ImageData source);
     [Throws] // Another overhead throws.
     void texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
                        GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
-                       ArrayBufferView srcData, optional GLuint srcOffset = 0);
+                       ArrayBufferView? srcData, optional GLuint srcOffset = 0);
 
     void copyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
                            GLint x, GLint y, GLsizei width, GLsizei height);
 
     void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width,
                               GLsizei height, GLint border, GLintptr offset);
     void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width,
                               GLsizei height, GLint border, ArrayBufferView srcData,
-                              optional GLuint srcOffset = 0, optional GLuint srcLength = 0);
+                              optional GLuint srcOffset = 0, optional GLuint srcLengthOverride = 0);
 
     void compressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width,
                               GLsizei height, GLsizei depth, GLint border, GLintptr offset);
     void compressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width,
                               GLsizei height, GLsizei depth, GLint border, ArrayBufferView srcData,
-                              optional GLuint srcOffset = 0, optional GLuint srcLength = 0);
+                              optional GLuint srcOffset = 0, optional GLuint srcLengthOverride = 0);
 
     void compressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                                  GLsizei width, GLsizei height, GLenum format, GLintptr offset);
     void compressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                                  GLsizei width, GLsizei height, GLenum format,
-                                 ArrayBufferView srcData, optional GLuint srcOffset = 0,
-                                 optional GLuint srcLength = 0);
+                                 ArrayBufferView srcData,
+                                 optional GLuint srcOffset = 0,
+                                 optional GLuint srcLengthOverride = 0);
 
     void compressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                                  GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
                                  GLenum format, GLintptr offset);
     void compressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                                  GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
                                  GLenum format, ArrayBufferView srcData,
-                                 optional GLuint srcOffset = 0, optional GLuint srcLength = 0);
+                                 optional GLuint srcOffset = 0,
+                                 optional GLuint srcLengthOverride = 0);
 
     /* Programs and shaders */
-    [WebGLHandlesContextLoss] GLint getFragDataLocation(WebGLProgram? program, DOMString name);
+    [WebGLHandlesContextLoss] GLint getFragDataLocation(WebGLProgram program, DOMString name);
 
     /* Uniforms */
     void uniform1ui(WebGLUniformLocation? location, GLuint v0);
     void uniform2ui(WebGLUniformLocation? location, GLuint v0, GLuint v1);
     void uniform3ui(WebGLUniformLocation? location, GLuint v0, GLuint v1, GLuint v2);
     void uniform4ui(WebGLUniformLocation? location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
 
     void uniform1fv(WebGLUniformLocation? location, Float32List data, optional GLuint srcOffset = 0,
@@ -587,22 +578,27 @@ interface WebGL2RenderingContext : WebGL
 
     /* Writing to the drawing buffer */
     void vertexAttribDivisor(GLuint index, GLuint divisor);
     void drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount);
     void drawElementsInstanced(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei instanceCount);
     void drawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLintptr offset);
 
     /* Reading back pixels */
+    // WebGL1:
+    [Throws] // Throws on readback in a write-only context.
+    void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
+                    ArrayBufferView? dstData);
+    // WebGL2:
     [Throws] // Throws on readback in a write-only context.
     void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
                     GLintptr offset);
     [Throws] // Throws on readback in a write-only context.
     void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
-                    ArrayBufferView dstData, optional GLuint dstOffset = 0);
+                    ArrayBufferView dstData, GLuint dstOffset);
 
     /* Multiple Render Targets */
     void drawBuffers(sequence<GLenum> buffers);
 
     void clearBufferfv(GLenum buffer, GLint drawbuffer, Float32List values,
                        optional GLuint srcOffset = 0);
     void clearBufferiv(GLenum buffer, GLint drawbuffer, Int32List values,
                        optional GLuint srcOffset = 0);
@@ -610,62 +606,63 @@ interface WebGL2RenderingContext : WebGL
                         optional GLuint srcOffset = 0);
 
     void clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
 
     /* Query Objects */
     WebGLQuery? createQuery();
     void deleteQuery(WebGLQuery? query);
     [WebGLHandlesContextLoss] GLboolean isQuery(WebGLQuery? query);
-    void beginQuery(GLenum target, WebGLQuery? query);
+    void beginQuery(GLenum target, WebGLQuery query);
     void endQuery(GLenum target);
     any getQuery(GLenum target, GLenum pname);
-    any getQueryParameter(WebGLQuery? query, GLenum pname);
+    any getQueryParameter(WebGLQuery query, GLenum pname);
 
     /* Sampler Objects */
     WebGLSampler? createSampler();
     void deleteSampler(WebGLSampler? sampler);
     [WebGLHandlesContextLoss] GLboolean isSampler(WebGLSampler? sampler);
     void bindSampler(GLuint unit, WebGLSampler? sampler);
-    void samplerParameteri(WebGLSampler? sampler, GLenum pname, GLint param);
-    void samplerParameterf(WebGLSampler? sampler, GLenum pname, GLfloat param);
-    any getSamplerParameter(WebGLSampler? sampler, GLenum pname);
+    void samplerParameteri(WebGLSampler sampler, GLenum pname, GLint param);
+    void samplerParameterf(WebGLSampler sampler, GLenum pname, GLfloat param);
+    any getSamplerParameter(WebGLSampler sampler, GLenum pname);
 
     /* Sync objects */
     WebGLSync? fenceSync(GLenum condition, GLbitfield flags);
     [WebGLHandlesContextLoss] GLboolean isSync(WebGLSync? sync);
     void deleteSync(WebGLSync? sync);
-    GLenum clientWaitSync(WebGLSync? sync, GLbitfield flags, GLint64 timeout);
-    void waitSync(WebGLSync? sync, GLbitfield flags, GLint64 timeout);
-    any getSyncParameter(WebGLSync? sync, GLenum pname);
+    GLenum clientWaitSync(WebGLSync sync, GLbitfield flags, GLuint64 timeout);
+    void waitSync(WebGLSync sync, GLbitfield flags, GLint64 timeout);
+    any getSyncParameter(WebGLSync sync, GLenum pname);
 
     /* Transform Feedback */
     WebGLTransformFeedback? createTransformFeedback();
     void deleteTransformFeedback(WebGLTransformFeedback? tf);
     [WebGLHandlesContextLoss] GLboolean isTransformFeedback(WebGLTransformFeedback? tf);
     void bindTransformFeedback(GLenum target, WebGLTransformFeedback? tf);
     void beginTransformFeedback(GLenum primitiveMode);
     void endTransformFeedback();
-    void transformFeedbackVaryings(WebGLProgram? program, sequence<DOMString> varyings, GLenum bufferMode);
-    [NewObject] WebGLActiveInfo? getTransformFeedbackVarying(WebGLProgram? program, GLuint index);
+    void transformFeedbackVaryings(WebGLProgram program, sequence<DOMString> varyings, GLenum bufferMode);
+    [NewObject]
+    WebGLActiveInfo? getTransformFeedbackVarying(WebGLProgram program, GLuint index);
     void pauseTransformFeedback();
     void resumeTransformFeedback();
 
     /* Uniform Buffer Objects and Transform Feedback Buffers */
     void bindBufferBase(GLenum target, GLuint index, WebGLBuffer? buffer);
     void bindBufferRange(GLenum target, GLuint index, WebGLBuffer? buffer, GLintptr offset, GLsizeiptr size);
     [Throws] // GetOrCreateDOMReflector can fail.
     any getIndexedParameter(GLenum target, GLuint index);
-    sequence<GLuint>? getUniformIndices(WebGLProgram? program, sequence<DOMString> uniformNames);
-    any getActiveUniforms(WebGLProgram? program, sequence<GLuint> uniformIndices, GLenum pname);
-    GLuint getUniformBlockIndex(WebGLProgram? program, DOMString uniformBlockName);
+    sequence<GLuint>? getUniformIndices(WebGLProgram program, sequence<DOMString> uniformNames);
+    any getActiveUniforms(WebGLProgram program, sequence<GLuint> uniformIndices, GLenum pname);
+    GLuint getUniformBlockIndex(WebGLProgram program, DOMString uniformBlockName);
     [Throws] // Creating a Uint32Array can fail.
-    any getActiveUniformBlockParameter(WebGLProgram? program, GLuint uniformBlockIndex, GLenum pname);
-    DOMString? getActiveUniformBlockName(WebGLProgram? program, GLuint uniformBlockIndex);
-    void uniformBlockBinding(WebGLProgram? program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
+    any getActiveUniformBlockParameter(WebGLProgram program, GLuint uniformBlockIndex, GLenum pname);
+    DOMString? getActiveUniformBlockName(WebGLProgram program, GLuint uniformBlockIndex);
+    void uniformBlockBinding(WebGLProgram program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
 
     /* Vertex Array Objects */
     WebGLVertexArrayObject? createVertexArray();
     void deleteVertexArray(WebGLVertexArrayObject? vertexArray);
     [WebGLHandlesContextLoss] GLboolean isVertexArray(WebGLVertexArrayObject? vertexArray);
     void bindVertexArray(WebGLVertexArrayObject? array);
 };
 
--- a/dom/webidl/WebGLRenderingContext.webidl
+++ b/dom/webidl/WebGLRenderingContext.webidl
@@ -31,23 +31,23 @@ typedef unsigned long  GLuint;
 typedef unrestricted float GLfloat;
 typedef unrestricted float GLclampf;
 typedef unsigned long long GLuint64EXT;
 
 dictionary WebGLContextAttributes {
     // boolean alpha = true;
     // We deviate from the spec here.
     // If alpha isn't specified, we rely on a pref ("webgl.default-no-alpha")
-    boolean alpha;
-    boolean depth = true;
-    boolean stencil = false;
-    boolean antialias = true;
-    boolean premultipliedAlpha = true;
-    boolean preserveDrawingBuffer = false;
-    boolean failIfMajorPerformanceCaveat = false;
+    GLboolean alpha;
+    GLboolean depth = true;
+    GLboolean stencil = false;
+    GLboolean antialias = true;
+    GLboolean premultipliedAlpha = true;
+    GLboolean preserveDrawingBuffer = false;
+    GLboolean failIfMajorPerformanceCaveat = false;
 };
 
 [Exposed=(Window,Worker),
  Func="mozilla::dom::OffscreenCanvas::PrefEnabledOnWorkerThread"]
 interface WebGLBuffer {
 };
 
 [Exposed=(Window,Worker),
@@ -534,44 +534,42 @@ interface WebGLRenderingContext {
     [WebGLHandlesContextLoss] boolean isContextLost();
 
     sequence<DOMString>? getSupportedExtensions();
 
     [Throws]
     object? getExtension(DOMString name);
 
     void activeTexture(GLenum texture);
-    void attachShader(WebGLProgram? program, WebGLShader? shader);
-    void bindAttribLocation(WebGLProgram? program, GLuint index, DOMString name);
+    void attachShader(WebGLProgram program, WebGLShader shader);
+    void bindAttribLocation(WebGLProgram program, GLuint index, DOMString name);
     void bindBuffer(GLenum target, WebGLBuffer? buffer);
     void bindFramebuffer(GLenum target, WebGLFramebuffer? framebuffer);
     void bindRenderbuffer(GLenum target, WebGLRenderbuffer? renderbuffer);
     void bindTexture(GLenum target, WebGLTexture? texture);
     void blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
     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);
 
     void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
+    void bufferData(GLenum target, ArrayBuffer? data, GLenum usage);
     void bufferData(GLenum target, ArrayBufferView data, GLenum usage);
-    void bufferData(GLenum target, ArrayBuffer? data, GLenum usage);
-    void bufferData(GLenum target, SharedArrayBuffer data, GLenum usage);
+    void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer data);
     void bufferSubData(GLenum target, GLintptr offset, ArrayBufferView data);
-    void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer? data);
-    void bufferSubData(GLenum target, GLintptr offset, SharedArrayBuffer data);
 
     [WebGLHandlesContextLoss] GLenum checkFramebufferStatus(GLenum target);
     void clear(GLbitfield mask);
     void clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
     void clearDepth(GLclampf depth);
     void clearStencil(GLint s);
     void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
-    void compileShader(WebGLShader? shader);
+    void compileShader(WebGLShader shader);
 
     void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
                               GLsizei width, GLsizei height, GLint border,
                               ArrayBufferView data);
     void compressedTexSubImage2D(GLenum target, GLint level,
                                  GLint xoffset, GLint yoffset,
                                  GLsizei width, GLsizei height, GLenum format,
                                  ArrayBufferView data);
@@ -596,17 +594,17 @@ interface WebGLRenderingContext {
     void deleteProgram(WebGLProgram? program);
     void deleteRenderbuffer(WebGLRenderbuffer? renderbuffer);
     void deleteShader(WebGLShader? shader);
     void deleteTexture(WebGLTexture? texture);
 
     void depthFunc(GLenum func);
     void depthMask(GLboolean flag);
     void depthRange(GLclampf zNear, GLclampf zFar);
-    void detachShader(WebGLProgram? program, WebGLShader? shader);
+    void detachShader(WebGLProgram program, WebGLShader shader);
     void disable(GLenum cap);
     void disableVertexAttribArray(GLuint index);
     void drawArrays(GLenum mode, GLint first, GLsizei count);
     void drawElements(GLenum mode, GLsizei count, GLenum type, GLintptr offset);
 
     void enable(GLenum cap);
     void enableVertexAttribArray(GLuint index);
     void finish();
@@ -616,114 +614,114 @@ interface WebGLRenderingContext {
                                  WebGLRenderbuffer? renderbuffer);
     void framebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget,
                               WebGLTexture? texture, GLint level);
     void frontFace(GLenum mode);
 
     void generateMipmap(GLenum target);
 
     [NewObject]
-    WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index);
+    WebGLActiveInfo? getActiveAttrib(WebGLProgram program, GLuint index);
     [NewObject]
-    WebGLActiveInfo? getActiveUniform(WebGLProgram? program, GLuint index);
+    WebGLActiveInfo? getActiveUniform(WebGLProgram program, GLuint index);
 
-    sequence<WebGLShader>? getAttachedShaders(WebGLProgram? program);
+    sequence<WebGLShader>? getAttachedShaders(WebGLProgram program);
 
-    [WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram? program, DOMString name);
+    [WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram program, DOMString name);
 
     any getBufferParameter(GLenum target, GLenum pname);
     [Throws]
     any getParameter(GLenum pname);
 
     [WebGLHandlesContextLoss] GLenum getError();
 
     [Throws]
     any getFramebufferAttachmentParameter(GLenum target, GLenum attachment,
                                           GLenum pname);
-    any getProgramParameter(WebGLProgram? program, GLenum pname);
-    DOMString? getProgramInfoLog(WebGLProgram? program);
+    any getProgramParameter(WebGLProgram program, GLenum pname);
+    DOMString? getProgramInfoLog(WebGLProgram program);
     any getRenderbufferParameter(GLenum target, GLenum pname);
-    any getShaderParameter(WebGLShader? shader, GLenum pname);
+    any getShaderParameter(WebGLShader shader, GLenum pname);
 
     [NewObject]
     WebGLShaderPrecisionFormat? getShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
 
-    DOMString? getShaderInfoLog(WebGLShader? shader);
+    DOMString? getShaderInfoLog(WebGLShader shader);
 
-    DOMString? getShaderSource(WebGLShader? shader);
+    DOMString? getShaderSource(WebGLShader shader);
 
     any getTexParameter(GLenum target, GLenum pname);
 
-    any getUniform(WebGLProgram? program, WebGLUniformLocation? location);
+    any getUniform(WebGLProgram program, WebGLUniformLocation location);
 
     [NewObject]
-    WebGLUniformLocation? getUniformLocation(WebGLProgram? program, DOMString name);
+    WebGLUniformLocation? getUniformLocation(WebGLProgram program, DOMString name);
 
     [Throws]
     any getVertexAttrib(GLuint index, GLenum pname);
 
-    [WebGLHandlesContextLoss] GLsizeiptr getVertexAttribOffset(GLuint index, GLenum pname);
+    [WebGLHandlesContextLoss] GLintptr getVertexAttribOffset(GLuint index, GLenum pname);
 
     void hint(GLenum target, GLenum mode);
     [WebGLHandlesContextLoss] GLboolean isBuffer(WebGLBuffer? buffer);
     [WebGLHandlesContextLoss] GLboolean isEnabled(GLenum cap);
     [WebGLHandlesContextLoss] GLboolean isFramebuffer(WebGLFramebuffer? framebuffer);
     [WebGLHandlesContextLoss] GLboolean isProgram(WebGLProgram? program);
     [WebGLHandlesContextLoss] GLboolean isRenderbuffer(WebGLRenderbuffer? renderbuffer);
     [WebGLHandlesContextLoss] GLboolean isShader(WebGLShader? shader);
     [WebGLHandlesContextLoss] GLboolean isTexture(WebGLTexture? texture);
     void lineWidth(GLfloat width);
-    void linkProgram(WebGLProgram? program);
+    void linkProgram(WebGLProgram program);
     void pixelStorei(GLenum pname, GLint param);
     void polygonOffset(GLfloat factor, GLfloat units);
 
     [Throws]
     void readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
                     GLenum format, GLenum type, ArrayBufferView? pixels);
 
     void renderbufferStorage(GLenum target, GLenum internalformat,
                              GLsizei width, GLsizei height);
     void sampleCoverage(GLclampf value, GLboolean invert);
     void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
 
-    void shaderSource(WebGLShader? shader, DOMString source);
+    void shaderSource(WebGLShader shader, DOMString source);
 
     void stencilFunc(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 fail, GLenum zfail, GLenum zpass);
     void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
 
 
     // Overloads must share [Throws].
     [Throws] // Can't actually throw.
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLsizei width, GLsizei height, GLint border, GLenum format,
                     GLenum type, ArrayBufferView? pixels);
     [Throws] // Can't actually throw.
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, ImageData pixels);
     [Throws]
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, HTMLImageElement image); // May throw DOMException
     [Throws]
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, HTMLCanvasElement canvas); // May throw DOMException
     [Throws]
-    void texImage2D(GLenum target, GLint level, GLenum internalformat,
+    void texImage2D(GLenum target, GLint level, GLint internalformat,
                     GLenum format, GLenum type, HTMLVideoElement video); // May throw DOMException
 
     void texParameterf(GLenum target, GLenum pname, GLfloat param);
     void texParameteri(GLenum target, GLenum pname, GLint param);
 
     [Throws] // Can't actually throw.
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
-                       GLsizei width, GLsizei height, GLenum format, GLenum type,
-                       ArrayBufferView pixels);
+                       GLsizei width, GLsizei height,
+                       GLenum format, GLenum type, ArrayBufferView? pixels);
     [Throws] // Can't actually throw.
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                        GLenum format, GLenum type, ImageData pixels);
     [Throws]
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
                        GLenum format, GLenum type, HTMLImageElement image); // May throw DOMException
     [Throws]
     void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
@@ -752,17 +750,17 @@ interface WebGLRenderingContext {
     void uniform3iv(WebGLUniformLocation? location, Int32List data);
     void uniform4iv(WebGLUniformLocation? location, Int32List data);
 
     void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, Float32List data);
     void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, Float32List data);
     void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, Float32List data);
 
     void useProgram(WebGLProgram? program);
-    void validateProgram(WebGLProgram? program);
+    void validateProgram(WebGLProgram program);
 
     void vertexAttrib1f(GLuint indx, GLfloat x);
     void vertexAttrib1fv(GLuint indx, Float32Array values);
     void vertexAttrib1fv(GLuint indx, sequence<GLfloat> values);
     void vertexAttrib2f(GLuint indx, GLfloat x, GLfloat y);
     void vertexAttrib2fv(GLuint indx, Float32Array values);
     void vertexAttrib2fv(GLuint indx, sequence<GLfloat> values);
     void vertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
@@ -840,17 +838,17 @@ interface WEBGL_debug_renderer_info
 {
     const GLenum UNMASKED_VENDOR_WEBGL        = 0x9245;
     const GLenum UNMASKED_RENDERER_WEBGL      = 0x9246;
 };
 
 [NoInterfaceObject]
 interface WEBGL_debug_shaders
 {
-    DOMString getTranslatedShaderSource(WebGLShader? shader);
+    DOMString getTranslatedShaderSource(WebGLShader shader);
 };
 
 [NoInterfaceObject]
 interface WEBGL_depth_texture
 {
     const GLenum UNSIGNED_INT_24_8_WEBGL = 0x84FA;
 };
 
@@ -1013,14 +1011,14 @@ interface EXT_disjoint_timer_query {
     const GLenum QUERY_RESULT_AVAILABLE_EXT = 0x8867;
     const GLenum TIME_ELAPSED_EXT = 0x88BF;
     const GLenum TIMESTAMP_EXT = 0x8E28;
     const GLenum GPU_DISJOINT_EXT = 0x8FBB;
 
     WebGLQuery? createQueryEXT();
     void deleteQueryEXT(WebGLQuery? query);
     [WebGLHandlesContextLoss] boolean isQueryEXT(WebGLQuery? query);
-    void beginQueryEXT(GLenum target, WebGLQuery? query);
+    void beginQueryEXT(GLenum target, WebGLQuery query);
     void endQueryEXT(GLenum target);
-    void queryCounterEXT(WebGLQuery? query, GLenum target);
+    void queryCounterEXT(WebGLQuery query, GLenum target);
     any getQueryEXT(GLenum target, GLenum pname);
-    any getQueryObjectEXT(WebGLQuery? query, GLenum pname);
+    any getQueryObjectEXT(WebGLQuery query, GLenum pname);
 };