| Index: Source/core/html/ImageData.cpp
|
| diff --git a/Source/core/html/ImageData.cpp b/Source/core/html/ImageData.cpp
|
| index 6b80be777cc5a465afd0fa926f1ed46d98f562d1..8268be7f68b0bc6d6bb3fbf5ba101e0fbbdea759 100644
|
| --- a/Source/core/html/ImageData.cpp
|
| +++ b/Source/core/html/ImageData.cpp
|
| @@ -84,42 +84,63 @@ PassRefPtrWillBeRawPtr<ImageData> ImageData::create(unsigned width, unsigned hei
|
| return adoptRefWillBeNoop(new ImageData(IntSize(width, height)));
|
| }
|
|
|
| -PassRefPtrWillBeRawPtr<ImageData> ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigned height, ExceptionState& exceptionState)
|
| +bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data, unsigned width, unsigned& lengthInPixels, ExceptionState& exceptionState)
|
| {
|
| - if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) {
|
| - exceptionState.throwTypeError("Illegal constructor");
|
| - return nullptr;
|
| - }
|
| - if (!data) {
|
| - exceptionState.throwTypeError("Expected a Uint8ClampedArray as first argument.");
|
| - return nullptr;
|
| - }
|
| if (!width) {
|
| exceptionState.throwDOMException(IndexSizeError, "The source width is zero or not a number.");
|
| - return nullptr;
|
| + return false;
|
| }
|
| -
|
| + ASSERT(data);
|
| unsigned length = data->length();
|
| if (!length) {
|
| exceptionState.throwDOMException(IndexSizeError, "The input data has a zero byte length.");
|
| - return nullptr;
|
| + return false;
|
| }
|
| if (length % 4) {
|
| exceptionState.throwDOMException(IndexSizeError, "The input data byte length is not a multiple of 4.");
|
| - return nullptr;
|
| + return false;
|
| }
|
| length /= 4;
|
| if (length % width) {
|
| exceptionState.throwDOMException(IndexSizeError, "The input data byte length is not a multiple of (4 * width).");
|
| + return false;
|
| + }
|
| + lengthInPixels = length;
|
| + return true;
|
| +}
|
| +
|
| +PassRefPtrWillBeRawPtr<ImageData> ImageData::create(DOMUint8ClampedArray* data, unsigned width, ExceptionState& exceptionState)
|
| +{
|
| + if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) {
|
| + exceptionState.throwTypeError("Illegal constructor");
|
| return nullptr;
|
| }
|
| - if (!height) {
|
| - height = length / width;
|
| - } else if (height != length / width) {
|
| - exceptionState.throwDOMException(IndexSizeError, "The input data byte length is not equal to (4 * width * height).");
|
| + unsigned lengthInPixels = 0;
|
| + if (!validateConstructorArguments(data, width, lengthInPixels, exceptionState)) {
|
| + ASSERT(exceptionState.hadException());
|
| return nullptr;
|
| }
|
| + ASSERT(lengthInPixels && width);
|
| + unsigned height = lengthInPixels / width;
|
| + return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data));
|
| +}
|
|
|
| +PassRefPtrWillBeRawPtr<ImageData> ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigned height, ExceptionState& exceptionState)
|
| +{
|
| + if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) {
|
| + exceptionState.throwTypeError("Illegal constructor");
|
| + return nullptr;
|
| + }
|
| + unsigned lengthInPixels = 0;
|
| + if (!validateConstructorArguments(data, width, lengthInPixels, exceptionState)) {
|
| + ASSERT(exceptionState.hadException());
|
| + return nullptr;
|
| + }
|
| + ASSERT(lengthInPixels && width);
|
| + if (height != lengthInPixels / width) {
|
| + exceptionState.throwDOMException(IndexSizeError, "The input data byte length is not equal to (4 * width * height).");
|
| + return nullptr;
|
| + }
|
| return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data));
|
| }
|
|
|
|
|