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