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

Side by Side Diff: Source/bindings/v8/custom/V8ImageDataCustom.cpp

Issue 196343032: Implement ImageData constructors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Have constructor instance wrappers keep a 'data' property instead. Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "V8ImageData.h" 32 #include "V8ImageData.h"
33 33
34 #include "bindings/v8/ExceptionState.h"
34 #include "bindings/v8/custom/V8Uint8ClampedArrayCustom.h" 35 #include "bindings/v8/custom/V8Uint8ClampedArrayCustom.h"
35 36
36 namespace WebCore { 37 namespace WebCore {
37 38
38 v8::Handle<v8::Object> wrap(ImageData* impl, v8::Handle<v8::Object> creationCont ext, v8::Isolate* isolate) 39 v8::Handle<v8::Object> wrap(ImageData* impl, v8::Handle<v8::Object> creationCont ext, v8::Isolate* isolate)
39 { 40 {
40 ASSERT(impl); 41 ASSERT(impl);
41 v8::Handle<v8::Object> wrapper = V8ImageData::createWrapper(impl, creationCo ntext, isolate); 42 v8::Handle<v8::Object> wrapper = V8ImageData::createWrapper(impl, creationCo ntext, isolate);
42 if (!wrapper.IsEmpty()) { 43 if (!wrapper.IsEmpty()) {
43 // Create a V8 Uint8ClampedArray object. 44 // Create a V8 Uint8ClampedArray object.
44 v8::Handle<v8::Value> pixelArray = toV8(impl->data(), creationContext, i solate); 45 v8::Handle<v8::Value> pixelArray = toV8(impl->data(), creationContext, i solate);
45 // Set the "data" property of the ImageData object to 46 // Set the "data" property of the ImageData object to
46 // the created v8 object, eliminating the C++ callback 47 // the created v8 object, eliminating the C++ callback
47 // when accessing the "data" property. 48 // when accessing the "data" property.
48 if (!pixelArray.IsEmpty()) 49 if (!pixelArray.IsEmpty())
49 wrapper->Set(v8AtomicString(isolate, "data"), pixelArray, v8::ReadOn ly); 50 wrapper->Set(v8AtomicString(isolate, "data"), pixelArray, v8::ReadOn ly);
50 } 51 }
51 52
52 return wrapper; 53 return wrapper;
53 } 54 }
54 55
56 void V8ImageData::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo)
57 {
58 ExceptionState exceptionState(ExceptionState::ConstructionContext, "ImageDat a", info.Holder(), info.GetIsolate());
59 if (info.Length() >= 2 && V8Uint8ClampedArray::hasInstance(info[0], info.Get Isolate())) {
60 V8TRYCATCH_VOID(Uint8ClampedArray*, data, info[0]->IsUint8ClampedArray() ? V8Uint8ClampedArray::toNative(v8::Handle<v8::Uint8ClampedArray>::Cast(info[0] )) : 0);
61 V8TRYCATCH_EXCEPTION_VOID(unsigned, width, toUInt32(info[1], exceptionSt ate), exceptionState);
62 V8TRYCATCH_EXCEPTION_VOID(unsigned, height, toUInt32(info[2], exceptionS tate), exceptionState);
63 RefPtr<ImageData> impl = ImageData::create(data, width, height, exceptio nState);
64 v8::Handle<v8::Object> wrapper = info.Holder();
65 if (exceptionState.throwIfNeeded())
66 return;
67
68 v8::Handle<v8::Value> pixelArray = toV8(impl->data(), wrapper, info.GetI solate());
69 V8DOMWrapper::associateObjectWithWrapper<V8ImageData>(impl.release(), &V 8ImageData::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::D ependent);
70 if (!pixelArray.IsEmpty())
71 wrapper->Set(v8AtomicString(info.GetIsolate(), "data"), pixelArray, v8::ReadOnly);
72 v8SetReturnValue(info, wrapper);
73 return;
74 }
75 if (info.Length() >= 2) {
76 V8TRYCATCH_EXCEPTION_VOID(unsigned, width, toUInt32(info[0], exceptionSt ate), exceptionState);
77 V8TRYCATCH_EXCEPTION_VOID(unsigned, height, toUInt32(info[1], exceptionS tate), exceptionState);
78 RefPtr<ImageData> impl = ImageData::create(width, height, exceptionState );
79 v8::Handle<v8::Object> wrapper = info.Holder();
80 if (exceptionState.throwIfNeeded())
81 return;
82
83 v8::Handle<v8::Value> pixelArray = toV8(impl->data(), wrapper, info.GetI solate());
84 V8DOMWrapper::associateObjectWithWrapper<V8ImageData>(impl.release(), &V 8ImageData::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::D ependent);
85 if (!pixelArray.IsEmpty())
86 wrapper->Set(v8AtomicString(info.GetIsolate(), "data"), pixelArray, v8::ReadOnly);
87 v8SetReturnValue(info, wrapper);
88 return;
89 }
90 if (UNLIKELY(info.Length() < 2)) {
91 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
92 exceptionState.throwIfNeeded();
93 return;
94 }
95 exceptionState.throwTypeError("No matching constructor signature.");
96 exceptionState.throwIfNeeded();
97 }
98
55 } // namespace WebCore 99 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698