Improve error message when passing a null ArrayBuffer to bufferData()
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Oct 2016 19:17:06 +0000 (19:17 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Oct 2016 19:17:06 +0000 (19:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163745

Reviewed by Dean Jackson.

Source/WebCore:

Test: fast/canvas/webgl/bufferData-nullable-array-buffer-view.html

Update the idl file to accept a nullable ArrayBuffer, and throw
the relevant error with a more helpful error string.

* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::bufferData):
* html/canvas/WebGLRenderingContextBase.h:
* html/canvas/WebGLRenderingContextBase.idl:

LayoutTests:

* fast/canvas/webgl/bufferData-nullable-array-buffer-view-expected.txt: Added.
* fast/canvas/webgl/bufferData-nullable-array-buffer-view.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207632 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/bufferData-nullable-array-buffer-view-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/bufferData-nullable-array-buffer-view.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.h
Source/WebCore/html/canvas/WebGLRenderingContextBase.idl

index 3fde3a8..0fd9e39 100644 (file)
@@ -1,3 +1,13 @@
+2016-10-20  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Improve error message when passing a null ArrayBuffer to bufferData()
+        https://bugs.webkit.org/show_bug.cgi?id=163745
+
+        Reviewed by Dean Jackson.
+
+        * fast/canvas/webgl/bufferData-nullable-array-buffer-view-expected.txt: Added.
+        * fast/canvas/webgl/bufferData-nullable-array-buffer-view.html: Added.
+
 2016-10-20  Zalan Bujtas  <zalan@apple.com>
 
         Stop searching for first-letter containers at multi-column boundary.
diff --git a/LayoutTests/fast/canvas/webgl/bufferData-nullable-array-buffer-view-expected.txt b/LayoutTests/fast/canvas/webgl/bufferData-nullable-array-buffer-view-expected.txt
new file mode 100644 (file)
index 0000000..0bc07a7
--- /dev/null
@@ -0,0 +1,13 @@
+CONSOLE MESSAGE: line 19: WebGL: INVALID_VALUE: bufferData: null data
+PASS context.getError() is context.NO_ERROR
+PASS context.getError() is context.NO_ERROR
+PASS context.getError() is context.NO_ERROR
+PASS undefined did not throw exception.
+PASS context.getError() is context.NO_ERROR
+PASS undefined did not throw exception.
+PASS context.getError() is context.INVALID_VALUE
+PASS context.getError() is context.NO_ERROR
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/canvas/webgl/bufferData-nullable-array-buffer-view.html b/LayoutTests/fast/canvas/webgl/bufferData-nullable-array-buffer-view.html
new file mode 100644 (file)
index 0000000..8d8b35d
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+var canvas = document.createElement("canvas");
+canvas.width = 2;
+canvas.height = 2;
+var context = canvas.getContext("webgl");
+shouldBe("context.getError()", "context.NO_ERROR");
+var buffer = context.createBuffer();
+shouldBe("context.getError()", "context.NO_ERROR");
+context.bindBuffer(context.ARRAY_BUFFER, buffer);
+shouldBe("context.getError()", "context.NO_ERROR");
+shouldNotThrow(context.bufferData(context.ARRAY_BUFFER, new ArrayBuffer(10), context.STATIC_DRAW));
+shouldBe("context.getError()", "context.NO_ERROR");
+shouldNotThrow(context.bufferData(context.ARRAY_BUFFER, null, context.STATIC_DRAW));
+shouldBe("context.getError()", "context.INVALID_VALUE");
+shouldBe("context.getError()", "context.NO_ERROR");
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
index 957a21e..d4f63a5 100644 (file)
@@ -1,3 +1,20 @@
+2016-10-20  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Improve error message when passing a null ArrayBuffer to bufferData()
+        https://bugs.webkit.org/show_bug.cgi?id=163745
+
+        Reviewed by Dean Jackson.
+
+        Test: fast/canvas/webgl/bufferData-nullable-array-buffer-view.html
+
+        Update the idl file to accept a nullable ArrayBuffer, and throw
+        the relevant error with a more helpful error string.
+
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::bufferData):
+        * html/canvas/WebGLRenderingContextBase.h:
+        * html/canvas/WebGLRenderingContextBase.idl:
+
 2016-10-20  Zalan Bujtas  <zalan@apple.com>
 
         Stop searching for first-letter containers at multi-column boundary.
index 9de71dd..ed02b7e 100644 (file)
@@ -1075,44 +1075,52 @@ void WebGLRenderingContextBase::bufferData(GC3Denum target, long long size, GC3D
     }
 }
 
-void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBuffer& data, GC3Denum usage, ExceptionCode&)
+void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBuffer* data, GC3Denum usage, ExceptionCode&)
 {
     if (isContextLostOrPending())
         return;
+    if (!data) {
+        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "null data");
+        return;
+    }
     WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usage);
     if (!buffer)
         return;
     if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
-        if (!buffer->associateBufferData(&data)) {
+        if (!buffer->associateBufferData(data)) {
             synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
             return;
         }
     }
 
     m_context->moveErrorsToSyntheticErrorList();
-    m_context->bufferData(target, data.byteLength(), data.data(), usage);
+    m_context->bufferData(target, data->byteLength(), data->data(), usage);
     if (m_context->moveErrorsToSyntheticErrorList()) {
         // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
         buffer->disassociateBufferData();
     }
 }
 
-void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBufferView& data, GC3Denum usage, ExceptionCode&)
+void WebGLRenderingContextBase::bufferData(GC3Denum target, RefPtr<ArrayBufferView>&& data, GC3Denum usage, ExceptionCode&)
 {
     if (isContextLostOrPending())
         return;
+    if (!data) {
+        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "null data");
+        return;
+    }
     WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usage);
     if (!buffer)
         return;
     if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
-        if (!buffer->associateBufferData(&data)) {
+        if (!buffer->associateBufferData(data.get())) {
             synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
             return;
         }
     }
 
     m_context->moveErrorsToSyntheticErrorList();
-    m_context->bufferData(target, data.byteLength(), data.baseAddress(), usage);
+    m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage);
     if (m_context->moveErrorsToSyntheticErrorList()) {
         // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
         buffer->disassociateBufferData();
index 84eeeaa..4913730 100644 (file)
@@ -139,8 +139,8 @@ public:
     void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
 
     void bufferData(GC3Denum target, long long size, GC3Denum usage, ExceptionCode&);
-    void bufferData(GC3Denum target, ArrayBuffer& data, GC3Denum usage, ExceptionCode&);
-    void bufferData(GC3Denum target, ArrayBufferView& data, GC3Denum usage, ExceptionCode&);
+    void bufferData(GC3Denum target, ArrayBuffer* data, GC3Denum usage, ExceptionCode&);
+    void bufferData(GC3Denum target, RefPtr<ArrayBufferView>&& data, GC3Denum usage, ExceptionCode&);
     void bufferSubData(GC3Denum target, long long offset, ArrayBuffer* data, ExceptionCode&);
     void bufferSubData(GC3Denum target, long long offset, RefPtr<ArrayBufferView>&& data, ExceptionCode&);
 
index e1af0aa..a75a272 100644 (file)
@@ -484,8 +484,8 @@ typedef unrestricted float GLclampf;
     void blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
     void blendFunc(GLenum sfactor, GLenum dfactor);
     void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
-    [MayThrowLegacyException] void bufferData(GLenum target, ArrayBuffer data, GLenum usage);
-    [MayThrowLegacyException] void bufferData(GLenum target, ArrayBufferView data, GLenum usage);
+    [MayThrowLegacyException] void bufferData(GLenum target, ArrayBuffer? data, GLenum usage);
+    [MayThrowLegacyException] void bufferData(GLenum target, ArrayBufferView? data, GLenum usage);
     [MayThrowLegacyException] void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
     [MayThrowLegacyException] void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer? data);
     [MayThrowLegacyException] void bufferSubData(GLenum target, GLintptr offset, ArrayBufferView? data);