Index: Source/bindings/v8/custom/V8ImageDataCustom.cpp |
diff --git a/Source/bindings/v8/custom/V8ImageDataCustom.cpp b/Source/bindings/v8/custom/V8ImageDataCustom.cpp |
index 813731456ecb5f2a7d3e1a80147467bace38a7e4..8573f9a9302df3c09ba4b31d1a3163222a82e609 100644 |
--- a/Source/bindings/v8/custom/V8ImageDataCustom.cpp |
+++ b/Source/bindings/v8/custom/V8ImageDataCustom.cpp |
@@ -31,6 +31,7 @@ |
#include "config.h" |
#include "V8ImageData.h" |
+#include "bindings/v8/ExceptionState.h" |
#include "bindings/v8/custom/V8Uint8ClampedArrayCustom.h" |
namespace WebCore { |
@@ -52,4 +53,47 @@ v8::Handle<v8::Object> wrap(ImageData* impl, v8::Handle<v8::Object> creationCont |
return wrapper; |
} |
+void V8ImageData::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
+{ |
+ ExceptionState exceptionState(ExceptionState::ConstructionContext, "ImageData", info.Holder(), info.GetIsolate()); |
+ if (info.Length() >= 2 && V8Uint8ClampedArray::hasInstance(info[0], info.GetIsolate())) { |
+ V8TRYCATCH_VOID(Uint8ClampedArray*, data, info[0]->IsUint8ClampedArray() ? V8Uint8ClampedArray::toNative(v8::Handle<v8::Uint8ClampedArray>::Cast(info[0])) : 0); |
+ V8TRYCATCH_EXCEPTION_VOID(unsigned, width, toUInt32(info[1], exceptionState), exceptionState); |
+ V8TRYCATCH_EXCEPTION_VOID(unsigned, height, toUInt32(info[2], exceptionState), exceptionState); |
+ RefPtr<ImageData> impl = ImageData::create(data, width, height, exceptionState); |
+ v8::Handle<v8::Object> wrapper = info.Holder(); |
+ if (exceptionState.throwIfNeeded()) |
+ return; |
+ |
+ v8::Handle<v8::Value> pixelArray = toV8(impl->data(), wrapper, info.GetIsolate()); |
+ V8DOMWrapper::associateObjectWithWrapper<V8ImageData>(impl.release(), &V8ImageData::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent); |
+ if (!pixelArray.IsEmpty()) |
+ wrapper->Set(v8AtomicString(info.GetIsolate(), "data"), pixelArray, v8::ReadOnly); |
+ v8SetReturnValue(info, wrapper); |
+ return; |
+ } |
+ if (info.Length() >= 2) { |
+ V8TRYCATCH_EXCEPTION_VOID(unsigned, width, toUInt32(info[0], exceptionState), exceptionState); |
+ V8TRYCATCH_EXCEPTION_VOID(unsigned, height, toUInt32(info[1], exceptionState), exceptionState); |
+ RefPtr<ImageData> impl = ImageData::create(width, height, exceptionState); |
+ v8::Handle<v8::Object> wrapper = info.Holder(); |
+ if (exceptionState.throwIfNeeded()) |
+ return; |
+ |
+ v8::Handle<v8::Value> pixelArray = toV8(impl->data(), wrapper, info.GetIsolate()); |
+ V8DOMWrapper::associateObjectWithWrapper<V8ImageData>(impl.release(), &V8ImageData::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent); |
+ if (!pixelArray.IsEmpty()) |
+ wrapper->Set(v8AtomicString(info.GetIsolate(), "data"), pixelArray, v8::ReadOnly); |
+ v8SetReturnValue(info, wrapper); |
+ return; |
+ } |
+ if (UNLIKELY(info.Length() < 2)) { |
+ exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, info.Length())); |
+ exceptionState.throwIfNeeded(); |
+ return; |
+ } |
+ exceptionState.throwTypeError("No matching constructor signature."); |
+ exceptionState.throwIfNeeded(); |
+} |
+ |
} // namespace WebCore |