Commit 494e1a75 authored by Aaron Krajeski's avatar Aaron Krajeski Committed by Commit Bot

Change type of error thrown by bad ImageData initialization

From: https://html.spec.whatwg.org/multipage/canvas.html:
"""
When the ImageData() constructor is invoked with its first argument
being an Uint8ClampedArray source and its second and optional third
arguments being numeric arguments sw and sh, it must run these steps:

1. Let length be the number of bytes in source.

2. If length is not a nonzero integral multiple of four, then throw an
"InvalidStateError" DOMException.
"""

Previously we were throwing an IndexSizeError. Change the error type
to match the spec.

Bug: 934838
Change-Id: Id122dcbae49426c3c10bf690f8bf940bbf481fc7
Reviewed-on: https://chromium-review.googlesource.com/c/1495195
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636613}
parent 46584179
......@@ -111,14 +111,14 @@ bool ImageData::ValidateConstructorArguments(
if (!data->byteLength()) {
return RaiseDOMExceptionAndReturnFalse(
exception_state, DOMExceptionCode::kIndexSizeError,
exception_state, DOMExceptionCode::kInvalidStateError,
"The input data has zero elements.");
}
data_length = data->byteLength() / data->TypeSize();
if (data_length % 4) {
return RaiseDOMExceptionAndReturnFalse(
exception_state, DOMExceptionCode::kIndexSizeError,
exception_state, DOMExceptionCode::kInvalidStateError,
"The input data length is not a multiple of 4.");
}
......
This is a testharness.js-based test.
FAIL ImageData has a usable constructor assert_throws: function "function() { new ImageData(new Uint8ClampedArray(0), 1); }" threw object "IndexSizeError: Failed to construct 'ImageData': The input data has zero elements." that is not a DOMException INVALID_STATE_ERR: property "code" is equal to 1, expected 11
Harness: the test ran to completion.
......@@ -2,9 +2,7 @@ This is a testharness.js-based test.
PASS ImageData(w, h), width cannot be 0
PASS ImageData(w, h), height cannot be 0
PASS ImageData(w, h), exposed attributes check
FAIL ImageData(buffer, w), the buffer size must be a multiple of 4 assert_throws: function "function() {
new ImageData(new Uint8ClampedArray(3), 1);
}" threw object "IndexSizeError: Failed to construct 'ImageData': The input data length is not a multiple of 4." that is not a DOMException InvalidStateError: property "code" is equal to 1, expected 11
PASS ImageData(buffer, w), the buffer size must be a multiple of 4
PASS ImageData(buffer, w), buffer size must be a multiple of the image width
PASS ImageData(buffer, w, h), buffer.length == 4 * w * h must be true
FAIL ImageData(buffer, w, opt h), Uint8ClampedArray argument type check assert_throws: function "function() {
......
......@@ -55,7 +55,7 @@ test(function(t) {
assert_throws("INDEX_SIZE_ERR", function() {
new ImageData(new Uint8Array(100), 25);
});
assert_throws("INDEX_SIZE_ERR", function() {
assert_throws("INVALID_STATE_ERR", function() {
new ImageData(new Uint8ClampedArray(27), 2);
});
assert_throws("INDEX_SIZE_ERR", function() {
......
......@@ -18,7 +18,7 @@ PASS [Worker] new ImageData('width', 'height') threw exception IndexSizeError: F
PASS [Worker] new ImageData(1 << 31, 1 << 31) threw exception IndexSizeError: Failed to construct 'ImageData': The requested image size exceeds the supported range..
PASS [Worker] new ImageData(new Uint8ClampedArray(0)) threw exception TypeError: Failed to construct 'ImageData': 2 arguments required, but only 1 present..
PASS [Worker] new ImageData(new Uint8Array(100), 25) threw exception IndexSizeError: Failed to construct 'ImageData': The source width is zero or not a number..
PASS [Worker] new ImageData(new Uint8ClampedArray(27), 2) threw exception IndexSizeError: Failed to construct 'ImageData': The input data length is not a multiple of 4..
PASS [Worker] new ImageData(new Uint8ClampedArray(27), 2) threw exception InvalidStateError: Failed to construct 'ImageData': The input data length is not a multiple of 4..
PASS [Worker] new ImageData(new Uint8ClampedArray(28), 7, 0) threw exception IndexSizeError: Failed to construct 'ImageData': The source height is zero or not a number..
PASS [Worker] new ImageData(new Uint8ClampedArray(104), 14) threw exception IndexSizeError: Failed to construct 'ImageData': The input data length is not a multiple of (4 * width)..
PASS [Worker] new ImageData(new Uint8ClampedArray([12, 34, 168, 65328]), 1, 151) threw exception IndexSizeError: Failed to construct 'ImageData': The input data length is not equal to (4 * width * height)..
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment