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 "JSDOMMimeTypeArray.h" |
23 | |
24 | #include "JSDOMAbstractOperations.h" |
25 | #include "JSDOMAttribute.h" |
26 | #include "JSDOMBinding.h" |
27 | #include "JSDOMConstructorNotConstructable.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSDOMConvertNullable.h" |
30 | #include "JSDOMConvertNumbers.h" |
31 | #include "JSDOMConvertStrings.h" |
32 | #include "JSDOMExceptionHandling.h" |
33 | #include "JSDOMGlobalObject.h" |
34 | #include "JSDOMMimeType.h" |
35 | #include "JSDOMOperation.h" |
36 | #include "JSDOMWrapperCache.h" |
37 | #include "ScriptExecutionContext.h" |
38 | #include <JavaScriptCore/ArrayPrototype.h> |
39 | #include <JavaScriptCore/BuiltinNames.h> |
40 | #include <JavaScriptCore/FunctionPrototype.h> |
41 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
42 | #include <JavaScriptCore/JSCInlines.h> |
43 | #include <JavaScriptCore/PropertyNameArray.h> |
44 | #include <wtf/GetPtr.h> |
45 | #include <wtf/PointerPreparations.h> |
46 | #include <wtf/URL.h> |
47 | |
48 | |
49 | namespace WebCore { |
50 | using namespace JSC; |
51 | |
52 | // Functions |
53 | |
54 | JSC::EncodedJSValue JSC_HOST_CALL jsDOMMimeTypeArrayPrototypeFunctionItem(JSC::ExecState*); |
55 | JSC::EncodedJSValue JSC_HOST_CALL jsDOMMimeTypeArrayPrototypeFunctionNamedItem(JSC::ExecState*); |
56 | |
57 | // Attributes |
58 | |
59 | JSC::EncodedJSValue jsDOMMimeTypeArrayConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
60 | bool setJSDOMMimeTypeArrayConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
61 | JSC::EncodedJSValue jsDOMMimeTypeArrayLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
62 | |
63 | class JSDOMMimeTypeArrayPrototype : public JSC::JSNonFinalObject { |
64 | public: |
65 | using Base = JSC::JSNonFinalObject; |
66 | static JSDOMMimeTypeArrayPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
67 | { |
68 | JSDOMMimeTypeArrayPrototype* ptr = new (NotNull, JSC::allocateCell<JSDOMMimeTypeArrayPrototype>(vm.heap)) JSDOMMimeTypeArrayPrototype(vm, globalObject, structure); |
69 | ptr->finishCreation(vm); |
70 | return ptr; |
71 | } |
72 | |
73 | DECLARE_INFO; |
74 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
75 | { |
76 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
77 | } |
78 | |
79 | private: |
80 | JSDOMMimeTypeArrayPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
81 | : JSC::JSNonFinalObject(vm, structure) |
82 | { |
83 | } |
84 | |
85 | void finishCreation(JSC::VM&); |
86 | }; |
87 | |
88 | using JSDOMMimeTypeArrayConstructor = JSDOMConstructorNotConstructable<JSDOMMimeTypeArray>; |
89 | |
90 | template<> JSValue JSDOMMimeTypeArrayConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
91 | { |
92 | UNUSED_PARAM(vm); |
93 | return globalObject.functionPrototype(); |
94 | } |
95 | |
96 | template<> void JSDOMMimeTypeArrayConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
97 | { |
98 | putDirect(vm, vm.propertyNames->prototype, JSDOMMimeTypeArray::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
99 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("MimeTypeArray"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
100 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
101 | } |
102 | |
103 | template<> const ClassInfo JSDOMMimeTypeArrayConstructor::s_info = { "MimeTypeArray" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMMimeTypeArrayConstructor) }; |
104 | |
105 | /* Hash table for prototype */ |
106 | |
107 | static const HashTableValue JSDOMMimeTypeArrayPrototypeTableValues[] = |
108 | { |
109 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMMimeTypeArrayConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMMimeTypeArrayConstructor) } }, |
110 | { "length" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMMimeTypeArrayLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
111 | { "item" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMMimeTypeArrayPrototypeFunctionItem), (intptr_t) (1) } }, |
112 | { "namedItem" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMMimeTypeArrayPrototypeFunctionNamedItem), (intptr_t) (1) } }, |
113 | }; |
114 | |
115 | const ClassInfo JSDOMMimeTypeArrayPrototype::s_info = { "MimeTypeArrayPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMMimeTypeArrayPrototype) }; |
116 | |
117 | void JSDOMMimeTypeArrayPrototype::finishCreation(VM& vm) |
118 | { |
119 | Base::finishCreation(vm); |
120 | reifyStaticProperties(vm, JSDOMMimeTypeArray::info(), JSDOMMimeTypeArrayPrototypeTableValues, *this); |
121 | putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum)); |
122 | } |
123 | |
124 | const ClassInfo JSDOMMimeTypeArray::s_info = { "MimeTypeArray" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMMimeTypeArray) }; |
125 | |
126 | JSDOMMimeTypeArray::JSDOMMimeTypeArray(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DOMMimeTypeArray>&& impl) |
127 | : JSDOMWrapper<DOMMimeTypeArray>(structure, globalObject, WTFMove(impl)) |
128 | { |
129 | } |
130 | |
131 | void JSDOMMimeTypeArray::finishCreation(VM& vm) |
132 | { |
133 | Base::finishCreation(vm); |
134 | ASSERT(inherits(vm, info())); |
135 | |
136 | } |
137 | |
138 | JSObject* JSDOMMimeTypeArray::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
139 | { |
140 | return JSDOMMimeTypeArrayPrototype::create(vm, &globalObject, JSDOMMimeTypeArrayPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
141 | } |
142 | |
143 | JSObject* JSDOMMimeTypeArray::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
144 | { |
145 | return getDOMPrototype<JSDOMMimeTypeArray>(vm, globalObject); |
146 | } |
147 | |
148 | JSValue JSDOMMimeTypeArray::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
149 | { |
150 | return getDOMConstructor<JSDOMMimeTypeArrayConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
151 | } |
152 | |
153 | void JSDOMMimeTypeArray::destroy(JSC::JSCell* cell) |
154 | { |
155 | JSDOMMimeTypeArray* thisObject = static_cast<JSDOMMimeTypeArray*>(cell); |
156 | thisObject->JSDOMMimeTypeArray::~JSDOMMimeTypeArray(); |
157 | } |
158 | |
159 | bool JSDOMMimeTypeArray::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot) |
160 | { |
161 | auto* thisObject = jsCast<JSDOMMimeTypeArray*>(object); |
162 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
163 | if (auto index = parseIndex(propertyName)) { |
164 | if (index.value() < thisObject->wrapped().length()) { |
165 | auto value = toJS<IDLNullable<IDLInterface<DOMMimeType>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index.value())); |
166 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
167 | return true; |
168 | } |
169 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
170 | } |
171 | using GetterIDLType = IDLInterface<DOMMimeType>; |
172 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
173 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomString(propertyName)); |
174 | if (!GetterIDLType::isNullValue(result)) |
175 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
176 | return WTF::nullopt; |
177 | }; |
178 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
179 | auto value = toJS<IDLNullable<IDLInterface<DOMMimeType>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
180 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), value); |
181 | return true; |
182 | } |
183 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
184 | } |
185 | |
186 | bool JSDOMMimeTypeArray::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot) |
187 | { |
188 | auto* thisObject = jsCast<JSDOMMimeTypeArray*>(object); |
189 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
190 | if (LIKELY(index <= MAX_ARRAY_INDEX)) { |
191 | if (index < thisObject->wrapped().length()) { |
192 | auto value = toJS<IDLNullable<IDLInterface<DOMMimeType>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index)); |
193 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
194 | return true; |
195 | } |
196 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
197 | } |
198 | auto propertyName = Identifier::from(state, index); |
199 | using GetterIDLType = IDLInterface<DOMMimeType>; |
200 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
201 | auto result = thisObject.wrapped().namedItem(propertyNameToAtomString(propertyName)); |
202 | if (!GetterIDLType::isNullValue(result)) |
203 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
204 | return WTF::nullopt; |
205 | }; |
206 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
207 | auto value = toJS<IDLNullable<IDLInterface<DOMMimeType>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
208 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), value); |
209 | return true; |
210 | } |
211 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
212 | } |
213 | |
214 | void JSDOMMimeTypeArray::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode) |
215 | { |
216 | auto* thisObject = jsCast<JSDOMMimeTypeArray*>(object); |
217 | ASSERT_GC_OBJECT_INHERITS(object, info()); |
218 | for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i) |
219 | propertyNames.add(Identifier::from(state, i)); |
220 | if (mode.includeDontEnumProperties()) { |
221 | for (auto& propertyName : thisObject->wrapped().supportedPropertyNames()) |
222 | propertyNames.add(Identifier::fromString(state, propertyName)); |
223 | } |
224 | JSObject::getOwnPropertyNames(object, state, propertyNames, mode); |
225 | } |
226 | |
227 | template<> inline JSDOMMimeTypeArray* IDLAttribute<JSDOMMimeTypeArray>::cast(ExecState& state, EncodedJSValue thisValue) |
228 | { |
229 | return jsDynamicCast<JSDOMMimeTypeArray*>(state.vm(), JSValue::decode(thisValue)); |
230 | } |
231 | |
232 | template<> inline JSDOMMimeTypeArray* IDLOperation<JSDOMMimeTypeArray>::cast(ExecState& state) |
233 | { |
234 | return jsDynamicCast<JSDOMMimeTypeArray*>(state.vm(), state.thisValue()); |
235 | } |
236 | |
237 | EncodedJSValue jsDOMMimeTypeArrayConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
238 | { |
239 | VM& vm = state->vm(); |
240 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
241 | auto* prototype = jsDynamicCast<JSDOMMimeTypeArrayPrototype*>(vm, JSValue::decode(thisValue)); |
242 | if (UNLIKELY(!prototype)) |
243 | return throwVMTypeError(state, throwScope); |
244 | return JSValue::encode(JSDOMMimeTypeArray::getConstructor(state->vm(), prototype->globalObject())); |
245 | } |
246 | |
247 | bool setJSDOMMimeTypeArrayConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
248 | { |
249 | VM& vm = state->vm(); |
250 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
251 | auto* prototype = jsDynamicCast<JSDOMMimeTypeArrayPrototype*>(vm, JSValue::decode(thisValue)); |
252 | if (UNLIKELY(!prototype)) { |
253 | throwVMTypeError(state, throwScope); |
254 | return false; |
255 | } |
256 | // Shadowing a built-in constructor |
257 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
258 | } |
259 | |
260 | static inline JSValue jsDOMMimeTypeArrayLengthGetter(ExecState& state, JSDOMMimeTypeArray& thisObject, ThrowScope& throwScope) |
261 | { |
262 | UNUSED_PARAM(throwScope); |
263 | UNUSED_PARAM(state); |
264 | auto& impl = thisObject.wrapped(); |
265 | JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length()); |
266 | return result; |
267 | } |
268 | |
269 | EncodedJSValue jsDOMMimeTypeArrayLength(ExecState* state, EncodedJSValue thisValue, PropertyName) |
270 | { |
271 | return IDLAttribute<JSDOMMimeTypeArray>::get<jsDOMMimeTypeArrayLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length" ); |
272 | } |
273 | |
274 | static inline JSC::EncodedJSValue jsDOMMimeTypeArrayPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSDOMMimeTypeArray>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
275 | { |
276 | UNUSED_PARAM(state); |
277 | UNUSED_PARAM(throwScope); |
278 | auto& impl = castedThis->wrapped(); |
279 | if (UNLIKELY(state->argumentCount() < 1)) |
280 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
281 | auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0)); |
282 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
283 | return JSValue::encode(toJS<IDLNullable<IDLInterface<DOMMimeType>>>(*state, *castedThis->globalObject(), impl.item(WTFMove(index)))); |
284 | } |
285 | |
286 | EncodedJSValue JSC_HOST_CALL jsDOMMimeTypeArrayPrototypeFunctionItem(ExecState* state) |
287 | { |
288 | return IDLOperation<JSDOMMimeTypeArray>::call<jsDOMMimeTypeArrayPrototypeFunctionItemBody>(*state, "item" ); |
289 | } |
290 | |
291 | static inline JSC::EncodedJSValue jsDOMMimeTypeArrayPrototypeFunctionNamedItemBody(JSC::ExecState* state, typename IDLOperation<JSDOMMimeTypeArray>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
292 | { |
293 | UNUSED_PARAM(state); |
294 | UNUSED_PARAM(throwScope); |
295 | auto& impl = castedThis->wrapped(); |
296 | if (UNLIKELY(state->argumentCount() < 1)) |
297 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
298 | auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
299 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
300 | return JSValue::encode(toJS<IDLNullable<IDLInterface<DOMMimeType>>>(*state, *castedThis->globalObject(), impl.namedItem(WTFMove(name)))); |
301 | } |
302 | |
303 | EncodedJSValue JSC_HOST_CALL jsDOMMimeTypeArrayPrototypeFunctionNamedItem(ExecState* state) |
304 | { |
305 | return IDLOperation<JSDOMMimeTypeArray>::call<jsDOMMimeTypeArrayPrototypeFunctionNamedItemBody>(*state, "namedItem" ); |
306 | } |
307 | |
308 | void JSDOMMimeTypeArray::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
309 | { |
310 | auto* thisObject = jsCast<JSDOMMimeTypeArray*>(cell); |
311 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
312 | if (thisObject->scriptExecutionContext()) |
313 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
314 | Base::heapSnapshot(cell, builder); |
315 | } |
316 | |
317 | bool JSDOMMimeTypeArrayOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
318 | { |
319 | auto* jsDOMMimeTypeArray = jsCast<JSDOMMimeTypeArray*>(handle.slot()->asCell()); |
320 | Frame* root = WTF::getPtr(jsDOMMimeTypeArray->wrapped().frame()); |
321 | if (!root) |
322 | return false; |
323 | if (UNLIKELY(reason)) |
324 | *reason = "Reachable from Frame" ; |
325 | return visitor.containsOpaqueRoot(root); |
326 | } |
327 | |
328 | void JSDOMMimeTypeArrayOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
329 | { |
330 | auto* jsDOMMimeTypeArray = static_cast<JSDOMMimeTypeArray*>(handle.slot()->asCell()); |
331 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
332 | uncacheWrapper(world, &jsDOMMimeTypeArray->wrapped(), jsDOMMimeTypeArray); |
333 | } |
334 | |
335 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<DOMMimeTypeArray>&& impl) |
336 | { |
337 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
338 | // attribute. You should remove that attribute. If the class has subclasses |
339 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
340 | // attribute to DOMMimeTypeArray. |
341 | static_assert(!std::is_polymorphic<DOMMimeTypeArray>::value, "DOMMimeTypeArray is polymorphic but the IDL claims it is not" ); |
342 | return createWrapper<DOMMimeTypeArray>(globalObject, WTFMove(impl)); |
343 | } |
344 | |
345 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, DOMMimeTypeArray& impl) |
346 | { |
347 | return wrap(state, globalObject, impl); |
348 | } |
349 | |
350 | DOMMimeTypeArray* JSDOMMimeTypeArray::toWrapped(JSC::VM& vm, JSC::JSValue value) |
351 | { |
352 | if (auto* wrapper = jsDynamicCast<JSDOMMimeTypeArray*>(vm, value)) |
353 | return &wrapper->wrapped(); |
354 | return nullptr; |
355 | } |
356 | |
357 | } |
358 | |