OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 if (dataSize.unsafeGet() < 0 | 58 if (dataSize.unsafeGet() < 0 |
59 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) | 59 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) |
60 return nullptr; | 60 return nullptr; |
61 | 61 |
62 return new ImageData(size, byteArray); | 62 return new ImageData(size, byteArray); |
63 } | 63 } |
64 | 64 |
65 ImageData* ImageData::create(unsigned width, unsigned height, ExceptionState& ex
ceptionState) | 65 ImageData* ImageData::create(unsigned width, unsigned height, ExceptionState& ex
ceptionState) |
66 { | 66 { |
67 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | |
68 exceptionState.throwTypeError("Illegal constructor"); | |
69 return nullptr; | |
70 } | |
71 if (!width || !height) { | 67 if (!width || !height) { |
72 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is zero or not a number.", width ? "height" : "width")); | 68 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is zero or not a number.", width ? "height" : "width")); |
73 return nullptr; | 69 return nullptr; |
74 } | 70 } |
75 | 71 |
76 Checked<unsigned, RecordOverflow> dataSize = 4; | 72 Checked<unsigned, RecordOverflow> dataSize = 4; |
77 dataSize *= width; | 73 dataSize *= width; |
78 dataSize *= height; | 74 dataSize *= height; |
79 if (dataSize.hasOverflowed()) { | 75 if (dataSize.hasOverflowed()) { |
80 exceptionState.throwDOMException(IndexSizeError, "The requested image si
ze exceeds the supported range."); | 76 exceptionState.throwDOMException(IndexSizeError, "The requested image si
ze exceeds the supported range."); |
(...skipping 23 matching lines...) Expand all Loading... |
104 if (length % width) { | 100 if (length % width) { |
105 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); | 101 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); |
106 return false; | 102 return false; |
107 } | 103 } |
108 lengthInPixels = length; | 104 lengthInPixels = length; |
109 return true; | 105 return true; |
110 } | 106 } |
111 | 107 |
112 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, Excepti
onState& exceptionState) | 108 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, Excepti
onState& exceptionState) |
113 { | 109 { |
114 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | |
115 exceptionState.throwTypeError("Illegal constructor"); | |
116 return nullptr; | |
117 } | |
118 unsigned lengthInPixels = 0; | 110 unsigned lengthInPixels = 0; |
119 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { | 111 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { |
120 ASSERT(exceptionState.hadException()); | 112 ASSERT(exceptionState.hadException()); |
121 return nullptr; | 113 return nullptr; |
122 } | 114 } |
123 ASSERT(lengthInPixels && width); | 115 ASSERT(lengthInPixels && width); |
124 unsigned height = lengthInPixels / width; | 116 unsigned height = lengthInPixels / width; |
125 return new ImageData(IntSize(width, height), data); | 117 return new ImageData(IntSize(width, height), data); |
126 } | 118 } |
127 | 119 |
128 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigne
d height, ExceptionState& exceptionState) | 120 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigne
d height, ExceptionState& exceptionState) |
129 { | 121 { |
130 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | |
131 exceptionState.throwTypeError("Illegal constructor"); | |
132 return nullptr; | |
133 } | |
134 unsigned lengthInPixels = 0; | 122 unsigned lengthInPixels = 0; |
135 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { | 123 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { |
136 ASSERT(exceptionState.hadException()); | 124 ASSERT(exceptionState.hadException()); |
137 return nullptr; | 125 return nullptr; |
138 } | 126 } |
139 ASSERT(lengthInPixels && width); | 127 ASSERT(lengthInPixels && width); |
140 if (height != lengthInPixels / width) { | 128 if (height != lengthInPixels / width) { |
141 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); | 129 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); |
142 return nullptr; | 130 return nullptr; |
143 } | 131 } |
(...skipping 27 matching lines...) Expand all Loading... |
171 { | 159 { |
172 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); | 160 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); |
173 } | 161 } |
174 | 162 |
175 void ImageData::dispose() | 163 void ImageData::dispose() |
176 { | 164 { |
177 m_data.clear(); | 165 m_data.clear(); |
178 } | 166 } |
179 | 167 |
180 } // namespace blink | 168 } // namespace blink |
OLD | NEW |