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 "JSHTMLFormControlsCollection.h" |
23 | |
24 | #include "Element.h" |
25 | #include "JSDOMAbstractOperations.h" |
26 | #include "JSDOMBinding.h" |
27 | #include "JSDOMConstructorNotConstructable.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSDOMConvertNullable.h" |
30 | #include "JSDOMConvertStrings.h" |
31 | #include "JSDOMConvertUnion.h" |
32 | #include "JSDOMExceptionHandling.h" |
33 | #include "JSDOMGlobalObject.h" |
34 | #include "JSDOMOperation.h" |
35 | #include "JSDOMWrapperCache.h" |
36 | #include "JSElement.h" |
37 | #include "JSHTMLElement.h" |
38 | #include "JSNode.h" |
39 | #include "JSNodeCustom.h" |
40 | #include "JSRadioNodeList.h" |
41 | #include "Node.h" |
42 | #include "ScriptExecutionContext.h" |
43 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
44 | #include <JavaScriptCore/JSCInlines.h> |
45 | #include <JavaScriptCore/PropertyNameArray.h> |
46 | #include <wtf/GetPtr.h> |
47 | #include <wtf/PointerPreparations.h> |
48 | #include <wtf/URL.h> |
49 | #include <wtf/Variant.h> |
50 | |
51 | |
52 | namespace WebCore { |
53 | using namespace JSC; |
54 | |
55 | // Functions |
56 | |
57 | JSC::EncodedJSValue JSC_HOST_CALL jsHTMLFormControlsCollectionPrototypeFunctionNamedItem(JSC::ExecState*); |
58 | |
59 | // Attributes |
60 | |
61 | JSC::EncodedJSValue jsHTMLFormControlsCollectionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
62 | bool setJSHTMLFormControlsCollectionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
63 | |
64 | class JSHTMLFormControlsCollectionPrototype : public JSC::JSNonFinalObject { |
65 | public: |
66 | using Base = JSC::JSNonFinalObject; |
67 | static JSHTMLFormControlsCollectionPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
68 | { |
69 | JSHTMLFormControlsCollectionPrototype* ptr = new (NotNull, JSC::allocateCell<JSHTMLFormControlsCollectionPrototype>(vm.heap)) JSHTMLFormControlsCollectionPrototype(vm, globalObject, structure); |
70 | ptr->finishCreation(vm); |
71 | return ptr; |
72 | } |
73 | |
74 | DECLARE_INFO; |
75 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
76 | { |
77 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
78 | } |
79 | |
80 | private: |
81 | JSHTMLFormControlsCollectionPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
82 | : JSC::JSNonFinalObject(vm, structure) |
83 | { |
84 | } |
85 | |
86 | void finishCreation(JSC::VM&); |
87 | }; |
88 | |
89 | using JSHTMLFormControlsCollectionConstructor = JSDOMConstructorNotConstructable<JSHTMLFormControlsCollection>; |
90 | |
91 | template<> JSValue JSHTMLFormControlsCollectionConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
92 | { |
93 | return JSHTMLCollection::getConstructor(vm, &globalObject); |
94 | } |
95 | |
96 | template<> void JSHTMLFormControlsCollectionConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
97 | { |
98 | putDirect(vm, vm.propertyNames->prototype, JSHTMLFormControlsCollection::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
99 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("HTMLFormControlsCollection"_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 JSHTMLFormControlsCollectionConstructor::s_info = { "HTMLFormControlsCollection" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLFormControlsCollectionConstructor) }; |
104 | |
105 | /* Hash table for prototype */ |
106 | |
107 | static const HashTableValue JSHTMLFormControlsCollectionPrototypeTableValues[] = |
108 | { |
109 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormControlsCollectionConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSHTMLFormControlsCollectionConstructor) } }, |
110 | { "namedItem" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsHTMLFormControlsCollectionPrototypeFunctionNamedItem), (intptr_t) (1) } }, |
111 | }; |
112 | |
113 | const ClassInfo JSHTMLFormControlsCollectionPrototype::s_info = { "HTMLFormControlsCollectionPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLFormControlsCollectionPrototype) }; |
114 | |
115 | void JSHTMLFormControlsCollectionPrototype::finishCreation(VM& vm) |
116 | { |
117 | Base::finishCreation(vm); |
118 | reifyStaticProperties(vm, JSHTMLFormControlsCollection::info(), JSHTMLFormControlsCollectionPrototypeTableValues, *this); |
119 | } |
120 | |
121 | const ClassInfo JSHTMLFormControlsCollection::s_info = { "HTMLFormControlsCollection" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLFormControlsCollection) }; |
122 | |
123 | JSHTMLFormControlsCollection::JSHTMLFormControlsCollection(Structure* structure, JSDOMGlobalObject& globalObject, Ref<HTMLFormControlsCollection>&& impl) |
124 | : JSHTMLCollection(structure, globalObject, WTFMove(impl)) |
125 | { |
126 | } |
127 | |
128 | void JSHTMLFormControlsCollection::finishCreation(VM& vm) |
129 | { |
130 | Base::finishCreation(vm); |
131 | ASSERT(inherits(vm, info())); |
132 | |
133 | } |
134 | |
135 | JSObject* JSHTMLFormControlsCollection::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
136 | { |
137 | return JSHTMLFormControlsCollectionPrototype::create(vm, &globalObject, JSHTMLFormControlsCollectionPrototype::createStructure(vm, &globalObject, JSHTMLCollection::prototype(vm, globalObject))); |
138 | } |
139 | |
140 | JSObject* JSHTMLFormControlsCollection::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
141 | { |
142 | return getDOMPrototype<JSHTMLFormControlsCollection>(vm, globalObject); |
143 | } |
144 | |
145 | JSValue JSHTMLFormControlsCollection::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
146 | { |
147 | return getDOMConstructor<JSHTMLFormControlsCollectionConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
148 | } |
149 | |
150 | bool JSHTMLFormControlsCollection::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot) |
151 | { |
152 | auto* thisObject = jsCast<JSHTMLFormControlsCollection*>(object); |
153 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
154 | if (auto index = parseIndex(propertyName)) { |
155 | if (index.value() < thisObject->wrapped().length()) { |
156 | auto value = toJS<IDLNullable<IDLInterface<HTMLElement>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index.value())); |
157 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
158 | return true; |
159 | } |
160 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
161 | } |
162 | using GetterIDLType = IDLUnion<IDLInterface<RadioNodeList>, IDLInterface<Element>>; |
163 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
164 | auto result = thisObject.wrapped().namedItemOrItems(propertyNameToAtomicString(propertyName)); |
165 | if (!GetterIDLType::isNullValue(result)) |
166 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
167 | return WTF::nullopt; |
168 | }; |
169 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
170 | auto value = toJS<IDLNullable<IDLUnion<IDLInterface<RadioNodeList>, IDLInterface<Element>>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
171 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
172 | return true; |
173 | } |
174 | return JSObject::getOwnPropertySlot(object, state, propertyName, slot); |
175 | } |
176 | |
177 | bool JSHTMLFormControlsCollection::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot) |
178 | { |
179 | auto* thisObject = jsCast<JSHTMLFormControlsCollection*>(object); |
180 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
181 | if (LIKELY(index <= MAX_ARRAY_INDEX)) { |
182 | if (index < thisObject->wrapped().length()) { |
183 | auto value = toJS<IDLNullable<IDLInterface<HTMLElement>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index)); |
184 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
185 | return true; |
186 | } |
187 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
188 | } |
189 | auto propertyName = Identifier::from(state, index); |
190 | using GetterIDLType = IDLUnion<IDLInterface<RadioNodeList>, IDLInterface<Element>>; |
191 | auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> { |
192 | auto result = thisObject.wrapped().namedItemOrItems(propertyNameToAtomicString(propertyName)); |
193 | if (!GetterIDLType::isNullValue(result)) |
194 | return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) }; |
195 | return WTF::nullopt; |
196 | }; |
197 | if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) { |
198 | auto value = toJS<IDLNullable<IDLUnion<IDLInterface<RadioNodeList>, IDLInterface<Element>>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value())); |
199 | slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value); |
200 | return true; |
201 | } |
202 | return JSObject::getOwnPropertySlotByIndex(object, state, index, slot); |
203 | } |
204 | |
205 | void JSHTMLFormControlsCollection::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode) |
206 | { |
207 | auto* thisObject = jsCast<JSHTMLFormControlsCollection*>(object); |
208 | ASSERT_GC_OBJECT_INHERITS(object, info()); |
209 | for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i) |
210 | propertyNames.add(Identifier::from(state, i)); |
211 | for (auto& propertyName : thisObject->wrapped().supportedPropertyNames()) |
212 | propertyNames.add(Identifier::fromString(state, propertyName)); |
213 | JSObject::getOwnPropertyNames(object, state, propertyNames, mode); |
214 | } |
215 | |
216 | template<> inline JSHTMLFormControlsCollection* IDLOperation<JSHTMLFormControlsCollection>::cast(ExecState& state) |
217 | { |
218 | return jsDynamicCast<JSHTMLFormControlsCollection*>(state.vm(), state.thisValue()); |
219 | } |
220 | |
221 | EncodedJSValue jsHTMLFormControlsCollectionConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
222 | { |
223 | VM& vm = state->vm(); |
224 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
225 | auto* prototype = jsDynamicCast<JSHTMLFormControlsCollectionPrototype*>(vm, JSValue::decode(thisValue)); |
226 | if (UNLIKELY(!prototype)) |
227 | return throwVMTypeError(state, throwScope); |
228 | return JSValue::encode(JSHTMLFormControlsCollection::getConstructor(state->vm(), prototype->globalObject())); |
229 | } |
230 | |
231 | bool setJSHTMLFormControlsCollectionConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
232 | { |
233 | VM& vm = state->vm(); |
234 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
235 | auto* prototype = jsDynamicCast<JSHTMLFormControlsCollectionPrototype*>(vm, JSValue::decode(thisValue)); |
236 | if (UNLIKELY(!prototype)) { |
237 | throwVMTypeError(state, throwScope); |
238 | return false; |
239 | } |
240 | // Shadowing a built-in constructor |
241 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
242 | } |
243 | |
244 | static inline JSC::EncodedJSValue jsHTMLFormControlsCollectionPrototypeFunctionNamedItemBody(JSC::ExecState* state, typename IDLOperation<JSHTMLFormControlsCollection>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
245 | { |
246 | UNUSED_PARAM(state); |
247 | UNUSED_PARAM(throwScope); |
248 | auto& impl = castedThis->wrapped(); |
249 | if (UNLIKELY(state->argumentCount() < 1)) |
250 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
251 | auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
252 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
253 | return JSValue::encode(toJS<IDLNullable<IDLUnion<IDLInterface<RadioNodeList>, IDLInterface<Element>>>>(*state, *castedThis->globalObject(), impl.namedItemOrItems(WTFMove(name)))); |
254 | } |
255 | |
256 | EncodedJSValue JSC_HOST_CALL jsHTMLFormControlsCollectionPrototypeFunctionNamedItem(ExecState* state) |
257 | { |
258 | return IDLOperation<JSHTMLFormControlsCollection>::call<jsHTMLFormControlsCollectionPrototypeFunctionNamedItemBody>(*state, "namedItem" ); |
259 | } |
260 | |
261 | void JSHTMLFormControlsCollection::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
262 | { |
263 | auto* thisObject = jsCast<JSHTMLFormControlsCollection*>(cell); |
264 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
265 | if (thisObject->scriptExecutionContext()) |
266 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
267 | Base::heapSnapshot(cell, builder); |
268 | } |
269 | |
270 | bool JSHTMLFormControlsCollectionOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
271 | { |
272 | auto* jsHTMLFormControlsCollection = jsCast<JSHTMLFormControlsCollection*>(handle.slot()->asCell()); |
273 | void* root = WebCore::root(jsHTMLFormControlsCollection->wrapped().ownerNode()); |
274 | if (UNLIKELY(reason)) |
275 | *reason = "Reachable from HTMLFormControlsCollection ownerNode" ; |
276 | return visitor.containsOpaqueRoot(root); |
277 | } |
278 | |
279 | void JSHTMLFormControlsCollectionOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
280 | { |
281 | auto* jsHTMLFormControlsCollection = static_cast<JSHTMLFormControlsCollection*>(handle.slot()->asCell()); |
282 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
283 | uncacheWrapper(world, &jsHTMLFormControlsCollection->wrapped(), jsHTMLFormControlsCollection); |
284 | } |
285 | |
286 | |
287 | } |
288 | |