Title: [124668] trunk
Revision
124668
Author
[email protected]
Date
2012-08-03 16:03:15 -0700 (Fri, 03 Aug 2012)

Log Message

Update TypedArrays to throw RangeError or similar instead of INDEX_SIZE_ERR
https://bugs.webkit.org/show_bug.cgi?id=45118

Patch by Arnaud Renevier <[email protected]> on 2012-08-03
Reviewed by Kenneth Russell.

Source/WebCore:

Update TypedArrays to raise _javascript_ RangeError instead of dom
INDEX_SIZE_ERR exceptions. Also, update TypedArrays to raise TypeError
instead of _javascript_ SyntaxError or dom exceptions SYNTAX_ERR when
calling set method with invalid arguments.

Specification does not define the type of exceptions to raise, but
other browsers raise _javascript_ errors, so those changes will improve
compatibility.

New Test: fast/canvas/webgl/array-set-invalid-arguments.html

Updated Tests expectations:
    fast/canvas/webgl/array-set-out-of-bounds.html
    fast/canvas/webgl/data-view-crash.html
    fast/canvas/webgl/data-view-test.html

* bindings/js/JSArrayBufferViewHelper.h:
(WebCore):
(WebCore::setWebGLArrayWithTypedArrayArgument):
(WebCore::setWebGLArrayHelper):
(WebCore::constructArrayBufferViewWithTypedArrayArgument):
(WebCore::constructArrayBufferViewWithArrayBufferArgument):
(WebCore::constructArrayBufferView):
* bindings/v8/custom/V8ArrayBufferViewCustom.h:
(WebCore):
(WebCore::constructWebGLArrayWithArrayBufferArgument):
(WebCore::setWebGLArrayHelper):

LayoutTests:

New test to test invalid arguments to TypedArray set method

Update array-set-out-of-bounds.html, data-view-crash.html and
data-view-test.html test expectations no match new exceptions thrown.

* fast/canvas/webgl/array-set-invalid-arguments-expected.txt: Added.
* fast/canvas/webgl/array-set-invalid-arguments.html: Added.
* fast/canvas/webgl/array-set-out-of-bounds-expected.txt:
* fast/canvas/webgl/data-view-crash-expected.txt:
* fast/canvas/webgl/data-view-test-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (124667 => 124668)


--- trunk/LayoutTests/ChangeLog	2012-08-03 22:42:29 UTC (rev 124667)
+++ trunk/LayoutTests/ChangeLog	2012-08-03 23:03:15 UTC (rev 124668)
@@ -1,3 +1,21 @@
+2012-08-03  Arnaud Renevier  <[email protected]>
+
+        Update TypedArrays to throw RangeError or similar instead of INDEX_SIZE_ERR
+        https://bugs.webkit.org/show_bug.cgi?id=45118
+
+        Reviewed by Kenneth Russell.
+
+        New test to test invalid arguments to TypedArray set method
+
+        Update array-set-out-of-bounds.html, data-view-crash.html and
+        data-view-test.html test expectations no match new exceptions thrown.
+
+        * fast/canvas/webgl/array-set-invalid-arguments-expected.txt: Added.
+        * fast/canvas/webgl/array-set-invalid-arguments.html: Added.
+        * fast/canvas/webgl/array-set-out-of-bounds-expected.txt:
+        * fast/canvas/webgl/data-view-crash-expected.txt:
+        * fast/canvas/webgl/data-view-test-expected.txt:
+
 2012-08-03  Dan Bernstein  <[email protected]>
 
         REGRESSION (Safari 5.1 - 6): Cannot correctly display Traditional Mongolian Script

Added: trunk/LayoutTests/fast/canvas/webgl/array-set-invalid-arguments-expected.txt (0 => 124668)


--- trunk/LayoutTests/fast/canvas/webgl/array-set-invalid-arguments-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/array-set-invalid-arguments-expected.txt	2012-08-03 23:03:15 UTC (rev 124668)
@@ -0,0 +1,29 @@
+Verifies that attempting to set invalid elements to a Typed Array throws an exception
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS typedArray.set() threw exception TypeError: Not enough arguments.
+PASS typedArray.set('hello world') threw exception TypeError: Invalid argument.
+PASS typedArray.set(otherArray, 1) threw exception RangeError: Index is out of range..
+PASS typedArray.set() threw exception TypeError: Not enough arguments.
+PASS typedArray.set('hello world') threw exception TypeError: Invalid argument.
+PASS typedArray.set(otherArray, 1) threw exception RangeError: Index is out of range..
+PASS typedArray.set() threw exception TypeError: Not enough arguments.
+PASS typedArray.set('hello world') threw exception TypeError: Invalid argument.
+PASS typedArray.set(otherArray, 1) threw exception RangeError: Index is out of range..
+PASS typedArray.set() threw exception TypeError: Not enough arguments.
+PASS typedArray.set('hello world') threw exception TypeError: Invalid argument.
+PASS typedArray.set(otherArray, 1) threw exception RangeError: Index is out of range..
+PASS typedArray.set() threw exception TypeError: Not enough arguments.
+PASS typedArray.set('hello world') threw exception TypeError: Invalid argument.
+PASS typedArray.set(otherArray, 1) threw exception RangeError: Index is out of range..
+PASS typedArray.set() threw exception TypeError: Not enough arguments.
+PASS typedArray.set('hello world') threw exception TypeError: Invalid argument.
+PASS typedArray.set(otherArray, 1) threw exception RangeError: Index is out of range..
+PASS typedArray.set() threw exception TypeError: Not enough arguments.
+PASS typedArray.set('hello world') threw exception TypeError: Invalid argument.
+PASS typedArray.set(otherArray, 1) threw exception RangeError: Index is out of range..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/webgl/array-set-invalid-arguments.html (0 => 124668)


--- trunk/LayoutTests/fast/canvas/webgl/array-set-invalid-arguments.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/array-set-invalid-arguments.html	2012-08-03 23:03:15 UTC (rev 124668)
@@ -0,0 +1,41 @@
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+
+description("Verifies that attempting to set invalid elements to a Typed Array throws an exception");
+
+// Global scope so shouldThrow can see it
+var typedArray, otherArray;
+
+function negativeTestSet(typeName) {
+    var type = window[typeName];
+    typedArray = new type(10);
+
+    shouldThrow("typedArray.set()");
+    shouldThrow("typedArray.set('hello world')");
+
+    otherArray = new type(typedArray.length);
+    shouldThrow("typedArray.set(otherArray, 1)");
+}
+
+negativeTestSet("Int8Array");
+negativeTestSet("Uint8Array");
+negativeTestSet("Int16Array");
+negativeTestSet("Uint16Array");
+negativeTestSet("Int32Array");
+negativeTestSet("Uint32Array");
+negativeTestSet("Float32Array");
+
+</script>
+
+<script src=""
+</body>
+</html>
+

Modified: trunk/LayoutTests/fast/canvas/webgl/array-set-out-of-bounds-expected.txt (124667 => 124668)


--- trunk/LayoutTests/fast/canvas/webgl/array-set-out-of-bounds-expected.txt	2012-08-03 22:42:29 UTC (rev 124667)
+++ trunk/LayoutTests/fast/canvas/webgl/array-set-out-of-bounds-expected.txt	2012-08-03 23:03:15 UTC (rev 124668)
@@ -4,26 +4,26 @@
 
 Regression test for https://bugs.webkit.org/show_bug.cgi?id=33352 : Passing array that is too large to set method of WebGLArrays does not throw an exception
 Testing Int8Array
-PASS webGLArray.set([4, 5], 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS webGLArray.set([4, 5, 6]) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS webGLArray.set([4, 5], 1) threw exception RangeError: Index is out of range..
+PASS webGLArray.set([4, 5, 6]) threw exception RangeError: Index is out of range..
 Testing Uint8Array
-PASS webGLArray.set([4, 5], 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS webGLArray.set([4, 5, 6]) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS webGLArray.set([4, 5], 1) threw exception RangeError: Index is out of range..
+PASS webGLArray.set([4, 5, 6]) threw exception RangeError: Index is out of range..
 Testing Int16Array
-PASS webGLArray.set([4, 5], 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS webGLArray.set([4, 5, 6]) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS webGLArray.set([4, 5], 1) threw exception RangeError: Index is out of range..
+PASS webGLArray.set([4, 5, 6]) threw exception RangeError: Index is out of range..
 Testing Uint16Array
-PASS webGLArray.set([4, 5], 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS webGLArray.set([4, 5, 6]) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS webGLArray.set([4, 5], 1) threw exception RangeError: Index is out of range..
+PASS webGLArray.set([4, 5, 6]) threw exception RangeError: Index is out of range..
 Testing Int32Array
-PASS webGLArray.set([4, 5], 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS webGLArray.set([4, 5, 6]) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS webGLArray.set([4, 5], 1) threw exception RangeError: Index is out of range..
+PASS webGLArray.set([4, 5, 6]) threw exception RangeError: Index is out of range..
 Testing Uint32Array
-PASS webGLArray.set([4, 5], 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS webGLArray.set([4, 5, 6]) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS webGLArray.set([4, 5], 1) threw exception RangeError: Index is out of range..
+PASS webGLArray.set([4, 5, 6]) threw exception RangeError: Index is out of range..
 Testing Float32Array
-PASS webGLArray.set([4, 5], 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS webGLArray.set([4, 5, 6]) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS webGLArray.set([4, 5], 1) threw exception RangeError: Index is out of range..
+PASS webGLArray.set([4, 5, 6]) threw exception RangeError: Index is out of range..
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/canvas/webgl/data-view-crash-expected.txt (124667 => 124668)


--- trunk/LayoutTests/fast/canvas/webgl/data-view-crash-expected.txt	2012-08-03 22:42:29 UTC (rev 124667)
+++ trunk/LayoutTests/fast/canvas/webgl/data-view-crash-expected.txt	2012-08-03 23:03:15 UTC (rev 124668)
@@ -2,8 +2,8 @@
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
-PASS view = new DataView(array.buffer, -4500000000) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS view = new DataView(array.buffer, -4500000000, 4500000000) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS view = new DataView(array.buffer, -4500000000) threw exception RangeError: Size is too large (or is negative)..
+PASS view = new DataView(array.buffer, -4500000000, 4500000000) threw exception RangeError: Size is too large (or is negative)..
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/canvas/webgl/data-view-test-expected.txt (124667 => 124668)


--- trunk/LayoutTests/fast/canvas/webgl/data-view-test-expected.txt	2012-08-03 22:42:29 UTC (rev 124667)
+++ trunk/LayoutTests/fast/canvas/webgl/data-view-test-expected.txt	2012-08-03 23:03:15 UTC (rev 124668)
@@ -22,9 +22,9 @@
 PASS view.byteLength is 1
 
 Test for constructor throwing exception
-PASS view = new DataView(arayBuffer, 0, 3) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS view = new DataView(arayBuffer, 1, 2) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
-PASS view = new DataView(arayBuffer, 2, 1) threw exception Error: INDEX_SIZE_ERR: DOM Exception 1.
+PASS view = new DataView(arayBuffer, 0, 3) threw exception RangeError: Size is too large (or is negative)..
+PASS view = new DataView(arayBuffer, 1, 2) threw exception RangeError: Size is too large (or is negative)..
+PASS view = new DataView(arayBuffer, 2, 1) threw exception RangeError: Size is too large (or is negative)..
 
 Test for get methods that work
 PASS view.getInt8(0) is 0

Modified: trunk/Source/WebCore/ChangeLog (124667 => 124668)


--- trunk/Source/WebCore/ChangeLog	2012-08-03 22:42:29 UTC (rev 124667)
+++ trunk/Source/WebCore/ChangeLog	2012-08-03 23:03:15 UTC (rev 124668)
@@ -1,3 +1,38 @@
+2012-08-03  Arnaud Renevier  <[email protected]>
+
+        Update TypedArrays to throw RangeError or similar instead of INDEX_SIZE_ERR
+        https://bugs.webkit.org/show_bug.cgi?id=45118
+
+        Reviewed by Kenneth Russell.
+
+        Update TypedArrays to raise _javascript_ RangeError instead of dom
+        INDEX_SIZE_ERR exceptions. Also, update TypedArrays to raise TypeError
+        instead of _javascript_ SyntaxError or dom exceptions SYNTAX_ERR when
+        calling set method with invalid arguments.
+
+        Specification does not define the type of exceptions to raise, but
+        other browsers raise _javascript_ errors, so those changes will improve
+        compatibility.
+
+        New Test: fast/canvas/webgl/array-set-invalid-arguments.html
+
+        Updated Tests expectations:
+            fast/canvas/webgl/array-set-out-of-bounds.html
+            fast/canvas/webgl/data-view-crash.html
+            fast/canvas/webgl/data-view-test.html
+
+        * bindings/js/JSArrayBufferViewHelper.h:
+        (WebCore):
+        (WebCore::setWebGLArrayWithTypedArrayArgument):
+        (WebCore::setWebGLArrayHelper):
+        (WebCore::constructArrayBufferViewWithTypedArrayArgument):
+        (WebCore::constructArrayBufferViewWithArrayBufferArgument):
+        (WebCore::constructArrayBufferView):
+        * bindings/v8/custom/V8ArrayBufferViewCustom.h:
+        (WebCore):
+        (WebCore::constructWebGLArrayWithArrayBufferArgument):
+        (WebCore::setWebGLArrayHelper):
+
 2012-08-03  Levi Weintraub  <[email protected]>
 
         Switch mapLocalToContainer to use a flag instead of boolean parameters

Modified: trunk/Source/WebCore/bindings/js/JSArrayBufferViewHelper.h (124667 => 124668)


--- trunk/Source/WebCore/bindings/js/JSArrayBufferViewHelper.h	2012-08-03 22:42:29 UTC (rev 124667)
+++ trunk/Source/WebCore/bindings/js/JSArrayBufferViewHelper.h	2012-08-03 23:03:15 UTC (rev 124668)
@@ -27,7 +27,6 @@
 #ifndef JSArrayBufferViewHelper_h
 #define JSArrayBufferViewHelper_h
 
-#include "ExceptionCode.h"
 #include "JSArrayBuffer.h"
 #include "JSArrayBufferView.h"
 #include "JSDOMBinding.h"
@@ -41,6 +40,9 @@
 
 namespace WebCore {
 
+static const char* tooLargeSize = "Size is too large (or is negative).";
+static const char* outOfRangeLengthAndOffset = "Index is out of range.";
+
 template<class C, typename T>
 bool copyTypedArrayBuffer(C* target, ArrayBufferView* source, unsigned sourceLength, unsigned offset)
 {
@@ -115,7 +117,7 @@
     uint32_t length = asObject(exec->argument(0))->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec);
 
     if (!(copyTypedArrayBuffer<C, T>(impl, array.get(), length, offset)))
-        setDOMException(exec, INDEX_SIZE_ERR);
+        throwError(exec, createRangeError(exec, outOfRangeLengthAndOffset));
 
     return true;
 }
@@ -124,7 +126,7 @@
 JSC::JSValue setWebGLArrayHelper(JSC::ExecState* exec, C* impl)
 {
     if (exec->argumentCount() < 1)
-        return JSC::throwSyntaxError(exec);
+        return JSC::throwError(exec, createNotEnoughArgumentsError(exec));
 
     if (setWebGLArrayWithTypedArrayArgument<C, T>(exec, impl))
         // void set(in WebGL<>Array array, [Optional] in unsigned long offset);
@@ -138,7 +140,7 @@
             offset = exec->argument(1).toInt32(exec);
         uint32_t length = array->get(exec, JSC::Identifier(exec, "length")).toInt32(exec);
         if (!impl->checkInboundData(offset, length))
-            setDOMException(exec, INDEX_SIZE_ERR);
+            throwError(exec, createRangeError(exec, outOfRangeLengthAndOffset));
         else {
             for (uint32_t i = 0; i < length; i++) {
                 JSC::JSValue v = array->get(exec, i);
@@ -151,7 +153,7 @@
         return JSC::jsUndefined();
     }
 
-    return JSC::throwSyntaxError(exec);
+    return JSC::throwTypeError(exec, "Invalid argument");
 }
 
 // Template function used by XXXArrayConstructors.
@@ -170,12 +172,12 @@
     uint32_t length = asObject(exec->argument(0))->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec);
     RefPtr<C> array = C::createUninitialized(length);
     if (!array) {
-        setDOMException(exec, INDEX_SIZE_ERR);
+        throwError(exec, createRangeError(exec, tooLargeSize));
         return array;
     }
 
     if (!(copyTypedArrayBuffer<C, T>(array.get(), source.get(), length, 0))) {
-        setDOMException(exec, INDEX_SIZE_ERR);
+        throwError(exec, createRangeError(exec, tooLargeSize));
         return array;
     }
 
@@ -204,7 +206,7 @@
     }
     RefPtr<C> array = C::create(buffer, offset, length);
     if (!array)
-        setDOMException(exec, INDEX_SIZE_ERR);
+        throwError(exec, createRangeError(exec, tooLargeSize));
     return array;
 }
 
@@ -245,7 +247,7 @@
         uint32_t length = srcArray->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec);
         RefPtr<C> array = C::createUninitialized(length);
         if (!array) {
-            setDOMException(exec, INDEX_SIZE_ERR);
+            throwError(exec, createRangeError(exec, tooLargeSize));
             return array;
         }
 
@@ -261,7 +263,7 @@
     if (length >= 0)
         result = C::create(static_cast<unsigned>(length));
     if (!result)
-        throwError(exec, createRangeError(exec, "ArrayBufferView size is not a small enough positive integer."));
+        throwError(exec, createRangeError(exec, tooLargeSize));
     return result;
 }
 

Modified: trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h (124667 => 124668)


--- trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h	2012-08-03 22:42:29 UTC (rev 124667)
+++ trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h	2012-08-03 23:03:15 UTC (rev 124668)
@@ -40,6 +40,9 @@
 
 namespace WebCore {
 
+static const char* tooLargeSize = "Size is too large (or is negative).";
+static const char* outOfRangeLengthAndOffset = "Index is out of range.";
+
 // Copy the elements from the source array to the typed destination array.
 // Returns true if it succeeded, otherwise returns false.
 bool copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray, uint32_t length, uint32_t offset, v8::Isolate*);
@@ -84,13 +87,11 @@
     }
     RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length);
     if (!array)
-        return V8Proxy::setDOMException(INDEX_SIZE_ERR, args.GetIsolate());
+        return V8Proxy::throwError(V8Proxy::RangeError, tooLargeSize, args.GetIsolate());
 
     return wrapArrayBufferView(args, type, array, arrayType, hasIndexer);
 }
 
-static const char* notSmallEnoughSize = "ArrayBufferView size is not a small enough positive integer.";
-
 // Template function used by the ArrayBufferView*Constructor callbacks.
 template<class ArrayClass, class _javascript_WrapperArrayType, class ElementType>
 v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType)
@@ -144,7 +145,7 @@
         uint32_t length = source->length();
         RefPtr<ArrayClass> array = ArrayClass::createUninitialized(length);
         if (!array.get())
-            return V8Proxy::throwError(V8Proxy::RangeError, notSmallEnoughSize, args.GetIsolate());
+            return V8Proxy::throwError(V8Proxy::RangeError, tooLargeSize, args.GetIsolate());
 
         memcpy(array->baseAddress(), source->baseAddress(), length * sizeof(ElementType));
 
@@ -179,7 +180,7 @@
     }
 
     if (!array.get())
-        return V8Proxy::throwError(V8Proxy::RangeError, notSmallEnoughSize, args.GetIsolate());
+        return V8Proxy::throwError(V8Proxy::RangeError, tooLargeSize, args.GetIsolate());
 
 
     // Transform the holder into a wrapper object for the array.
@@ -204,7 +205,7 @@
 v8::Handle<v8::Value> setWebGLArrayHelper(const v8::Arguments& args)
 {
     if (args.Length() < 1)
-        return V8Proxy::setDOMException(SYNTAX_ERR, args.GetIsolate());
+        return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
 
     CPlusPlusArrayType* impl = _javascript_WrapperArrayType::toNative(args.Holder());
 
@@ -215,7 +216,7 @@
         if (args.Length() == 2)
             offset = toUInt32(args[1]);
         if (!impl->set(src, offset))
-            return V8Proxy::setDOMException(INDEX_SIZE_ERR, args.GetIsolate());
+            return V8Proxy::throwError(V8Proxy::RangeError, outOfRangeLengthAndOffset, args.GetIsolate());
         return v8::Undefined();
     }
 
@@ -230,7 +231,7 @@
             || offset + length > impl->length()
             || offset + length < offset) {
             // Out of range offset or overflow
-            return V8Proxy::setDOMException(INDEX_SIZE_ERR, args.GetIsolate());
+            return V8Proxy::throwError(V8Proxy::RangeError, outOfRangeLengthAndOffset, args.GetIsolate());
         }
         bool copied = copyElements(args.Holder(), array, length, offset, args.GetIsolate());
         if (!copied) {
@@ -240,7 +241,7 @@
         return v8::Undefined();
     }
 
-    return V8Proxy::setDOMException(SYNTAX_ERR, args.GetIsolate());
+    return V8Proxy::throwTypeError("Invalid argument", args.GetIsolate());
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to