Changeset 223611 in webkit


Ignore:
Timestamp:
Oct 18, 2017 9:59:52 AM (7 years ago)
Author:
Chris Dumez
Message:

Align ImageData constructor with the specification
https://bugs.webkit.org/show_bug.cgi?id=178406

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Rebaseline test now that one more check is passing.

  • web-platform-tests/html/semantics/embedded-content/the-canvas-element/imagedata-expected.txt:

Source/WebCore:

Align ImageData constructor with the specification:

It sometimes throws the wrong exception.

No new tests, rebaselined existing test.

  • html/ImageData.cpp:

(WebCore::ImageData::create):

  • html/ImageData.h:
  • html/ImageData.idl:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/fast/canvas/canvas-imageData-expected.txt

    r219663 r223611  
    1111PASS new ImageData(20, 0) threw exception IndexSizeError: The index is not in the allowed range..
    1212PASS new ImageData(0, 20) threw exception IndexSizeError: The index is not in the allowed range..
    13 PASS new ImageData(-20, 20) threw exception TypeError: Type error.
    14 PASS new ImageData(20, -20) threw exception TypeError: Type error.
     13PASS new ImageData(-20, 20) threw exception RangeError: Cannot allocate a buffer of this size.
     14PASS new ImageData(20, -20) threw exception RangeError: Cannot allocate a buffer of this size.
    1515PASS new ImageData(null, 20) threw exception IndexSizeError: The index is not in the allowed range..
    16 PASS new ImageData(32768, 32768) threw exception TypeError: Type error.
     16PASS new ImageData(32768, 32768) threw exception RangeError: Cannot allocate a buffer of this size.
    1717PASS new ImageData(null, 20, 20) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
    1818PASS new ImageData(imageData, 20, 20) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
     
    2121PASS new ImageData(imageData, 0, 20) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
    2222PASS new ImageData(imageData, 10, 5) threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
    23 PASS new ImageData(imageData.data, 10, 5) threw exception IndexSizeError: The index is not in the allowed range..
    24 PASS new ImageData(imageData.data, -10, 5) threw exception InvalidStateError: The object is in an invalid state..
    25 PASS new ImageData(imageData.data, 10, -10) threw exception IndexSizeError: The index is not in the allowed range..
    26 PASS new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2); threw exception InvalidStateError: The object is in an invalid state..
     23PASS new ImageData(imageData.data, 10, 5) threw exception IndexSizeError: sh value is not equal to height.
     24PASS new ImageData(imageData.data, -10, 5) threw exception IndexSizeError: Length is not a multiple of sw.
     25PASS new ImageData(imageData.data, 10, -10) threw exception IndexSizeError: sh value is not equal to height.
     26PASS new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2); threw exception IndexSizeError: Length is not a multiple of sw.
    2727PASS new ImageData({},2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
    2828PASS new ImageData(undefined,2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
    2929PASS new ImageData("none",2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
    3030PASS new ImageData(0,2,2); threw exception TypeError: Argument 1 ('data') to the ImageData constructor must be an instance of Uint8ClampedArray.
    31 PASS new ImageData(imageData.data, 32768, 32768) threw exception InvalidStateError: The object is in an invalid state..
    32 PASS new ImageData(imageData.data, Infinity, Infinity) threw exception IndexSizeError: The index is not in the allowed range..
    33 PASS new ImageData(imageData.data, NaN, NaN) threw exception IndexSizeError: The index is not in the allowed range..
     31PASS new ImageData(imageData.data, 32768, 32768) threw exception IndexSizeError: Length is not a multiple of sw.
     32PASS new ImageData(imageData.data, Infinity, Infinity) threw exception IndexSizeError: Length is not a multiple of sw.
     33PASS new ImageData(imageData.data, NaN, NaN) threw exception IndexSizeError: Length is not a multiple of sw.
     34PASS new ImageData(imageData.data, 10, 0) threw exception IndexSizeError: sh value is not equal to height.
    3435
    3536Test valid ImageData constructors.
  • trunk/LayoutTests/fast/canvas/canvas-imageData.html

    r217390 r223611  
    2020shouldThrowErrorName('new ImageData(20, 0)', 'IndexSizeError');
    2121shouldThrowErrorName('new ImageData(0, 20)', 'IndexSizeError');
    22 shouldThrowErrorName('new ImageData(-20, 20)', 'TypeError');
    23 shouldThrowErrorName('new ImageData(20, -20)', 'TypeError');
     22shouldThrowErrorName('new ImageData(-20, 20)', 'RangeError');
     23shouldThrowErrorName('new ImageData(20, -20)', 'RangeError');
    2424shouldThrowErrorName('new ImageData(null, 20)', 'IndexSizeError');
    25 shouldThrowErrorName('new ImageData(32768, 32768)', 'TypeError');
     25shouldThrowErrorName('new ImageData(32768, 32768)', 'RangeError');
    2626shouldThrowErrorName('new ImageData(null, 20, 20)', 'TypeError');
    2727shouldThrowErrorName('new ImageData(imageData, 20, 20)', 'TypeError');
     
    3131shouldThrowErrorName('new ImageData(imageData, 10, 5)', 'TypeError');
    3232shouldThrowErrorName('new ImageData(imageData.data, 10, 5)', 'IndexSizeError');
    33 shouldThrowErrorName('new ImageData(imageData.data, -10, 5)', 'InvalidStateError');
     33shouldThrowErrorName('new ImageData(imageData.data, -10, 5)', 'IndexSizeError');
    3434shouldThrowErrorName('new ImageData(imageData.data, 10, -10)', 'IndexSizeError');
    35 shouldThrowErrorName('new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2);', 'InvalidStateError');
     35shouldThrowErrorName('new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2);', 'IndexSizeError');
    3636shouldThrowErrorName('new ImageData({},2,2);', 'TypeError');
    3737shouldThrowErrorName('new ImageData(undefined,2,2);', 'TypeError');
    3838shouldThrowErrorName('new ImageData("none",2,2);', 'TypeError');
    3939shouldThrowErrorName('new ImageData(0,2,2);', 'TypeError');
    40 shouldThrowErrorName('new ImageData(imageData.data, 32768, 32768)', 'InvalidStateError');
     40shouldThrowErrorName('new ImageData(imageData.data, 32768, 32768)', 'IndexSizeError');
    4141shouldThrowErrorName('new ImageData(imageData.data, Infinity, Infinity)', 'IndexSizeError');
    4242shouldThrowErrorName('new ImageData(imageData.data, NaN, NaN)', 'IndexSizeError');
     43shouldThrowErrorName('new ImageData(imageData.data, 10, 0)', 'IndexSizeError');
    4344debug('');
    4445
     
    4748new ImageData(imageData.data, 10, 10);
    4849new ImageData(imageData.data, 10);
    49 // This should throw but doesn't because of a CodeGeneratorJS bug.
    50 new ImageData(imageData.data, 10, 0);
    5150
    5251debug('Test that we got the pixel array from imageData.');
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r223441 r223611  
     12017-10-18  Chris Dumez  <cdumez@apple.com>
     2
     3        Align ImageData constructor with the specification
     4        https://bugs.webkit.org/show_bug.cgi?id=178406
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Rebaseline test now that one more check is passing.
     9
     10        * web-platform-tests/html/semantics/embedded-content/the-canvas-element/imagedata-expected.txt:
     11
    1122017-10-16  Youenn Fablet  <youenn@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-canvas-element/imagedata-expected.txt

    r219663 r223611  
    44PASS ImageData(w, h), exposed attributes check
    55PASS ImageData(buffer, w), the buffer size must be a multiple of 4
    6 FAIL ImageData(buffer, w), buffer size must be a multiple of the image width assert_throws: function "function () {
    7         new ImageData(new Uint8ClampedArray(16), 3);
    8     }" threw object "InvalidStateError: The object is in an invalid state." that is not a DOMException IndexSizeError: property "code" is equal to 11, expected 1
     6PASS ImageData(buffer, w), buffer size must be a multiple of the image width
    97PASS ImageData(buffer, w, h), buffer.lenght == 4 * w * h must be true
    108FAIL ImageData(buffer, w, opt h), Uint8ClampedArray argument type check assert_throws: function "function () {
  • trunk/Source/WebCore/ChangeLog

    r223608 r223611  
     12017-10-18  Chris Dumez  <cdumez@apple.com>
     2
     3        Align ImageData constructor with the specification
     4        https://bugs.webkit.org/show_bug.cgi?id=178406
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Align ImageData constructor with the specification:
     9        - https://html.spec.whatwg.org/multipage/canvas.html#dom-imagedata
     10
     11        It sometimes throws the wrong exception.
     12
     13        No new tests, rebaselined existing test.
     14
     15        * html/ImageData.cpp:
     16        (WebCore::ImageData::create):
     17        * html/ImageData.h:
     18        * html/ImageData.idl:
     19
    1202017-10-18  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/Source/WebCore/html/ImageData.cpp

    r219856 r223611  
    4545    dataSize *= sh;
    4646    if (dataSize.hasOverflowed())
    47         return Exception { TypeError }; // FIXME: Seems a peculiar choice of exception here.
     47        return Exception { RangeError, ASCIILiteral("Cannot allocate a buffer of this size") };
    4848
    4949    IntSize size(sw, sh);
     
    7878}
    7979
    80 ExceptionOr<RefPtr<ImageData>> ImageData::create(Ref<Uint8ClampedArray>&& byteArray, unsigned sw, unsigned sh)
     80ExceptionOr<RefPtr<ImageData>> ImageData::create(Ref<Uint8ClampedArray>&& byteArray, unsigned sw, std::optional<unsigned> sh)
    8181{
    8282    unsigned length = byteArray->length();
    83     if (!length || length % 4 != 0)
    84         return Exception { InvalidStateError };
     83    if (!length || length % 4)
     84        return Exception { InvalidStateError, ASCIILiteral("Length is not a non-zero multiple of 4") };
    8585
    86     if (!sw)
    87         return Exception { IndexSizeError };
    88 
     86    ASSERT(length > 0);
    8987    length /= 4;
    90     if (length % sw != 0)
    91         return Exception { InvalidStateError };
     88    if (!sw || length % sw)
     89        return Exception { IndexSizeError, ASCIILiteral("Length is not a multiple of sw") };
    9290
    9391    unsigned height = length / sw;
    94     if (sh && sh != height)
    95         return Exception { IndexSizeError };
     92    if (sh && sh.value() != height)
     93        return Exception { IndexSizeError, ASCIILiteral("sh value is not equal to height") };
    9694
    9795    return create(IntSize(sw, height), WTFMove(byteArray));
  • trunk/Source/WebCore/html/ImageData.h

    r214806 r223611  
    4040    static RefPtr<ImageData> create(const IntSize&);
    4141    static RefPtr<ImageData> create(const IntSize&, Ref<Uint8ClampedArray>&&);
    42     static ExceptionOr<RefPtr<ImageData>> create(Ref<Uint8ClampedArray>&&, unsigned sw, unsigned sh);
     42    static ExceptionOr<RefPtr<ImageData>> create(Ref<Uint8ClampedArray>&&, unsigned sw, std::optional<unsigned> sh);
    4343
    4444    IntSize size() const { return m_size; }
  • trunk/Source/WebCore/html/ImageData.idl

    r221598 r223611  
    2929[
    3030    Constructor(unsigned long sw, unsigned long sh),
    31     Constructor(Uint8ClampedArray data, unsigned long sw, optional unsigned long sh = 0), // FIXME: sh should not have a default value
     31    Constructor(Uint8ClampedArray data, unsigned long sw, optional unsigned long sh),
    3232    ConstructorMayThrowException,
    3333    CustomToJSObject,
Note: See TracChangeset for help on using the changeset viewer.