1 | /* |
2 | This file is part of the WebKit open source project. |
3 | This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #include "config.h" |
22 | #include "JSImageData.h" |
23 | |
24 | #include "JSDOMAttribute.h" |
25 | #include "JSDOMBinding.h" |
26 | #include "JSDOMConstructor.h" |
27 | #include "JSDOMConvertBufferSource.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSDOMConvertNumbers.h" |
30 | #include "JSDOMExceptionHandling.h" |
31 | #include "JSDOMGlobalObject.h" |
32 | #include "JSDOMWrapperCache.h" |
33 | #include "ScriptExecutionContext.h" |
34 | #include <JavaScriptCore/FunctionPrototype.h> |
35 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
36 | #include <JavaScriptCore/JSCInlines.h> |
37 | #include <wtf/GetPtr.h> |
38 | #include <wtf/PointerPreparations.h> |
39 | #include <wtf/URL.h> |
40 | |
41 | |
42 | namespace WebCore { |
43 | using namespace JSC; |
44 | |
45 | // Attributes |
46 | |
47 | JSC::EncodedJSValue jsImageDataConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
48 | bool setJSImageDataConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
49 | JSC::EncodedJSValue jsImageDataWidth(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
50 | JSC::EncodedJSValue jsImageDataHeight(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
51 | JSC::EncodedJSValue jsImageDataData(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
52 | |
53 | class JSImageDataPrototype : public JSC::JSNonFinalObject { |
54 | public: |
55 | using Base = JSC::JSNonFinalObject; |
56 | static JSImageDataPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
57 | { |
58 | JSImageDataPrototype* ptr = new (NotNull, JSC::allocateCell<JSImageDataPrototype>(vm.heap)) JSImageDataPrototype(vm, globalObject, structure); |
59 | ptr->finishCreation(vm); |
60 | return ptr; |
61 | } |
62 | |
63 | DECLARE_INFO; |
64 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
65 | { |
66 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
67 | } |
68 | |
69 | private: |
70 | JSImageDataPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
71 | : JSC::JSNonFinalObject(vm, structure) |
72 | { |
73 | } |
74 | |
75 | void finishCreation(JSC::VM&); |
76 | }; |
77 | |
78 | using JSImageDataConstructor = JSDOMConstructor<JSImageData>; |
79 | |
80 | static inline EncodedJSValue constructJSImageData1(ExecState* state) |
81 | { |
82 | VM& vm = state->vm(); |
83 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
84 | UNUSED_PARAM(throwScope); |
85 | auto* castedThis = jsCast<JSImageDataConstructor*>(state->jsCallee()); |
86 | ASSERT(castedThis); |
87 | auto sw = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
88 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
89 | auto sh = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(1)); |
90 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
91 | auto object = ImageData::create(WTFMove(sw), WTFMove(sh)); |
92 | return JSValue::encode(toJSNewlyCreated<IDLInterface<ImageData>>(*state, *castedThis->globalObject(), throwScope, WTFMove(object))); |
93 | } |
94 | |
95 | static inline EncodedJSValue constructJSImageData2(ExecState* state) |
96 | { |
97 | VM& vm = state->vm(); |
98 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
99 | UNUSED_PARAM(throwScope); |
100 | auto* castedThis = jsCast<JSImageDataConstructor*>(state->jsCallee()); |
101 | ASSERT(castedThis); |
102 | auto data = convert<IDLUint8ClampedArray>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "data" , "ImageData" , nullptr, "Uint8ClampedArray" ); }); |
103 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
104 | auto sw = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(1)); |
105 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
106 | auto sh = state->argument(2).isUndefined() ? Optional<Converter<IDLUnsignedLong>::ReturnType>() : Optional<Converter<IDLUnsignedLong>::ReturnType>(convert<IDLUnsignedLong>(*state, state->uncheckedArgument(2))); |
107 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
108 | auto object = ImageData::create(data.releaseNonNull(), WTFMove(sw), WTFMove(sh)); |
109 | return JSValue::encode(toJSNewlyCreated<IDLInterface<ImageData>>(*state, *castedThis->globalObject(), throwScope, WTFMove(object))); |
110 | } |
111 | |
112 | template<> EncodedJSValue JSC_HOST_CALL JSImageDataConstructor::construct(ExecState* state) |
113 | { |
114 | VM& vm = state->vm(); |
115 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
116 | UNUSED_PARAM(throwScope); |
117 | size_t argsCount = std::min<size_t>(3, state->argumentCount()); |
118 | if (argsCount == 2) { |
119 | JSValue distinguishingArg = state->uncheckedArgument(0); |
120 | if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSUint8ClampedArray>(vm)) |
121 | return constructJSImageData2(state); |
122 | if (distinguishingArg.isNumber()) |
123 | return constructJSImageData1(state); |
124 | return constructJSImageData1(state); |
125 | } |
126 | if (argsCount == 3) { |
127 | return constructJSImageData2(state); |
128 | } |
129 | return argsCount < 2 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
130 | } |
131 | |
132 | template<> JSValue JSImageDataConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
133 | { |
134 | UNUSED_PARAM(vm); |
135 | return globalObject.functionPrototype(); |
136 | } |
137 | |
138 | template<> void JSImageDataConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
139 | { |
140 | putDirect(vm, vm.propertyNames->prototype, JSImageData::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
141 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("ImageData"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
142 | putDirect(vm, vm.propertyNames->length, jsNumber(2), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
143 | } |
144 | |
145 | template<> const ClassInfo JSImageDataConstructor::s_info = { "ImageData" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSImageDataConstructor) }; |
146 | |
147 | /* Hash table for prototype */ |
148 | |
149 | static const HashTableValue JSImageDataPrototypeTableValues[] = |
150 | { |
151 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsImageDataConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSImageDataConstructor) } }, |
152 | { "width" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsImageDataWidth), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
153 | { "height" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsImageDataHeight), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
154 | { "data" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsImageDataData), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
155 | }; |
156 | |
157 | const ClassInfo JSImageDataPrototype::s_info = { "ImageDataPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSImageDataPrototype) }; |
158 | |
159 | void JSImageDataPrototype::finishCreation(VM& vm) |
160 | { |
161 | Base::finishCreation(vm); |
162 | reifyStaticProperties(vm, JSImageData::info(), JSImageDataPrototypeTableValues, *this); |
163 | } |
164 | |
165 | const ClassInfo JSImageData::s_info = { "ImageData" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSImageData) }; |
166 | |
167 | JSImageData::JSImageData(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ImageData>&& impl) |
168 | : JSDOMWrapper<ImageData>(structure, globalObject, WTFMove(impl)) |
169 | { |
170 | } |
171 | |
172 | void JSImageData::finishCreation(VM& vm) |
173 | { |
174 | Base::finishCreation(vm); |
175 | ASSERT(inherits(vm, info())); |
176 | |
177 | } |
178 | |
179 | JSObject* JSImageData::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
180 | { |
181 | return JSImageDataPrototype::create(vm, &globalObject, JSImageDataPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
182 | } |
183 | |
184 | JSObject* JSImageData::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
185 | { |
186 | return getDOMPrototype<JSImageData>(vm, globalObject); |
187 | } |
188 | |
189 | JSValue JSImageData::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
190 | { |
191 | return getDOMConstructor<JSImageDataConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
192 | } |
193 | |
194 | void JSImageData::destroy(JSC::JSCell* cell) |
195 | { |
196 | JSImageData* thisObject = static_cast<JSImageData*>(cell); |
197 | thisObject->JSImageData::~JSImageData(); |
198 | } |
199 | |
200 | template<> inline JSImageData* IDLAttribute<JSImageData>::cast(ExecState& state, EncodedJSValue thisValue) |
201 | { |
202 | return jsDynamicCast<JSImageData*>(state.vm(), JSValue::decode(thisValue)); |
203 | } |
204 | |
205 | EncodedJSValue jsImageDataConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
206 | { |
207 | VM& vm = state->vm(); |
208 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
209 | auto* prototype = jsDynamicCast<JSImageDataPrototype*>(vm, JSValue::decode(thisValue)); |
210 | if (UNLIKELY(!prototype)) |
211 | return throwVMTypeError(state, throwScope); |
212 | return JSValue::encode(JSImageData::getConstructor(state->vm(), prototype->globalObject())); |
213 | } |
214 | |
215 | bool setJSImageDataConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
216 | { |
217 | VM& vm = state->vm(); |
218 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
219 | auto* prototype = jsDynamicCast<JSImageDataPrototype*>(vm, JSValue::decode(thisValue)); |
220 | if (UNLIKELY(!prototype)) { |
221 | throwVMTypeError(state, throwScope); |
222 | return false; |
223 | } |
224 | // Shadowing a built-in constructor |
225 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
226 | } |
227 | |
228 | static inline JSValue jsImageDataWidthGetter(ExecState& state, JSImageData& thisObject, ThrowScope& throwScope) |
229 | { |
230 | UNUSED_PARAM(throwScope); |
231 | UNUSED_PARAM(state); |
232 | auto& impl = thisObject.wrapped(); |
233 | JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.width()); |
234 | return result; |
235 | } |
236 | |
237 | EncodedJSValue jsImageDataWidth(ExecState* state, EncodedJSValue thisValue, PropertyName) |
238 | { |
239 | return IDLAttribute<JSImageData>::get<jsImageDataWidthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "width" ); |
240 | } |
241 | |
242 | static inline JSValue jsImageDataHeightGetter(ExecState& state, JSImageData& thisObject, ThrowScope& throwScope) |
243 | { |
244 | UNUSED_PARAM(throwScope); |
245 | UNUSED_PARAM(state); |
246 | auto& impl = thisObject.wrapped(); |
247 | JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.height()); |
248 | return result; |
249 | } |
250 | |
251 | EncodedJSValue jsImageDataHeight(ExecState* state, EncodedJSValue thisValue, PropertyName) |
252 | { |
253 | return IDLAttribute<JSImageData>::get<jsImageDataHeightGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "height" ); |
254 | } |
255 | |
256 | static inline JSValue jsImageDataDataGetter(ExecState& state, JSImageData& thisObject, ThrowScope& throwScope) |
257 | { |
258 | UNUSED_PARAM(throwScope); |
259 | UNUSED_PARAM(state); |
260 | auto& impl = thisObject.wrapped(); |
261 | JSValue result = toJS<IDLUint8ClampedArray>(state, *thisObject.globalObject(), throwScope, impl.data()); |
262 | return result; |
263 | } |
264 | |
265 | EncodedJSValue jsImageDataData(ExecState* state, EncodedJSValue thisValue, PropertyName) |
266 | { |
267 | return IDLAttribute<JSImageData>::get<jsImageDataDataGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "data" ); |
268 | } |
269 | |
270 | void JSImageData::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
271 | { |
272 | auto* thisObject = jsCast<JSImageData*>(cell); |
273 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
274 | if (thisObject->scriptExecutionContext()) |
275 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
276 | Base::heapSnapshot(cell, builder); |
277 | } |
278 | |
279 | bool JSImageDataOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
280 | { |
281 | UNUSED_PARAM(handle); |
282 | UNUSED_PARAM(visitor); |
283 | UNUSED_PARAM(reason); |
284 | return false; |
285 | } |
286 | |
287 | void JSImageDataOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
288 | { |
289 | auto* jsImageData = static_cast<JSImageData*>(handle.slot()->asCell()); |
290 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
291 | uncacheWrapper(world, &jsImageData->wrapped(), jsImageData); |
292 | } |
293 | |
294 | ImageData* JSImageData::toWrapped(JSC::VM& vm, JSC::JSValue value) |
295 | { |
296 | if (auto* wrapper = jsDynamicCast<JSImageData*>(vm, value)) |
297 | return &wrapper->wrapped(); |
298 | return nullptr; |
299 | } |
300 | |
301 | } |
302 | |