Bug 1313541 - Reimplement glue in accordance to webidl deviation minimization. - r=ethlin, a=gchang
authorJeff Gilbert (:jgilbert) <jgilbert@mozilla.com>
Fri, 14 Oct 2016 15:59:27 -0700
changeset 439989 4eb05beee849033aff9ca75954c0181163f18b79
parent 439988 fe55eee60666b77cd23e4cdbdf60a672b52ba95a
child 439990 8b56b957a05ba8fdfadd693ba19b641c8479c283
push id36143
push userjkingston@mozilla.com
push dateWed, 16 Nov 2016 22:20:38 +0000
reviewersethlin, gchang
bugs1313541
milestone51.0a2
Bug 1313541 - Reimplement glue in accordance to webidl deviation minimization. - r=ethlin, a=gchang MozReview-Commit-ID: 6w56cfegTz5
dom/canvas/WebGL2Context.h
dom/canvas/WebGL2ContextTextures.cpp
dom/canvas/WebGL2ContextUniforms.cpp
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLProgram.h
--- a/dom/canvas/WebGL2Context.h
+++ b/dom/canvas/WebGL2Context.h
@@ -99,30 +99,30 @@ private:
                     GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
                     GLenum unpackType, const dom::ArrayBufferView* srcView,
                     GLuint srcElemOffset);
 
 public:
     void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
                     GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
                     GLenum unpackType,
-                    const dom::Nullable<dom::ArrayBufferView>& maybeSrc)
+                    const dom::Nullable<dom::ArrayBufferView>& maybeSrc, ErrorResult&)
     {
         const dom::ArrayBufferView* srcView = nullptr;
         if (!maybeSrc.IsNull()) {
             srcView = &maybeSrc.Value();
         }
         TexImage3D(target, level, internalFormat, width, height, depth, border,
                    unpackFormat, unpackType, srcView, 0);
     }
 
     void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
                     GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
                     GLenum unpackType, const dom::ArrayBufferView& srcView,
-                    GLuint srcElemOffset)
+                    GLuint srcElemOffset, ErrorResult&)
     {
         TexImage3D(target, level, internalFormat, width, height, depth, border,
                    unpackFormat, unpackType, &srcView, srcElemOffset);
     }
 
     ////
 
     void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
@@ -154,17 +154,17 @@ public:
                                  const dom::ArrayBufferView& srcView,
                                  GLuint srcElemOffset);
 
     ////////////////
     // Texture PBOs
 
     void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
                     GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
-                    GLenum unpackType, WebGLsizeiptr offset);
+                    GLenum unpackType, WebGLsizeiptr offset, ErrorResult&);
 
     void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
                        GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
                        GLenum unpackFormat, GLenum unpackType, WebGLsizeiptr offset,
                        ErrorResult&);
 
     // -------------------------------------------------------------------------
     // Programs and shaders - WebGL2ContextPrograms.cpp
@@ -303,31 +303,31 @@ public:
     // -------------------------------------------------------------------------
     // 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(GLenum target, GLuint index,
-                             dom::Nullable<dom::OwningWebGLBufferOrLongLong>& retval);
+    void GetIndexedParameter(JSContext* cx, GLenum target, GLuint index,
+                             JS::MutableHandleValue retval, ErrorResult& rv);
     void GetUniformIndices(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,
                            JS::MutableHandleValue retval);
 
     GLuint GetUniformBlockIndex(WebGLProgram* program, const nsAString& uniformBlockName);
     void GetActiveUniformBlockParameter(JSContext*, WebGLProgram* program,
                                         GLuint uniformBlockIndex, GLenum pname,
-                                        dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
+                                        JS::MutableHandleValue retval,
                                         ErrorResult& rv);
     void GetActiveUniformBlockName(WebGLProgram* program, GLuint uniformBlockIndex,
                                    nsAString& retval);
     void UniformBlockBinding(WebGLProgram* program, GLuint uniformBlockIndex,
                              GLuint uniformBlockBinding);
 
 
     // -------------------------------------------------------------------------
--- a/dom/canvas/WebGL2ContextTextures.cpp
+++ b/dom/canvas/WebGL2ContextTextures.cpp
@@ -260,17 +260,18 @@ WebGLContext::TexSubImage2D(GLenum rawTe
                        unpackType, offset);
 }
 
 //////////
 
 void
 WebGL2Context::TexImage3D(GLenum rawTexImageTarget, GLint level, GLenum internalFormat,
                           GLsizei width, GLsizei height, GLsizei depth, GLint border,
-                          GLenum unpackFormat, GLenum unpackType, WebGLsizeiptr offset)
+                          GLenum unpackFormat, GLenum unpackType, WebGLsizeiptr offset,
+                          ErrorResult&)
 {
     const char funcName[] = "texImage3D";
     const uint8_t funcDims = 3;
 
     TexImageTarget target;
     WebGLTexture* tex;
     if (!ValidateTexImageTarget(this, funcName, funcDims, rawTexImageTarget, &target,
                                 &tex))
--- a/dom/canvas/WebGL2ContextUniforms.cpp
+++ b/dom/canvas/WebGL2ContextUniforms.cpp
@@ -66,21 +66,21 @@ WebGLContext::Uniform4ui(WebGLUniformLoc
     MakeContextCurrent();
     gl->fUniform4ui(loc->mLoc, v0, v1, v2, v3);
 }
 
 // -------------------------------------------------------------------------
 // Uniform Buffer Objects and Transform Feedback Buffers
 
 void
-WebGL2Context::GetIndexedParameter(GLenum target, GLuint index,
-                                   dom::Nullable<dom::OwningWebGLBufferOrLongLong>& retval)
+WebGL2Context::GetIndexedParameter(JSContext* cx, GLenum target, GLuint index,
+                                   JS::MutableHandleValue retval, ErrorResult& out_error)
 {
     const char funcName[] = "getIndexedParameter";
-    retval.SetNull();
+    retval.set(JS::NullValue());
     if (IsContextLost())
         return;
 
     const std::vector<IndexedBufferBinding>* bindings;
     switch (target) {
     case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
     case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
     case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
@@ -100,34 +100,38 @@ WebGL2Context::GetIndexedParameter(GLenu
 
     if (index >= bindings->size()) {
         ErrorInvalidValue("%s: `index` must be < %s.", funcName,
                           "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS");
         return;
     }
     const auto& binding = (*bindings)[index];
 
+    JS::Value ret = JS::NullValue();
+
     switch (target) {
     case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
     case LOCAL_GL_UNIFORM_BUFFER_BINDING:
         if (binding.mBufferBinding) {
-            retval.SetValue().SetAsWebGLBuffer() = binding.mBufferBinding;
+            ret = WebGLObjectAsJSValue(cx, binding.mBufferBinding.get(), out_error);
         }
         break;
 
     case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
     case LOCAL_GL_UNIFORM_BUFFER_START:
-        retval.SetValue().SetAsLongLong() = binding.mRangeStart;
+        ret = JS::NumberValue(binding.mRangeStart);
         break;
 
     case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
     case LOCAL_GL_UNIFORM_BUFFER_SIZE:
-        retval.SetValue().SetAsLongLong() = binding.mRangeSize;
+        ret = JS::NumberValue(binding.mRangeSize);
         break;
     }
+
+    retval.set(ret);
 }
 
 void
 WebGL2Context::GetUniformIndices(WebGLProgram* program,
                                  const dom::Sequence<nsString>& uniformNames,
                                  dom::Nullable< nsTArray<GLuint> >& retval)
 {
     retval.SetNull();
@@ -241,39 +245,40 @@ WebGL2Context::GetUniformBlockIndex(WebG
         return 0;
 
     return program->GetUniformBlockIndex(uniformBlockName);
 }
 
 void
 WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, WebGLProgram* program,
                                               GLuint uniformBlockIndex, GLenum pname,
-                                              dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
-                                              ErrorResult& rv)
+                                              JS::MutableHandleValue out_retval,
+                                              ErrorResult& out_error)
 {
-    retval.SetNull();
+    out_retval.set(JS::NullValue());
     if (IsContextLost())
         return;
 
     if (!ValidateObject("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:
-        program->GetActiveUniformBlockParam(uniformBlockIndex, pname, retval);
+        out_retval.set(program->GetActiveUniformBlockParam(uniformBlockIndex, pname));
         return;
 
     case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
-        program->GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex, retval, rv);
+        out_retval.set(program->GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex,
+                                                                    &out_error));
         return;
     }
 
     ErrorInvalidEnumInfo("getActiveUniformBlockParameter: parameter", pname);
 }
 
 void
 WebGL2Context::GetActiveUniformBlockName(WebGLProgram* program, GLuint uniformBlockIndex,
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -774,91 +774,89 @@ WebGLProgram::GetActiveUniformBlockName(
         return;
     }
 
     const webgl::UniformBlockInfo* blockInfo = linkInfo->uniformBlocks[uniformBlockIndex];
 
     retval.Assign(NS_ConvertASCIItoUTF16(blockInfo->mBaseUserName));
 }
 
-void
-WebGLProgram::GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname,
-                                         dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval) const
+JS::Value
+WebGLProgram::GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname) const
 {
-    retval.SetNull();
     if (!IsLinked()) {
         mContext->ErrorInvalidOperation("getActiveUniformBlockParameter: `program` must be linked.");
-        return;
+        return JS::NullValue();
     }
 
     const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
     GLuint uniformBlockCount = (GLuint)linkInfo->uniformBlocks.size();
     if (uniformBlockIndex >= uniformBlockCount) {
         mContext->ErrorInvalidValue("getActiveUniformBlockParameter: index %u invalid.", uniformBlockIndex);
-        return;
+        return JS::NullValue();
     }
 
     gl::GLContext* gl = mContext->GL();
     GLint param = 0;
 
     switch (pname) {
     case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
     case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
         gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex, pname, &param);
-        retval.SetValue().SetAsBoolean() = (param != 0);
-        return;
+        return JS::BooleanValue(bool(param));
 
     case LOCAL_GL_UNIFORM_BLOCK_BINDING:
     case LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE:
     case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
         gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex, pname, &param);
-        retval.SetValue().SetAsUnsignedLong() = param;
-        return;
+        return JS::NumberValue(param);
+
+    default:
+        MOZ_CRASH("bad `pname`.");
     }
 }
 
-void
+JS::Value
 WebGLProgram::GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex,
-                                                  dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
-                                                  ErrorResult& rv) const
+                                                  ErrorResult* const out_error) const
 {
+    const char funcName[] = "getActiveUniformBlockParameter";
     if (!IsLinked()) {
-        mContext->ErrorInvalidOperation("getActiveUniformBlockParameter: `program` must be linked.");
-        return;
+        mContext->ErrorInvalidOperation("%s: `program` must be linked.", funcName);
+        return JS::NullValue();
     }
 
     const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
     GLuint uniformBlockCount = (GLuint)linkInfo->uniformBlocks.size();
     if (uniformBlockIndex >= uniformBlockCount) {
-        mContext->ErrorInvalidValue("getActiveUniformBlockParameter: index %u invalid.", uniformBlockIndex);
-        return;
+        mContext->ErrorInvalidValue("%s: Index %u invalid.", funcName, uniformBlockIndex);
+        return JS::NullValue();
     }
 
     gl::GLContext* gl = mContext->GL();
     GLint activeUniformCount = 0;
     gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex,
                                  LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS,
                                  &activeUniformCount);
     JS::RootedObject obj(cx, dom::Uint32Array::Create(cx, mContext, activeUniformCount,
                                                       nullptr));
     if (!obj) {
-        rv = NS_ERROR_OUT_OF_MEMORY;
-        return;
+        *out_error = NS_ERROR_OUT_OF_MEMORY;
+        return JS::NullValue();
     }
 
     dom::Uint32Array result;
     DebugOnly<bool> inited = result.Init(obj);
     MOZ_ASSERT(inited);
     result.ComputeLengthAndData();
     gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex,
                                  LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
                                  (GLint*)result.Data());
 
-    inited = retval.SetValue().SetAsUint32Array().Init(obj);
-    MOZ_ASSERT(inited);
+    return JS::ObjectValue(*obj);
 }
 
 already_AddRefed<WebGLUniformLocation>
 WebGLProgram::GetUniformLocation(const nsAString& userName_wide) const
 {
     if (!ValidateGLSLVariableName(userName_wide, mContext, "getUniformLocation"))
         return nullptr;
 
--- a/dom/canvas/WebGLProgram.h
+++ b/dom/canvas/WebGLProgram.h
@@ -150,21 +150,19 @@ public:
     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;
     void GetActiveUniformBlockName(GLuint uniformBlockIndex, nsAString& name) const;
-    void GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname,
-                                    dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval) const;
-    void GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex,
-                                             dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
-                                             ErrorResult& rv) const;
+    JS::Value GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname) const;
+    JS::Value GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex,
+                                                  ErrorResult* const out_error) const;
     already_AddRefed<WebGLUniformLocation> GetUniformLocation(const nsAString& name) const;
     void GetUniformIndices(const dom::Sequence<nsString>& uniformNames,
                            dom::Nullable< nsTArray<GLuint> >& retval) const;
     void UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const;
 
     void LinkProgram();
     bool UseProgram() const;
     void ValidateProgram() const;