Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Unified Diff: Source/core/html/ImageData.cpp

Issue 871563003: Fix ImageData constructor infelicity. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/ImageData.h ('k') | Source/core/html/ImageData.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
« no previous file with comments | « Source/core/html/ImageData.h ('k') | Source/core/html/ImageData.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698